summaryrefslogtreecommitdiff
path: root/eater_cpu/cpp/Veater_computer__main.cpp
blob: b986029a9b209801a0b9514606f01a33656cf382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Verilated -*- C++ -*-
// DESCRIPTION: Verilator output: main() simulation loop, created with --main

#include "Veater_computer.h"
#include "Veater_computer_eater_computer.h"
#include "Veater_computer_my_mem__DB10.h"
#include "verilated.h"
#include "verilatedos.h"

#include "verilated_fst_c.h"

#include "simpc_ui.h"

//======================

void load_program(const std::unique_ptr<Veater_computer> &topp) {
  // LDA 14
  topp->eater_computer->RAM->r_datastore[0] = 0x1e;
  // ADD 15
  topp->eater_computer->RAM->r_datastore[1] = 0x2f;
  // OUT
  topp->eater_computer->RAM->r_datastore[2] = 0xe0;
  // NOP
  topp->eater_computer->RAM->r_datastore[3] = 0x00;
  // HALT
  topp->eater_computer->RAM->r_datastore[4] = 0xf0;
  // Data @ 14
  topp->eater_computer->RAM->r_datastore[14] = 14;
  // Data @ 15
  topp->eater_computer->RAM->r_datastore[15] = 28;
}

int main(int argc, char **argv, char **) {
  // Setup context, defaults, and parse command line
  Verilated::debug(0);
  const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
  contextp->traceEverOn(true);
  contextp->threads(1);
  contextp->commandArgs(argc, argv);

  // Construct the Verilated model, from Vtop.h generated from Verilating
  const std::unique_ptr<Veater_computer> topp{
      new Veater_computer{contextp.get(), ""}};

  // waveforms!!!
  VerilatedFstC *tfp = new VerilatedFstC;
  topp->trace(tfp, 100);
  tfp->open("eater.vvp");

  topp->clk_in = 0;
  topp->auto_run_in = 1;

  // Load program
  load_program(topp);

  simpc_ui_init();

  // Simulate until $finish
  while (VL_LIKELY(!contextp->gotFinish()) &&
         VL_LIKELY(contextp->time() < 100) &&
         VL_LIKELY(!(topp->eater_computer->flags.__PVT__halt))) {
    // Evaluate model
    topp->eval();

    tfp->dump(contextp->time());
    simpc_ui_write(topp, contextp->time());

    // Advance time
    contextp->timeInc(1);

    topp->clk_in = !topp->clk_in;

    if (topp->eater_computer->PC_out == 6 &&
        topp->eater_computer->decoder__DOT__internal_state == 0x01)
      break;
  }
  contextp->timeInc(10);
  tfp->dump(contextp->time());

  tfp->close();
  simpc_ui_finish_message(contextp, topp);

  if (VL_LIKELY(!contextp->gotFinish())) {
    VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n"););
  }

  // Execute 'final' processes
  topp->final();

  // Print statistical summary report
  contextp->statsPrintSummary();

  simpc_ui_cleanup();

  return 0;
}