aboutsummaryrefslogtreecommitdiff
path: root/j1/sim_main.cpp
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2019-10-30 20:04:56 +0100
committerDimitri Sokolyuk <demon@dim13.org>2019-10-30 20:04:56 +0100
commita76977af62010a392c16010c367185e61e856ffe (patch)
tree56cf4177d5bc0e3ead781d1c60818c13b1df0f3c /j1/sim_main.cpp
parentc0165d167d7cb40d80028bcf7a4a6b160b5a7e83 (diff)
mv to docs
Diffstat (limited to 'j1/sim_main.cpp')
-rw-r--r--j1/sim_main.cpp76
1 files changed, 0 insertions, 76 deletions
diff --git a/j1/sim_main.cpp b/j1/sim_main.cpp
deleted file mode 100644
index ee075ac..0000000
--- a/j1/sim_main.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-#include <stdio.h>
-#include "Vj1.h"
-#include "verilated_vcd_c.h"
-
-int main(int argc, char **argv)
-{
- Verilated::commandArgs(argc, argv);
- Vj1* top = new Vj1;
- int i;
-
- // Verilated::traceEverOn(true);
- // VerilatedVcdC* tfp = new VerilatedVcdC;
- // top->trace (tfp, 99);
- // tfp->open ("simx.vcd");
-
- if (argc != 2) {
- fprintf(stderr, "usage: sim <hex-file>\n");
- exit(1);
- }
-
- union {
- uint32_t ram32[4096];
- uint16_t ram16[8192];
- };
-
- FILE *hex = fopen(argv[1], "r");
- for (i = 0; i < 4096; i++) {
- unsigned int v;
- if (fscanf(hex, "%x\n", &v) != 1) {
- fprintf(stderr, "invalid hex value at line %d\n", i + 1);
- exit(1);
- }
- ram32[i] = v;
- }
-
- FILE *log = fopen("log", "w");
- int t = 0;
-
- top->resetq = 0;
- top->eval();
- top->resetq = 1;
- top->eval();
-
- for (i = 0; i < 100000000; i++) {
- uint16_t a = top->mem_addr;
- uint16_t b = top->code_addr;
- if (top->mem_wr)
- ram32[(a & 16383) / 4] = top->dout;
- top->clk = 1;
- top->eval();
- t += 20;
-
- top->mem_din = ram32[(a & 16383) / 4];
- top->insn = ram16[b];
- top->clk = 0;
- top->eval();
- t += 20;
- if (top->io_wr) {
- putchar(top->dout);
- putc(top->dout, log);
- if (top->dout == '#')
- break;
- }
-#if 0
- if (top->io_inp && (top->io_n == 2)) {
- top->io_din = getchar();
- }
-#endif
- }
- printf("\nSimulation ended after %d cycles\n", i);
- delete top;
- // tfp->close();
- fclose(log);
-
- exit(0);
-}