summaryrefslogtreecommitdiff
path: root/nandgame/Vcomputer__main.cpp
diff options
context:
space:
mode:
authoruvok2026-01-10 12:18:49 +0100
committeruvok2026-01-10 12:18:49 +0100
commit35b2bd8bea29a6c3f1361e98a35ff4230af75880 (patch)
tree9f9acf03eb54ca01c876abdeeb7d2aab4384e9ef /nandgame/Vcomputer__main.cpp
parentea6eec53186633beb6713583f133f8207f40fd43 (diff)
sim: Properly display results
since halt somehow erases everything directly at the falling egde (WTF?), make two ticks per instructions, and display before and after eval.
Diffstat (limited to 'nandgame/Vcomputer__main.cpp')
-rw-r--r--nandgame/Vcomputer__main.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/nandgame/Vcomputer__main.cpp b/nandgame/Vcomputer__main.cpp
index 5a1b803..21fbf21 100644
--- a/nandgame/Vcomputer__main.cpp
+++ b/nandgame/Vcomputer__main.cpp
@@ -13,6 +13,7 @@
#include <cstdio>
#include <sched.h>
+#define TICKS_PER_INS 2
#define NCUR 1
#include "../assembler/disas.h"
@@ -20,7 +21,7 @@
#if NCUR
#include <ncurses.h>
-#define NCUR_DELAY_MS 300
+#define NCUR_DELAY_MS 100
#define NCUR_X 5
#define PRINT_ME(x, y, ...) { mvprintw(x, y, __VA_ARGS__); }
@@ -35,10 +36,15 @@
//======================
-void draw_ui(const std::unique_ptr<Vcomputer> &topp, int &i) {
+enum class StepPosition_t {
+ BEFORE_EVAL,
+ AFTER_EVAL
+};
+
+void draw_ui(const std::unique_ptr<Vcomputer> &topp, int &i, StepPosition_t sp) {
uint16_t opcode = topp->computer->PC_content_int;
- PRINT_ME(1, 1, "Step: %10d", i);
+ PRINT_ME(1, 1, "Step: %10d \b%c", i, sp == StepPosition_t::BEFORE_EVAL ? 'A' : 'B');
PRINT_ME(1 + NCUR_OFFSET, NCUR_X, "CLK1: %4d\tPC: @0x%04X\tINS: 0x%04X\tHLT: %d",
topp->clk_in,
// wrong
@@ -112,13 +118,19 @@ int main(int argc, char **argv, char **) {
#endif
while (VL_LIKELY(!contextp->gotFinish()) && i < 500) {
- //topp->computer->clk_in = ~topp->computer->clk_in;
- topp->clk_in = !topp->clk_in;
+ // doesn't work.
+ // topp->computer->clk_in = ~topp->computer->clk_in;
+
+ if (i != 0 && (i % TICKS_PER_INS) == 0) {
+ topp->clk_in = !topp->clk_in;
+ }
+
+ draw_ui(topp, i, StepPosition_t::BEFORE_EVAL);
// Evaluate model
topp->eval();
- draw_ui(topp, i);
+ draw_ui(topp, i, StepPosition_t::AFTER_EVAL);
// both bits 14 and 15 need to be set
uint16_t opcode = topp->computer->PC_content_int;
@@ -130,7 +142,18 @@ int main(int argc, char **argv, char **) {
i++;
}
+#if NCUR
+ refresh();
+#endif
+
PRINT_ME(10 + NCUR_OFFSET, 10, "Simulation finished.");
+ if (topp->halt) {
+ PRINT_ME(11 + NCUR_OFFSET, 10, "Halt encountered.");
+ } else if (!contextp->gotFinish()) {
+ PRINT_ME(11 + NCUR_OFFSET, 10, "Step count exceeded.");
+ } else {
+ PRINT_ME(11 + NCUR_OFFSET, 10, "Regular finish.");
+ }
if (VL_LIKELY(!contextp->gotFinish())) {
VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n"););