diff options
| author | Julian Blake Kongslie | 2022-10-29 12:55:08 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-10-29 13:14:13 -0700 |
| commit | ff66523bb076a246c2fc159f0f76947bd6f84fc1 (patch) | |
| tree | 63dbffc8be3c41eb5ec2f74dd7919f5f34a25a53 | |
| parent | Add untested interrupt-based echo program with input buffer (diff) | |
| download | biggolf-ff66523bb076a246c2fc159f0f76947bd6f84fc1.tar.xz | |
Control register values should not be "unsigned int"
Diffstat (limited to '')
| -rw-r--r-- | io/event.h | 7 | ||||
| -rw-r--r-- | io/model.cpp | 2 | ||||
| -rw-r--r-- | io/model.h | 5 | ||||
| -rw-r--r-- | isa/checker.h | 3 | ||||
| -rw-r--r-- | isa/decode.cpp | 19 | ||||
| -rw-r--r-- | isa/isa.h | 3 | ||||
| -rw-r--r-- | programs/echo.pal | 64 |
7 files changed, 37 insertions, 66 deletions
| @@ -1,14 +1,15 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <cstdint> | ||
| 3 | #include <map> | 4 | #include <map> |
| 4 | 5 | ||
| 5 | #include "isa/isa.h" | 6 | #include "isa/isa.h" |
| 6 | 7 | ||
| 7 | struct event { | 8 | struct event { |
| 8 | ctlreg reg; | 9 | ctlreg reg; |
| 9 | unsigned int mask; | 10 | std::uint_fast32_t mask; |
| 10 | unsigned int value; | 11 | std::uint_fast32_t value; |
| 11 | event(ctlreg reg, unsigned int value, unsigned int mask=~0) | 12 | event(ctlreg reg, std::uint_fast32_t value, std::uint_fast32_t mask=~0) |
| 12 | : reg(reg) | 13 | : reg(reg) |
| 13 | , mask(mask) | 14 | , mask(mask) |
| 14 | , value(value) | 15 | , 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 @@ | |||
| 6 | #include "io/model.h" | 6 | #include "io/model.h" |
| 7 | #include "isa/isa.h" | 7 | #include "isa/isa.h" |
| 8 | 8 | ||
| 9 | bool iomodel::interact(std::array<unsigned int, NUM_CTLREGS> &ctlregs) { | 9 | bool iomodel::interact(std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs) { |
| 10 | auto [ebegin, eend] = log.equal_range(time); | 10 | auto [ebegin, eend] = log.equal_range(time); |
| 11 | for (auto e = ebegin; e != eend; ++e) { | 11 | for (auto e = ebegin; e != eend; ++e) { |
| 12 | auto &r = ctlregs[e->second.reg]; | 12 | auto &r = ctlregs[e->second.reg]; |
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | #include <array> | 3 | #include <array> |
| 4 | #include <cstdint> | 4 | #include <cstdint> |
| 5 | #include <istream> | ||
| 5 | 6 | ||
| 6 | #include "io/event.h" | 7 | #include "io/event.h" |
| 7 | #include "isa/isa.h" | 8 | #include "isa/isa.h" |
| @@ -11,5 +12,7 @@ struct iomodel { | |||
| 11 | 12 | ||
| 12 | event_log log; | 13 | event_log log; |
| 13 | std::uint64_t time = 0; | 14 | std::uint64_t time = 0; |
| 14 | bool interact(std::array<unsigned int, NUM_CTLREGS> &ctlregs); | 15 | bool interact(std::array<std::uint_fast32_t, NUM_CTLREGS> &ctlregs); |
| 16 | |||
| 17 | void load_evt(std::istream &fh); | ||
| 15 | }; | 18 | }; |
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 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <array> | 3 | #include <array> |
| 4 | #include <cstdint> | ||
| 4 | #include <map> | 5 | #include <map> |
| 5 | 6 | ||
| 6 | #include "io/model.h" | 7 | #include "io/model.h" |
| @@ -41,7 +42,7 @@ struct checker { | |||
| 41 | unsigned int link = 0; | 42 | unsigned int link = 0; |
| 42 | unsigned int mq = 0; | 43 | unsigned int mq = 0; |
| 43 | unsigned int pc = 00200; | 44 | unsigned int pc = 00200; |
| 44 | std::array<unsigned int, NUM_CTLREGS> ctlregs; | 45 | std::array<std::uint_fast32_t, NUM_CTLREGS> ctlregs; |
| 45 | iomodel &system; | 46 | iomodel &system; |
| 46 | instruction_context inst; | 47 | instruction_context inst; |
| 47 | funcmem mem; | 48 | 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 | |||
| 140 | break; | 140 | break; |
| 141 | } | 141 | } |
| 142 | break; | 142 | break; |
| 143 | case 003: | ||
| 144 | // KEYBOARD | ||
| 145 | switch (bits & 07) { | ||
| 146 | case 1: | ||
| 147 | // KSF skip if TTI flag is set | ||
| 148 | inst.read_ctlreg = TT_BITS; | ||
| 149 | inst.possibly_redirects = true; | ||
| 150 | inst.ef = [](auto &ctx) { | ||
| 151 | if (ctx.ctlval.value() & TTI_FLAG) | ||
| 152 | ctx.next_pc = (ctx.next_pc & ~07777) | ((ctx.next_pc + 1) & 07777); | ||
| 153 | }; | ||
| 154 | break; | ||
| 155 | default: | ||
| 156 | inst.ef = [bits](auto &ctx) { | ||
| 157 | std::cerr << "unimplemented IOT KB suboperation " << (bits & 07) << "\n"; | ||
| 158 | assert(false); | ||
| 159 | }; | ||
| 160 | } | ||
| 161 | break; | ||
| 143 | case 004: | 162 | case 004: |
| 144 | // TELETYPE TELEPRINTER/PUNCH | 163 | // TELETYPE TELEPRINTER/PUNCH |
| 145 | switch (bits & 07) { | 164 | switch (bits & 07) { |
| @@ -1,5 +1,6 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <cstdint> | ||
| 3 | #include <functional> | 4 | #include <functional> |
| 4 | #include <optional> | 5 | #include <optional> |
| 5 | 6 | ||
| @@ -49,7 +50,7 @@ struct instruction_context { | |||
| 49 | unsigned int next_pc; // includes IF | 50 | unsigned int next_pc; // includes IF |
| 50 | std::optional<unsigned int> init_address; // includes DF | 51 | std::optional<unsigned int> init_address; // includes DF |
| 51 | std::optional<unsigned int> final_address; // includes DF | 52 | std::optional<unsigned int> final_address; // includes DF |
| 52 | std::optional<unsigned int> ctlval; | 53 | std::optional<std::uint_fast32_t> ctlval; // control registers may be larger than 16 bits (e.g. TT_BITS) |
| 53 | std::optional<unsigned int> data; | 54 | std::optional<unsigned int> data; |
| 54 | std::optional<unsigned int> acc; | 55 | std::optional<unsigned int> acc; |
| 55 | std::optional<bool> link; | 56 | std::optional<bool> 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 @@ | |||
| 1 | / vim: set sw=8 noexpandtab : | 1 | / vim: set sw=8 noexpandtab : |
| 2 | 2 | ||
| 3 | *000 | ||
| 4 | |||
| 5 | INTRET, 0 | ||
| 6 | JMP GOTINT | ||
| 7 | |||
| 8 | INPUTY, 1000 / Address of youngest byte in input buffer | ||
| 9 | INPUTO, 1000 / Address of oldest byte in input buffer | ||
| 10 | |||
| 11 | *200 | 3 | *200 |
| 12 | 4 | LOOP, TSF | |
| 13 | / Main program enables keyboard interrupt, then enters echo loop | ||
| 14 | KIE | ||
| 15 | ION | ||
| 16 | LOOP, TSF / Call ECHO if printer is ready | ||
| 17 | JMS ECHO | 5 | JMS ECHO |
| 18 | JMP LOOP | 6 | JMP LOOP |
| 19 | 7 | ||
| 20 | ECHO, 0 | 8 | ECHO, 0 |
| 21 | TAD INPUTO | 9 | WAIT, KSF |
| 22 | CMA IAC / Negate | 10 | JMP WAIT |
| 23 | TAD INPUTY | 11 | KRB |
| 24 | SNA / Abandon echo if input buffer is empty (n.b. or full, because we don't have wrap bits) | 12 | TLS |
| 25 | JMP I ECHO | ||
| 26 | TAD I INPUTO / Read from input buffer | ||
| 27 | TLS / Print | ||
| 28 | JMS FIXO | ||
| 29 | JMP I ECHO | 13 | JMP I ECHO |
| 30 | |||
| 31 | GOTINT, KSF / Skip reading keyboard if nothing was typed | ||
| 32 | JMP NOIN | ||
| 33 | DCA SAVED | ||
| 34 | KRB / Read from keyboard | ||
| 35 | DCA I INPUTY / Write to input buffer | ||
| 36 | JMS FIXY | ||
| 37 | CLA | ||
| 38 | TAD SAVED | ||
| 39 | NOIN, RMF | ||
| 40 | ION | ||
| 41 | JMP I INTRET | ||
| 42 | |||
| 43 | / Wrap INPUTY pointer at 2000 back to 1000 | ||
| 44 | FIXY, 0 | ||
| 45 | TAD INPUTY | ||
| 46 | TAD [-2000] | ||
| 47 | SZA | ||
| 48 | JMP I FIXY | ||
| 49 | CLA | ||
| 50 | TAD [1000] | ||
| 51 | DCA INPUTY | ||
| 52 | JMP I FIXY | ||
| 53 | |||
| 54 | / Wrap INPUTO pointer at 2000 back to 1000 | ||
| 55 | FIXO, 0 | ||
| 56 | TAD INPUTO | ||
| 57 | TAD [-2000] | ||
| 58 | SZA | ||
| 59 | JMP I FIXO | ||
| 60 | CLA | ||
| 61 | TAD [1000] | ||
| 62 | DCA INPUTO | ||
| 63 | JMP I FIXO | ||
| 64 | |||
| 65 | *300 | ||
| 66 | |||
| 67 | SAVED, 0 | ||
