From dbc338a887a14c5a206b53708f44189dd43a3502 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 15 Sep 2018 00:47:26 +0300 Subject: [PATCH] =?UTF-8?q?Compensate=20for=20prefetch=20in=20DIV=E2=80=99?= =?UTF-8?q?s=20initial=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/gb.c | 3 +++ Core/timing.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/Core/gb.c b/Core/gb.c index ff5851e..73edb11 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -553,6 +553,9 @@ void GB_reset(GB_gameboy_t *gb) gb->io_registers[GB_IO_DMA] = gb->io_registers[GB_IO_OBP0] = gb->io_registers[GB_IO_OBP1] = GB_is_cgb(gb)? 0x00 : 0xFF; gb->accessed_oam_row = -1; + + /* Todo: Ugly, fixme, see comment in the timer state machine */ + gb->div_state = 3; gb->magic = (uintptr_t)'SAME'; } diff --git a/Core/timing.c b/Core/timing.c index 58177d5..65382e4 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -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)