summaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--io/event.h2
-rw-r--r--io/model.cpp44
-rw-r--r--io/model.h4
3 files changed, 46 insertions, 4 deletions
diff --git a/io/event.h b/io/event.h
index 2da3323..e17c333 100644
--- a/io/event.h
+++ b/io/event.h
@@ -9,7 +9,7 @@ struct event {
9 ctlreg reg; 9 ctlreg reg;
10 std::uint_fast32_t mask; 10 std::uint_fast32_t mask;
11 std::uint_fast32_t value; 11 std::uint_fast32_t value;
12 event(ctlreg reg, std::uint_fast32_t value, std::uint_fast32_t mask=~0) 12 event(ctlreg reg, std::uint_fast32_t value, std::uint_fast32_t mask=~(std::uint_fast32_t)0)
13 : reg(reg) 13 : reg(reg)
14 , mask(mask) 14 , mask(mask)
15 , value(value) 15 , value(value)
diff --git a/io/model.cpp b/io/model.cpp
index 4b37be4..e9caba0 100644
--- a/io/model.cpp
+++ b/io/model.cpp
@@ -1,4 +1,5 @@
1#include <array> 1#include <array>
2#include <cassert>
2#include <cstdint> 3#include <cstdint>
3#include <iostream> 4#include <iostream>
4#include <utility> 5#include <utility>
@@ -17,8 +18,7 @@ bool iomodel::interact(std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs) {
17 ++time; 18 ++time;
18 19
19 if (ctlregs[TT_BITS] & TTO_TX) { 20 if (ctlregs[TT_BITS] & TTO_TX) {
20 // PDP-8 doesn't really have support for 8-bit output, this is Jules' contribution 21 std::cout << (char)(((ctlregs[TT_BITS] & TTO_DATA) >> TTO_DATA_SHIFT) & 0x7f) << std::flush;
21 std::cout << (char)(((ctlregs[TT_BITS] & TTO_DATA) >> TTO_DATA_SHIFT) ^ 0x80) << std::flush;
22 ctlregs[TT_BITS] &= ~TTO_TX & ~TTO_DATA; 22 ctlregs[TT_BITS] &= ~TTO_TX & ~TTO_DATA;
23 log.emplace(time + TT_OUTPUT_DELAY, event(TT_BITS, TTO_FLAG, 0)); 23 log.emplace(time + TT_OUTPUT_DELAY, event(TT_BITS, TTO_FLAG, 0));
24 } 24 }
@@ -46,4 +46,42 @@ bool iomodel::interact(std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs) {
46 } 46 }
47 47
48 return interrupt; 48 return interrupt;
49}; 49}
50
51void iomodel::load_evt(std::istream &fh) {
52 // File format:
53 // +time advances time by relative increment
54 // regname=value/mask adds event that sets regname = (regname & ~mask) | value
55 // regname=value adds event that sets regname = value
56 // FIXME: add assertions
57 // FIXME: add DMA
58 for (std::string line; std::getline(fh, line); ) {
59 if (line.size() == 0)
60 continue;
61 if (line[0] == '+') {
62 char *end = nullptr;
63 auto step = std::strtoull(line.c_str(), &end, 0);
64 assert(end && *end == '\0');
65 load_time += step;
66 } else {
67 auto eqpos = line.find('=');
68 assert(eqpos != std::string::npos);
69 auto regname = line.substr(0, eqpos);
70 ctlreg reg = ctlreg_map.at(regname);
71 std::uint_fast32_t value, mask;
72 auto slashpos = line.find('/', eqpos);
73 auto valuestr = line.substr(eqpos + 1, slashpos - (eqpos + 1));
74 char *end = nullptr;
75 value = std::strtoull(valuestr.c_str(), &end, 0);
76 assert(end && *end == '\0');
77 if (slashpos == std::string::npos) {
78 mask = ~(std::uint_fast32_t)0;
79 } else {
80 auto maskstr = line.substr(slashpos + 1);
81 mask = std::strtoull(maskstr.c_str(), &end, 0);
82 assert(end && *end == '\0');
83 }
84 log.emplace(load_time, event(reg, value, mask));
85 }
86 }
87}
diff --git a/io/model.h b/io/model.h
index 8758a43..2826170 100644
--- a/io/model.h
+++ b/io/model.h
@@ -13,6 +13,10 @@ struct iomodel {
13 event_log log; 13 event_log log;
14 std::uint64_t time = 0; 14 std::uint64_t time = 0;
15 bool interact(std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs); 15 bool interact(std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs);
16 bool done() {
17 return log.lower_bound(time) == log.end();
18 }
16 19
20 std::uint64_t load_time = 0;
17 void load_evt(std::istream &fh); 21 void load_evt(std::istream &fh);
18}; 22};