-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (41 loc) · 1.17 KB
/
Copy pathmain.cpp
File metadata and controls
46 lines (41 loc) · 1.17 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
/*
* CHIP-8 Emulator (Interpeter)
* October 2020
* ~aml
*/
#include "engine.h"
#include <cstdio>
#include <cstdlib>
#include <chrono>
#include <string>
int main(int argc, char* argv[])
{
if (argc != 4) {
printf("Invalid arguments. Usage: chip8emulator.exe <game.ch8> <delayValue> <scale>");
return 0;
}
Engine myEngine;
printf("Loading %s\n", argv[1]);
myEngine.scale = atoi(argv[3]);
myEngine.loadGame(argv[1]);
if (!myEngine.initGraphics())
return 0;
//Get time on startup to setup delay in the busy loop
auto lastCycleTime = std::chrono::high_resolution_clock::now();
int cycleDelay = atoi(argv[2]);
while (!myEngine.quit) {
auto currentTime = std::chrono::high_resolution_clock::now();
//Get differential time between last cycle and now. If enough time has passed, the CPU cycle will execute
float t = std::chrono::duration<float, std::chrono::milliseconds::period>(currentTime - lastCycleTime).count();
if (t > cycleDelay) {
lastCycleTime = currentTime;
myEngine.parseInput(myEngine.key);
myEngine.emulateCycle();
if (myEngine.drawFlag)
myEngine.videoRender();
if (myEngine.delayTimer != 0)
myEngine.delayTimer--;
}
}
return 0;
}