-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (36 loc) · 1.21 KB
/
main.cpp
File metadata and controls
40 lines (36 loc) · 1.21 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
#include "src/cartridge.h"
#include "src/cpu.h"
#include "src/bus.h"
#include <thread>
int main(int argc, char **argv) {
if (argc < 2) {
std::cerr << "No ROM file was passed in!" << std::endl;
std::cout << "Usage: " << argv[0] << " <rom>" << std::endl;
return 1;
}
std::string path = argv[1];
auto cartridge = new Cartridge();
if (!cartridge->load(path)) {
LOG_ERROR("Could not load ROM at path " << path)
return 1;
}
auto *bus = new Bus();
auto *ppu = new Ppu();
auto *cpu = new Cpu(bus);
bus->connect_cpu(cpu);
bus->connect_ppu(ppu);
bus->load_cartridge(cartridge);
cpu->initialize();
// Each cycle is 1/60th of a second
auto delay = std::chrono::microseconds(1000000 / 60);
using clock = std::chrono::high_resolution_clock;
using microseconds = std::chrono::microseconds;
while (true) {
auto start = clock::now();
// Perform one cycle.
bus->cycle();
// Sleep for the remainder of the delay (minus the amount of time the cycle took)
auto duration = clock::now() - start;
std::this_thread::sleep_for(std::chrono::duration_cast<microseconds>(delay - duration));
}
}