-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
66 lines (52 loc) · 916 Bytes
/
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
#include <cstdio>
#include <array>
#include <algorithm>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
#include "chip8.h"
#include "window.h"
int main(int argc, char* args[])
{
Chip8 vm;
Window window;
FILE* binFile;
fopen_s(&binFile, "roms/pong2.c8", "rb");
char buffer[512];
fread(buffer, 4, 512, binFile);
if (binFile == NULL) {
printf("file not found \n");
return 0;
}
else {
printf("rom opened \n");
}
fclose(binFile);
vm.initialize();
vm.loadGame(512, buffer);
window.create();
while (true) {
*vm.key = window.getKeySate(vm.key);
vm.emulateCycle();
if (vm.clearFlag)
{
window.clear();
vm.clearFlag = false;
}
if (vm.drawFlag)
{
std::array<bool, 2048> gfx = vm.gfx;
window.clear();
window.render(gfx);
vm.drawFlag = false;
}
else {
std::fill_n(vm.key, 16, false);
}
//Sleep(5);
}
window.destroy();
return 0;
}