diff options
| author | uvok | 2026-01-08 20:03:28 +0100 |
|---|---|---|
| committer | uvok | 2026-01-08 20:03:28 +0100 |
| commit | eb4810b57bf7cd2c941c4bfd5447953fa6441e56 (patch) | |
| tree | 875c65122b62e624e8e2e462826d45315723835f /nandgame/Vcomputer__main.cpp | |
| parent | 642bc651174e4b42ce9576c42a861985a8848d49 (diff) | |
Add really nice ncurses UI
Diffstat (limited to 'nandgame/Vcomputer__main.cpp')
| -rw-r--r-- | nandgame/Vcomputer__main.cpp | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/nandgame/Vcomputer__main.cpp b/nandgame/Vcomputer__main.cpp index 5c3cd1e..ebac129 100644 --- a/nandgame/Vcomputer__main.cpp +++ b/nandgame/Vcomputer__main.cpp @@ -17,6 +17,14 @@ #if NCUR #include <ncurses.h> #define NCUR_DELAY_MS 300 +#define NCUR_X 5 + +#define PRINT_ME(x, y, ...) { mvprintw(x, y, __VA_ARGS__); } + +#else + +#define PRINT_ME(x, y, ...) { printf("%*s", x, ""); printf(__VA_ARGS__); printf("\n"); } + #endif //====================== @@ -70,18 +78,13 @@ int main(int argc, char** argv, char**) { topp->clk_in = !topp->clk_in; //uint16_t opcode = (topp->computer->PC_content_int & 0xff) << 8 | (topp->computer->PC_content_int >> 8); uint16_t opcode = topp->computer->PC_content_int; -#if NCUR - mvprintw(1, 1, "Step: %10d", i); -#endif -#if NCUR - mvprintw(1 + ncur_offset, 1, -#else - printf( -#endif - "CLK1: %4d\tCLK2: %4d\tPC: @0x%04X\tINS: 0x%04X\n", + PRINT_ME(1, 1, "Step: %10d", i); + PRINT_ME(1 + ncur_offset, NCUR_X, + "CLK1: %4d\tPC: @0x%04X\tINS: 0x%04X", topp->clk_in, - topp->computer->clk_in, + // wrong + //topp->computer->clk_in, topp->computer->PC_addr_int, opcode ); @@ -106,32 +109,20 @@ int main(int argc, char** argv, char**) { #else { auto insline = print_decoded(opcode, true); -#if NCUR - mvprintw(3 + ncur_offset, 5, "%s", -#else - printf(" %s\n", -#endif - insline.c_str()); + + PRINT_ME(3 + ncur_offset, NCUR_X, "%s", insline.c_str()); } #endif -#if NCUR - mvprintw(5 + ncur_offset, 5, -#else - printf(" " -#endif - "A: 0x%04X\tD: 0x%04X\tM: 0x%04X\tRES: 0x%04X\n", + 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 ); -#if NCUR - mvprintw(6 + ncur_offset, 5, -#else - printf(" " -#endif - "A: %6" PRId16 "\tD: %6" PRId16 "\tM: %6" PRId16 "\tRES: %6" PRId16 "\n", + 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, @@ -142,6 +133,7 @@ int main(int argc, char** argv, char**) { // Advance time contextp->timeInc(1); i++; + #if NCUR refresh(); napms(NCUR_DELAY_MS); #else @@ -149,12 +141,7 @@ int main(int argc, char** argv, char**) { #endif } -#if NCUR - mvprintw(10 + ncur_offset, 10, -#else - puts( -#endif - "Simulation finished"); + PRINT_ME(10 + ncur_offset, 10, "Simulation finished."); if (VL_LIKELY(!contextp->gotFinish())) { VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n");); |
