-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (35 loc) · 1.18 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
#include "Chip8.h"
#include "Platform.h"
#include <chrono>
#include <iostream>
int main(int argc, char **argv)
{
using namespace chip8;
if (argc != 4)
{
std::cerr << "Usage: " << argv[0] << " <Scale> <Delay> <ROM>\n";
std::exit(EXIT_FAILURE);
}
int videoScale = std::stoi(argv[1]);
int cycleDelay = std::stoi(argv[2]);
char const *romFilename = argv[3];
Platform platform("CHIP-8 Emulator", SCREEN_WIDTH * videoScale, SCREEN_HEIGHT * videoScale, SCREEN_WIDTH, SCREEN_HEIGHT);
Chip8 chip8;
chip8.loadGame(romFilename);
int videoPitch = sizeof(chip8.m_display[0]) * SCREEN_WIDTH;
auto lastCycleTime = std::chrono::high_resolution_clock::now();
bool quit = false;
while (!quit)
{
quit = Platform::ProcessInput(chip8.m_keypad);
auto currentTime = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - lastCycleTime).count();
if (elapsed > cycleDelay)
{
lastCycleTime = currentTime;
chip8.cycle();
platform.Update(chip8.m_display, videoPitch);
}
}
return 0;
}