From ff66523bb076a246c2fc159f0f76947bd6f84fc1 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sat, 29 Oct 2022 12:55:08 -0700 Subject: Control register values should not be "unsigned int" --- io/event.h | 7 +++--- io/model.cpp | 2 +- io/model.h | 5 ++++- isa/checker.h | 3 ++- isa/decode.cpp | 19 +++++++++++++++++ isa/isa.h | 3 ++- programs/echo.pal | 64 +++++-------------------------------------------------- 7 files changed, 37 insertions(+), 66 deletions(-) diff --git a/io/event.h b/io/event.h index 02f3fab..2da3323 100644 --- a/io/event.h +++ b/io/event.h @@ -1,14 +1,15 @@ #pragma once +#include #include #include "isa/isa.h" struct event { ctlreg reg; - unsigned int mask; - unsigned int value; - event(ctlreg reg, unsigned int value, unsigned int mask=~0) + std::uint_fast32_t mask; + std::uint_fast32_t value; + event(ctlreg reg, std::uint_fast32_t value, std::uint_fast32_t mask=~0) : reg(reg) , mask(mask) , value(value) diff --git a/io/model.cpp b/io/model.cpp index d6e36f9..4b37be4 100644 --- a/io/model.cpp +++ b/io/model.cpp @@ -6,7 +6,7 @@ #include "io/model.h" #include "isa/isa.h" -bool iomodel::interact(std::array &ctlregs) { +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]; diff --git a/io/model.h b/io/model.h index c7199ea..8758a43 100644 --- a/io/model.h +++ b/io/model.h @@ -2,6 +2,7 @@ #include #include +#include #include "io/event.h" #include "isa/isa.h" @@ -11,5 +12,7 @@ struct iomodel { event_log log; std::uint64_t time = 0; - bool interact(std::array &ctlregs); + bool interact(std::array &ctlregs); + + void load_evt(std::istream &fh); }; diff --git a/isa/checker.h b/isa/checker.h index 332c483..571bbc8 100644 --- a/isa/checker.h +++ b/isa/checker.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "io/model.h" @@ -41,7 +42,7 @@ struct checker { unsigned int link = 0; unsigned int mq = 0; unsigned int pc = 00200; - std::array ctlregs; + std::array ctlregs; iomodel &system; instruction_context inst; funcmem mem; diff --git a/isa/decode.cpp b/isa/decode.cpp index 4af9a0d..9563327 100644 --- a/isa/decode.cpp +++ b/isa/decode.cpp @@ -140,6 +140,25 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit break; } break; + case 003: + // KEYBOARD + switch (bits & 07) { + case 1: + // KSF skip if TTI flag is set + inst.read_ctlreg = TT_BITS; + inst.possibly_redirects = true; + inst.ef = [](auto &ctx) { + if (ctx.ctlval.value() & TTI_FLAG) + ctx.next_pc = (ctx.next_pc & ~07777) | ((ctx.next_pc + 1) & 07777); + }; + break; + default: + inst.ef = [bits](auto &ctx) { + std::cerr << "unimplemented IOT KB suboperation " << (bits & 07) << "\n"; + assert(false); + }; + } + break; case 004: // TELETYPE TELEPRINTER/PUNCH switch (bits & 07) { diff --git a/isa/isa.h b/isa/isa.h index 1ad5a77..84a783c 100644 --- a/isa/isa.h +++ b/isa/isa.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -49,7 +50,7 @@ struct instruction_context { unsigned int next_pc; // includes IF std::optional init_address; // includes DF std::optional final_address; // includes DF - std::optional ctlval; + std::optional ctlval; // control registers may be larger than 16 bits (e.g. TT_BITS) std::optional data; std::optional acc; std::optional link; diff --git a/programs/echo.pal b/programs/echo.pal index 16d8fda..4e59623 100644 --- a/programs/echo.pal +++ b/programs/echo.pal @@ -1,67 +1,13 @@ / vim: set sw=8 noexpandtab : -*000 - -INTRET, 0 - JMP GOTINT - -INPUTY, 1000 / Address of youngest byte in input buffer -INPUTO, 1000 / Address of oldest byte in input buffer - *200 - -/ Main program enables keyboard interrupt, then enters echo loop - KIE - ION -LOOP, TSF / Call ECHO if printer is ready +LOOP, TSF JMS ECHO JMP LOOP ECHO, 0 - TAD INPUTO - CMA IAC / Negate - TAD INPUTY - SNA / Abandon echo if input buffer is empty (n.b. or full, because we don't have wrap bits) - JMP I ECHO - TAD I INPUTO / Read from input buffer - TLS / Print - JMS FIXO +WAIT, KSF + JMP WAIT + KRB + TLS JMP I ECHO - -GOTINT, KSF / Skip reading keyboard if nothing was typed - JMP NOIN - DCA SAVED - KRB / Read from keyboard - DCA I INPUTY / Write to input buffer - JMS FIXY - CLA - TAD SAVED -NOIN, RMF - ION - JMP I INTRET - -/ Wrap INPUTY pointer at 2000 back to 1000 -FIXY, 0 - TAD INPUTY - TAD [-2000] - SZA - JMP I FIXY - CLA - TAD [1000] - DCA INPUTY - JMP I FIXY - -/ Wrap INPUTO pointer at 2000 back to 1000 -FIXO, 0 - TAD INPUTO - TAD [-2000] - SZA - JMP I FIXO - CLA - TAD [1000] - DCA INPUTO - JMP I FIXO - -*300 - -SAVED, 0 -- cgit v1.2.3