Repository navigation
Expand file tree
/
Copy pathch8dis.cpp
More file actions
66 lines (54 loc) · 1.61 KB
/
Copy pathch8dis.cpp
File metadata and controls
66 lines (54 loc) · 1.61 KB
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
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include "include/disassembler/disassembler.hpp"
constexpr auto VERSION = 0.1;
void print_help() {
std::cout << "usage: ch8dis <input_file> [--verbose] [--help] [--version]\n";
std::cout << "options:\n"
<< " --verbose enable verbose disassembly\n"
<< " --help show this help message\n"
<< " --version show version info\n";
}
void print_version() { std::cout << "ch8dis nuts version " << VERSION << "\n"; }
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cerr << "error: no input file provided.\n";
print_help();
return 1;
}
std::string input_file;
bool verbose = false;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--help") {
print_help();
return 0;
} else if (arg == "--version") {
print_version();
return 0;
} else if (arg == "--verbose") {
verbose = true;
} else if (input_file.empty()) {
input_file = arg;
} else {
std::cerr << "unknown argument: " << arg << "\n";
return 1;
}
}
try {
std::ifstream file(input_file, std::ios::binary);
if (!file) {
throw std::runtime_error("failed to open input file: " + input_file);
}
std::vector<uint8_t> rom((std::istreambuf_iterator<char>(file)), {});
Disassembler dis;
std::string output = dis.DecodeRomFromArray(rom, verbose);
std::cout << output;
} catch (const std::exception &e) {
std::cerr << "disassembler error: " << e.what() << "\n";
return 1;
}
return 0;
}