blob: 5788c54ed548c22c18b4768475b09f95ec156d38 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include <arpa/inet.h>
#include <cstdint>
#include <fmt/format.h>
#include <iostream>
#include <unordered_map>
#include "isa/checker.h"
extern std::uint8_t _binary_count_bin_start[];
static const std::unordered_map<std::string, std::uint8_t *> 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;
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) {
std::cout << fmt::format("{:04o}: ", checker.pc);
checker.execute();
std::cout << fmt::format("acc={:04o}\n", checker.acc);
}
return 0;
}
|