-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
78 lines (58 loc) · 1.56 KB
/
main.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
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
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <chrono>
#include <argparse/argparse.hpp>
#include "display/display_window.h"
#include "processor/processor.h"
using namespace std;
using namespace cchip8::display;
using namespace cchip8::processor;
void run_emulator(argparse::ArgumentParser& arg_parser)
{
const auto rom = arg_parser.get<string>("--rom");
const auto vs = arg_parser.get<int>("--video-scale"), cd = arg_parser.get<int>("--cycle-delay");
display_window win{ static_cast<uint32_t>(vs), "CHIP8" };
machine emulator{};
emulator.load(rom);
auto last_cycle_time = chrono::high_resolution_clock::now();
bool quit = false;
while (!quit)
{
quit = win.process_events(emulator.keypad());
auto time = chrono::high_resolution_clock::now();
auto dt = std::chrono::duration<float, std::chrono::milliseconds::period>(time - last_cycle_time).count();
if (dt > cd)
{
last_cycle_time = time;
emulator.cycle();
win.update(emulator.screen());
}
}
}
int main(int argc, char** argv)
{
argparse::ArgumentParser arg_parser{ "cchip8" };
arg_parser.add_argument("-r", "--rom")
.help("the CHIP8 ROM file")
.required()
.nargs(1);
arg_parser.add_argument("-vs", "--video-scale")
.help("Video scale.")
.default_value(10)
.scan<'i', int>();
arg_parser.add_argument("-cd", "--cycle-delay")
.help("Delay per cycle.")
.default_value(1)
.scan<'i', int>();
try
{
arg_parser.parse_args(argc, argv);
}
catch (const std::runtime_error& err)
{
cout << err.what() << endl;
cout << arg_parser;
return 1;
}
run_emulator(arg_parser);
return 0;
}