-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
45 lines (37 loc) · 1.04 KB
/
main.c
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
#include <time.h>
#include "structures.h"
int main(int argc, char **argv) {
if (!(argv[1])) {
fprintf(LOGFILE, "Error! No ROM given to run!\n");
return 1;
}
srand(time(NULL));
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *win = SDL_CreateWindow(WIN_NAME,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, WINFLAGS);
SDL_Renderer *rend = SDL_CreateRenderer(win, -1, RENDFLAGS);
SDL_RenderSetLogicalSize(rend, WIDTH, HEIGHT);
SDL_Texture *tex = SDL_CreateTexture(rend, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STATIC, ORIG_WIDTH, ORIG_HEIGHT);
memset(pixels, 0, ORIG_PIXEL_COUNT - 1);
initmemory();
loadROM(argv[1]);
while (running) {
inputResult in = getInput();
running = in.running;
key = in.value;
time_t beginningTime = time(NULL);
for (;ipc < INST_PER_SEC; ipc++) {
if (!(ipc % 60)) {
updateTimers();
}
eval(fetch(), rend, tex);
}
if (time(NULL) - beginningTime >= 1) {
ipc = 0;
}
}
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(rend);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}