diff --git a/Core/display.c b/Core/display.c index 1adcc50..b55d66f 100755 --- a/Core/display.c +++ b/Core/display.c @@ -528,8 +528,7 @@ static void update_display_state(GB_gameboy_t *gb, uint8_t cycles) } else if (position_in_line == MODE2_LENGTH + MODE3_LENGTH + stat_delay + scx_delay + 16) { if (gb->hdma_on_hblank) { - gb->hdma_on = true; - gb->hdma_cycles = 0; + gb->hdma_starting = true; } } } diff --git a/Core/gb.h b/Core/gb.h index c93aa3d..48171f8 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -276,6 +276,7 @@ struct GB_gameboy_internal_s { int16_t dma_cycles; bool is_dma_restarting; uint8_t last_opcode_read; /* Required to emulte HDMA reads from Exxx */ + bool hdma_starting; ); /* MBC */ diff --git a/Core/z80_cpu.c b/Core/z80_cpu.c index 4794df5..6ff69b4 100644 --- a/Core/z80_cpu.c +++ b/Core/z80_cpu.c @@ -1402,4 +1402,10 @@ void GB_cpu_run(GB_gameboy_t *gb) else { GB_advance_cycles(gb, 4); } + + if (gb->hdma_starting) { + gb->hdma_starting = false; + gb->hdma_on = true; + gb->hdma_cycles = 0; + } }