From d97b32ac6a2ccca3704f567b12ab0378dc7e8dac Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 16 Oct 2022 17:19:25 -0700 Subject: Nearly-working version of TTY output --- io/model.cpp | 2 +- isa/decode.cpp | 76 ++++++++++++++++++++++++++++---- main.cpp | 2 +- programs/count.pal | 2 +- programs/mike_fib.pal | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+), 11 deletions(-) create mode 100644 programs/mike_fib.pal diff --git a/io/model.cpp b/io/model.cpp index dd55ce6..eaa6ca8 100644 --- a/io/model.cpp +++ b/io/model.cpp @@ -18,7 +18,7 @@ bool iomodel::interact(std::array &ctlregs) { 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); + std::cout << (char)((ctlregs[TT_OUTPUT] & 0xff) ^ 0x80) << std::flush; ctlregs[TT_OUTPUT] &= ~0x1ff; log.emplace(time + TT_OUTPUT_DELAY, event(TT_OUTPUT, 0x200, 0)); } diff --git a/isa/decode.cpp b/isa/decode.cpp index d24632b..cb6a694 100644 --- a/isa/decode.cpp +++ b/isa/decode.cpp @@ -23,7 +23,7 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit inst.need_read_acc = true; inst.need_write_acc = true; inst.ef = [](auto &ctx) { - ctx.acc = ctx.acc.value() & ctx.data.value(); + ctx.acc = ctx.acc.value() & ctx.data.value() & 07777; }; break; case 1: // TAD @@ -44,7 +44,7 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit inst.possibly_redirects = true; inst.ef = [](auto &ctx) { ctx.data = (ctx.data.value() + 1) & 07777; - if (*ctx.data) + if (*ctx.data == 0) ctx.next_pc = (ctx.next_pc & ~07777) | ((ctx.next_pc + 1) & 07777); }; break; @@ -72,9 +72,69 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit }; break; case 6: // IOT - inst.ef = [](auto &ctx) { - assert(false); - }; + switch ((bits >> 3) & 077) { + case 004: + switch (bits & 07) { + case 0: + inst.write_ctlreg = TT_OUTPUT; + inst.ef = [](auto &ctx) { + ctx.ctlval = 0x600; + }; + break; + case 1: + inst.read_ctlreg = TT_OUTPUT; + inst.possibly_redirects = true; + inst.ef = [](auto &ctx) { + if (ctx.ctlval.value() & 0x200) + ctx.next_pc = (ctx.next_pc & ~07777) | ((ctx.next_pc + 1) & 07777); + }; + break; + case 2: + inst.write_ctlreg = TT_OUTPUT; + inst.ef = [](auto &ctx) { + ctx.ctlval = 0; + }; + break; + case 4: + inst.need_read_acc = true; + inst.read_ctlreg = TT_OUTPUT; + inst.write_ctlreg = TT_OUTPUT; + inst.ef = [](auto &ctx) { + auto &x = ctx.ctlval.value(); + x &= ~0x1ff; + x |= (ctx.acc.value() & 0xff) ^ 0x80; // 0x7f instead of 0xff for real PDP-8 IO + x |= 0x100; + }; + break; + case 5: + inst.possibly_redirects = true; + // FIXME this instruction wants to read both TT_OUTPUT and TT_INPUT + inst.ef = [](auto &ctx) { + assert(false); + }; + break; + case 6: + inst.need_read_acc = true; + inst.read_ctlreg = TT_OUTPUT; + inst.write_ctlreg = TT_OUTPUT; + inst.ef = [](auto &ctx) { + auto &x = ctx.ctlval.value(); + x &= ~0x7ff; + x |= (ctx.acc.value() & 0xff) ^ 0x80; + x |= 0x100; + }; + break; + default: + inst.ef = [](auto &ctx) { + assert(false); + }; + } + break; + default: + inst.ef = [](auto &ctx) { + assert(false); + }; + } break; case 7: // OPR if ((bits & 0400) == 0000) { @@ -93,7 +153,7 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit inst.ef = [cla, cll, cma, cml, rar, ral, bsw, iac](auto &ctx) { if (cla) ctx.acc = 0; if (cll) ctx.link = 0; - if (cma) ctx.acc = ~ctx.acc.value(); + if (cma) ctx.acc = ~ctx.acc.value() & 07777; if (cml) ctx.link = !ctx.link.value(); if (iac) { if (++ctx.acc.value() == 0) ctx.link = !ctx.link.value(); @@ -139,7 +199,7 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit assert(!osr); if (hlt) ctx.ctlval = 1; if (skip) - ctx.next_pc = (ctx.next_pc & 070000) | ((ctx.next_pc + 1) & 007777); + ctx.next_pc = (ctx.next_pc & ~07777) | ((ctx.next_pc + 1) & 07777); }; } else if ((bits & 0411) == 0410) { bool cla = bits & 0200; @@ -163,7 +223,7 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit assert(!osr); if (hlt) ctx.ctlval = 1; if (skip) - ctx.next_pc = (ctx.next_pc & 070000) | ((ctx.next_pc + 1) & 007777); + ctx.next_pc = (ctx.next_pc & ~07777) | ((ctx.next_pc + 1) & 07777); }; } else if ((bits & 0401) == 0401) { bool cla = bits & 0200; diff --git a/main.cpp b/main.cpp index b587ce4..46be782 100644 --- a/main.cpp +++ b/main.cpp @@ -66,7 +66,7 @@ int main(int argc, const char *argv[]) { } while (true) { - std::cout << fmt::format("{:9} @{:04o} {:01o}:{:04o}:{:04o}\n", system.time, checker.pc, checker.link, checker.acc, checker.mq); + //std::cout << fmt::format("{:9} @{:04o} {:01o}:{:04o}:{:04o} TTO={:x}\n", system.time, checker.pc, checker.link, checker.acc, checker.mq, checker.ctlregs[TT_OUTPUT]); checker.execute(); } diff --git a/programs/count.pal b/programs/count.pal index 2e96759..aa34be6 100644 --- a/programs/count.pal +++ b/programs/count.pal @@ -2,5 +2,5 @@ *200 -LOOP, TAD [1] +LOOP, TAD (1) JMP LOOP diff --git a/programs/mike_fib.pal b/programs/mike_fib.pal new file mode 100644 index 0000000..6f56109 --- /dev/null +++ b/programs/mike_fib.pal @@ -0,0 +1,117 @@ + *200 +MAIN, CLA + TAD (-26) + DCA FIBN + DCA FIB0 + IAC + DCA FIB1 +LOOP, CLA + TAD FIB0 + JMS PUTN + CLA + TAD (054) + JMS PUTC + CLA + TAD FIB0 + TAD FIB1 + DCA FIB2 + TAD FIB1 + DCA FIB0 + TAD FIB2 + DCA FIB1 + ISZ FIBN + JMP LOOP +EXIT, HLT + CLA IAC + DCA FIB1 + DCA FIB0 + JMP MAIN +PUTN, 0 + JMS ITOA + CMA IAC + IAC + CMA IAC + DCA 10 +PUTNL, CLA + TAD I 10 + SPA + JMP I PUTN + TAD (60) + JMS PUTC + JMP PUTNL +PUTC, 0 + TLS + TSF + JMP .-1 + JMP I PUTC +ITOA, 0 + DCA ITOAV + DCA ITOAD + DCA ITOAD+1 + DCA ITOAD+2 + DCA ITOAD+3 + TAD (-14) + DCA ITOAN +ITOAL, CLL / LOOP OVER BINARY INPUT BITS + TAD ITOAD+3 + JMS ITOA2X + DCA ITOAD+3 + TAD ITOAD+2 + JMS ITOA2X + DCA ITOAD+2 + TAD ITOAD+1 + JMS ITOA2X + DCA ITOAD+1 + TAD ITOAD + JMS ITOA2X + DCA ITOAD + CLL + TAD ITOAV / SHIFT MSB OUT OF INPUT VALUE + RAL + DCA ITOAV + RAL + TAD ITOAD+3 / ADD SHIFTED-OUT MSB TO DECIMAL LSD + DCA ITOAD+3 + ISZ ITOAN + JMP ITOAL / NEXT LOOP ITERATION + TAD (ITOAD) + DCA ITOAR +ITOAJ, TAD I ITOAR + SZA + JMP ITOAX + ISZ ITOAR + TAD I ITOAR + SZA + JMP ITOAX + ISZ ITOAR + TAD I ITOAR + SZA + JMP ITOAX + ISZ ITOAR +ITOAX, CLA + TAD ITOAR + JMP I ITOA +ITOA2X, 0 + RAL / PUTS 0 IN LINK + DCA ITOAT + TAD (-12) + TAD ITOAT / PUTS 1 IN LINK IF WRAPPED + SMA + DCA ITOAT + CLA + TAD ITOAT + JMP I ITOA2X +FIB0, 0 +FIB1, 1 +FIB2, 0 +FIBN, -27 +ITOAD, 0 / OUTPUT DIGITS (MSD FIRST) + 0 + 0 + 0 + 4000 / OUTPUT SENTINEL +ITOAN, 0 / INPUT BITS LOOP COUNTER +ITOAR, 0 / POINTER TO FIRST NONZERO DIGIT +ITOAT, 0 / SCRATCHPAD FOR ITOA2X +ITOAV, 0 / VALUE BEING CONVERTED (TEMPORARY) +$ -- cgit v1.2.3