Compensate for prefetch in DIV’s initial value

This commit is contained in:
Lior Halphon 2018-09-15 00:47:26 +03:00
parent 629550c30b
commit dbc338a887
2 changed files with 13 additions and 0 deletions

View File

@ -554,6 +554,9 @@ void GB_reset(GB_gameboy_t *gb)
gb->accessed_oam_row = -1;
/* Todo: Ugly, fixme, see comment in the timer state machine */
gb->div_state = 3;
gb->magic = (uintptr_t)'SAME';
}

View File

@ -144,9 +144,11 @@ static void GB_timers_run(GB_gameboy_t *gb, uint8_t cycles)
GB_STATE_MACHINE(gb, div, cycles, 1) {
GB_STATE(gb, div, 1);
GB_STATE(gb, div, 2);
GB_STATE(gb, div, 3);
}
GB_set_internal_div_counter(gb, 0);
main:
GB_SLEEP(gb, div, 1, 3);
while (true) {
advance_tima_state_machine(gb);
@ -154,6 +156,14 @@ static void GB_timers_run(GB_gameboy_t *gb, uint8_t cycles)
gb->apu.apu_cycles += 4 << !gb->cgb_double_speed;
GB_SLEEP(gb, div, 2, 4);
}
/* Todo: This is ugly to allow compatibility with 0.11 save states. Fix me when breaking save compatibility */
{
div3:
/* Compensate for lack of prefetch emulation, as well as DIV's internal initial value */
GB_set_internal_div_counter(gb, 8);
goto main;
}
}
void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles)