summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nandgame/cpp/CMakeLists.txt5
-rw-r--r--nandgame/cpp/simpc_config.h2
-rw-r--r--nandgame/cpp/simpc_term.cpp93
-rw-r--r--nandgame/cpp/simpc_ui.cpp18
4 files changed, 99 insertions, 19 deletions
diff --git a/nandgame/cpp/CMakeLists.txt b/nandgame/cpp/CMakeLists.txt
index 533b439..99318c1 100644
--- a/nandgame/cpp/CMakeLists.txt
+++ b/nandgame/cpp/CMakeLists.txt
@@ -31,7 +31,7 @@ else()
message(STATUS "FLTK library was not found.")
endif()
-add_executable(Vcomputer Vcomputer__main.cpp disas.cpp simpc_ui.cpp)
+add_executable(Vcomputer Vcomputer__main.cpp disas.cpp )
verilate(Vcomputer
SOURCES ../computer.sv
TOP_MODULE computer
@@ -43,4 +43,7 @@ verilate(Vcomputer
if (USE_NCURSES)
target_compile_definitions(Vcomputer PRIVATE NCUR)
target_link_libraries(Vcomputer PRIVATE Curses::Curses)
+ target_sources(Vcomputer PUBLIC simpc_ui.cpp)
+else()
+ target_sources(Vcomputer PUBLIC simpc_term.cpp)
endif()
diff --git a/nandgame/cpp/simpc_config.h b/nandgame/cpp/simpc_config.h
index 8759c2e..39ad7b5 100644
--- a/nandgame/cpp/simpc_config.h
+++ b/nandgame/cpp/simpc_config.h
@@ -1,4 +1,4 @@
#pragma once
#define TICKS_PER_INS 2
-#define NCUR_DELAY_MS 100
+#define NCUR_DELAY_MS 10
diff --git a/nandgame/cpp/simpc_term.cpp b/nandgame/cpp/simpc_term.cpp
new file mode 100644
index 0000000..4db7266
--- /dev/null
+++ b/nandgame/cpp/simpc_term.cpp
@@ -0,0 +1,93 @@
+#include "simpc_ui.h"
+
+#include "disas.h"
+
+#define NCUR_X 5
+#define attroff(...)
+#define attron(...)
+#define PRINT_ME(y, x, ...) \
+ { \
+ printf("%*c", x, ' '); \
+ printf(__VA_ARGS__); \
+ printf("\n"); \
+ }
+#define PRINT_ME_W(w, y, x, ...) \
+ { \
+ printf("%*c", x, ' '); \
+ printf(__VA_ARGS__); \
+ printf("\n"); \
+ }
+#define PRINT_NEXT() \
+ { puts("-----"); }
+
+
+#include "Vcomputer.h"
+#include "Vcomputer___024root.h"
+#include "Vcomputer_computer.h"
+#include "verilated.h"
+#include <cstdint>
+#include <cstdio>
+#include <sched.h>
+
+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;
+
+ PRINT_ME_W(status_top, 0, 0, "Step: %10lu \b%c", i,
+ sp == StepPosition_t::BEFORE_EVAL ? 'A' : 'B');
+ PRINT_ME_W(status_top, 1, 0, "%-20s", paused ? "Paused" : "Running");
+
+ PRINT_ME(3, NCUR_X, "CLK1: %4d\tPC: @0x%04X\tINS: 0x%04X\tHLT: %d",
+ topp->clk_in,
+ // wrong
+ // topp->computer->clk_in,
+ topp->computer->PC_addr_int, opcode, topp->halt);
+
+ auto insline = print_decoded(opcode, true);
+ PRINT_ME(5, NCUR_X, "%-80s", insline.c_str());
+
+ PRINT_ME(7, NCUR_X, "A: 0x%04X\tD: 0x%04X\tM: 0x%04X\tRES: 0x%04X",
+ topp->computer->reg_A_int, topp->computer->reg_D_int,
+ topp->computer->reg_pA_int, topp->computer->result_int);
+ PRINT_ME(
+ 8, NCUR_X, "%c%8d\t%c%8d\t%c%8d\t%11d",
+ topp->computer->store_to_A_int ? '*' : ' ', topp->computer->reg_A_int,
+ topp->computer->store_to_D_int ? '*' : ' ', topp->computer->reg_D_int,
+ topp->computer->store_to_pA_int ? '*' : ' ', topp->computer->reg_pA_int,
+ topp->computer->result_int);
+
+ PRINT_NEXT();
+}
+
+void simpc_ui_finish_message(const std::unique_ptr<VerilatedContext> &contextp,
+ const std::unique_ptr<Vcomputer> &topp) {
+ attron(A_BOLD);
+ auto xpos = 20;
+ PRINT_ME_W(status_top, 0, xpos, "Simulation finished.");
+ const char *msg;
+ if (topp->halt) {
+ msg = "Halt encountered.";
+ } else if (!contextp->gotFinish()) {
+ msg = "Step count exceeded.";
+ } else {
+ msg = "Regular finish.";
+ }
+ PRINT_ME_W(status_top, 1, xpos, "%s", msg);
+
+ attroff(A_BOLD);
+}
+
+void simpc_ui_init(void) {
+}
+
+void simpc_ui_cleanup(void) {
+
+}
+
+void simpc_ui_confirm_finish(void) {
+
+}
diff --git a/nandgame/cpp/simpc_ui.cpp b/nandgame/cpp/simpc_ui.cpp
index 5b7591e..53e9b06 100644
--- a/nandgame/cpp/simpc_ui.cpp
+++ b/nandgame/cpp/simpc_ui.cpp
@@ -6,7 +6,6 @@
#define NCUR_X 5
#define MEMORY_CONTEXT 3
-#if NCUR
#include <ncurses.h>
#define PRINT_ME(y, x, ...) \
@@ -17,6 +16,7 @@
{ \
refresh(); \
napms(NCUR_DELAY_MS); \
+ wrefresh(status_top); \
}
#define SIMPLE_BORDER(w, lr, tb, c) \
@@ -24,21 +24,6 @@
static WINDOW *status_top = NULL;
-#else
-
-#define attroff(...)
-#define attron(...)
-#define PRINT_ME(y, x, ...) \
- { \
- printf("%*c", x, ' '); \
- printf(__VA_ARGS__); \
- printf("\n"); \
- }
-#define PRINT_NEXT() \
- { puts("-----"); }
-
-#endif
-
#include "Vcomputer.h"
#include "Vcomputer___024root.h"
#include "Vcomputer_comb_mem.h"
@@ -60,7 +45,6 @@ void simpc_ui_write(const std::unique_ptr<Vcomputer> &topp, uint64_t &i,
PRINT_ME_W(status_top, 0, 0, "Step: %10lu \b%c", i,
sp == StepPosition_t::BEFORE_EVAL ? 'A' : 'B');
PRINT_ME_W(status_top, 1, 0, "%-20s", paused ? "Paused" : "Running");
- wrefresh(status_top);
PRINT_ME(3, NCUR_X, "CLK1: %4d\tPC: @0x%04X\tINS: 0x%04X\tHLT: %d",
topp->clk_in,