From f04928432487bfdea7085e21861f624e531143d3 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 20 Sep 2016 01:22:21 +0300 Subject: [PATCH] Emulate the HALT bug on a DMG --- Core/z80_cpu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Core/z80_cpu.c b/Core/z80_cpu.c index 2ea16d3..6db9007 100644 --- a/Core/z80_cpu.c +++ b/Core/z80_cpu.c @@ -1333,7 +1333,10 @@ void GB_cpu_run(GB_gameboy_t *gb) { gb->vblank_just_occured = false; bool interrupt = gb->interrupt_enable & gb->io_registers[GB_IO_IF]; + bool halt_bug = false; + if (interrupt) { + halt_bug = gb->halted && !gb->is_cgb; /* Todo: Does this bug happen on a CGB? */ gb->halted = false; } @@ -1363,6 +1366,9 @@ void GB_cpu_run(GB_gameboy_t *gb) } else if(!gb->halted && !gb->stopped) { uint8_t opcode = GB_read_memory(gb, gb->pc++); + if (halt_bug) { + gb->pc--; + } opcodes[opcode](gb, opcode); } else {