summaryrefslogtreecommitdiff
path: root/nandgame
diff options
context:
space:
mode:
authoruvok2026-01-10 20:35:59 +0100
committeruvok2026-01-10 20:35:59 +0100
commitd12e166f991c9bdebc9c2eea3a7cdf60bcbdb439 (patch)
tree5e5a2aac88a15cb02b088fca00c563ee4a18ab73 /nandgame
parentcd8997b778e5762d3e1f70608a7efd6bc8363df7 (diff)
Redesign UI, add program content
also, stop program in while loop header
Diffstat (limited to 'nandgame')
-rw-r--r--nandgame/Vcomputer__main.cpp48
1 files changed, 29 insertions, 19 deletions
diff --git a/nandgame/Vcomputer__main.cpp b/nandgame/Vcomputer__main.cpp
index a22d09c..4ca2029 100644
--- a/nandgame/Vcomputer__main.cpp
+++ b/nandgame/Vcomputer__main.cpp
@@ -17,12 +17,11 @@
#define NCUR 1
#include "../assembler/disas.h"
-#define NCUR_OFFSET 3
#define NCUR_X 5
#if NCUR
#include <ncurses.h>
-#define NCUR_DELAY_MS 100
+#define NCUR_DELAY_MS 10
#define PRINT_ME(y, x, ...) \
{ \
@@ -59,25 +58,35 @@ void draw_ui(const std::unique_ptr<Vcomputer> &topp, uint64_t &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,
+ 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(3 + NCUR_OFFSET, NCUR_X, "%-80s", insline.c_str());
+ PRINT_ME(5, NCUR_X, "%-80s", insline.c_str());
- PRINT_ME(5 + NCUR_OFFSET, NCUR_X,
- "A: 0x%04X\tD: 0x%04X\tM: 0x%04X\tRES: 0x%04X",
+ 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(
- 6 + NCUR_OFFSET, NCUR_X, "%c%8d\t%c%8d\t%c%8d\t%11d",
+ 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_ME(10, NCUR_X, "--- ROM ---");
+ for (int i = -1; i <= 1; i++) {
+ const char *prefix = i == 0 ? "> " : " ";
+ uint16_t curadr = topp->computer->PC_addr_int + i;
+ const uint16_t p = curadr;
+ const uint16_t program_op_code = topp->computer->ROM->r_datastore[p];
+ auto disas_code = print_decoded(program_op_code, true);
+ PRINT_ME(12 + i, NCUR_X, "%04X %s%04X %-30s", curadr, prefix,
+ program_op_code, disas_code.c_str());
+ }
// PRINT_ME(7 + NCUR_OFFSET, NCUR_X, "ALU");
// PRINT_ME(8 + NCUR_OFFSET, NCUR_X, "X: %5d\tY: %5d",
// topp->computer->CPU->my_alu->int_op_x,
@@ -126,7 +135,8 @@ int main(int argc, char **argv, char **) {
curs_set(0);
#endif
- while (VL_LIKELY(!contextp->gotFinish()) && contextp->time() < 500) {
+ while (VL_LIKELY(!contextp->gotFinish()) && contextp->time() < 500 &&
+ !topp->halt) {
auto i = contextp->time();
draw_ui(topp, i, StepPosition_t::BEFORE_EVAL);
@@ -136,13 +146,9 @@ int main(int argc, char **argv, char **) {
}
topp->eval();
- // both bits 14 and 15 need to be set
- if (topp->halt)
- break;
-
- draw_ui(topp, i, StepPosition_t::AFTER_EVAL);
+ draw_ui(topp, i, StepPosition_t::AFTER_EVAL);
- // Advance time
+ // Advance time
contextp->timeInc(1);
}
@@ -150,14 +156,18 @@ int main(int argc, char **argv, char **) {
refresh();
#endif
- PRINT_ME(10 + NCUR_OFFSET, 10, "Simulation finished.");
+ // PRINT_ME(9, 0, "%80c", ' ');
+ PRINT_ME(1, 30, "Simulation finished.");
+ const char *msg;
if (topp->halt) {
- PRINT_ME(11 + NCUR_OFFSET, 10, "Halt encountered.");
+ msg = "Halt encountered.";
} else if (!contextp->gotFinish()) {
- PRINT_ME(11 + NCUR_OFFSET, 10, "Step count exceeded.");
+ msg = "Step count exceeded.";
} else {
- PRINT_ME(11 + NCUR_OFFSET, 10, "Regular finish.");
+ msg = "Regular finish.";
}
+ PRINT_ME(2, 30, "%s", msg);
+ // PRINT_ME(12, 0, "%80c", ' ');
if (VL_LIKELY(!contextp->gotFinish())) {
VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n"););