-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
46 lines (38 loc) · 1.25 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
#include <iostream>
#include <chrono>
#include "src/Chip8.h"
#include "src/Screen.h"
#include "src/EventHandler.h"
int main(int argc, char** argv) {
const int modifier = 20; // Factor each pixel by this value
const int window_w = modifier * Chip8::SCREEN_W;
const int window_h = modifier * Chip8::SCREEN_H;
if (argc < 2) {
std::cout << "Missing rom file. Usage: chip8 APPLICATION.c8" << std::endl;
return 1;
}
Debugger debugger;
Chip8 chip8(&debugger);
Screen screen(window_w, window_h);
EventHandler eventHandler(&chip8);
if (!screen.init()) {
std::cout << SDL_GetError() << std::endl;
}
chip8.loadApplication(argv[1]);
for (;;) {
chip8.cycle();
if (chip8.getDrawFlag()) {
for (int y = 0; y < Chip8::SCREEN_H; ++y) {
for (int x = 0; x < Chip8::SCREEN_W; ++x) {
if (chip8.getScreen()[x + (y * Chip8::SCREEN_W)] == 1) {
screen.renderSquare(x, y, modifier, 0xFF, 0xFF, 0xFF);
} else {
screen.renderSquare(x, y, modifier, 0, 0, 0);
}
}
}
screen.update();
}
eventHandler.processEvent();
}
}