... | ... |
@@ -42,7 +42,6 @@ WITH REGARD TO THIS SOFTWARE. |
42 | 42 |
#define WIDTH 64 * 8 |
43 | 43 |
#define HEIGHT 40 * 8 |
44 | 44 |
#define TIMEOUT_MS 334 |
45 |
-#define BENCH 0 |
|
46 | 45 |
|
47 | 46 |
static SDL_Window *emu_window; |
48 | 47 |
static SDL_Texture *emu_texture; |
... | ... |
@@ -443,31 +442,37 @@ handle_events(Uxn *u) |
443 | 442 |
} |
444 | 443 |
|
445 | 444 |
static int |
446 |
-gameloop(Uxn *u) |
|
445 |
+run(Uxn *u) |
|
447 | 446 |
{ |
448 | 447 |
Uint64 next_refresh = 0; |
449 |
- Uint64 now; |
|
450 | 448 |
Uint64 frame_interval = SDL_GetPerformanceFrequency() / 60; |
449 |
+ window_created = 1; |
|
450 |
+ 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); |
|
451 |
+ if(emu_window == NULL) |
|
452 |
+ return system_error("sdl_window", SDL_GetError()); |
|
453 |
+ emu_renderer = SDL_CreateRenderer(emu_window, -1, 0); |
|
454 |
+ if(emu_renderer == NULL) |
|
455 |
+ return system_error("sdl_renderer", SDL_GetError()); |
|
456 |
+ emu_resize(uxn_screen.width, uxn_screen.height); |
|
457 |
+ /* game loop */ |
|
451 | 458 |
for(;;) { |
452 | 459 |
Uint16 screen_vector; |
460 |
+ Uint64 now = SDL_GetPerformanceCounter(); |
|
453 | 461 |
/* .System/halt */ |
454 | 462 |
if(u->dev[0x0f]) |
455 | 463 |
return system_error("Run", "Ended."); |
456 |
- now = SDL_GetPerformanceCounter(); |
|
457 | 464 |
exec_deadline = now + deadline_interval; |
458 | 465 |
if(!handle_events(u)) |
459 | 466 |
return 0; |
460 | 467 |
screen_vector = PEEK2(&u->dev[0x20]); |
461 |
- if(BENCH || now >= next_refresh) { |
|
468 |
+ if(now >= next_refresh) { |
|
462 | 469 |
now = SDL_GetPerformanceCounter(); |
463 | 470 |
next_refresh = now + frame_interval; |
464 | 471 |
uxn_eval(u, screen_vector); |
465 | 472 |
if(uxn_screen.x2) |
466 | 473 |
emu_redraw(); |
467 | 474 |
} |
468 |
- if(BENCH) { |
|
469 |
- /* no delay */ |
|
470 |
- } else if(screen_vector || uxn_screen.x2) { |
|
475 |
+ if(screen_vector || uxn_screen.x2) { |
|
471 | 476 |
Uint64 delay_ms = (next_refresh - now) / ms_interval; |
472 | 477 |
if(delay_ms > 0) SDL_Delay(delay_ms); |
473 | 478 |
} else |
... | ... |
@@ -475,20 +480,6 @@ gameloop(Uxn *u) |
475 | 480 |
} |
476 | 481 |
} |
477 | 482 |
|
478 |
-int |
|
479 |
-show(void) |
|
480 |
-{ |
|
481 |
- window_created = 1; |
|
482 |
- 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 |
- if(emu_window == NULL) |
|
484 |
- return system_error("sdl_window", SDL_GetError()); |
|
485 |
- emu_renderer = SDL_CreateRenderer(emu_window, -1, 0); |
|
486 |
- if(emu_renderer == NULL) |
|
487 |
- return system_error("sdl_renderer", SDL_GetError()); |
|
488 |
- emu_resize(uxn_screen.width, uxn_screen.height); |
|
489 |
- return 1; |
|
490 |
-} |
|
491 |
- |
|
492 | 483 |
int |
493 | 484 |
main(int argc, char **argv) |
494 | 485 |
{ |
... | ... |
@@ -512,8 +503,7 @@ main(int argc, char **argv) |
512 | 503 |
console_input(&u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA); |
513 | 504 |
} |
514 | 505 |
/* start rom */ |
515 |
- show(); |
|
516 |
- gameloop(&u); |
|
506 |
+ run(&u); |
|
517 | 507 |
/* finished */ |
518 | 508 |
#ifdef _WIN32 |
519 | 509 |
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" |