From 2b60a1e0a74fee170c59a9fb490f2c705c31e61c Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sun, 4 Jun 2017 19:05:14 +0100 Subject: [PATCH] Pass Ctrl-C to the emulator. Use F2 to leave. Signed-off-by: Andrea Odetti --- source/frontends/ncurses/main.cpp | 20 ++++++++++++++++---- source/frontends/ncurses/world.cpp | 20 +++++++++++++++++--- source/frontends/ncurses/world.h | 3 ++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/source/frontends/ncurses/main.cpp b/source/frontends/ncurses/main.cpp index 0cc67365..0fbde15e 100644 --- a/source/frontends/ncurses/main.cpp +++ b/source/frontends/ncurses/main.cpp @@ -14,8 +14,9 @@ #include "Video.h" #include "frontends/ncurses/world.h" +#include "ncurses.h" -static void ContinueExecution() +static bool ContinueExecution() { const auto start = std::chrono::steady_clock::now(); @@ -37,7 +38,14 @@ static void ContinueExecution() DiskUpdatePosition(uActualCyclesExecuted); - ProcessKeyboard(); + const int key = ProcessKeyboard(); + + switch (key) + { + case KEY_F(2): + return false; + } + if (g_dwCyclesThisFrame >= dwClksPerFrame) { g_dwCyclesThisFrame -= dwClksPerFrame; @@ -55,13 +63,14 @@ static void ContinueExecution() usleep(nExecutionPeriodUsec - ms); } } + + return true; } void EnterMessageLoop() { - while (true) + while (ContinueExecution()) { - ContinueExecution(); } } @@ -126,6 +135,9 @@ void foo(int argc, const char * argv []) EnterMessageLoop(); } while (g_bRestart); + + VideoUninitialize(); + } int main(int argc, const char * argv []) diff --git a/source/frontends/ncurses/world.cpp b/source/frontends/ncurses/world.cpp index 625737b2..6a05befc 100644 --- a/source/frontends/ncurses/world.cpp +++ b/source/frontends/ncurses/world.cpp @@ -62,8 +62,11 @@ namespace void sig_handler(int signo) { - endwin(); - exit(1); + // Ctrl-C + // is there a race condition here? + // is it a problem? + nextKey = 0x83; + keyReady = true; } chtype mapCharacter(BYTE ch) @@ -358,6 +361,11 @@ void VideoInitialize() signal(SIGINT, sig_handler); } +void VideoUninitialize() +{ + endwin(); +} + void VideoRedrawScreen() { @@ -419,7 +427,7 @@ void VideoRedrawScreen() wrefresh(frame->getWindow()); } -void ProcessKeyboard() +int ProcessKeyboard() { const int inch = wgetch(frame->getWindow()); @@ -474,6 +482,12 @@ void ProcessKeyboard() { nextKey = ch | 0x80; keyReady = true; + return ERR; + } + else + { + // pass it back + return inch; } } diff --git a/source/frontends/ncurses/world.h b/source/frontends/ncurses/world.h index 6acabebc..d6413ff8 100644 --- a/source/frontends/ncurses/world.h +++ b/source/frontends/ncurses/world.h @@ -1,5 +1,6 @@ #pragma once -void ProcessKeyboard(); +int ProcessKeyboard(); void VideoInitialize(); +void VideoUninitialize(); void VideoRedrawScreen();