| ... | ... |
@@ -41,6 +41,13 @@ emu_deo(Uxn *u, Uint8 addr) |
| 41 | 41 |
} |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
+int |
|
| 45 |
+emu_end(Uxn *u) |
|
| 46 |
+{
|
|
| 47 |
+ free(u->ram); |
|
| 48 |
+ return u->dev[0x0f] & 0x7f; |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 44 | 51 |
int |
| 45 | 52 |
main(int argc, char **argv) |
| 46 | 53 |
{
|
| ... | ... |
@@ -69,6 +76,5 @@ main(int argc, char **argv) |
| 69 | 76 |
console_input(&u, (Uint8)c, CONSOLE_STD); |
| 70 | 77 |
} |
| 71 | 78 |
} |
| 72 |
- free(u.ram); |
|
| 73 |
- return u.dev[0x0f] & 0x7f; |
|
| 79 |
+ return emu_end(&u); |
|
| 74 | 80 |
} |
| ... | ... |
@@ -251,6 +251,8 @@ emu_init(void) |
| 251 | 251 |
SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff); |
| 252 | 252 |
ms_interval = SDL_GetPerformanceFrequency() / 1000; |
| 253 | 253 |
deadline_interval = ms_interval * TIMEOUT_MS; |
| 254 |
+ exec_deadline = SDL_GetPerformanceCounter() + deadline_interval; |
|
| 255 |
+ screen_resize(WIDTH, HEIGHT); |
|
| 254 | 256 |
return 1; |
| 255 | 257 |
} |
| 256 | 258 |
|
| ... | ... |
@@ -269,6 +271,7 @@ static void |
| 269 | 271 |
emu_restart(Uxn *u) |
| 270 | 272 |
{
|
| 271 | 273 |
screen_resize(WIDTH, HEIGHT); |
| 274 |
+ SDL_SetWindowTitle(emu_window, rom_path); |
|
| 272 | 275 |
if(!emu_start(u, "launcher.rom")) |
| 273 | 276 |
emu_start(u, rom_path); |
| 274 | 277 |
} |
| ... | ... |
@@ -476,7 +479,7 @@ handle_events(Uxn *u) |
| 476 | 479 |
} |
| 477 | 480 |
|
| 478 | 481 |
static int |
| 479 |
-run(Uxn *u, char *rom) |
|
| 482 |
+emu_run(Uxn *u, char *rom) |
|
| 480 | 483 |
{
|
| 481 | 484 |
Uint64 next_refresh = 0; |
| 482 | 485 |
Uint64 frame_interval = SDL_GetPerformanceFrequency() / 60; |
| ... | ... |
@@ -514,6 +517,19 @@ run(Uxn *u, char *rom) |
| 514 | 517 |
} |
| 515 | 518 |
} |
| 516 | 519 |
|
| 520 |
+int |
|
| 521 |
+emu_end(Uxn *u) |
|
| 522 |
+{
|
|
| 523 |
+#ifdef _WIN32 |
|
| 524 |
+#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" |
|
| 525 |
+ TerminateThread((HANDLE)SDL_GetThreadID(stdin_thread), 0); |
|
| 526 |
+#elif !defined(__APPLE__) |
|
| 527 |
+ close(0); /* make stdin thread exit */ |
|
| 528 |
+#endif |
|
| 529 |
+ SDL_Quit(); |
|
| 530 |
+ return u->dev[0x0f] & 0x7f; |
|
| 531 |
+} |
|
| 532 |
+ |
|
| 517 | 533 |
int |
| 518 | 534 |
main(int argc, char **argv) |
| 519 | 535 |
{
|
| ... | ... |
@@ -544,21 +560,11 @@ main(int argc, char **argv) |
| 544 | 560 |
return system_error("Init", "Failed to initialize varvara.");
|
| 545 | 561 |
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom_path)) |
| 546 | 562 |
return system_error("Init", "Failed to initialize uxn.");
|
| 563 |
+ /* Game Loop */ |
|
| 547 | 564 |
u.dev[0x17] = argc - i; |
| 548 |
- /* load rom */ |
|
| 549 |
- if(!emu_start(&u, rom_path)) |
|
| 550 |
- return system_error("Start", "Failed");
|
|
| 551 |
- /* read arguments */ |
|
| 552 |
- console_listen(&u, i, argc, argv); |
|
| 553 |
- /* start rom */ |
|
| 554 |
- run(&u, rom_path); |
|
| 555 |
- /* finished */ |
|
| 556 |
-#ifdef _WIN32 |
|
| 557 |
-#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" |
|
| 558 |
- TerminateThread((HANDLE)SDL_GetThreadID(stdin_thread), 0); |
|
| 559 |
-#elif !defined(__APPLE__) |
|
| 560 |
- close(0); /* make stdin thread exit */ |
|
| 561 |
-#endif |
|
| 562 |
- SDL_Quit(); |
|
| 563 |
- return 0; |
|
| 565 |
+ if(uxn_eval(&u, PAGE_PROGRAM)) {
|
|
| 566 |
+ console_listen(&u, i, argc, argv); |
|
| 567 |
+ emu_run(&u, rom_path); |
|
| 568 |
+ } |
|
| 569 |
+ return emu_end(&u); |
|
| 564 | 570 |
} |