summaryrefslogtreecommitdiff
path: root/io/model.cpp
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-10-16 16:24:49 -0700
committerJulian Blake Kongslie2022-10-16 16:24:49 -0700
commita59407a215d6112c2e20b1a746b33742209e5f87 (patch)
tree64ba2fc875ad1985be10d7b8e6d23deb39d49b3e /io/model.cpp
parentStrip the leader from palbart output (diff)
downloadbiggolf-a59407a215d6112c2e20b1a746b33742209e5f87.tar.xz
Support for log-based event model
Diffstat (limited to 'io/model.cpp')
-rw-r--r--io/model.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/io/model.cpp b/io/model.cpp
new file mode 100644
index 0000000..dd55ce6
--- /dev/null
+++ b/io/model.cpp
@@ -0,0 +1,49 @@
1#include <array>
2#include <cstdint>
3#include <iostream>
4#include <utility>
5
6#include "io/model.h"
7#include "isa/isa.h"
8
9bool iomodel::interact(std::array<unsigned int, NUM_CTLREGS> &ctlregs) {
10 auto [ebegin, eend] = log.equal_range(time);
11 for (auto e = ebegin; e != eend; ++e) {
12 auto &r = ctlregs[e->second.reg];
13 r &= ~e->second.mask;
14 r |= e->second.value;
15 }
16
17 ++time;
18
19 if (ctlregs[TT_OUTPUT] & 0x100) {
20 // PDP-8 doesn't really have support for 8-bit output, this is Jules' contribution
21 std::cout << (char)((ctlregs[TT_OUTPUT] & 0xff) ^ 0x80);
22 ctlregs[TT_OUTPUT] &= ~0x1ff;
23 log.emplace(time + TT_OUTPUT_DELAY, event(TT_OUTPUT, 0x200, 0));
24 }
25
26 bool interrupt = false;
27 if (ctlregs[INT_ENABLE] & 1) {
28 if (ctlregs[TT_INPUT_INT_ENABLE]) {
29 if (ctlregs[TT_INPUT] & 0x100)
30 interrupt = true;
31 }
32 if (ctlregs[TT_OUTPUT_INT_ENABLE]) {
33 if (!(ctlregs[TT_OUTPUT] & 0x400) && (ctlregs[TT_OUTPUT] & 0x200))
34 interrupt = true;
35 }
36 }
37
38 if (interrupt) {
39 ctlregs[DATA_INSTRUCTION_FIELD_SAVED] = ctlregs[DATA_INSTRUCTION_FIELD_BUFFER];
40 ctlregs[DATA_INSTRUCTION_FIELD_BUFFER] = 0;
41 ctlregs[HALTED] = 0;
42 ctlregs[INT_ENABLE] = 0;
43 ctlregs[TT_OUTPUT] = (ctlregs[TT_OUTPUT] & 0x200) * 3;
44 } else {
45 ctlregs[INT_ENABLE] = (ctlregs[INT_ENABLE] >> 1) * 3;
46 }
47
48 return interrupt;
49};