-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
73 lines (57 loc) · 1.55 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <chrono>
#include <thread>
#include <map>
#include <SDL2/SDL.h>
#include "Chip8.cpp"
using namespace std;
Chip8 myChip8;
int main()
{
const Uint8 *keyboard_state;
SDL_Init(SDL_INIT_VIDEO);
// Set up render system, audio and register input callbacks
myChip8.setupGraphics(50);
myChip8.setupAudio();
myChip8.setupInput();
// Initialize the Chip8 system and load the game into the memory
myChip8.initialize();
myChip8.loadGame("BRIX");
int continuer = 1;
SDL_Event event;
while (continuer)
{
myChip8.emulateCycle();
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
continuer = 0;
break;
}
}
keyboard_state = SDL_GetKeyboardState(NULL);
for (std::map<Uint8, unsigned char>::iterator it = myChip8.keypadMap.begin(); it != myChip8.keypadMap.end(); it++)
{
if (keyboard_state[it->first])
{
cout << it->first << " is pressed" << endl;
myChip8.key[it->second] = 1;
}
else
{
myChip8.key[it->second] = 0;
}
}
// If the draw flag is set, update the screen
if (myChip8.drawFlag == 1)
{
myChip8.drawGraphics();
}
// Sleep to slow down emulation speed
std::this_thread::sleep_for(std::chrono::microseconds(1200));
}
myChip8.clearGraphics();
return 0;
}