-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (48 loc) · 1.46 KB
/
main.cpp
File metadata and controls
68 lines (48 loc) · 1.46 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
67
68
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
#include "Chip8.hpp"
#include "Display.hpp"
#define CLOCK_SPEED 500 // CHIP8 should be 500Hz, SuperCHIP should be 1000hz
using Clock=std::chrono::system_clock;
void draw_display_cout(Chip8 *chip_8) {
for (auto & rows : chip_8->display) {
for (uint8_t point : rows) {
std::cout << (point ? "#" : " ");
}
std::cout << std::endl;
}
}
int main(int argc, char **argv) {
bool running = true;
if (argc < 2) {
std::cout << "Usage: chip8ler <rom_file>" << std::endl;
return 1;
}
std::string rom_path = argv[1];
auto *chip_8 = new Chip8(true);
if (!chip_8->LoadRom(rom_path)) {
return 1;
}
std::cout << "Starting " << rom_path << std::endl;
auto *display = new Display(chip_8, rom_path.c_str());
std::chrono::system_clock::time_point stamp;
while (running) {
stamp = Clock::now();
chip_8->Cycle();
// Draw to display
if (chip_8->ShouldUpdateDisplay()) {
display->Draw();
}
// TODO: implement buzz
if (chip_8->ShouldBuzz()) {
}
display->HandleInput(running);
long delta = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - stamp).count();
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / CLOCK_SPEED - delta));
}
delete(display);
delete(chip_8);
return 0;
}