-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entry.c
79 lines (61 loc) · 1.47 KB
/
Entry.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
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
74
75
76
77
78
79
#include <stdio.h>
#include <SDl.h>
#include "Setup.h"
#include "Memory.h"
#include "Computer.h"
#include "LiquidClearDisplay.h"
#include "Input.h"
#include "Sound.h"
int main(int arc, char* argv[]) {
SDL_Window* window;
SDL_Renderer* renderer;
char running;
char draw_flag;
Setup();
SetupSound();
window = CreateWindow();
renderer = CreateRenderer(window);
running = 1;
SetupMemory();
LoadGame(GAMETITLE);
DumpMemory();
SetupComputer();
ClearInput();
SetupScreen();
draw_flag = 0;
int current_time = SDL_GetPerformanceCounter();
int last_time = 0;
double delta_time = 0;
double time_elapsed = 0;
double cpu_time_elapsed = 0;
while (running) {
last_time = current_time;
current_time = SDL_GetPerformanceCounter();
delta_time = (((double)current_time - last_time) * 1000 / (double)SDL_GetPerformanceFrequency());
time_elapsed += delta_time;
cpu_time_elapsed = time_elapsed;
if (time_elapsed > 1000/SCREEN_FPS) {
time_elapsed = 0;
UpdateTimers();
}
if (cpu_time_elapsed > 1000/CPU_RATE) {
cpu_time_elapsed = 0;
if (draw_flag == 1) {
SDL_RenderClear(renderer);
UpdateScreen(renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderPresent(renderer);
//wait for draw instruction to finish
SDL_Delay(16);
}
FetchInstruction();
draw_flag = 0;
ExecuteInsruction(&draw_flag);
UpdateInput(&running);
}
}
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
CleanupSound();
return 0;
}