| ... | ... |
@@ -166,6 +166,18 @@ set_window_size(SDL_Window *window, int w, int h) |
| 166 | 166 |
SDL_SetWindowSize(window, w, h); |
| 167 | 167 |
} |
| 168 | 168 |
|
| 169 |
+static void |
|
| 170 |
+set_zoom(Uint8 z, int win) |
|
| 171 |
+{
|
|
| 172 |
+ if(z >= 1) {
|
|
| 173 |
+ zoom = z; |
|
| 174 |
+ if(win) |
|
| 175 |
+ set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom); |
|
| 176 |
+ } |
|
| 177 |
+} |
|
| 178 |
+ |
|
| 179 |
+/* emulator primitives */ |
|
| 180 |
+ |
|
| 169 | 181 |
int |
| 170 | 182 |
emu_resize(int width, int height) |
| 171 | 183 |
{
|
| ... | ... |
@@ -218,13 +230,12 @@ emu_init(void) |
| 218 | 230 |
SDL_StartTextInput(); |
| 219 | 231 |
SDL_ShowCursor(SDL_DISABLE); |
| 220 | 232 |
SDL_EventState(SDL_DROPFILE, SDL_ENABLE); |
| 233 |
+ SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff); |
|
| 221 | 234 |
ms_interval = SDL_GetPerformanceFrequency() / 1000; |
| 222 | 235 |
deadline_interval = ms_interval * TIMEOUT_MS; |
| 223 | 236 |
return 1; |
| 224 | 237 |
} |
| 225 | 238 |
|
| 226 |
-/* Boot */ |
|
| 227 |
- |
|
| 228 | 239 |
static int |
| 229 | 240 |
emu_start(Uxn *u, char *rom, int queue) |
| 230 | 241 |
{
|
| ... | ... |
@@ -242,13 +253,11 @@ emu_start(Uxn *u, char *rom, int queue) |
| 242 | 253 |
} |
| 243 | 254 |
|
| 244 | 255 |
static void |
| 245 |
-set_zoom(Uint8 z, int win) |
|
| 256 |
+emu_restart(Uxn *u) |
|
| 246 | 257 |
{
|
| 247 |
- if(z >= 1) {
|
|
| 248 |
- zoom = z; |
|
| 249 |
- if(win) |
|
| 250 |
- set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom); |
|
| 251 |
- } |
|
| 258 |
+ screen_resize(WIDTH, HEIGHT); |
|
| 259 |
+ if(!emu_start(u, "launcher.rom", 0)) |
|
| 260 |
+ emu_start(u, rom_path, 0); |
|
| 252 | 261 |
} |
| 253 | 262 |
|
| 254 | 263 |
static void |
| ... | ... |
@@ -282,14 +291,6 @@ capture_screen(void) |
| 282 | 291 |
SDL_FreeSurface(surface); |
| 283 | 292 |
} |
| 284 | 293 |
|
| 285 |
-static void |
|
| 286 |
-emu_restart(Uxn *u) |
|
| 287 |
-{
|
|
| 288 |
- screen_resize(WIDTH, HEIGHT); |
|
| 289 |
- if(!emu_start(u, "launcher.rom", 0)) |
|
| 290 |
- emu_start(u, rom_path, 0); |
|
| 291 |
-} |
|
| 292 |
- |
|
| 293 | 294 |
static Uint8 |
| 294 | 295 |
get_button(SDL_Event *event) |
| 295 | 296 |
{
|
| ... | ... |
@@ -441,7 +442,7 @@ handle_events(Uxn *u) |
| 441 | 442 |
} |
| 442 | 443 |
|
| 443 | 444 |
static int |
| 444 |
-emu_run(Uxn *u) |
|
| 445 |
+gameloop(Uxn *u) |
|
| 445 | 446 |
{
|
| 446 | 447 |
Uint64 next_refresh = 0; |
| 447 | 448 |
Uint64 now; |
| ... | ... |
@@ -474,7 +475,7 @@ emu_run(Uxn *u) |
| 474 | 475 |
} |
| 475 | 476 |
|
| 476 | 477 |
int |
| 477 |
-emu_show(void) |
|
| 478 |
+show(void) |
|
| 478 | 479 |
{
|
| 479 | 480 |
window_created = 1; |
| 480 | 481 |
emu_window = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, uxn_screen.width * zoom, uxn_screen.height * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
| ... | ... |
@@ -483,7 +484,6 @@ emu_show(void) |
| 483 | 484 |
emu_renderer = SDL_CreateRenderer(emu_window, -1, 0); |
| 484 | 485 |
if(emu_renderer == NULL) |
| 485 | 486 |
return system_error("sdl_renderer", SDL_GetError());
|
| 486 |
- SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff); |
|
| 487 | 487 |
emu_resize(uxn_screen.width, uxn_screen.height); |
| 488 | 488 |
return 1; |
| 489 | 489 |
} |
| ... | ... |
@@ -491,7 +491,6 @@ emu_show(void) |
| 491 | 491 |
int |
| 492 | 492 |
main(int argc, char **argv) |
| 493 | 493 |
{
|
| 494 |
- SDL_DisplayMode DM; |
|
| 495 | 494 |
Uxn u = {0};
|
| 496 | 495 |
int i = 1; |
| 497 | 496 |
if(!emu_init()) |
| ... | ... |
@@ -501,8 +500,6 @@ main(int argc, char **argv) |
| 501 | 500 |
/* default zoom */ |
| 502 | 501 |
if(argc > 1 && (strcmp(argv[i], "-1x") == 0 || strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)) |
| 503 | 502 |
set_zoom(argv[i++][1] - '0', 0); |
| 504 |
- else if(SDL_GetCurrentDisplayMode(0, &DM) == 0) |
|
| 505 |
- set_zoom(DM.w / 1280, 0); |
|
| 506 | 503 |
/* load rom */ |
| 507 | 504 |
if(i == argc) |
| 508 | 505 |
return system_error("usage", "uxnemu [-2x][-3x] file.rom [args...]");
|
| ... | ... |
@@ -516,8 +513,8 @@ main(int argc, char **argv) |
| 516 | 513 |
console_input(&u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA); |
| 517 | 514 |
} |
| 518 | 515 |
/* start rom */ |
| 519 |
- emu_show(); |
|
| 520 |
- emu_run(&u); |
|
| 516 |
+ show(); |
|
| 517 |
+ gameloop(&u); |
|
| 521 | 518 |
/* finished */ |
| 522 | 519 |
#ifdef _WIN32 |
| 523 | 520 |
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" |