From 1c0f65177f8264343348a43aa11bb18b9753af4b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 9 Dec 2023 15:54:57 +0200 Subject: [PATCH] Fix HDMA5 not being correctly updated in memory when disabling hblank HDMA --- Core/memory.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Core/memory.c b/Core/memory.c index 0b73700eb..1eff3357c 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -1678,6 +1678,7 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) return; case GB_IO_HDMA5: if (!gb->cgb_mode) return; + gb->hdma_steps_left = (value & 0x7F) + 1; if ((value & 0x80) == 0 && gb->hdma_on_hblank) { gb->hdma_on_hblank = false; return; @@ -1687,8 +1688,6 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) if (gb->hdma_on_hblank && (gb->io_registers[GB_IO_STAT] & 3) == 0 && gb->display_state != 7) { gb->hdma_on = true; } - gb->io_registers[GB_IO_HDMA5] = value; - gb->hdma_steps_left = (gb->io_registers[GB_IO_HDMA5] & 0x7F) + 1; return; /* TODO: What happens when starting a transfer during external clock? @@ -1918,7 +1917,6 @@ void GB_hdma_run(GB_gameboy_t *gb) if (--gb->hdma_steps_left == 0 || gb->hdma_current_dest == 0) { gb->hdma_on = false; gb->hdma_on_hblank = false; - gb->io_registers[GB_IO_HDMA5] &= 0x7F; } else if (gb->hdma_on_hblank) { gb->hdma_on = false;