-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (42 loc) · 1.14 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 <iostream>
#include "cpu.h"
#include<chrono>
#include <thread>
#include "SDL2/SDL.h"
int main(int argc, char* argv[])
{
CPU emu = CPU();
if(emu.loadRom(argv[1]) != 0)
{
std::cout << "Could not load rom file" << std::endl;
return -1;
}
while( emu.isRunning())
{
emu.emulateCycle();
SDL_Event e;
if(SDL_PollEvent(&e))
{
switch (e.type) {
case SDL_QUIT:
std::cout << "Bye!" << std::endl;
emu.shutdown();
break;
case SDL_KEYDOWN:
emu.handle_key_pressed(e.key.keysym.scancode);
break;
case SDL_KEYUP:
emu.handle_key_released(e.key.keysym.scancode);
break;
default:
break;
}
}
if(emu.draw() && emu.isRunning()) //In case we exit the emulator and the draw flag is set, we check if the emu will be running in the next iteration.
{
emu.draw_screen();
}
std::this_thread::sleep_for(std::chrono::microseconds(1200));
}
return 0;
}