From 36e4230bf6558351652bdc6e73837d4fcf7a692d Mon Sep 17 00:00:00 2001 From: sinamas Date: Tue, 20 Aug 2019 18:29:22 +0200 Subject: [PATCH] libgambatte: also test late mode=2 vram reads on the dmg This is apparently different on the DMG. Fixes mooneye-gb "lcdon_timing-GS" in "DMG" mode. --- libgambatte/src/memory.cpp | 4 +- libgambatte/src/video.cpp | 13 ++- libgambatte/src/video.h | 3 +- .../vram_m3/preread_1_dmg08_cgb04c_out0.asm | 104 ++++++++++++++++++ .../preread_2_dmg08_out3_cgb04c_out0.asm | 104 ++++++++++++++++++ .../vram_m3/preread_3_dmg08_cgb04c_out3.asm | 104 ++++++++++++++++++ 6 files changed, 328 insertions(+), 4 deletions(-) create mode 100644 test/hwtests/vram_m3/preread_1_dmg08_cgb04c_out0.asm create mode 100644 test/hwtests/vram_m3/preread_2_dmg08_out3_cgb04c_out0.asm create mode 100644 test/hwtests/vram_m3/preread_3_dmg08_cgb04c_out3.asm diff --git a/libgambatte/src/memory.cpp b/libgambatte/src/memory.cpp index a230de16..d0b6eeb0 100644 --- a/libgambatte/src/memory.cpp +++ b/libgambatte/src/memory.cpp @@ -648,7 +648,7 @@ unsigned Memory::nontrivial_read(unsigned const p, unsigned long const cc) { return cart_.romdata(p >> 14)[p]; if (p < mm_sram_begin) { - if (!lcd_.vramAccessible(cc)) + if (!lcd_.vramReadable(cc)) return 0xFF; return cart_.vrambankptr()[p]; @@ -1135,7 +1135,7 @@ void Memory::nontrivial_write(unsigned const p, unsigned const data, unsigned lo if (p < mm_sram_begin) { if (p < mm_vram_begin) { cart_.mbcWrite(p, data); - } else if (lcd_.vramAccessible(cc)) { + } else if (lcd_.vramWritable(cc)) { lcd_.vramChange(cc); cart_.vrambankptr()[p] = data; } diff --git a/libgambatte/src/video.cpp b/libgambatte/src/video.cpp index 54d2704e..c24e62eb 100644 --- a/libgambatte/src/video.cpp +++ b/libgambatte/src/video.cpp @@ -349,7 +349,18 @@ bool LCD::isHdmaPeriod(unsigned long const cc) { return ::isHdmaPeriod(ppu_.lyCounter(), m0TimeOfCurrentLine(cc), cc); } -bool LCD::vramAccessible(unsigned long const cc) { +bool LCD::vramReadable(unsigned long const cc) { + if (cc >= eventTimes_.nextEventTime()) + update(cc); + + return !(ppu_.lcdc() & lcdc_en) + || ppu_.lyCounter().ly() >= lcd_vres + || ppu_.inactivePeriodAfterDisplayEnable(cc + 1 - ppu_.cgb() + isDoubleSpeed()) + || ppu_.lyCounter().lineCycles(cc) + isDoubleSpeed() < 76u + 3 * ppu_.cgb() + || cc + 2 >= m0TimeOfCurrentLine(cc); +} + +bool LCD::vramWritable(unsigned long const cc) { if (cc >= eventTimes_.nextEventTime()) update(cc); diff --git a/libgambatte/src/video.h b/libgambatte/src/video.h index a6d7db8f..50093786 100644 --- a/libgambatte/src/video.h +++ b/libgambatte/src/video.h @@ -97,7 +97,8 @@ public: void updateScreen(bool blanklcd, unsigned long cc); void resetCc(unsigned long oldCC, unsigned long newCc); void speedChange(unsigned long cycleCounter); - bool vramAccessible(unsigned long cycleCounter); + bool vramReadable(unsigned long cycleCounter); + bool vramWritable(unsigned long cycleCounter); bool oamReadable(unsigned long cycleCounter); bool oamWritable(unsigned long cycleCounter); void wxChange(unsigned newValue, unsigned long cycleCounter); diff --git a/test/hwtests/vram_m3/preread_1_dmg08_cgb04c_out0.asm b/test/hwtests/vram_m3/preread_1_dmg08_cgb04c_out0.asm new file mode 100644 index 00000000..8a7c7298 --- /dev/null +++ b/test/hwtests/vram_m3/preread_1_dmg08_cgb04c_out0.asm @@ -0,0 +1,104 @@ +.size 8000 + +.text@48 + jp lstatint + +.text@100 + jp lbegin + +.data@143 + 80 + +.text@150 +lbegin: + ld b, 98 + call lwaitly_b + xor a, a + ld(8000), a + ld a, 01 + ldff(45), a + ld a, 40 + ldff(41), a + ld a, 02 + ldff(ff), a + xor a, a + ldff(0f), a + ei + +.text@1000 +lstatint: + +.text@1006 + ld a, (8000) + and a, 03 + jp lprint_a + +.text@7000 +lprint_a: + push af + ld b, 91 + call lwaitly_b + xor a, a + ldff(40), a + pop af + ld(9800), a + ld bc, 7a00 + ld hl, 8000 + ld d, a0 +lprint_copytiles: + ld a, (bc) + inc bc + ld(hl++), a + dec d + jrnz lprint_copytiles + ld a, c0 + ldff(47), a + ld a, 80 + ldff(68), a + ld a, ff + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + xor a, a + ldff(69), a + ldff(69), a + ldff(43), a + ld a, 91 + ldff(40), a +lprint_limbo: + jr lprint_limbo + +.text@7400 +lwaitly_b: + ld c, 44 +lwaitly_b_loop: + ldff a, (c) + cmp a, b + jrnz lwaitly_b_loop + ret + +.data@7a00 + 00 00 7f 7f 41 41 41 41 + 41 41 41 41 41 41 7f 7f + 00 00 08 08 08 08 08 08 + 08 08 08 08 08 08 08 08 + 00 00 7f 7f 01 01 01 01 + 7f 7f 40 40 40 40 7f 7f + 00 00 7f 7f 01 01 01 01 + 3f 3f 01 01 01 01 7f 7f + 00 00 41 41 41 41 41 41 + 7f 7f 01 01 01 01 01 01 + 00 00 7f 7f 40 40 40 40 + 7e 7e 01 01 01 01 7e 7e + 00 00 7f 7f 40 40 40 40 + 7f 7f 41 41 41 41 7f 7f + 00 00 7f 7f 01 01 02 02 + 04 04 08 08 10 10 10 10 + 00 00 3e 3e 41 41 41 41 + 3e 3e 41 41 41 41 3e 3e + 00 00 7f 7f 41 41 41 41 + 7f 7f 01 01 01 01 7f 7f + diff --git a/test/hwtests/vram_m3/preread_2_dmg08_out3_cgb04c_out0.asm b/test/hwtests/vram_m3/preread_2_dmg08_out3_cgb04c_out0.asm new file mode 100644 index 00000000..49c1ea0e --- /dev/null +++ b/test/hwtests/vram_m3/preread_2_dmg08_out3_cgb04c_out0.asm @@ -0,0 +1,104 @@ +.size 8000 + +.text@48 + jp lstatint + +.text@100 + jp lbegin + +.data@143 + 80 + +.text@150 +lbegin: + ld b, 98 + call lwaitly_b + xor a, a + ld(8000), a + ld a, 01 + ldff(45), a + ld a, 40 + ldff(41), a + ld a, 02 + ldff(ff), a + xor a, a + ldff(0f), a + ei + +.text@1000 +lstatint: + +.text@1007 + ld a, (8000) + and a, 03 + jp lprint_a + +.text@7000 +lprint_a: + push af + ld b, 91 + call lwaitly_b + xor a, a + ldff(40), a + pop af + ld(9800), a + ld bc, 7a00 + ld hl, 8000 + ld d, a0 +lprint_copytiles: + ld a, (bc) + inc bc + ld(hl++), a + dec d + jrnz lprint_copytiles + ld a, c0 + ldff(47), a + ld a, 80 + ldff(68), a + ld a, ff + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + xor a, a + ldff(69), a + ldff(69), a + ldff(43), a + ld a, 91 + ldff(40), a +lprint_limbo: + jr lprint_limbo + +.text@7400 +lwaitly_b: + ld c, 44 +lwaitly_b_loop: + ldff a, (c) + cmp a, b + jrnz lwaitly_b_loop + ret + +.data@7a00 + 00 00 7f 7f 41 41 41 41 + 41 41 41 41 41 41 7f 7f + 00 00 08 08 08 08 08 08 + 08 08 08 08 08 08 08 08 + 00 00 7f 7f 01 01 01 01 + 7f 7f 40 40 40 40 7f 7f + 00 00 7f 7f 01 01 01 01 + 3f 3f 01 01 01 01 7f 7f + 00 00 41 41 41 41 41 41 + 7f 7f 01 01 01 01 01 01 + 00 00 7f 7f 40 40 40 40 + 7e 7e 01 01 01 01 7e 7e + 00 00 7f 7f 40 40 40 40 + 7f 7f 41 41 41 41 7f 7f + 00 00 7f 7f 01 01 02 02 + 04 04 08 08 10 10 10 10 + 00 00 3e 3e 41 41 41 41 + 3e 3e 41 41 41 41 3e 3e + 00 00 7f 7f 41 41 41 41 + 7f 7f 01 01 01 01 7f 7f + diff --git a/test/hwtests/vram_m3/preread_3_dmg08_cgb04c_out3.asm b/test/hwtests/vram_m3/preread_3_dmg08_cgb04c_out3.asm new file mode 100644 index 00000000..bd600df9 --- /dev/null +++ b/test/hwtests/vram_m3/preread_3_dmg08_cgb04c_out3.asm @@ -0,0 +1,104 @@ +.size 8000 + +.text@48 + jp lstatint + +.text@100 + jp lbegin + +.data@143 + 80 + +.text@150 +lbegin: + ld b, 98 + call lwaitly_b + xor a, a + ld(8000), a + ld a, 01 + ldff(45), a + ld a, 40 + ldff(41), a + ld a, 02 + ldff(ff), a + xor a, a + ldff(0f), a + ei + +.text@1000 +lstatint: + +.text@1008 + ld a, (8000) + and a, 03 + jp lprint_a + +.text@7000 +lprint_a: + push af + ld b, 91 + call lwaitly_b + xor a, a + ldff(40), a + pop af + ld(9800), a + ld bc, 7a00 + ld hl, 8000 + ld d, a0 +lprint_copytiles: + ld a, (bc) + inc bc + ld(hl++), a + dec d + jrnz lprint_copytiles + ld a, c0 + ldff(47), a + ld a, 80 + ldff(68), a + ld a, ff + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + ldff(69), a + xor a, a + ldff(69), a + ldff(69), a + ldff(43), a + ld a, 91 + ldff(40), a +lprint_limbo: + jr lprint_limbo + +.text@7400 +lwaitly_b: + ld c, 44 +lwaitly_b_loop: + ldff a, (c) + cmp a, b + jrnz lwaitly_b_loop + ret + +.data@7a00 + 00 00 7f 7f 41 41 41 41 + 41 41 41 41 41 41 7f 7f + 00 00 08 08 08 08 08 08 + 08 08 08 08 08 08 08 08 + 00 00 7f 7f 01 01 01 01 + 7f 7f 40 40 40 40 7f 7f + 00 00 7f 7f 01 01 01 01 + 3f 3f 01 01 01 01 7f 7f + 00 00 41 41 41 41 41 41 + 7f 7f 01 01 01 01 01 01 + 00 00 7f 7f 40 40 40 40 + 7e 7e 01 01 01 01 7e 7e + 00 00 7f 7f 40 40 40 40 + 7f 7f 41 41 41 41 7f 7f + 00 00 7f 7f 01 01 02 02 + 04 04 08 08 10 10 10 10 + 00 00 3e 3e 41 41 41 41 + 3e 3e 41 41 41 41 3e 3e + 00 00 7f 7f 41 41 41 41 + 7f 7f 01 01 01 01 7f 7f +