diff options
| author | Julian Blake Kongslie | 2022-10-14 11:48:14 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-10-14 11:48:14 -0700 |
| commit | 66bf7bb81fe0f408d3348a7a1b33066d1f369216 (patch) | |
| tree | 08bf8e02dfbd9bb54aa7c1c95c548f7c600f5da5 /main.cpp | |
| parent | Trivial infinite increment-and-loop as sample image. (diff) | |
| download | biggolf-66bf7bb81fe0f408d3348a7a1b33066d1f369216.tar.xz | |
Actual palbart-compatible rim/bin loader
Diffstat (limited to '')
| -rw-r--r-- | main.cpp | 53 |
1 files changed, 47 insertions, 6 deletions
| @@ -2,20 +2,61 @@ | |||
| 2 | #include <cstdint> | 2 | #include <cstdint> |
| 3 | #include <fmt/format.h> | 3 | #include <fmt/format.h> |
| 4 | #include <iostream> | 4 | #include <iostream> |
| 5 | #include <unordered_map> | ||
| 5 | 6 | ||
| 6 | #include "isa/checker.h" | 7 | #include "isa/checker.h" |
| 7 | 8 | ||
| 8 | extern std::uint16_t _binary_build___image_bin_start[]; | 9 | extern std::uint8_t _binary_count_bin_start[]; |
| 9 | extern std::uint16_t _binary_build___image_bin_end[]; | 10 | |
| 11 | static const std::unordered_map<std::string, std::uint8_t *> programs = { | ||
| 12 | { "count", _binary_count_bin_start } | ||
| 13 | }; | ||
| 10 | 14 | ||
| 11 | int main(int argc, const char *argv[]) { | 15 | int main(int argc, const char *argv[]) { |
| 16 | if (argc != 2) { | ||
| 17 | std::cerr << "Usage: " << argv[0] << " program\n"; | ||
| 18 | std::cerr << "Programs:\n"; | ||
| 19 | for (const auto &p : programs) | ||
| 20 | std::cerr << "\t" << p.first << "\n"; | ||
| 21 | return 1; | ||
| 22 | } | ||
| 23 | |||
| 24 | auto program = programs.at(argv[1]); | ||
| 25 | |||
| 12 | checker checker; | 26 | checker checker; |
| 13 | 27 | ||
| 28 | bool seen_non_leader = false; | ||
| 29 | bool comment = false; | ||
| 30 | unsigned int field = 0; | ||
| 14 | unsigned int address = 0; | 31 | unsigned int address = 0; |
| 15 | for (auto *src = _binary_build___image_bin_start; src < _binary_build___image_bin_end; ++src, ++address) { | 32 | while (true) { |
| 16 | auto word = ntohs(*src); | 33 | auto b1 = *program++; |
| 17 | std::cout << fmt::format("mem[{:04o}] = {:04o}\n", address, word); | 34 | if (comment) { |
| 18 | checker.mem.store(address, word); | 35 | if (b1 == 0377) |
| 36 | comment = false; | ||
| 37 | } else { | ||
| 38 | if (b1 == 0377) { | ||
| 39 | comment = true; | ||
| 40 | } else if (b1 == 0200) { | ||
| 41 | if (seen_non_leader) | ||
| 42 | break; | ||
| 43 | } else if ((b1 & 0300) == 0100) { | ||
| 44 | seen_non_leader = true; | ||
| 45 | address = ((b1 & 0077) << 6) | *program++; | ||
| 46 | } else if ((b1 & 0300) == 0000) { | ||
| 47 | seen_non_leader = true; | ||
| 48 | auto a = field | address++; | ||
| 49 | auto d = ((b1 & 0077) << 6) | *program++; | ||
| 50 | //std::cout << fmt::format("mem[{:06o}] = {:04o}\n", a, d); | ||
| 51 | checker.mem.store(a, d); | ||
| 52 | } else if ((b1 & 0307) == 0300) { | ||
| 53 | seen_non_leader = true; | ||
| 54 | field = (b1 & 0070) << 3; | ||
| 55 | } else { | ||
| 56 | std::cerr << "Invalid program BIN\n"; | ||
| 57 | return 2; | ||
| 58 | } | ||
| 59 | } | ||
| 19 | } | 60 | } |
| 20 | 61 | ||
| 21 | while (!checker.halted) { | 62 | while (!checker.halted) { |
