Prevent starting HDMA in the middle of an instruction, making both the CPU and DMA access memory at the same time. Closes #47

This commit is contained in:
Lior Halphon 2018-03-19 20:01:31 +02:00
parent 80b1275e07
commit b50c97f4a7
3 changed files with 8 additions and 2 deletions

View File

@ -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) { else if (position_in_line == MODE2_LENGTH + MODE3_LENGTH + stat_delay + scx_delay + 16) {
if (gb->hdma_on_hblank) { if (gb->hdma_on_hblank) {
gb->hdma_on = true; gb->hdma_starting = true;
gb->hdma_cycles = 0;
} }
} }
} }

View File

@ -276,6 +276,7 @@ struct GB_gameboy_internal_s {
int16_t dma_cycles; int16_t dma_cycles;
bool is_dma_restarting; bool is_dma_restarting;
uint8_t last_opcode_read; /* Required to emulte HDMA reads from Exxx */ uint8_t last_opcode_read; /* Required to emulte HDMA reads from Exxx */
bool hdma_starting;
); );
/* MBC */ /* MBC */

View File

@ -1402,4 +1402,10 @@ void GB_cpu_run(GB_gameboy_t *gb)
else { else {
GB_advance_cycles(gb, 4); GB_advance_cycles(gb, 4);
} }
if (gb->hdma_starting) {
gb->hdma_starting = false;
gb->hdma_on = true;
gb->hdma_cycles = 0;
}
} }