Emulate the HALT bug on a DMG

This commit is contained in:
Lior Halphon 2016-09-20 01:22:21 +03:00
parent 1a3a96762b
commit f049284324

View File

@ -1333,7 +1333,10 @@ void GB_cpu_run(GB_gameboy_t *gb)
{ {
gb->vblank_just_occured = false; gb->vblank_just_occured = false;
bool interrupt = gb->interrupt_enable & gb->io_registers[GB_IO_IF]; bool interrupt = gb->interrupt_enable & gb->io_registers[GB_IO_IF];
bool halt_bug = false;
if (interrupt) { if (interrupt) {
halt_bug = gb->halted && !gb->is_cgb; /* Todo: Does this bug happen on a CGB? */
gb->halted = false; gb->halted = false;
} }
@ -1363,6 +1366,9 @@ void GB_cpu_run(GB_gameboy_t *gb)
} }
else if(!gb->halted && !gb->stopped) { else if(!gb->halted && !gb->stopped) {
uint8_t opcode = GB_read_memory(gb, gb->pc++); uint8_t opcode = GB_read_memory(gb, gb->pc++);
if (halt_bug) {
gb->pc--;
}
opcodes[opcode](gb, opcode); opcodes[opcode](gb, opcode);
} }
else { else {