diff options
Diffstat (limited to 'main.cpp')
| -rw-r--r-- | main.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
| @@ -2,13 +2,15 @@ | |||
| 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 | #include <map> |
| 6 | #include <optional> | ||
| 7 | #include <utility> | ||
| 6 | 8 | ||
| 7 | #include "isa/checker.h" | 9 | #include "isa/checker.h" |
| 8 | 10 | ||
| 9 | extern std::uint8_t _binary_count_bin_start[]; | 11 | extern std::uint8_t _binary_count_bin_start[]; |
| 10 | 12 | ||
| 11 | static const std::unordered_map<std::string, std::uint8_t *> programs = { | 13 | static const std::map<std::string, std::uint8_t *> programs = { |
| 12 | { "count", _binary_count_bin_start } | 14 | { "count", _binary_count_bin_start } |
| 13 | }; | 15 | }; |
| 14 | 16 | ||
| @@ -17,6 +19,7 @@ int load_program(checker &checker, const std::uint8_t *program) { | |||
| 17 | bool comment = false; | 19 | bool comment = false; |
| 18 | unsigned int field = 0; | 20 | unsigned int field = 0; |
| 19 | unsigned int address = 0; | 21 | unsigned int address = 0; |
| 22 | std::optional<std::pair<unsigned int, unsigned int>> data; | ||
| 20 | while (true) { | 23 | while (true) { |
| 21 | auto b1 = *program++; | 24 | auto b1 = *program++; |
| 22 | if (comment) { | 25 | if (comment) { |
| @@ -33,10 +36,13 @@ int load_program(checker &checker, const std::uint8_t *program) { | |||
| 33 | address = ((b1 & 0077) << 6) | *program++; | 36 | address = ((b1 & 0077) << 6) | *program++; |
| 34 | } else if ((b1 & 0300) == 0000) { | 37 | } else if ((b1 & 0300) == 0000) { |
| 35 | seen_non_leader = true; | 38 | seen_non_leader = true; |
| 39 | if (data.has_value()) { | ||
| 40 | //std::cout << fmt::format("mem[{:06o}] = {:04o}\n", data->first, data->second); | ||
| 41 | checker.mem.store(data->first, data->second); | ||
| 42 | } | ||
| 36 | auto a = field | address++; | 43 | auto a = field | address++; |
| 37 | auto d = ((b1 & 0077) << 6) | *program++; | 44 | auto d = ((b1 & 0077) << 6) | *program++; |
| 38 | //std::cout << fmt::format("mem[{:06o}] = {:04o}\n", a, d); | 45 | data = std::make_pair(a, d); |
| 39 | checker.mem.store(a, d); | ||
| 40 | } else if ((b1 & 0307) == 0300) { | 46 | } else if ((b1 & 0307) == 0300) { |
| 41 | seen_non_leader = true; | 47 | seen_non_leader = true; |
| 42 | field = (b1 & 0070) << 3; | 48 | field = (b1 & 0070) << 3; |
