From 4d78cf157bd14755bcc39520d523a6d21a56966a Mon Sep 17 00:00:00 2001 From: uvok Date: Sun, 11 Jan 2026 11:17:13 +0100 Subject: Add paused state, print help fix separate "wait for feedback" --- nandgame/cpp/Vcomputer__main.cpp | 1 + nandgame/cpp/simpc_ui.cpp | 30 ++++++++++++++++++++++++++---- nandgame/cpp/simpc_ui.h | 6 ++++-- 3 files changed, 31 insertions(+), 6 deletions(-) (limited to 'nandgame') diff --git a/nandgame/cpp/Vcomputer__main.cpp b/nandgame/cpp/Vcomputer__main.cpp index ec9eb31..cc0f7c0 100644 --- a/nandgame/cpp/Vcomputer__main.cpp +++ b/nandgame/cpp/Vcomputer__main.cpp @@ -94,6 +94,7 @@ int main(int argc, char **argv, char **) { // Print statistical summary report // contextp->statsPrintSummary(); + simpc_ui_confirm_finish(); simpc_ui_cleanup(); return 0; diff --git a/nandgame/cpp/simpc_ui.cpp b/nandgame/cpp/simpc_ui.cpp index 44d3424..e3435bc 100644 --- a/nandgame/cpp/simpc_ui.cpp +++ b/nandgame/cpp/simpc_ui.cpp @@ -42,12 +42,15 @@ #include #include +bool paused = false; + void simpc_ui_write(const std::unique_ptr &topp, int &i, - StepPosition_t sp) { + StepPosition_t sp) { uint16_t opcode = topp->computer->PC_content_int; PRINT_ME(1, 1, "Step: %10d \b%c", i, sp == StepPosition_t::BEFORE_EVAL ? 'A' : 'B'); + PRINT_ME(2, 1, "%-20s", paused ? "Paused" : "Running"); PRINT_ME(1 + NCUR_OFFSET, NCUR_X, "CLK1: %4d\tPC: @0x%04X\tINS: 0x%04X\tHLT: %d", topp->clk_in, // wrong @@ -72,13 +75,24 @@ void simpc_ui_write(const std::unique_ptr &topp, int &i, PRINT_ME(7 + NCUR_OFFSET, NCUR_X, "ALU"); PRINT_ME(8 + NCUR_OFFSET, NCUR_X, "X: %5" PRId16 "\tY: %5" PRId16, topp->computer->CPU->my_alu->int_op_x, - topp->computer->CPU->my_alu->int_op_y) + topp->computer->CPU->my_alu->int_op_y); + PRINT_ME(getmaxy(stdscr) - 1, 1, "q - Quit; p - (Un)pause; any key in pause - step"); + PRINT_NEXT(); + + int ch = getch(); + if (ch == 'p') { + nodelay(stdscr, paused); + paused = !paused; + } else if (ch == 'q') { + simpc_ui_cleanup(); + exit(0); + } } void simpc_ui_finish_message(const std::unique_ptr &contextp, - const std::unique_ptr &topp) { + const std::unique_ptr &topp) { #if NCUR refresh(); #endif @@ -96,12 +110,20 @@ void simpc_ui_init(void) { #if NCUR initscr(); curs_set(0); + nodelay(stdscr, TRUE); + noecho(); #endif } void simpc_ui_cleanup(void) { #if NCUR - getch(); endwin(); #endif } + +void simpc_ui_confirm_finish(void) { +#if NCUR + nodelay(stdscr, FALSE); + getch(); +#endif +} \ No newline at end of file diff --git a/nandgame/cpp/simpc_ui.h b/nandgame/cpp/simpc_ui.h index 3312b64..4a990a6 100644 --- a/nandgame/cpp/simpc_ui.h +++ b/nandgame/cpp/simpc_ui.h @@ -6,7 +6,9 @@ #include void simpc_ui_init(void); -void simpc_ui_write(const std::unique_ptr &topp, int &i, StepPosition_t sp); +void simpc_ui_write(const std::unique_ptr &topp, int &i, + StepPosition_t sp); void simpc_ui_finish_message(const std::unique_ptr &contextp, - const std::unique_ptr &topp); + const std::unique_ptr &topp); +void simpc_ui_confirm_finish(void); void simpc_ui_cleanup(void); -- cgit v1.2.3