STAT reads 0 during mode 2 if DMA is active

This commit is contained in:
Lior Halphon 2022-02-05 17:43:48 +02:00
parent 6a8db89ae5
commit b5eea012cc
2 changed files with 8 additions and 0 deletions

View File

@ -397,6 +397,9 @@ void GB_set_light_temperature(GB_gameboy_t *gb, double temperature)
void GB_STAT_update(GB_gameboy_t *gb) void GB_STAT_update(GB_gameboy_t *gb)
{ {
if (!(gb->io_registers[GB_IO_LCDC] & 0x80)) return; 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; bool previous_interrupt_line = gb->stat_interrupt_line;
/* Set LY=LYC bit */ /* Set LY=LYC bit */

View File

@ -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_dest = 0xFF;
gb->dma_current_src = value << 8; gb->dma_current_src = value << 8;
gb->io_registers[GB_IO_DMA] = value; gb->io_registers[GB_IO_DMA] = value;
GB_STAT_update(gb);
return; return;
case GB_IO_SVBK: case GB_IO_SVBK:
if (gb->cgb_mode || (GB_is_cgb(gb) && !gb->boot_rom_finished)) { 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; cycles -= 4;
if (gb->dma_current_dest >= 0xa0) { if (gb->dma_current_dest >= 0xa0) {
gb->dma_current_dest++; gb->dma_current_dest++;
if (gb->display_state == 8) {
gb->io_registers[GB_IO_STAT] |= 2;
GB_STAT_update(gb);
}
break; break;
} }
if (unlikely(gb->hdma_in_progress && (gb->hdma_steps_left > 1 || (gb->hdma_current_dest & 0xF) != 0xF))) { if (unlikely(gb->hdma_in_progress && (gb->hdma_steps_left > 1 || (gb->hdma_current_dest & 0xF) != 0xF))) {