summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok2026-01-11 14:06:24 +0100
committeruvok2026-01-11 14:06:24 +0100
commit7d9445b85cf129a9c3a7b6fd21d7cf414c0f0a52 (patch)
tree32328f7bb24f513203f4ee66325ed0451436f11d
parent746b2167f573f6a32c3b06adafc72ba9122d192e (diff)
key handling, print finish in bold
-rw-r--r--nandgame/cpp/simpc_config.h1
-rw-r--r--nandgame/cpp/simpc_ui.cpp46
2 files changed, 36 insertions, 11 deletions
diff --git a/nandgame/cpp/simpc_config.h b/nandgame/cpp/simpc_config.h
index 6e35517..8759c2e 100644
--- a/nandgame/cpp/simpc_config.h
+++ b/nandgame/cpp/simpc_config.h
@@ -1,3 +1,4 @@
#pragma once
#define TICKS_PER_INS 2
+#define NCUR_DELAY_MS 100
diff --git a/nandgame/cpp/simpc_ui.cpp b/nandgame/cpp/simpc_ui.cpp
index b7971fb..8f48554 100644
--- a/nandgame/cpp/simpc_ui.cpp
+++ b/nandgame/cpp/simpc_ui.cpp
@@ -1,4 +1,5 @@
#include "simpc_ui.h"
+#include "simpc_config.h"
#define NCUR 1
#include "disas.h"
@@ -8,7 +9,6 @@
#if NCUR
#include <ncurses.h>
-#define NCUR_DELAY_MS 100
#define PRINT_ME(y, x, ...) \
{ mvprintw(y, x, __VA_ARGS__); }
@@ -20,6 +20,8 @@
#else
+#define attroff(...)
+#define attron(...)
#define PRINT_ME(y, x, ...) \
{ \
printf("%*c", x, ' '); \
@@ -43,6 +45,8 @@
bool paused = false;
+static void handle_key();
+
void simpc_ui_write(const std::unique_ptr<Vcomputer> &topp, uint64_t &i,
StepPosition_t sp) {
uint16_t opcode = topp->computer->PC_content_int;
@@ -116,22 +120,16 @@ void simpc_ui_write(const std::unique_ptr<Vcomputer> &topp, uint64_t &i,
// topp->computer->CPU->my_alu->int_op_y);
PRINT_ME(getmaxy(stdscr) - 1, 1,
- "q - Quit; p - (Un)pause; any key in pause - step");
+ "q - Quit; p - (Un)pause; s - step (while paused)");
PRINT_NEXT();
- int ch = getch();
- if (ch == 'p') {
- nodelay(stdscr, paused);
- paused = !paused;
- } else if (ch == 'q') {
- simpc_ui_cleanup();
- exit(0);
- }
+ handle_key();
}
void simpc_ui_finish_message(const std::unique_ptr<VerilatedContext> &contextp,
const std::unique_ptr<Vcomputer> &topp) {
+ attron(A_BOLD);
PRINT_ME(1, 30, "Simulation finished.");
const char *msg;
if (topp->halt) {
@@ -145,6 +143,7 @@ void simpc_ui_finish_message(const std::unique_ptr<VerilatedContext> &contextp,
#if NCUR
refresh();
#endif
+ attroff(A_BOLD);
}
void simpc_ui_init(void) {
@@ -170,4 +169,29 @@ void simpc_ui_confirm_finish(void) {
nodelay(stdscr, FALSE);
getch();
#endif
-} \ No newline at end of file
+}
+
+static void handle_key() {
+ bool block_here = paused;
+
+ do {
+ int ch = getch();
+
+ switch (ch) {
+ case 'p':
+ // pass *current* state.
+ // pass false (currently running) - getch will block (entering step mode).
+ // pass true (currently paused) - getch will be non-blocking.
+ nodelay(stdscr, paused);
+ paused = !paused;
+ break;
+ case 'q':
+ simpc_ui_cleanup();
+ exit(0);
+ break;
+ case 's':
+ block_here = false;
+ break;
+ }
+ } while (block_here);
+}