Skip to content

Commit

Permalink
gb: fix infinite loop on infinite halt
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
deltabeard committed Jan 17, 2025
1 parent 3b8fde4 commit 1fbf964
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions peanut_gb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1fbf964

Please sign in to comment.