Last fix was wrong, this is correct

This commit is contained in:
Lior Halphon 2022-06-17 18:17:29 +03:00
parent 517f455486
commit 22f8ab6509
2 changed files with 13 additions and 0 deletions

View File

@ -436,6 +436,7 @@ struct GB_gameboy_internal_s {
bool dma_ppu_vram_conflict; bool dma_ppu_vram_conflict;
uint16_t dma_ppu_vram_conflict_addr; uint16_t dma_ppu_vram_conflict_addr;
uint8_t hdma_open_bus; /* Required to emulate HDMA reads from Exxx */ uint8_t hdma_open_bus; /* Required to emulate HDMA reads from Exxx */
bool allow_hdma_on_wake;
) )
/* MBC */ /* MBC */

View File

@ -360,6 +360,7 @@ static void enter_stop_mode(GB_gameboy_t *gb)
gb->div_cycles = -4; // Emulate the CPU-side DIV-reset signal being held gb->div_cycles = -4; // Emulate the CPU-side DIV-reset signal being held
} }
gb->stopped = true; gb->stopped = true;
gb->allow_hdma_on_wake = (gb->io_registers[GB_IO_STAT] & 3);
gb->oam_ppu_blocked = !gb->oam_read_blocked; gb->oam_ppu_blocked = !gb->oam_read_blocked;
gb->vram_ppu_blocked = !gb->vram_read_blocked; gb->vram_ppu_blocked = !gb->vram_read_blocked;
gb->cgb_palettes_ppu_blocked = !gb->cgb_palettes_blocked; gb->cgb_palettes_ppu_blocked = !gb->cgb_palettes_blocked;
@ -368,6 +369,9 @@ static void enter_stop_mode(GB_gameboy_t *gb)
static void leave_stop_mode(GB_gameboy_t *gb) static void leave_stop_mode(GB_gameboy_t *gb)
{ {
gb->stopped = false; gb->stopped = false;
if (gb->hdma_on_hblank && (gb->io_registers[GB_IO_STAT] & 3) == 0 && gb->allow_hdma_on_wake) {
gb->hdma_on = true;
}
// TODO: verify this // TODO: verify this
gb->dma_cycles = 4; gb->dma_cycles = 4;
GB_dma_run(gb); GB_dma_run(gb);
@ -437,6 +441,7 @@ static void stop(GB_gameboy_t *gb, uint8_t opcode)
GB_dma_run(gb); GB_dma_run(gb);
gb->halted = true; gb->halted = true;
gb->just_halted = true; gb->just_halted = true;
gb->allow_hdma_on_wake = (gb->io_registers[GB_IO_STAT] & 3);
} }
else { else {
gb->speed_switch_halt_countdown = 0; gb->speed_switch_halt_countdown = 0;
@ -1038,6 +1043,7 @@ static void halt(GB_gameboy_t *gb, uint8_t opcode)
} }
else { else {
gb->halted = true; gb->halted = true;
gb->allow_hdma_on_wake = (gb->io_registers[GB_IO_STAT] & 3);
} }
gb->just_halted = true; gb->just_halted = true;
} }
@ -1631,6 +1637,9 @@ void GB_cpu_run(GB_gameboy_t *gb)
/* Wake up from HALT mode without calling interrupt code. */ /* Wake up from HALT mode without calling interrupt code. */
if (gb->halted && !effective_ime && interrupt_queue) { if (gb->halted && !effective_ime && interrupt_queue) {
gb->halted = false; gb->halted = false;
if (gb->hdma_on_hblank && (gb->io_registers[GB_IO_STAT] & 3) == 0 && gb->allow_hdma_on_wake) {
gb->hdma_on = true;
}
gb->dma_cycles = 4; gb->dma_cycles = 4;
GB_dma_run(gb); GB_dma_run(gb);
gb->speed_switch_halt_countdown = 0; gb->speed_switch_halt_countdown = 0;
@ -1639,6 +1648,9 @@ void GB_cpu_run(GB_gameboy_t *gb)
/* Call interrupt */ /* Call interrupt */
else if (effective_ime && interrupt_queue) { else if (effective_ime && interrupt_queue) {
gb->halted = false; gb->halted = false;
if (gb->hdma_on_hblank && (gb->io_registers[GB_IO_STAT] & 3) == 0 && gb->allow_hdma_on_wake) {
gb->hdma_on = true;
}
// TODO: verify the timing! // TODO: verify the timing!
gb->dma_cycles = 4; gb->dma_cycles = 4;
GB_dma_run(gb); GB_dma_run(gb);