Vblank should occur 1 T-cycle later

This commit is contained in:
Lior Halphon 2021-06-19 02:14:16 +03:00
parent b4709fd66b
commit 23e8cc58c5

View File

@ -854,7 +854,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles)
GB_STATE(gb, display, 21); GB_STATE(gb, display, 21);
GB_STATE(gb, display, 22); GB_STATE(gb, display, 22);
GB_STATE(gb, display, 23); GB_STATE(gb, display, 23);
// GB_STATE(gb, display, 24); GB_STATE(gb, display, 24);
GB_STATE(gb, display, 25); GB_STATE(gb, display, 25);
GB_STATE(gb, display, 26); GB_STATE(gb, display, 26);
GB_STATE(gb, display, 27); GB_STATE(gb, display, 27);
@ -1287,7 +1287,9 @@ abort_fetching_object:
gb->wy_triggered = true; gb->wy_triggered = true;
} }
GB_SLEEP(gb, display, 31, 2); GB_SLEEP(gb, display, 31, 2);
gb->mode_for_interrupt = 2; if (gb->current_line != LINES - 1) {
gb->mode_for_interrupt = 2;
}
// Todo: unverified timing // Todo: unverified timing
gb->current_lcd_line++; gb->current_lcd_line++;
@ -1310,7 +1312,9 @@ abort_fetching_object:
} }
GB_SLEEP(gb, display, 12, 2); GB_SLEEP(gb, display, 12, 2);
gb->ly_for_comparison = gb->current_line; gb->ly_for_comparison = gb->current_line;
GB_STAT_update(gb);
GB_SLEEP(gb, display, 24, 1);
if (gb->current_line == LINES) { if (gb->current_line == LINES) {
/* Entering VBlank state triggers the OAM interrupt */ /* Entering VBlank state triggers the OAM interrupt */
gb->io_registers[GB_IO_STAT] &= ~3; gb->io_registers[GB_IO_STAT] &= ~3;
@ -1350,8 +1354,7 @@ abort_fetching_object:
} }
} }
GB_STAT_update(gb); GB_SLEEP(gb, display, 13, LINE_LENGTH - 5);
GB_SLEEP(gb, display, 13, LINE_LENGTH - 4);
} }
/* TODO: Verified on SGB2 and CGB-E. Actual interrupt timings not tested. */ /* TODO: Verified on SGB2 and CGB-E. Actual interrupt timings not tested. */