summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok2026-01-10 15:36:19 +0100
committeruvok2026-01-10 20:34:37 +0100
commite583d4747a1a37bd900dc49c7006bbb4c3ec2ab9 (patch)
treefed1111ab423723916692bb964100d1c41c055bf
parent34ac7a712f62d67372c2d293c3dfc27c476f90a4 (diff)
reformatcomputer, get rid of i
-rw-r--r--nandgame/Vcomputer__main.cpp130
1 files 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 <cinttypes>
#include <cstdint>
#include <cstdio>
@@ -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<Vcomputer> &topp, int &i, StepPosition_t sp) {
+void draw_ui(const std::unique_ptr<Vcomputer> &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;
}