-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
113 lines (94 loc) · 2.72 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <string.h>
#include <unistd.h>
#include <iostream>
#include "chip8.h"
#include "display.h"
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cout << "Usage: chip8 --rom <rom>" << std::endl;
return 0;
}
bool DEBUG_MODE = false;
bool audio = false;
std::string filename;
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "-d") == 0) {
std::cout << "Debug mode" << std::endl;
DEBUG_MODE = true;
}
if (strcmp(argv[i], "-a") == 0) {
std::cout << "Audio enabled" << std::endl;
audio = true;
}
if (strcmp(argv[i], "--scale") == 0) {
std::cout << "Scaling set to " << argv[i + 1] << std::endl;
disp_scaling = atoi(argv[i + 1]);
}
if (!strcmp(argv[i], "--rom") && (i + 1) < argc) filename = argv[i + 1];
}
if (DEBUG_MODE) {
std::cout << "Running in DEBUG MODE" << std::endl;
}
CHIP8 chip8(audio);
chip8.loadROM(filename);
std::cout << "Successfully loaded ROM" << std::endl;
bool init_success = sdlInit();
if (!init_success) return 0;
bool quit = false;
auto time_prev = std::chrono::system_clock::now();
while (!quit) {
// std::string x;
// std::cin >> x;
bool result = chip8.runCycle();
chip8.dumpRegisters();
if (!result) {
std::cout << "Could not process last instruction..." << std::endl;
break;
}
if (chip8.draw_flag) {
std::cout << "drawing" << std::endl;
sdlDraw(&chip8);
// chip8.debugDraw();
}
quit = sdlRun(&chip8);
// if (chip8.key_pressed != -1) {
// std::cout << "Key pressed " << chip8.key_pressed << std::endl;
// }
auto time_now = std::chrono::system_clock::now();
// std::chrono::duration<double> diff = time_now - time_prev;
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
time_now - time_prev);
if (milliseconds.count() >= CLOCK_RATE_MS) {
// chip8.timerTick();
// time_prev = time_now;
}
usleep(1500);
}
sdlCleanup();
// if (DEBUG_MODE) {
// std::cout << "Enter command (`r` to run the next cycle, `print` to print
// "
// "state, `draw` to debug draw";
// }
// while (true) {
// bool result = true;
// if (DEBUG_MODE) {
// std::string command;
// std::cin >> command;
// if (command == "r") {
// result = chip8->runCycle();
// } else if (command == "print") {
// chip8->dumpRegisters();
// } else if (command == "exit") {
// result = false;
// } else if (command == "draw") {
// chip8->debugDraw();
// } else {
// std::cout << "Unknown command" << std::endl;
// }
// } else {
// result = chip8->runCycle();
// }
// }
return 0;
}