diff --git a/npc/csrc_nvboard/main.cpp b/npc/csrc_nvboard/main.cpp index c1165d4..e9df24c 100644 --- a/npc/csrc_nvboard/main.cpp +++ b/npc/csrc_nvboard/main.cpp @@ -1,40 +1,55 @@ -#include +#include #include #include +#include #include #include -#include -#include #ifndef VERILATOR_TOPMODULE #define VERILATOR_TOPMODULE VSegHandler #endif -const int MAX_SIM_TIME=100; +const int MAX_SIM_TIME = 100; +int keycode = 0; -void nvboard_bind_all_pins(VERILATOR_TOPMODULE* top); - -static void single_cycle(VERILATOR_TOPMODULE* top) { - top->clock = 0; top->eval(); - top->clock = 1; top->eval(); +template void cycle(VERILATOR_TOPMODULE *top, F &&f) { + top->clock = 0; + top->eval(); + f(); + top->clock = 1; + top->eval(); } -static void reset(VERILATOR_TOPMODULE* top, int n) { +void nvboard_bind_all_pins(VERILATOR_TOPMODULE *top); + +static void single_cycle(VERILATOR_TOPMODULE *top) { + top->clock = 0; + top->eval(); + top->clock = 1; + top->eval(); +} + +static void reset(VERILATOR_TOPMODULE *top, int n) { top->reset = 1; - while (n -- > 0) single_cycle(top); + while (n-- > 0) + single_cycle(top); top->reset = 0; } int main(int argc, char **argv, char **env) { - VERILATOR_TOPMODULE *top = new VERILATOR_TOPMODULE; + VERILATOR_TOPMODULE *top = new VERILATOR_TOPMODULE; - nvboard_bind_all_pins(top); - nvboard_init(); - reset(top, 10); - while (true) { - nvboard_update(); - top->eval(); - single_cycle(top); - } - delete top; + nvboard_bind_all_pins(top); + nvboard_init(); + reset(top, 10); + while (true) { + nvboard_update(); + cycle(top, [&] { + if (keycode != top->io_keycode_bits) { + printf("%d\n", top->io_keycode_bits); + keycode = top->io_keycode_bits; + } + }); + } + delete top; } \ No newline at end of file