#include "simpc_ui.h" #define NCUR 1 #include "disas.h" #define NCUR_OFFSET 3 #if NCUR #include #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); \ } #else #define PRINT_ME(x, y, ...) \ { \ printf("%*s", x, ""); \ printf(__VA_ARGS__); \ printf("\n"); \ } #define PRINT_NEXT() \ { puts("-----"); } #endif #include "Vcomputer.h" #include "Vcomputer___024root.h" #include "Vcomputer_alu.h" #include "Vcomputer_computer.h" #include "Vcomputer_instruction_decode.h" #include "verilated.h" #include #include #include #include void draw_ui(const std::unique_ptr &topp, int &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, // 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()); // 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_NEXT(); } void draw_finish(const std::unique_ptr &contextp, const std::unique_ptr &topp) { #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."); } } void draw_init(void) { #if NCUR initscr(); curs_set(0); #endif } void ui_finish(void) { #if NCUR getch(); endwin(); #endif }