#include #include #include #include #include #include "isa/checker.h" extern std::uint8_t _binary_count_bin_start[]; static const std::unordered_map programs = { { "count", _binary_count_bin_start } }; int load_program(checker &checker, const std::uint8_t *program) { bool seen_non_leader = false; bool comment = false; unsigned int field = 0; unsigned int address = 0; 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; } } } return 0; } int main(int argc, const char *argv[]) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " program [program ...]\n"; std::cerr << "Programs:\n"; for (const auto &p : programs) std::cerr << "\t" << p.first << "\n"; return 1; } checker checker; for (--argc, ++argv; argc; --argc, ++argv) { auto program = programs.at(argv[0]); if (auto err = load_program(checker, program)) return err; } while (!checker.halted) { std::cout << fmt::format("{:04o}: ", checker.pc); checker.execute(); std::cout << fmt::format("acc={:04o}\n", checker.acc); } return 0; }