From 1fbf964aa8e3f1e8b6a55c877974da8d53c2caf7 Mon Sep 17 00:00:00 2001 From: Mahyar Koshkouei Date: Fri, 17 Jan 2025 19:49:49 +0000 Subject: [PATCH] gb: fix infinite loop on infinite halt Fixes issue #83 whereby the Game Boy may be placed into HALT mode indefinitely, which is a valid state to be in (e.g. when Dragon Quest III puts a message on the screen forever). Peanut-GB now returns on each VBLANK (which means after rendering each frame), to allow the emulation to continue. Signed-off-by: Mahyar Koshkouei --- peanut_gb.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/peanut_gb.h b/peanut_gb.h index 92707d7..2e6a166 100644 --- a/peanut_gb.h +++ b/peanut_gb.h @@ -2412,15 +2412,6 @@ void __gb_step_cpu(struct gb_s *gb) /* TODO: Emulate HALT bug? */ gb->gb_halt = true; - if (gb->hram_io[IO_IE] == 0) - { - /* Return program counter where this halt forever state started. */ - /* This may be intentional, but this is required to stop an infinite - * loop. */ - (gb->gb_error)(gb, GB_HALT_FOREVER, gb->cpu_reg.pc.reg - 1); - PGB_UNREACHABLE(); - } - if(gb->hram_io[IO_SC] & SERIAL_SC_TX_START) { int serial_cycles = SERIAL_CYCLES - @@ -3410,6 +3401,9 @@ void __gb_step_cpu(struct gb_s *gb) !gb->display.interlace_count; } #endif + /* If halted forever, then return on VBLANK. */ + if(gb->gb_halt && !gb->hram_io[IO_IE]) + break; } /* Normal Line */ else if(gb->hram_io[IO_LY] < LCD_HEIGHT)