From e583d4747a1a37bd900dc49c7006bbb4c3ec2ab9 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 15:36:19 +0100 Subject: reformatcomputer, get rid of i --- nandgame/Vcomputer__main.cpp | 130 +++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/nandgame/Vcomputer__main.cpp b/nandgame/Vcomputer__main.cpp index 26d8aa6..8a2c094 100644 --- a/nandgame/Vcomputer__main.cpp +++ b/nandgame/Vcomputer__main.cpp @@ -1,13 +1,13 @@ // Verilated -*- C++ -*- // DESCRIPTION: Verilator output: main() simulation loop, created with --main +#include "Vcomputer.h" #include "Vcomputer___024root.h" #include "Vcomputer_alu.h" #include "Vcomputer_computer.h" #include "Vcomputer_instruction_decode.h" #include "Vcomputer_my_mem__D10_DB10000.h" #include "verilated.h" -#include "Vcomputer.h" #include #include #include @@ -24,34 +24,46 @@ #define NCUR_DELAY_MS 100 #define NCUR_X 5 -#define PRINT_ME(x, y, ...) { mvprintw(x, y, __VA_ARGS__); } -#define PRINT_NEXT() { refresh(); napms(NCUR_DELAY_MS); } +#define PRINT_ME(x, y, ...) \ + { \ + mvprintw(x, y, __VA_ARGS__); \ + } +#define PRINT_NEXT() \ + { \ + refresh(); \ + napms(NCUR_DELAY_MS); \ + } #else -#define PRINT_ME(x, y, ...) { printf("%*s", x, ""); printf(__VA_ARGS__); printf("\n"); } -#define PRINT_NEXT() { puts("-----"); } +#define PRINT_ME(x, y, ...) \ + { \ + printf("%*s", x, ""); \ + printf(__VA_ARGS__); \ + printf("\n"); \ + } +#define PRINT_NEXT() \ + { \ + puts("-----"); \ + } #endif //====================== -enum class StepPosition_t { - BEFORE_EVAL, - AFTER_EVAL -}; +enum class StepPosition_t { BEFORE_EVAL, AFTER_EVAL }; -void draw_ui(const std::unique_ptr &topp, int &i, StepPosition_t sp) { +void draw_ui(const std::unique_ptr &topp, uint64_t &i, + StepPosition_t sp) { uint16_t opcode = topp->computer->PC_content_int; - 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(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 // topp->computer->clk_in, - topp->computer->PC_addr_int, opcode, - topp->halt - ); + 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()); @@ -92,7 +104,6 @@ int main(int argc, char **argv, char **) { fprintf(stderr, "Usage: %.20s [filename]\n\n", argv[0]); exit(-1); } - int i = 0; puts("Start simulation."); // topp->computer->clk_in = 0; topp->clk_in = 0; @@ -113,65 +124,62 @@ int main(int argc, char **argv, char **) { } #if NCUR - initscr(); - curs_set(0); + initscr(); + curs_set(0); #endif - while (VL_LIKELY(!contextp->gotFinish()) && i < 500) { - // 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; - } + while (VL_LIKELY(!contextp->gotFinish()) && contextp->time() < 500) { + auto i = contextp->time(); + draw_ui(topp, i, StepPosition_t::BEFORE_EVAL); - draw_ui(topp, i, StepPosition_t::BEFORE_EVAL); - - // Evaluate model - topp->eval(); + // Evaluate model + if (i != 0 && (i % TICKS_PER_INS) == 0) { + topp->clk_in = !topp->clk_in; + } + topp->eval(); - // both bits 14 and 15 need to be set - if (topp->halt) - break; + // 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 - contextp->timeInc(1); - i++; - } + // Advance time + contextp->timeInc(1); + } #if NCUR - refresh(); + 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."); - } + 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");); - } + if (VL_LIKELY(!contextp->gotFinish())) { + VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n");); + } - // for tracefile to properly show - for (int i = 0; i < 10; i++) { - contextp->timeInc(1); - topp->eval(); - } - // Execute 'final' processes - topp->final(); + // for tracefile to properly show + for (int i = 0; i < 10; i++) { + contextp->timeInc(1); + topp->eval(); + } + // Execute 'final' processes + topp->final(); - // Print statistical summary report - //contextp->statsPrintSummary(); + // Print statistical summary report + // contextp->statsPrintSummary(); #if NCUR - getch(); endwin(); + getch(); + endwin(); #endif - return 0; + return 0; } -- cgit v1.2.3 From f8b21cd577f6e25e696ca058c4a5da61414b7013 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 17:02:56 +0100 Subject: comb_mem: Test when output occurs --- nandgame/comb_mem_tb.sv | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nandgame/comb_mem_tb.sv b/nandgame/comb_mem_tb.sv index 6f8e226..f7211cc 100644 --- a/nandgame/comb_mem_tb.sv +++ b/nandgame/comb_mem_tb.sv @@ -37,6 +37,12 @@ always #10 tst_clk = ~tst_clk; initial begin repeat(3) @(posedge tst_clk); + tst_X = 16'h02; + tst_write_A = 1; + repeat(3) @(posedge tst_clk); + tst_write_A = 0; + repeat(3) @(posedge tst_clk); + tst_X = 16'h55; tst_write_A = 1; repeat(3) @(posedge tst_clk); assert (tst_reg_A == 16'h55) -- cgit v1.2.3 From ba14e988328b250db727b50c9d0db6f0aefc37ff Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 17:03:33 +0100 Subject: mem: Add async data output --- playground/my_mem.v | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/playground/my_mem.v b/playground/my_mem.v index 1153ec7..c38db3a 100644 --- a/playground/my_mem.v +++ b/playground/my_mem.v @@ -16,11 +16,25 @@ module my_mem #( input [$clog2(DATA_DEPTH)-1:0] r_write_addr, input [(DATA_WIDTH-1) : 0] data_i, - output reg [(DATA_WIDTH-1) : 0] data_o + output reg [(DATA_WIDTH-1) : 0] data_o, + output [(DATA_WIDTH-1) : 0] async_data_o ); reg [(DATA_WIDTH-1) : 0] r_datastore [(DATA_DEPTH-1) : 0] /* verilator public */; +`ifdef VERILATE +initial begin + r_datastore[0] = 'h11; + r_datastore[1] = 'h22; + r_datastore[2] = 'h33; + r_datastore[3] = 'h44; + r_datastore[4] = 'h55; + r_datastore[5] = 'h66; + r_datastore[6] = 'h77; + r_datastore[7] = 'h88; +end +`endif + `ifdef DEBUG // for debugging simulations, as iverilog // does't show r_datastore @@ -44,6 +58,8 @@ always @(posedge clk_i) begin end end +assign async_data_o = r_datastore[r_read_addr]; + endmodule `endif -- cgit v1.2.3 From 7228de23dff4aa102ff325bcd1fee267eeec0ac0 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 17:03:43 +0100 Subject: Add second example --- nandgame/assembler/ex2.asm | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 nandgame/assembler/ex2.asm diff --git a/nandgame/assembler/ex2.asm b/nandgame/assembler/ex2.asm new file mode 100644 index 0000000..50bdc63 --- /dev/null +++ b/nandgame/assembler/ex2.asm @@ -0,0 +1,10 @@ + mov A, #13 + add _, #0, A + add D, #0, A + dec DM, #0 + add _, D, A + add M, D, A + and _, #0, A + and _, #0, A + mov A, #123 + hlt -- cgit v1.2.3 From f1cea5a6fa3d6c5957936ab9d0f897685f9ac4a1 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 17:04:04 +0100 Subject: comb_mem: Use async data o --- nandgame/comb_mem.sv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nandgame/comb_mem.sv b/nandgame/comb_mem.sv index 766552c..b68fc22 100644 --- a/nandgame/comb_mem.sv +++ b/nandgame/comb_mem.sv @@ -45,7 +45,8 @@ my_mem #( .read_en_i(1'b1), .r_read_addr(reg_A_out), .r_write_addr(reg_A_out), - .data_o(reg_pA_out), + .data_o(), + .async_data_o(reg_pA_out), .data_i(X_in) ); -- cgit v1.2.3 From 7d7ce2586c2a769259340c7e84f97eb3fd5b4b3e Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 17:05:00 +0100 Subject: computer: Fix x/y --- nandgame/Vcomputer__main.cpp | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/nandgame/Vcomputer__main.cpp b/nandgame/Vcomputer__main.cpp index 8a2c094..a22d09c 100644 --- a/nandgame/Vcomputer__main.cpp +++ b/nandgame/Vcomputer__main.cpp @@ -18,15 +18,15 @@ #include "../assembler/disas.h" #define NCUR_OFFSET 3 +#define NCUR_X 5 #if NCUR #include #define NCUR_DELAY_MS 100 -#define NCUR_X 5 -#define PRINT_ME(x, y, ...) \ +#define PRINT_ME(y, x, ...) \ { \ - mvprintw(x, y, __VA_ARGS__); \ + mvprintw(y, x, __VA_ARGS__); \ } #define PRINT_NEXT() \ { \ @@ -36,9 +36,9 @@ #else -#define PRINT_ME(x, y, ...) \ +#define PRINT_ME(y, x, ...) \ { \ - printf("%*s", x, ""); \ + printf("%*c", x, ' '); \ printf(__VA_ARGS__); \ printf("\n"); \ } @@ -68,22 +68,20 @@ void draw_ui(const std::unique_ptr &topp, uint64_t &i, auto insline = print_decoded(opcode, true); PRINT_ME(3 + NCUR_OFFSET, NCUR_X, "%-80s", insline.c_str()); - // keep old state - if (topp->halt) - return; - PRINT_ME(5 + NCUR_OFFSET, 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, - "%9" PRId16 "\t%9" PRId16 "\t%9" PRId16 "\t%11" PRId16, - topp->computer->reg_A_int, topp->computer->reg_D_int, - topp->computer->reg_pA_int, topp->computer->result_int); - PRINT_ME(7 + NCUR_OFFSET, NCUR_X, "ALU"); - PRINT_ME(8 + NCUR_OFFSET, NCUR_X, "X: %5" PRId16 "\tY: %5" PRId16, - topp->computer->CPU->my_alu->int_op_x, - topp->computer->CPU->my_alu->int_op_y) + PRINT_ME( + 6 + NCUR_OFFSET, 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(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, + // topp->computer->CPU->my_alu->int_op_y); PRINT_NEXT(); } @@ -140,11 +138,11 @@ int main(int argc, char **argv, char **) { // both bits 14 and 15 need to be set if (topp->halt) - break; - - draw_ui(topp, i, StepPosition_t::AFTER_EVAL); + break; + + draw_ui(topp, i, StepPosition_t::AFTER_EVAL); - // Advance time + // Advance time contextp->timeInc(1); } -- cgit v1.2.3 From 05cf070db62bfdaff99292660105159bd0367a66 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 17:11:55 +0100 Subject: Remove rando int --- playground/my_mem.v | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/playground/my_mem.v b/playground/my_mem.v index c38db3a..ebffcb8 100644 --- a/playground/my_mem.v +++ b/playground/my_mem.v @@ -22,18 +22,18 @@ module my_mem #( reg [(DATA_WIDTH-1) : 0] r_datastore [(DATA_DEPTH-1) : 0] /* verilator public */; -`ifdef VERILATE -initial begin - r_datastore[0] = 'h11; - r_datastore[1] = 'h22; - r_datastore[2] = 'h33; - r_datastore[3] = 'h44; - r_datastore[4] = 'h55; - r_datastore[5] = 'h66; - r_datastore[6] = 'h77; - r_datastore[7] = 'h88; -end -`endif +// `ifdef VERILATE +// initial begin +// r_datastore[0] = 'h11; +// r_datastore[1] = 'h22; +// r_datastore[2] = 'h33; +// r_datastore[3] = 'h44; +// r_datastore[4] = 'h55; +// r_datastore[5] = 'h66; +// r_datastore[6] = 'h77; +// r_datastore[7] = 'h88; +// end +// `endif `ifdef DEBUG // for debugging simulations, as iverilog -- cgit v1.2.3 From bc78c7ae5356055c71918628d986f41d2f6bca35 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 17:12:22 +0100 Subject: CPU: Annotate unconnected pin --- nandgame/computer.sv | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nandgame/computer.sv b/nandgame/computer.sv index 7f42c05..8b52f19 100644 --- a/nandgame/computer.sv +++ b/nandgame/computer.sv @@ -28,7 +28,9 @@ my_mem #( .r_read_addr(PC_addr_int), .r_write_addr(0), .data_i(0), - .data_o(PC_content_int) + .data_o(PC_content_int), + // ??? + .async_data_o() ); logic [15:0] reg_A_int /* verilator public */, -- cgit v1.2.3 From 83ead3b54478cb8512597045786035aa4c11d069 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 18:24:51 +0100 Subject: Use sync output for ROM --- nandgame/computer.sv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nandgame/computer.sv b/nandgame/computer.sv index 8b52f19..258c323 100644 --- a/nandgame/computer.sv +++ b/nandgame/computer.sv @@ -28,9 +28,9 @@ my_mem #( .r_read_addr(PC_addr_int), .r_write_addr(0), .data_i(0), - .data_o(PC_content_int), + .data_o(), // ??? - .async_data_o() + .async_data_o(PC_content_int) ); logic [15:0] reg_A_int /* verilator public */, -- cgit v1.2.3 From cd8997b778e5762d3e1f70608a7efd6bc8363df7 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 20:35:31 +0100 Subject: Add third assembler example --- nandgame/assembler/ex3.asm | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 nandgame/assembler/ex3.asm diff --git a/nandgame/assembler/ex3.asm b/nandgame/assembler/ex3.asm new file mode 100644 index 0000000..0073ca8 --- /dev/null +++ b/nandgame/assembler/ex3.asm @@ -0,0 +1,7 @@ +; just checking when memory happens + mov A, #1 + mov A, #2 + mov A, #3 + inc A, A + inc A, A + inc A, A -- cgit v1.2.3 From d12e166f991c9bdebc9c2eea3a7cdf60bcbdb439 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 20:35:59 +0100 Subject: Redesign UI, add program content also, stop program in while loop header --- nandgame/Vcomputer__main.cpp | 48 ++++++++++++++++++++++++++------------------ 1 file 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 -#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 &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");); -- cgit v1.2.3 From 148c30cb28e59acb746d300626b54da21e09bc9e Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 10 Jan 2026 21:10:51 +0100 Subject: Show ROM/RAM --- nandgame/Vcomputer__main.cpp | 53 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/nandgame/Vcomputer__main.cpp b/nandgame/Vcomputer__main.cpp index 4ca2029..1857f1e 100644 --- a/nandgame/Vcomputer__main.cpp +++ b/nandgame/Vcomputer__main.cpp @@ -4,6 +4,7 @@ #include "Vcomputer.h" #include "Vcomputer___024root.h" #include "Vcomputer_alu.h" +#include "Vcomputer_comb_mem.h" #include "Vcomputer_computer.h" #include "Vcomputer_instruction_decode.h" #include "Vcomputer_my_mem__D10_DB10000.h" @@ -21,7 +22,7 @@ #if NCUR #include -#define NCUR_DELAY_MS 10 +#define NCUR_DELAY_MS 100 #define PRINT_ME(y, x, ...) \ { \ @@ -76,16 +77,48 @@ void draw_ui(const std::unique_ptr &topp, uint64_t &i, 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++) { +#define MEMORY_CONTEXT 3 + + const int ram1_pos_offset = 35 + 1; + const int ram2_pos_offset = ram1_pos_offset + 14 + 1; + PRINT_ME(10, NCUR_X, "%-35s", "--- ROM ---"); + PRINT_ME(10, NCUR_X + ram1_pos_offset, "%-35s", "--- RAM1 ---"); + PRINT_ME(10, NCUR_X + ram2_pos_offset, "%-35s", "-- RAM2 --"); + for (int i = -MEMORY_CONTEXT; i <= MEMORY_CONTEXT; i++) { + const int ypos_base = 10 + 1 + MEMORY_CONTEXT; 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()); + int32_t current_ROM_address = topp->computer->PC_addr_int + i; + int32_t current_RAM_address = topp->computer->reg_A_int + i; + if (current_ROM_address < 0) { + PRINT_ME( + ypos_base + i, NCUR_X, "%.35s", + "---------------------------------------------------------------"); + } else { + const uint16_t p = current_ROM_address; + const uint16_t program_op_code = topp->computer->ROM->r_datastore[p]; + auto disas_code = print_decoded(program_op_code, true); + PRINT_ME(ypos_base + i, NCUR_X, "%04X %s%04X %-30s", + current_ROM_address, prefix, program_op_code, + disas_code.c_str()); + } + if (current_RAM_address < 0) { + PRINT_ME( + ypos_base + i, NCUR_X + ram1_pos_offset, "%.12s", + "---------------------------------------------------------------"); + } else { + const uint16_t p = current_RAM_address; + const uint16_t mem_content = + topp->computer->RAM->nand_memory->r_datastore[p]; + PRINT_ME(ypos_base + i, NCUR_X + ram1_pos_offset, "%04X %s%04X", + current_RAM_address, prefix, mem_content); + } + { + const uint16_t p = MEMORY_CONTEXT + i; + const uint16_t mem_content = + topp->computer->RAM->nand_memory->r_datastore[p]; + PRINT_ME(ypos_base + i, NCUR_X + ram2_pos_offset, "%04X %04X%30c", p, + mem_content, ' '); + } } // PRINT_ME(7 + NCUR_OFFSET, NCUR_X, "ALU"); // PRINT_ME(8 + NCUR_OFFSET, NCUR_X, "X: %5d\tY: %5d", -- cgit v1.2.3