-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
58 lines (43 loc) · 1.43 KB
/
main.cc
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
#include "chip-8.h"
#include "gameWindow.h"
#include <chrono>
#include <iostream>
int main(int argc, char** argv)
{
//If given an invalid argument count exit
if(argc != 4)
{
return -1;
}
//load in arguments as variables
int videoScale = std::stoi(argv[1]);
int cycleDelay = std::stoi(argv[2]);
char const* fileName = argv[3];
//Create Game window
GameWindow Window(fileName, DISPLAY_WIDTH * videoScale, DISPLAY_HIGHT * videoScale, DISPLAY_WIDTH, DISPLAY_HIGHT);
//create CHIP-8
Chip8 Chip8_Emulator;
Chip8_Emulator.loadROM(fileName);
int videoPitch = sizeof(Chip8_Emulator.display[0]) * DISPLAY_WIDTH;
//set condition variable to false and set now to be the time of the first cycle
auto lastcycle = std::chrono::high_resolution_clock::now();
bool quit = false;
//emulation loop
while(!quit)
{
//if signaled to quit exit
quit = Window.processInput(Chip8_Emulator.keypad);
//get the current time and find the difference since we set the fist cycle
auto currentTime = std::chrono::high_resolution_clock::now();
float delta_t = std::chrono::duration<float, std::chrono::milliseconds::period>(currentTime - lastcycle).count();
//if the change in time is greater that the delay set then run a cycle
if(delta_t > cycleDelay)
{
// Chip8_Emulator.printState();
lastcycle = currentTime;
Chip8_Emulator.cycle();
Window.Update(Chip8_Emulator.display, videoPitch);
}
}
return 0;
}