From d1b556c5c56a79487209a304733628e53db6d56a Mon Sep 17 00:00:00 2001 From: David Schmidt <1110325+david-schmidt@users.noreply.github.com> Date: Wed, 19 Aug 2020 15:24:31 -0400 Subject: [PATCH] Fix from Kent Dickey on the WAI instruction Fantavision hangs when it starts on KEGS-based emulators (which includes GSport and GSplus) due to a bug in the way KEGS handles the WAI instruction. Fantavision masks interrupts with SEI, sets a SHR line interrupt, and then does a WAI instruction. This hangs KEGS since it expects an actual interrupt to end the WAI, but there won't be one since interrupts are masked. I never realized this was a valid WAI use case. The fix is easy. In `instable.h`, change: ``` instcb_SYM /* WAI */ g_wait_pending = 1; CYCLES_FINISH ``` (There may be some stale #ifdef ASM code, just ignore that) to: ``` instcb_SYM /* WAI */ if(g_irq_pending) { g_wait_pending = 0; INC_KPC_1; } else { g_wait_pending = 1; } ``` Kent --- src/instable.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/instable.h b/src/instable.h index d78db63..3f9a835 100644 --- a/src/instable.h +++ b/src/instable.h @@ -1,6 +1,6 @@ /* GSport - an Apple //gs Emulator - Copyright (C) 2010 by GSport contributors + Copyright (C) 2010 - 2020 by GSport contributors Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey @@ -2231,8 +2231,12 @@ instcb_SYM /* WAI */ b dispatch stw scratch2,r%g_wait_pending(scratch1) #else - g_wait_pending = 1; - CYCLES_FINISH + if(g_irq_pending) { + g_wait_pending = 0; + INC_KPC_1; + } else { + g_wait_pending = 1; + } #endif instcc_SYM /* CPY abs */