From a59407a215d6112c2e20b1a746b33742209e5f87 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 16 Oct 2022 16:24:49 -0700 Subject: Support for log-based event model --- io/model.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 io/model.cpp (limited to 'io/model.cpp') 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 @@ +#include +#include +#include +#include + +#include "io/model.h" +#include "isa/isa.h" + +bool iomodel::interact(std::array &ctlregs) { + auto [ebegin, eend] = log.equal_range(time); + for (auto e = ebegin; e != eend; ++e) { + auto &r = ctlregs[e->second.reg]; + r &= ~e->second.mask; + r |= e->second.value; + } + + ++time; + + if (ctlregs[TT_OUTPUT] & 0x100) { + // PDP-8 doesn't really have support for 8-bit output, this is Jules' contribution + std::cout << (char)((ctlregs[TT_OUTPUT] & 0xff) ^ 0x80); + ctlregs[TT_OUTPUT] &= ~0x1ff; + log.emplace(time + TT_OUTPUT_DELAY, event(TT_OUTPUT, 0x200, 0)); + } + + bool interrupt = false; + if (ctlregs[INT_ENABLE] & 1) { + if (ctlregs[TT_INPUT_INT_ENABLE]) { + if (ctlregs[TT_INPUT] & 0x100) + interrupt = true; + } + if (ctlregs[TT_OUTPUT_INT_ENABLE]) { + if (!(ctlregs[TT_OUTPUT] & 0x400) && (ctlregs[TT_OUTPUT] & 0x200)) + interrupt = true; + } + } + + if (interrupt) { + ctlregs[DATA_INSTRUCTION_FIELD_SAVED] = ctlregs[DATA_INSTRUCTION_FIELD_BUFFER]; + ctlregs[DATA_INSTRUCTION_FIELD_BUFFER] = 0; + ctlregs[HALTED] = 0; + ctlregs[INT_ENABLE] = 0; + ctlregs[TT_OUTPUT] = (ctlregs[TT_OUTPUT] & 0x200) * 3; + } else { + ctlregs[INT_ENABLE] = (ctlregs[INT_ENABLE] >> 1) * 3; + } + + return interrupt; +}; -- cgit v1.2.3