commit b66d3f26123e6512bf4d1f1ea3310c2af2a5a1a2
parent 4d7ce3e893c68a64c95bb1f968beffbe2bd9e641
Author: neauoire <aliceffekt@gmail.com>
Date: Tue, 15 Aug 2023 18:44:16 -0700
Abstracted emu_end()
Diffstat:
2 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/src/uxncli.c b/src/uxncli.c
@@ -42,6 +42,13 @@ emu_deo(Uxn *u, Uint8 addr)
}
int
+emu_end(Uxn *u)
+{
+ free(u->ram);
+ return u->dev[0x0f] & 0x7f;
+}
+
+int
main(int argc, char **argv)
{
Uxn u;
@@ -69,6 +76,5 @@ main(int argc, char **argv)
console_input(&u, (Uint8)c, CONSOLE_STD);
}
}
- free(u.ram);
- return u.dev[0x0f] & 0x7f;
+ return emu_end(&u);
}
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -251,6 +251,8 @@ emu_init(void)
SDL_SetRenderDrawColor(emu_renderer, 0x00, 0x00, 0x00, 0xff);
ms_interval = SDL_GetPerformanceFrequency() / 1000;
deadline_interval = ms_interval * TIMEOUT_MS;
+ exec_deadline = SDL_GetPerformanceCounter() + deadline_interval;
+ screen_resize(WIDTH, HEIGHT);
return 1;
}
@@ -269,6 +271,7 @@ static void
emu_restart(Uxn *u)
{
screen_resize(WIDTH, HEIGHT);
+ SDL_SetWindowTitle(emu_window, rom_path);
if(!emu_start(u, "launcher.rom"))
emu_start(u, rom_path);
}
@@ -476,7 +479,7 @@ handle_events(Uxn *u)
}
static int
-run(Uxn *u, char *rom)
+emu_run(Uxn *u, char *rom)
{
Uint64 next_refresh = 0;
Uint64 frame_interval = SDL_GetPerformanceFrequency() / 60;
@@ -515,6 +518,19 @@ run(Uxn *u, char *rom)
}
int
+emu_end(Uxn *u)
+{
+#ifdef _WIN32
+#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
+ TerminateThread((HANDLE)SDL_GetThreadID(stdin_thread), 0);
+#elif !defined(__APPLE__)
+ close(0); /* make stdin thread exit */
+#endif
+ SDL_Quit();
+ return u->dev[0x0f] & 0x7f;
+}
+
+int
main(int argc, char **argv)
{
Uxn u = {0};
@@ -544,21 +560,11 @@ main(int argc, char **argv)
return system_error("Init", "Failed to initialize varvara.");
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom_path))
return system_error("Init", "Failed to initialize uxn.");
+ /* Game Loop */
u.dev[0x17] = argc - i;
- /* load rom */
- if(!emu_start(&u, rom_path))
- return system_error("Start", "Failed");
- /* read arguments */
- console_listen(&u, i, argc, argv);
- /* start rom */
- run(&u, rom_path);
- /* finished */
-#ifdef _WIN32
-#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
- TerminateThread((HANDLE)SDL_GetThreadID(stdin_thread), 0);
-#elif !defined(__APPLE__)
- close(0); /* make stdin thread exit */
-#endif
- SDL_Quit();
- return 0;
+ if(uxn_eval(&u, PAGE_PROGRAM)) {
+ console_listen(&u, i, argc, argv);
+ emu_run(&u, rom_path);
+ }
+ return emu_end(&u);
}