diff --git a/libgambatte/src/video.cpp b/libgambatte/src/video.cpp index c24e62eb..85325f59 100644 --- a/libgambatte/src/video.cpp +++ b/libgambatte/src/video.cpp @@ -419,7 +419,8 @@ bool LCD::oamWritable(unsigned long const cc) { if (ppu_.lyCounter().lineCycles(cc) + 3 + ppu_.cgb() >= lcd_cycles_per_line) return ppu_.lyCounter().ly() >= lcd_vres - 1 && ppu_.lyCounter().ly() < lcd_lines_per_frame - 1; - return ppu_.lyCounter().ly() >= lcd_vres || cc + 2 >= m0TimeOfCurrentLine(cc); + return ppu_.lyCounter().ly() >= lcd_vres || cc + 2 >= m0TimeOfCurrentLine(cc) + || (ppu_.lyCounter().lineCycles(cc) == 76 && !ppu_.cgb()); } void LCD::mode3CyclesChange() { diff --git a/test/hwtests/oam_access/midread_1_dmg08_cgb04c_out3.asm b/test/hwtests/oam_access/midread_1_dmg08_cgb04c_out3.asm new file mode 100644 index 00000000..daf1d512 --- /dev/null +++ b/test/hwtests/oam_access/midread_1_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(fe00), 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, (fe00) + 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/oam_access/midread_2_dmg08_cgb04c_out3.asm b/test/hwtests/oam_access/midread_2_dmg08_cgb04c_out3.asm new file mode 100644 index 00000000..6e636402 --- /dev/null +++ b/test/hwtests/oam_access/midread_2_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(fe00), 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, (fe00) + 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/oam_access/midread_3_dmg08_cgb04c_out3.asm b/test/hwtests/oam_access/midread_3_dmg08_cgb04c_out3.asm new file mode 100644 index 00000000..2d471ff5 --- /dev/null +++ b/test/hwtests/oam_access/midread_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(fe00), 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, (fe00) + 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/oam_access/midwrite_1_dmg08_cgb04c_out0.asm b/test/hwtests/oam_access/midwrite_1_dmg08_cgb04c_out0.asm new file mode 100644 index 00000000..a2775f06 --- /dev/null +++ b/test/hwtests/oam_access/midwrite_1_dmg08_cgb04c_out0.asm @@ -0,0 +1,103 @@ +.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(fe00), 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@1004 + ld a, 01 + ld (fe00), a + jp lprint_fe00 + +.text@7000 +lprint_fe00: + ld b, 91 + call lwaitly_b + xor a, a + ldff(40), a + ld a, (fe00) + 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/oam_access/midwrite_2_dmg08_out1_cgb04c_out0.asm b/test/hwtests/oam_access/midwrite_2_dmg08_out1_cgb04c_out0.asm new file mode 100644 index 00000000..62f4bb1e --- /dev/null +++ b/test/hwtests/oam_access/midwrite_2_dmg08_out1_cgb04c_out0.asm @@ -0,0 +1,103 @@ +.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(fe00), 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@1005 + ld a, 01 + ld (fe00), a + jp lprint_fe00 + +.text@7000 +lprint_fe00: + ld b, 91 + call lwaitly_b + xor a, a + ldff(40), a + ld a, (fe00) + 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/oam_access/midwrite_3_dmg08_cgb04c_out0.asm b/test/hwtests/oam_access/midwrite_3_dmg08_cgb04c_out0.asm new file mode 100644 index 00000000..3da7f7ab --- /dev/null +++ b/test/hwtests/oam_access/midwrite_3_dmg08_cgb04c_out0.asm @@ -0,0 +1,103 @@ +.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(fe00), 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, 01 + ld (fe00), a + jp lprint_fe00 + +.text@7000 +lprint_fe00: + ld b, 91 + call lwaitly_b + xor a, a + ldff(40), a + ld a, (fe00) + 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 +