From 66bf7bb81fe0f408d3348a7a1b33066d1f369216 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Fri, 14 Oct 2022 11:48:14 -0700 Subject: Actual palbart-compatible rim/bin loader --- main.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index bc17427..5788c54 100644 --- a/main.cpp +++ b/main.cpp @@ -2,20 +2,61 @@ #include #include #include +#include #include "isa/checker.h" -extern std::uint16_t _binary_build___image_bin_start[]; -extern std::uint16_t _binary_build___image_bin_end[]; +extern std::uint8_t _binary_count_bin_start[]; + +static const std::unordered_map programs = { + { "count", _binary_count_bin_start } +}; int main(int argc, const char *argv[]) { + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " program\n"; + std::cerr << "Programs:\n"; + for (const auto &p : programs) + std::cerr << "\t" << p.first << "\n"; + return 1; + } + + auto program = programs.at(argv[1]); + checker checker; + bool seen_non_leader = false; + bool comment = false; + unsigned int field = 0; unsigned int address = 0; - for (auto *src = _binary_build___image_bin_start; src < _binary_build___image_bin_end; ++src, ++address) { - auto word = ntohs(*src); - std::cout << fmt::format("mem[{:04o}] = {:04o}\n", address, word); - checker.mem.store(address, word); + while (true) { + auto b1 = *program++; + if (comment) { + if (b1 == 0377) + comment = false; + } else { + if (b1 == 0377) { + comment = true; + } else if (b1 == 0200) { + if (seen_non_leader) + break; + } else if ((b1 & 0300) == 0100) { + seen_non_leader = true; + address = ((b1 & 0077) << 6) | *program++; + } else if ((b1 & 0300) == 0000) { + seen_non_leader = true; + auto a = field | address++; + auto d = ((b1 & 0077) << 6) | *program++; + //std::cout << fmt::format("mem[{:06o}] = {:04o}\n", a, d); + checker.mem.store(a, d); + } else if ((b1 & 0307) == 0300) { + seen_non_leader = true; + field = (b1 & 0070) << 3; + } else { + std::cerr << "Invalid program BIN\n"; + return 2; + } + } } while (!checker.halted) { -- cgit v1.2.3