summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/unittest-cpp/tests/TestTestRunner.cpp
blob: 6f7c1bb571dfdbf9599ca905f257a280261461f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#include "UnitTest++/UnitTestPP.h"
#include "RecordingReporter.h"
#include "UnitTest++/ReportAssert.h"
#include "UnitTest++/TestList.h"
#include "UnitTest++/TimeHelpers.h"
#include "UnitTest++/TimeConstraint.h"
#include "UnitTest++/ReportAssertImpl.h"

using namespace UnitTest;

namespace
{
    
    struct MockTest : public Test
    {
        MockTest(char const* testName, bool const success_, bool const assert_, int const count_ = 1)
        : Test(testName)
        , success(success_)
        , asserted(assert_)
        , count(count_)
        {
        }
        
        virtual void RunImpl() const
        {
            TestResults& testResults_ = *CurrentTest::Results();

            for (int i=0; i < count; ++i)
            {
                if (asserted)
                {
                    ReportAssert("desc", "file", 0);
                }
                else if (!success)
                {
                    testResults_.OnTestFailure(m_details, "message");
                }
            }
        }
        
        bool const success;
        bool const asserted;
        int const count;
    };
    
    struct FixtureBase
    {
        FixtureBase()
        : runner(reporter)
        {
        }

        template <class Predicate>
        int RunTestsIf(TestList const& list, char const* suiteName,
                       const Predicate& predicate, int maxTestTimeInMs)
        {
            TestResults* oldResults = CurrentTest::Results();
            const TestDetails* oldDetails = CurrentTest::Details();
            int result = runner.RunTestsIf(list, suiteName, predicate, maxTestTimeInMs);
            CurrentTest::Results() = oldResults;
            CurrentTest::Details() = oldDetails;
            return result;
        }

        TestRunner runner;
        RecordingReporter reporter;
    };
    
    struct TestRunnerFixture : public FixtureBase
    {
        TestList list;
    };
    
    TEST_FIXTURE(TestRunnerFixture, TestStartIsReportedCorrectly)
    {
        MockTest test("goodtest", true, false);
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(1, reporter.testRunCount);
        CHECK_EQUAL("goodtest", reporter.lastStartedTest);
    }
    
    TEST_FIXTURE(TestRunnerFixture, TestFinishIsReportedCorrectly)
    {
        MockTest test("goodtest", true, false);
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(1, reporter.testFinishedCount);
        CHECK_EQUAL("goodtest", reporter.lastFinishedTest);
    }
    
    class SlowTest : public Test
    {
    public:
        SlowTest()
        : Test("slow", "somesuite", "filename", 123)
        {
        }
        
        virtual void RunImpl() const
        {
            TimeHelpers::SleepMs(20);
        }
    };
    
    TEST_FIXTURE(TestRunnerFixture, TestFinishIsCalledWithCorrectTime)
    {
        SlowTest test;
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK(reporter.lastFinishedTestTime >= 0.005f && reporter.lastFinishedTestTime <= 0.050f);
    }
    
    TEST_FIXTURE(TestRunnerFixture, FailureCountIsZeroWhenNoTestsAreRun)
    {
        CHECK_EQUAL(0, RunTestsIf(list, NULL, True(), 0));
        CHECK_EQUAL(0, reporter.testRunCount);
        CHECK_EQUAL(0, reporter.testFailedCount);
    }
    
    TEST_FIXTURE(TestRunnerFixture, CallsReportFailureOncePerFailingTest)
    {
        MockTest test1("test", false, false);
        list.Add(&test1);
        MockTest test2("test", true, false);
        list.Add(&test2);
        MockTest test3("test", false, false);
        list.Add(&test3);
        
        CHECK_EQUAL(2, RunTestsIf(list, NULL, True(), 0));
        CHECK_EQUAL(2, reporter.testFailedCount);
    }
    
    TEST_FIXTURE(TestRunnerFixture, TestsThatAssertAreReportedAsFailing)
    {
        MockTest test("test", true, true);
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(1, reporter.testFailedCount);
    }
    
    
    TEST_FIXTURE(TestRunnerFixture, ReporterNotifiedOfTestCount)
    {
        MockTest test1("test", true, false);
        MockTest test2("test", true, false);
        MockTest test3("test", true, false);
        list.Add(&test1);
        list.Add(&test2);
        list.Add(&test3);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(3, reporter.summaryTotalTestCount);
    }
    
    TEST_FIXTURE(TestRunnerFixture, ReporterNotifiedOfFailedTests)
    {
        MockTest test1("test", false, false, 2);
        MockTest test2("test", true, false);
        MockTest test3("test", false, false, 3);
        list.Add(&test1);
        list.Add(&test2);
        list.Add(&test3);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(2, reporter.summaryFailedTestCount);
    }
    
    TEST_FIXTURE(TestRunnerFixture, ReporterNotifiedOfFailures)
    {
        MockTest test1("test", false, false, 2);
        MockTest test2("test", true, false);
        MockTest test3("test", false, false, 3);
        list.Add(&test1);
        list.Add(&test2);
        list.Add(&test3);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(5, reporter.summaryFailureCount);
    }
    
    TEST_FIXTURE(TestRunnerFixture, SlowTestPassesForHighTimeThreshold)
    {
        SlowTest test;
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(0, reporter.testFailedCount);
    }
    
    TEST_FIXTURE(TestRunnerFixture, SlowTestFailsForLowTimeThreshold)
    {
        SlowTest test;
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 3);
        CHECK_EQUAL(1, reporter.testFailedCount);
    }
    
    TEST_FIXTURE(TestRunnerFixture, SlowTestHasCorrectFailureInformation)
    {
        SlowTest test;
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 3);
        
        using namespace std;
        
        CHECK_EQUAL(test.m_details.testName, reporter.lastFailedTest);
        CHECK(strstr(test.m_details.filename, reporter.lastFailedFile));
        CHECK_EQUAL(test.m_details.lineNumber, reporter.lastFailedLine);
        
        CHECK(strstr(reporter.lastFailedMessage, "Global time constraint failed"));
        CHECK(strstr(reporter.lastFailedMessage, "3ms"));
    }
    
    TEST_FIXTURE(TestRunnerFixture, SlowTestWithTimeExemptionPasses)
    {
        class SlowExemptedTest : public Test
        {
        public:
            SlowExemptedTest() : Test("slowexempted", "", 0) {}
            virtual void RunImpl() const
            {
                UNITTEST_TIME_CONSTRAINT_EXEMPT();
                TimeHelpers::SleepMs(20);
            }
        };
        
        SlowExemptedTest test;
        list.Add(&test);
        
        RunTestsIf(list, NULL, True(), 3);
        CHECK_EQUAL(0, reporter.testFailedCount);
    }
    
    struct TestSuiteFixture : FixtureBase
    {
        TestSuiteFixture()
        : test1("TestInDefaultSuite")
        , test2("TestInOtherSuite", "OtherSuite")
        , test3("SecondTestInDefaultSuite")
        {
            list.Add(&test1);
            list.Add(&test2);
        }
        
        Test test1;
        Test test2;
        Test test3;
        TestList list;
    };
    
    TEST_FIXTURE(TestSuiteFixture, TestRunnerRunsAllSuitesIfNullSuiteIsPassed)
    {
        RunTestsIf(list, NULL, True(), 0);
        CHECK_EQUAL(2, reporter.summaryTotalTestCount);
    }
    
    TEST_FIXTURE(TestSuiteFixture,TestRunnerRunsOnlySpecifiedSuite)
    {
        RunTestsIf(list, "OtherSuite", True(), 0);
        CHECK_EQUAL(1, reporter.summaryTotalTestCount);
        CHECK_EQUAL("TestInOtherSuite", reporter.lastFinishedTest);
    }
    
    struct RunTestIfNameIs
    {
        RunTestIfNameIs(char const* name_)
        : name(name_)
        {
        }
        
        bool operator()(const Test* const test) const
        {
            using namespace std;
            return (0 == strcmp(test->m_details.testName, name));
        }
        
        char const* name;
    };
    
    TEST(TestMockPredicateBehavesCorrectly)
    {
        RunTestIfNameIs predicate("pass");
        
        Test pass("pass");
        Test fail("fail");
        
        CHECK(predicate(&pass));
        CHECK(!predicate(&fail));   
    }
    
    TEST_FIXTURE(TestRunnerFixture, TestRunnerRunsTestsThatPassPredicate)
    {
        Test should_run("goodtest");
        list.Add(&should_run);
        
        Test should_not_run("badtest");
        list.Add(&should_not_run);
        
        RunTestsIf(list, NULL, RunTestIfNameIs("goodtest"), 0);
        CHECK_EQUAL(1, reporter.testRunCount);
        CHECK_EQUAL("goodtest", reporter.lastStartedTest);
    }
    
    TEST_FIXTURE(TestRunnerFixture, TestRunnerOnlyRunsTestsInSpecifiedSuiteAndThatPassPredicate)
    {
        Test runningTest1("goodtest", "suite");
        Test skippedTest2("goodtest");
        Test skippedTest3("badtest", "suite");
        Test skippedTest4("badtest");
        
        list.Add(&runningTest1);
        list.Add(&skippedTest2);
        list.Add(&skippedTest3);
        list.Add(&skippedTest4);
        
        RunTestsIf(list, "suite", RunTestIfNameIs("goodtest"), 0);
        
        CHECK_EQUAL(1, reporter.testRunCount);
        CHECK_EQUAL("goodtest", reporter.lastStartedTest);
        CHECK_EQUAL("suite", reporter.lastStartedSuite);
    }
    
}
class="n">WIDTH40_REG]) { if(!m_screen->visible_area().contains(res_x+1, res_y)) continue; if(pen != -1) bitmap.pix32(res_y, res_x+1) = palette[pen]; } } } } } } /************************************************* * * Flip Flop registers * ************************************************/ WRITE8_MEMBER(pc9801_state::pc9801_video_ff_w) { /* TODO: this is my best bet so far. Register 4 is annoying, the pattern seems to be: Write to video FF register Graphic -> 00 Write to video FF register 200 lines -> 0x Write to video FF register 200 lines -> 00 where x is the current mode. */ switch((data & 0x0e) >> 1) { case 1: m_gfx_ff = 1; if(data & 1) logerror("Graphic f/f actually enabled!\n"); break; case 4: if(m_gfx_ff) { m_video_ff[(data & 0x0e) >> 1] = data &1; m_gfx_ff = 0; } break; default: m_video_ff[(data & 0x0e) >> 1] = data & 1; break; } if(0) { static const char *const video_ff_regnames[] = { "Attribute Select", // 0 "Graphic", // 1 "Column", // 2 "Font Select", // 3 "200 lines", // 4 "KAC?", // 5 "Memory Switch", // 6 "Display ON" // 7 }; logerror("Write to video FF register %s -> %02x\n",video_ff_regnames[(data & 0x0e) >> 1],data & 1); } } READ8_MEMBER(pc9801_state::txt_scrl_r) { //logerror("Read to display register [%02x]\n",offset+0x70); /* TODO: ok? */ if(offset <= 5) return m_txt_scroll_reg[offset]; return 0xff; } WRITE8_MEMBER(pc9801_state::txt_scrl_w) { //logerror("Write to display register [%02x] %02x\n",offset+0x70,data); if(offset <= 5) m_txt_scroll_reg[offset] = data; //popmessage("%02x %02x %02x %02x",m_txt_scroll_reg[0],m_txt_scroll_reg[1],m_txt_scroll_reg[2],m_txt_scroll_reg[3]); } /************************************************* * * Video accessors * ************************************************/ READ8_MEMBER(pc9801_state::pc9801_a0_r) { if((offset & 1) == 0) { switch(offset & 0xe) { case 0x00: case 0x02: return m_hgdc2->read(space, (offset & 2) >> 1); /* TODO: double check these two */ case 0x04: return m_vram_disp & 1; case 0x06: return m_vram_bank & 1; /* bitmap palette clut read */ case 0x08: case 0x0a: case 0x0c: case 0x0e: return m_pal_clut[(offset & 0x6) >> 1]; } return 0xff; //code unreachable } else // odd { switch((offset & 0xe) + 1) { case 0x09://cg window font read { uint32_t pcg_offset; pcg_offset = (m_font_addr & 0x7f7f) << 5; pcg_offset|= m_font_line; pcg_offset|= m_font_lr; return m_kanji_rom[pcg_offset]; } } logerror("Read to undefined port [%02x]\n",offset+0xa0); return 0xff; } } WRITE8_MEMBER(pc9801_state::pc9801_a0_w) { if((offset & 1) == 0) { switch(offset & 0xe) { case 0x00: case 0x02: m_hgdc2->write(space, (offset & 2) >> 1,data); return; case 0x04: m_vram_disp = data & 1; return; case 0x06: m_vram_bank = data & 1; return; /* bitmap palette clut write */ case 0x08: case 0x0a: case 0x0c: case 0x0e: { uint8_t pal_entry; m_pal_clut[(offset & 0x6) >> 1] = data; /* can't be more twisted I presume ... :-/ */ pal_entry = (((offset & 4) >> 1) | ((offset & 2) << 1)) >> 1; pal_entry ^= 3; m_palette->set_pen_color((pal_entry)|4|8, pal1bit((data & 0x2) >> 1), pal1bit((data & 4) >> 2), pal1bit((data & 1) >> 0)); m_palette->set_pen_color((pal_entry)|8, pal1bit((data & 0x20) >> 5), pal1bit((data & 0x40) >> 6), pal1bit((data & 0x10) >> 4)); return; } default: logerror("Write to undefined port [%02x] <- %02x\n",offset+0xa0,data); return; } } else // odd { switch((offset & 0xe) + 1) { case 0x01: m_font_addr = (data & 0xff) | (m_font_addr & 0xff00); return; case 0x03: m_font_addr = ((data & 0xff) << 8) | (m_font_addr & 0xff); return; case 0x05: //logerror("%02x\n",data); m_font_line = ((data & 0x0f) << 1); m_font_lr = ((data & 0x20) >> 5) ^ 1; return; case 0x09: //cg window font write { uint32_t pcg_offset; pcg_offset = (m_font_addr & 0x7fff) << 5; pcg_offset|= m_font_line; pcg_offset|= m_font_lr; //logerror("%04x %02x %02x %08x\n",m_font_addr,m_font_line,m_font_lr,pcg_offset); if((m_font_addr & 0xff00) == 0x5600 || (m_font_addr & 0xff00) == 0x5700) { m_kanji_rom[pcg_offset] = data; m_gfxdecode->gfx(2)->mark_dirty(pcg_offset >> 5); } return; } } //logerror("Write to undefined port [%02x) <- %02x\n",offset+0xa0,data); } } /************************************************* * * Text layer accessors * ************************************************/ /* TODO: banking? */ READ16_MEMBER(pc9801_state::tvram_r) { uint16_t res; if((offset & 0x1000) && (mem_mask == 0xff00)) return 0xffff; res = m_tvram[offset]; return res; } WRITE16_MEMBER(pc9801_state::tvram_w) { if(offset < (0x3fe2>>1) || m_video_ff[MEMSW_REG]) COMBINE_DATA(&m_tvram[offset]); COMBINE_DATA(&m_video_ram_1[offset]); //TODO: check me } /************************************************* * * Graphic layer accessors * ************************************************/ /* +0x8000 is trusted (bank 0 is actually used by 16 colors mode) */ READ8_MEMBER(pc9801_state::gvram_r) { return bitswap<8>(m_video_ram_2[(offset>>1)+0x04000+m_vram_bank*0x10000] >> ((offset & 1) << 3),0,1,2,3,4,5,6,7); } WRITE8_MEMBER(pc9801_state::gvram_w) { uint16_t ram = m_video_ram_2[(offset>>1)+0x04000+m_vram_bank*0x10000]; int mask = (offset & 1) << 3; data = bitswap<8>(data,0,1,2,3,4,5,6,7); m_video_ram_2[(offset>>1)+0x04000+m_vram_bank*0x10000] = (ram & (0xff00 >> mask)) | (data << mask); } /************************************************* * * GRCG (GRaphic CharGer) * ************************************************/ READ16_MEMBER(pc9801_state::upd7220_grcg_r) { uint16_t res = 0; if(!(m_grcg.mode & 0x80) || machine().side_effects_disabled()) res = m_video_ram_2[offset]; else if(m_ex_video_ff[2]) res = egc_blit_r(offset, mem_mask); else if(!(m_grcg.mode & 0x40)) { int i; offset &= 0x13fff; res = 0; for(i=0;i<4;i++) { if((m_grcg.mode & (1 << i)) == 0) { res |= m_video_ram_2[offset | (((i + 1) & 3) * 0x4000)] ^ (m_grcg.tile[i] | m_grcg.tile[i] << 8); } } res ^= 0xffff; } return res; } WRITE16_MEMBER(pc9801_state::upd7220_grcg_w) { if(!(m_grcg.mode & 0x80)) COMBINE_DATA(&m_video_ram_2[offset]); else if(m_ex_video_ff[2]) egc_blit_w(offset, data, mem_mask); else { int i; uint8_t *vram = (uint8_t *)m_video_ram_2.target(); offset = (offset << 1) & 0x27fff; if(m_grcg.mode & 0x40) // RMW { for(i=0;i<4;i++) { if((m_grcg.mode & (1 << i)) == 0) { if(mem_mask & 0xff) { vram[offset | (((i + 1) & 3) * 0x8000)] &= ~(data >> 0); vram[offset | (((i + 1) & 3) * 0x8000)] |= m_grcg.tile[i] & (data >> 0); } if(mem_mask & 0xff00) { vram[offset | (((i + 1) & 3) * 0x8000) | 1] &= ~(data >> 8); vram[offset | (((i + 1) & 3) * 0x8000) | 1] |= m_grcg.tile[i] & (data >> 8); } } } } else // TDW { for(i=0;i<4;i++) { if((m_grcg.mode & (1 << i)) == 0) { if(mem_mask & 0xff) vram[offset | (((i + 1) & 3) * 0x8000)] = m_grcg.tile[i]; if(mem_mask & 0xff00) vram[offset | (((i + 1) & 3) * 0x8000) | 1] = m_grcg.tile[i]; } } } } } /************************************************* * * EGC (Enhanced Graphics Charger) * ************************************************/ uint16_t pc9801_state::egc_shift(int plane, uint16_t val) { int src_off = m_egc.regs[6] & 0xf, dst_off = (m_egc.regs[6] >> 4) & 0xf; int left = src_off - dst_off, right = dst_off - src_off; uint16_t out; if(m_egc.regs[6] & 0x1000) { if(right >= 0) { out = (val >> right) | m_egc.leftover[plane]; m_egc.leftover[plane] = val << (16 - right); } else { out = (val >> (16 - left)) | m_egc.leftover[plane]; m_egc.leftover[plane] = val << left; } } else { if(right >= 0) { out = (val << right) | m_egc.leftover[plane]; m_egc.leftover[plane] = val >> (16 - right); } else { out = (val << (16 - left)) | m_egc.leftover[plane]; m_egc.leftover[plane] = val >> left; } } return out; } uint16_t pc9801_state::egc_do_partial_op(int plane, uint16_t src, uint16_t pat, uint16_t dst) const { uint16_t out = 0; for(int i = 7; i >= 0; i--) { if(BIT(m_egc.regs[2], i)) out |= src & pat & dst; pat = ~pat; dst = (!(i & 1)) ? ~dst : dst; src = (i == 4) ? ~src : src; } return out; } void pc9801_state::egc_blit_w(uint32_t offset, uint16_t data, uint16_t mem_mask) { uint16_t mask = m_egc.regs[4] & mem_mask, out = 0; bool dir = !(m_egc.regs[6] & 0x1000); int dst_off = (m_egc.regs[6] >> 4) & 0xf, src_off = m_egc.regs[6] & 0xf; offset &= 0x13fff; if(!m_egc.init && (src_off > dst_off)) { if(BIT(m_egc.regs[2], 10)) { m_egc.leftover[0] = 0; egc_shift(0, data); // leftover[0] is inited above, set others to same m_egc.leftover[1] = m_egc.leftover[2] = m_egc.leftover[3] = m_egc.leftover[0]; } m_egc.init = true; return; } // mask off the bits before the start if(m_egc.first) { mask &= dir ? ~((1 << dst_off) - 1) : ((1 << (16 - dst_off)) - 1); if(BIT(m_egc.regs[2], 10) && !m_egc.init) m_egc.leftover[0] = m_egc.leftover[1] = m_egc.leftover[2] = m_egc.leftover[3] = 0; } // mask off the bits past the end of the blit if(((m_egc.count < 8) && (mem_mask != 0xffff)) || ((m_egc.count < 16) && (mem_mask == 0xffff))) { uint16_t end_mask = dir ? ((1 << m_egc.count) - 1) : ~((1 << (16 - m_egc.count)) - 1); // if the blit is less than the write size, adjust the masks if(m_egc.first) { if(dir) end_mask <<= dst_off; else end_mask >>= dst_off; } mask &= end_mask; } for(int i = 0; i < 4; i++) { if(!BIT(m_egc.regs[0], i)) { uint16_t src = m_egc.src[i], pat = m_egc.pat[i]; if(BIT(m_egc.regs[2], 10)) src = egc_shift(i, data); if((m_egc.regs[2] & 0x300) == 0x200) pat = m_video_ram_2[offset + (((i + 1) & 3) * 0x4000)]; switch((m_egc.regs[2] >> 11) & 3) { case 0: out = data; break; case 1: out = egc_do_partial_op(i, src, pat, m_video_ram_2[offset + (((i + 1) & 3) * 0x4000)]); break; case 2: out = pat; break; case 3: logerror("Invalid EGC blit operation\n"); return; } m_video_ram_2[offset + (((i + 1) & 3) * 0x4000)] &= ~mask; m_video_ram_2[offset + (((i + 1) & 3) * 0x4000)] |= out & mask; } } if(mem_mask != 0xffff) { if(m_egc.first) m_egc.count -= 8 - (dst_off & 7); else m_egc.count -= 8; } else { if(m_egc.first) m_egc.count -= 16 - dst_off; else m_egc.count -= 16; } m_egc.first = false; if(m_egc.count <= 0) { m_egc.first = true; m_egc.init = false; m_egc.count = (m_egc.regs[7] & 0xfff) + 1; } } uint16_t pc9801_state::egc_blit_r(uint32_t offset, uint16_t mem_mask) { uint32_t plane_off = offset & 0x13fff; if((m_egc.regs[2] & 0x300) == 0x100) { m_egc.pat[0] = m_video_ram_2[plane_off + 0x4000]; m_egc.pat[1] = m_video_ram_2[plane_off + (0x4000 * 2)]; m_egc.pat[2] = m_video_ram_2[plane_off + (0x4000 * 3)]; m_egc.pat[3] = m_video_ram_2[plane_off]; } if(m_egc.first && !m_egc.init) { m_egc.leftover[0] = m_egc.leftover[1] = m_egc.leftover[2] = m_egc.leftover[3] = 0; if(((m_egc.regs[6] >> 4) & 0xf) >= (m_egc.regs[6] & 0xf)) // check if we have enough bits m_egc.init = true; } for(int i = 0; i < 4; i++) m_egc.src[i] = egc_shift(i, m_video_ram_2[plane_off + (((i + 1) & 3) * 0x4000)]); if(BIT(m_egc.regs[2], 13)) return m_video_ram_2[offset]; else return m_egc.src[(m_egc.regs[1] >> 8) & 3]; }