From 742c9e95d3d133ff3ca53097c0bc63cfce43bb6e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 8 Sep 2017 23:46:38 +0300 Subject: [PATCH] Updated previous timing improvements to correctly implement double speed behavior --- Core/display.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Core/display.c b/Core/display.c index 2106617..c0f385f 100755 --- a/Core/display.c +++ b/Core/display.c @@ -291,8 +291,14 @@ static void update_display_state(GB_gameboy_t *gb, uint8_t cycles) these findings. Todo: Investigate what causes the difference between our findings */ uint8_t stat_delay = gb->cgb_double_speed? 2 : 4; // (gb->cgb_mode? 0 : 4); - /* Todo: This is correct for DMG and single speed CGB. Is it correct for double speed and DMG mode CGB?*/ - uint8_t scx_delay = (gb->effective_scx + (gb->first_scanline ? 2 : 0)) & (gb->cgb_double_speed? ~1 : ~3); + /* Todo: Is this correct for DMG mode CGB? */ + uint8_t scx_delay = gb->effective_scx; + if (gb->cgb_double_speed) { + scx_delay = (scx_delay + 1) & ~1; + } + else { + scx_delay = (scx_delay + (gb->first_scanline ? 2 : 0)) & ~3; + } /* Todo: These are correct for DMG, DMG-mode CGB, and single speed CGB. Is is correct for double speed CGB? */ uint8_t oam_blocking_rush = gb->cgb_double_speed? 2 : 4; @@ -544,7 +550,7 @@ static void update_display_state(GB_gameboy_t *gb, uint8_t cycles) switch (gb->io_registers[GB_IO_STAT] & 3) { case 0: gb->stat_interrupt_line = (gb->io_registers[GB_IO_STAT] & 8); - if (just_entered_hblank && ((gb->effective_scx + (gb->first_scanline ? 2 : 0)) & 3) == 3) { + if (!gb->cgb_double_speed && just_entered_hblank && ((gb->effective_scx + (gb->first_scanline ? 2 : 0)) & 3) == 3) { gb->stat_interrupt_line = false; } break;