summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-11-05 16:57:34 -0700
committerJulian Blake Kongslie2022-11-05 16:57:34 -0700
commit7c7dfe8a3150981f47bd6283d97f9b84e05371c3 (patch)
treee689349c6ea38b247b7e9a2f53759432094b0702
parentAdd support for replaying event logs (diff)
downloadbiggolf-7c7dfe8a3150981f47bd6283d97f9b84e05371c3.tar.xz
Support for more line formats in evt reader
Diffstat (limited to '')
-rw-r--r--io/model.cpp20
-rw-r--r--io/model.h9
2 files changed, 14 insertions, 15 deletions
diff --git a/io/model.cpp b/io/model.cpp
index d332908..741a885 100644
--- a/io/model.cpp
+++ b/io/model.cpp
@@ -51,10 +51,10 @@ bool iomodel::interact(std::uint64_t icount, std::array<std::uint_fast32_t, NUM_
51 51
52void iomodel::load_evt(std::istream &fh) { 52void iomodel::load_evt(std::istream &fh) {
53 // File format: 53 // File format:
54 // +time advances time by relative increment 54 // +icount advances icount by relative increment
55 // regname=value/mask adds event that sets regname = (regname & ~mask) | value 55 // regname=value/mask adds event that sets regname = (regname & ~mask) | value
56 // regname=value adds event that sets regname = value 56 // regname=value adds event that sets regname = value
57 // $x adds events that input the remaining line (excluding trailing whitespace) character-at-a-time with 1000 cycles between them 57 // $x adds events that input the remaining line (excluding trailing whitespace) character-at-a-time with 1000 icounts between them
58 // FIXME: add assertions 58 // FIXME: add assertions
59 // FIXME: add DMA 59 // FIXME: add DMA
60 for (std::string line; std::getline(fh, line); ) { 60 for (std::string line; std::getline(fh, line); ) {
@@ -70,11 +70,11 @@ void iomodel::load_evt(std::istream &fh) {
70 char *end = nullptr; 70 char *end = nullptr;
71 auto step = std::strtoull(line.c_str(), &end, 0); 71 auto step = std::strtoull(line.c_str(), &end, 0);
72 assert(end && *end == '\0'); 72 assert(end && *end == '\0');
73 load_time += step; 73 load_icount += step;
74 } else if (line[0] == '$') { 74 } else if (line[0] == '$') {
75 for (unsigned int i = 1; i < line.size(); ++i) { 75 for (unsigned int i = 1; i < line.size(); ++i) {
76 log.emplace(load_time, event(TT_BITS, (line[i] << 8) | TTI_FLAG, TTI_DATA | TTI_FLAG)); 76 log.emplace(load_icount, event(TT_BITS, (line[i] << 8) | TTI_FLAG, TTI_DATA | TTI_FLAG));
77 load_time += 1000; 77 load_icount += 1000;
78 } 78 }
79 } else { 79 } else {
80 auto eqpos = line.find('='); 80 auto eqpos = line.find('=');
@@ -94,17 +94,17 @@ void iomodel::load_evt(std::istream &fh) {
94 mask = std::strtoull(maskstr.c_str(), &end, 0); 94 mask = std::strtoull(maskstr.c_str(), &end, 0);
95 assert(end && *end == '\0'); 95 assert(end && *end == '\0');
96 } 96 }
97 log.emplace(load_time, event(reg, value, mask)); 97 log.emplace(load_icount, event(reg, value, mask));
98 } 98 }
99 } 99 }
100} 100}
101 101
102std::ostream & iomodel::write_evt(std::ostream &fh) { 102std::ostream & iomodel::write_evt(std::ostream &fh) {
103 std::uint64_t time = 0; 103 std::uint64_t icount = 0;
104 for (const auto &e : log) { 104 for (const auto &e : log) {
105 if (e.first != time) { 105 if (e.first != icount) {
106 fh << fmt::format("+{}\n", e.first - time); 106 fh << fmt::format("+{}\n", e.first - icount);
107 time = e.first; 107 icount = e.first;
108 } 108 }
109 if (e.second.mask == ~(std::uint_fast32_t)0) { 109 if (e.second.mask == ~(std::uint_fast32_t)0) {
110 fh << fmt::format("{}=0x{:x}\n", ctlreg_names[e.second.reg], e.second.value); 110 fh << fmt::format("{}=0x{:x}\n", ctlreg_names[e.second.reg], e.second.value);
diff --git a/io/model.h b/io/model.h
index be16283..16e7ca7 100644
--- a/io/model.h
+++ b/io/model.h
@@ -12,13 +12,12 @@ struct iomodel {
12 static constexpr unsigned int TT_OUTPUT_DELAY = 10; 12 static constexpr unsigned int TT_OUTPUT_DELAY = 10;
13 13
14 event_log log; 14 event_log log;
15 std::uint64_t time = 0; 15 bool interact(std::uint64_t icount, std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs, bool replay=false);
16 bool interact(std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs); 16 bool done(std::uint64_t icount) {
17 bool done() { 17 return log.lower_bound(icount) == log.end();
18 return log.lower_bound(time) == log.end();
19 } 18 }
20 19
21 std::uint64_t load_time = 0; 20 std::uint64_t load_icount = 0;
22 void load_evt(std::istream &fh); 21 void load_evt(std::istream &fh);
23 22
24 std::ostream & write_evt(std::ostream &fh); 23 std::ostream & write_evt(std::ostream &fh);