-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
232 lines (205 loc) · 8.1 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// On linux compile with:
// g++ -std=c++17 main.cpp glad/src/glad.c -I./glad/include -o prog -lSDL2 -ldl
// On windows compile with (if using mingw)
// g++ main.cpp ./glad/src/glad.c -I./glad/include -o prog.exe -lmingw32 -lSDL2main -lSDL2
#include <iostream>
#include "hardware.h"
#include "load_game.h"
#include "emulator.h"
#include "graphics.h"
#include "joypad.h"
#include<unistd.h>
static BYTE bios [0x100] = {
0x31, 0xFE, 0xFF, 0xAF, 0x21, 0xFF, 0x9F, 0x32, 0xCB, 0x7C, 0x20, 0xFB, 0x21, 0x26, 0xFF, 0x0E,
0x11, 0x3E, 0x80, 0x32, 0xE2, 0x0C, 0x3E, 0xF3, 0xE2, 0x32, 0x3E, 0x77, 0x77, 0x3E, 0xFC, 0xE0,
0x47, 0x11, 0x04, 0x01, 0x21, 0x10, 0x80, 0x1A, 0xCD, 0x95, 0x00, 0xCD, 0x96, 0x00, 0x13, 0x7B,
0xFE, 0x34, 0x20, 0xF3, 0x11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x20,
0xF5, 0x06, 0x19, 0x78, 0x86, 0x23, 0x05, 0x20, 0xFB, 0x86, 0x20, 0xFE, 0x3E, 0x01, 0xE0, 0x50 };
extern BYTE first_100 [0x100];
int main(int argc, char* argv[]){
load_game_method();
makefile();
create_window();
// Infinite loop for our application
bool gameIsRunning = true;
bool started = false;
while(gameIsRunning){
if(!started) {
memcpy(cartridge_memory, bios, 0x100 * sizeof(BYTE));
}
else if(read_memory(0xFF50))
memcpy(cartridge_memory, first_100, 0x100 * sizeof(BYTE));
update();
started = true;
glViewport(0,0,640,480);
SDL_Event event;
// Start our event loop
while(SDL_PollEvent(&event)){
// Handle each specific event
if(event.type == SDL_QUIT){
gameIsRunning= false;
}
if (event.type == SDL_KEYDOWN) {
switch (event.key.keysym.sym) {
case SDLK_RIGHT:
printf("right\n");
key_pressed(0);
break;
case SDLK_LEFT:
printf("left\n");
key_pressed(1);
break;
case SDLK_UP:
printf("up\n");
key_pressed(2);
break;
case SDLK_DOWN:
printf("down\n");
key_pressed(3);
break;
case SDLK_a:
printf("a\n");
key_pressed(4);
break;
case SDLK_s:
printf("s\n");
key_pressed(5);
break;
case SDLK_SPACE:
printf("space\n");
key_pressed(6);
break;
case SDLK_RETURN:
printf("return\n");
key_pressed(7);
break;
}
}
if (event.type == SDL_KEYUP) {
switch (event.key.keysym.sym) {
case SDLK_RIGHT:
printf("right up\n");
key_released(0);
break;
case SDLK_LEFT:
printf("left up\n");
key_released(1);
break;
case SDLK_UP:
printf("up up\n");
key_released(2);
break;
case SDLK_DOWN:
printf("down up\n");
key_released(3);
break;
case SDLK_a:
printf("a up\n");
key_released(4);
break;
case SDLK_s:
printf("s up\n");
key_released(5);
break;
case SDLK_SPACE:
printf("space up\n");
key_released(6);
break;
case SDLK_RETURN:
printf("return up\n");
key_released(7);
break;
}
}
}
/*glClearColor(1.0f,0.0f,0.0f,1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
SDL_GL_SwapWindow(window);
//sleep(1);
usleep(16000);
}
// We destroy our window. We are passing in the pointer
// that points to the memory allocated by the
// 'SDL_CreateWindow' function. Remember, this is
// a 'C-style' API, we don't have destructors.
SDL_DestroyWindow(window);
// We safely uninitialize SDL2, that is, we are
// taking down the subsystems here before we exit
// We add a delay in order to see that our window
// has successfully popped up.
SDL_Delay(3000);
// We add a delay in order to see that our window
// has successfully popped up.
SDL_Delay(3000);
// We add a delay in order to see that our window
// has successfully popped up.
SDL_Delay(3000);
// We add a delay in order to see that our window
// has successfully popped up.
SDL_Delay(3000);
// We add a delay in order to see that our window
// has successfully popped up.
SDL_Delay(3000);
// our program.
SDL_Quit();
closefile();
return 0;
}
/*#include "hardware.h"
#include "load_game.h"
#include "emulator.h"
#include<unistd.h>
#include <SDL.h>
#include <iostream>
#include "graphics.h"
int main(int argc, char* argv[]) {
printf("hello");
load_game_method(); // possibly use args to determine which game to load
// set up glut window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutInitWindowPosition(100, 100);
int MainWindow = glutCreateWindow("Hello Graphics!!");
glClearColor(0.0, 0.0, 0.0, 0);
while (true) { // call the update method 60 times in a second
update();
usleep(16000);
}
}*/
/*
while(SDL_PollEvent(&event)){
// Handle each specific event
if(event.type == SDL_QUIT){
gameIsRunning= false;
}
if(event.type == SDL_MOUSEMOTION){
std::cout << "mouse has been moved\n";
}
if(event.type == SDL_KEYDOWN){
std::cout << "a key has been pressed\n";
if(event.key.keysym.sym == SDLK_0){
std::cout << "0 was pressed\n";
}else{
std::cout << "0 was not pressed\n";
}
}
// Retrieve the state of all of the keys
// Then we can query the scan code of one or more
// keys at a time
const Uint8* state = SDL_GetKeyboardState(NULL);
if(state[SDL_SCANCODE_RIGHT]){
std::cout << "right arrow key is pressed\n";
}
}*/