diff --git a/Source/Emulator/io.c b/Source/Emulator/io.c index 679b8ab..a821816 100644 --- a/Source/Emulator/io.c +++ b/Source/Emulator/io.c @@ -643,6 +643,10 @@ void consoleResetInput(void) { clearInterrupt(PORT_CONSOLE); } +int resetIsPending(void) { + return resetWanted; +} + int takeResetRequest(void) { int wanted = resetWanted; resetWanted = 0; diff --git a/Source/Emulator/io.h b/Source/Emulator/io.h index 68047ee..98dfb35 100644 --- a/Source/Emulator/io.h +++ b/Source/Emulator/io.h @@ -306,6 +306,10 @@ void serviceDevices(void); // the instruction that asked - the CPU is mid-step and its state is not yet consistent. int takeResetRequest(void); +// Whether one is waiting, without taking it. For anything that has to behave differently +// while a restart is on its way but is not the thing that performs it. +int resetIsPending(void); + // ---- The button on the front of the case ---- // // A machine has one, and a window is the case. Writing MACHINE_RESET is how a PROGRAM asks; diff --git a/Source/Emulator/voyager.c b/Source/Emulator/voyager.c index 44f4779..5b6fd0a 100644 --- a/Source/Emulator/voyager.c +++ b/Source/Emulator/voyager.c @@ -173,16 +173,11 @@ static void drainKeyboard(void) { // a bare metal program escapable - Once puts a demo in front of the next start and deletes // the request before jumping, so a demo that has taken the whole machine is one gesture from // the system coming back, rather than closing the window and opening it again. -static int resetPending = 0; - static void checkResetButton(void) { const int control = IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL); const int shift = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT); if (control && shift && IsKeyPressed(KEY_R)) { requestReset(); - // Remembered as well as asked for, so that a machine waiting on a key can be woken - // to go and notice it. See voyagerKey. - resetPending = 1; } } @@ -249,8 +244,13 @@ static int voyagerKey(int mayWait) { // // So the wait ends. The console treats that as the end of input, which it is for the // machine that is about to stop existing, and the reset puts the console's input back. - if (resetPending) { - resetPending = 0; + // + // ASKED OF THE REQUEST ITSELF rather than remembered here. A flag of its own outlived + // the reset it belonged to: a program that never read the console - picture.bin, say, + // which draws and halts - left it set, and the NEXT machine's first read came back as + // the end of input. CosmOS booted and stopped immediately, having been told there was + // nobody there. There is one fact and it lives in one place. + if (resetIsPending()) { return CONSOLE_GONE; } // Whatever is already waiting, however long ago it was typed. This is the answer to