-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
60 lines (49 loc) · 1.67 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
#include <chrono>
#include <thread>
#include "include/chip.h"
#include "include/device.h"
CHIP8 chip8;
Device device; // Init our device
using namespace std;
int main(int argc, char* args[]) {
if (argc < 2 or argc > 3) {
cerr << "Invalid arguments entered. Format: .chip8 <path_to_rom>. For verbose mode, add \"--v\" flag.\n";
return 1;
}
for (int i=1; i<argc; i++) {
string debug_flag = "--v";
if (debug_flag == args[i]) {
chip8.debugger.setDebug(true);
continue;
}
string filename = args[i];
int result = chip8.loadProgram(filename);
if (result == 1) {
cerr << "Path to ROM file is not valid.\n";
cerr << "Invalid arguments entered. Format: .chip8 <path_to_rom>. For verbose mode, add \"--v\" flag.\n";
return 1;
}
}
int quit_flag = false;
// Set up the render system and the graphics;
thread keyboard_thread = thread(&Device::runKeyboardMonitor, &device, &quit_flag);
// Register input callbacks
// Call initialize()
// Load the game (loadProgram)
//chip8.displayGraphics();
int clock_time_period = 1000/CLOCK_FREQ; // Rounded to the nearest millisecond
while(chip8.checkValidPC() and not quit_flag) {
// Check for key-presses
chip8.setKeys(&device);
// Run an emulateCycle();
chip8.emulateCycle();
// If drawFlag has been set by DRW
if (chip8.checkDrawFlag()) {
chip8.displayGraphics(&device);
}
chip8.resetKeys();
this_thread::sleep_for(chrono::milliseconds(clock_time_period));
}
keyboard_thread.join();
return 0;
}