From 9f4aa97822adc791f700670ef0fc7636849563b7 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sat, 29 Oct 2022 18:18:26 -0700 Subject: Understanding interrupt handling within SIMH (see echo_int.pal) Add list of Bugs Add event log file parser More changes associated with widening the ctlregs (FIXME add a typedef) Add some keyboard instructions --- io/event.h | 2 +- io/model.cpp | 44 +++++++++++++++++++++++++++++++++++++++++--- io/model.h | 4 ++++ 3 files changed, 46 insertions(+), 4 deletions(-) (limited to 'io') 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 { ctlreg reg; std::uint_fast32_t mask; std::uint_fast32_t value; - event(ctlreg reg, std::uint_fast32_t value, std::uint_fast32_t mask=~0) + event(ctlreg reg, std::uint_fast32_t value, std::uint_fast32_t mask=~(std::uint_fast32_t)0) : reg(reg) , mask(mask) , 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 @@ #include +#include #include #include #include @@ -17,8 +18,7 @@ bool iomodel::interact(std::array &ctlregs) { ++time; if (ctlregs[TT_BITS] & TTO_TX) { - // PDP-8 doesn't really have support for 8-bit output, this is Jules' contribution - std::cout << (char)(((ctlregs[TT_BITS] & TTO_DATA) >> TTO_DATA_SHIFT) ^ 0x80) << std::flush; + std::cout << (char)(((ctlregs[TT_BITS] & TTO_DATA) >> TTO_DATA_SHIFT) & 0x7f) << std::flush; ctlregs[TT_BITS] &= ~TTO_TX & ~TTO_DATA; log.emplace(time + TT_OUTPUT_DELAY, event(TT_BITS, TTO_FLAG, 0)); } @@ -46,4 +46,42 @@ bool iomodel::interact(std::array &ctlregs) { } return interrupt; -}; +} + +void iomodel::load_evt(std::istream &fh) { + // File format: + // +time advances time by relative increment + // regname=value/mask adds event that sets regname = (regname & ~mask) | value + // regname=value adds event that sets regname = value + // FIXME: add assertions + // FIXME: add DMA + for (std::string line; std::getline(fh, line); ) { + if (line.size() == 0) + continue; + if (line[0] == '+') { + char *end = nullptr; + auto step = std::strtoull(line.c_str(), &end, 0); + assert(end && *end == '\0'); + load_time += step; + } else { + auto eqpos = line.find('='); + assert(eqpos != std::string::npos); + auto regname = line.substr(0, eqpos); + ctlreg reg = ctlreg_map.at(regname); + std::uint_fast32_t value, mask; + auto slashpos = line.find('/', eqpos); + auto valuestr = line.substr(eqpos + 1, slashpos - (eqpos + 1)); + char *end = nullptr; + value = std::strtoull(valuestr.c_str(), &end, 0); + assert(end && *end == '\0'); + if (slashpos == std::string::npos) { + mask = ~(std::uint_fast32_t)0; + } else { + auto maskstr = line.substr(slashpos + 1); + mask = std::strtoull(maskstr.c_str(), &end, 0); + assert(end && *end == '\0'); + } + log.emplace(load_time, event(reg, value, mask)); + } + } +} 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 { event_log log; std::uint64_t time = 0; bool interact(std::array &ctlregs); + bool done() { + return log.lower_bound(time) == log.end(); + } + std::uint64_t load_time = 0; void load_evt(std::istream &fh); }; -- cgit v1.2.3