summaryrefslogtreecommitdiff
path: root/nandgame/Vcomputer__main.cpp
diff options
context:
space:
mode:
authoruvok2026-01-08 19:41:49 +0100
committeruvok2026-01-08 19:41:49 +0100
commit7b06a9a40f2f951ace9f66740ab78fcb2dcff081 (patch)
treebbee6ab9877dc4e583f68a60e109b6ab4b4ff89c /nandgame/Vcomputer__main.cpp
parent70c3bd1af18d5ff24e8ad5d2a7a07b3088ecc86d (diff)
nandgame: ncurses interface
Diffstat (limited to 'nandgame/Vcomputer__main.cpp')
-rw-r--r--nandgame/Vcomputer__main.cpp62
1 files changed, 54 insertions, 8 deletions
diff --git a/nandgame/Vcomputer__main.cpp b/nandgame/Vcomputer__main.cpp
index 79137c6..5c3cd1e 100644
--- a/nandgame/Vcomputer__main.cpp
+++ b/nandgame/Vcomputer__main.cpp
@@ -11,11 +11,18 @@
#include <cstdio>
#include <sched.h>
+#define NCUR 1
#include "../assembler/disas.h"
+#if NCUR
+#include <ncurses.h>
+#define NCUR_DELAY_MS 300
+#endif
+
//======================
int main(int argc, char** argv, char**) {
+
// Setup context, defaults, and parse command line
Verilated::debug(0);
const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
@@ -53,13 +60,26 @@ int main(int argc, char** argv, char**) {
exit(-1);
}
+#if NCUR
+ initscr();
+#endif
+
+ int ncur_offset = 3;
while (VL_LIKELY(!contextp->gotFinish()) && i < 100) {
//topp->computer->clk_in = ~topp->computer->clk_in;
topp->clk_in = !topp->clk_in;
//uint16_t opcode = (topp->computer->PC_content_int & 0xff) << 8 | (topp->computer->PC_content_int >> 8);
uint16_t opcode = topp->computer->PC_content_int;
+#if NCUR
+ mvprintw(1, 1, "Step: %10d", i);
+#endif
+
+#if NCUR
+ mvprintw(1 + ncur_offset, 1,
+#else
printf(
- "CLK1: %4d, CLK2: %4d, PC: @0x%04X, INS: 0x%04X\n",
+#endif
+ "CLK1: %4d\tCLK2: %4d\tPC: @0x%04X\tINS: 0x%04X\n",
topp->clk_in,
topp->computer->clk_in,
topp->computer->PC_addr_int,
@@ -86,20 +106,32 @@ int main(int argc, char** argv, char**) {
#else
{
auto insline = print_decoded(opcode, true);
- printf(" %s\n", insline.c_str());
+#if NCUR
+ mvprintw(3 + ncur_offset, 5, "%s",
+#else
+ printf(" %s\n",
+#endif
+ insline.c_str());
}
#endif
-
- printf(
- " A: 0x%04X, D: 0x%04X, M: 0x%04X, RES: 0x%04X\n",
+#if NCUR
+ mvprintw(5 + ncur_offset, 5,
+#else
+ printf(" "
+#endif
+ "A: 0x%04X\tD: 0x%04X\tM: 0x%04X\tRES: 0x%04X\n",
topp->computer->reg_A_int,
topp->computer->reg_D_int,
topp->computer->reg_pA_int,
topp->computer->result_int
);
- printf(
- " A: %5" PRId16 ", D: %5" PRId16 ", M: %5" PRId16 ", RES: %5" PRId16 "\n",
+#if NCUR
+ mvprintw(6 + ncur_offset, 5,
+#else
+ printf(" "
+#endif
+ "A: %6" PRId16 "\tD: %6" PRId16 "\tM: %6" PRId16 "\tRES: %6" PRId16 "\n",
topp->computer->reg_A_int,
topp->computer->reg_D_int,
topp->computer->reg_pA_int,
@@ -110,9 +142,19 @@ int main(int argc, char** argv, char**) {
// Advance time
contextp->timeInc(1);
i++;
+#if NCUR
+ refresh(); napms(NCUR_DELAY_MS);
+#else
puts("-----");
+#endif
}
- puts("Simulation finished");
+
+#if NCUR
+ mvprintw(10 + ncur_offset, 10,
+#else
+ puts(
+#endif
+ "Simulation finished");
if (VL_LIKELY(!contextp->gotFinish())) {
VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n"););
@@ -124,5 +166,9 @@ int main(int argc, char** argv, char**) {
// Print statistical summary report
//contextp->statsPrintSummary();
+#if NCUR
+ getch(); endwin();
+#endif
+
return 0;
}