From b5eea012cc6e5785a6aa40c5d9ad1592d67f85c7 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 5 Feb 2022 17:43:48 +0200 Subject: [PATCH] STAT reads 0 during mode 2 if DMA is active --- Core/display.c | 3 +++ Core/memory.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Core/display.c b/Core/display.c index 09991d3..a3fded5 100644 --- a/Core/display.c +++ b/Core/display.c @@ -397,6 +397,9 @@ void GB_set_light_temperature(GB_gameboy_t *gb, double temperature) void GB_STAT_update(GB_gameboy_t *gb) { if (!(gb->io_registers[GB_IO_LCDC] & 0x80)) return; + if (GB_is_dma_active(gb) && (gb->io_registers[GB_IO_STAT] & 3) == 2) { + gb->io_registers[GB_IO_STAT] &= ~3; + } bool previous_interrupt_line = gb->stat_interrupt_line; /* Set LY=LYC bit */ diff --git a/Core/memory.c b/Core/memory.c index 0ad9c84..19a4121 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -1471,6 +1471,7 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) gb->dma_current_dest = 0xFF; gb->dma_current_src = value << 8; gb->io_registers[GB_IO_DMA] = value; + GB_STAT_update(gb); return; case GB_IO_SVBK: if (gb->cgb_mode || (GB_is_cgb(gb) && !gb->boot_rom_finished)) { @@ -1701,6 +1702,10 @@ void GB_dma_run(GB_gameboy_t *gb) cycles -= 4; if (gb->dma_current_dest >= 0xa0) { gb->dma_current_dest++; + if (gb->display_state == 8) { + gb->io_registers[GB_IO_STAT] |= 2; + GB_STAT_update(gb); + } break; } if (unlikely(gb->hdma_in_progress && (gb->hdma_steps_left > 1 || (gb->hdma_current_dest & 0xF) != 0xF))) {