-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.cpp
40 lines (33 loc) · 1.08 KB
/
dump.cpp
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
#include "InstrTable.h"
#include "pch.h"
#include "iNES.h"
#include <filesystem>
#include <cstdint>
#include <iostream>
int main(int argc, char *argv[]) {
VERIFY(argc == 2, "Usage: {} <rom>", argv[0]);
iNES ines(argv[1]);
auto prg_rom = ines.GetPrgRom();
size_t pc = 0;
while (pc < prg_rom.size()) {
auto opcode = prg_rom[pc];
auto instrData = InstrDataTable[opcode];
auto addrData = AddrModeDataTable[instrData.mode];
switch (addrData.size) {
case 0:
fmt::print(fmt::runtime(addrData.fmt), instrData.mnemonic);
break;
case 1:
fmt::print(fmt::runtime(addrData.fmt), instrData.mnemonic, prg_rom[pc + 1]);
break;
case 2:
fmt::print(fmt::runtime(addrData.fmt), instrData.mnemonic, prg_rom[pc + 1], prg_rom[pc + 2]);
break;
case 3:
fmt::print(fmt::runtime(addrData.fmt), instrData.mnemonic, prg_rom[pc + 1], prg_rom[pc + 2], prg_rom[pc + 3]);
break;
}
pc += addrData.size;
}
return 0;
}