From 31929e5550e92a1b6ccdedf12df943a6b64d7595 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Tue, 21 Nov 2017 19:47:36 +0300 Subject: [PATCH] added live cart reloading #374 --- src/console.c | 22 +++++++++++++++++++++- src/console.h | 1 + src/studio.c | 27 +++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/console.c b/src/console.c index d92ecd2..8f06b81 100644 --- a/src/console.c +++ b/src/console.c @@ -731,6 +731,25 @@ static bool loadProject(Console* console, const char* data, s32 size, tic_cartri return done; } +static void updateProject(Console* console) +{ + tic_mem* tic = console->tic; + + if(strlen(console->romName)) + { + s32 size = 0; + void* data = fsLoadFile(console->fs, console->romName, &size); + + if(data) + { + loadProject(console, data, size, &tic->cart); + SDL_free(data); + + studioRomLoaded(); + } + } +} + static bool hasExt(const char* name, const char* ext) { return strcmp(name + strlen(name) - strlen(ext), ext) == 0; @@ -2721,10 +2740,11 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, #if defined(TIC80_PRO) .loadProject = loadProject, + .updateProject = updateProject, #else .loadProject = NULL, + .updateProject = NULL, #endif - .error = error, .trace = trace, .tick = tick, diff --git a/src/console.h b/src/console.h index c21bd9e..21768a2 100644 --- a/src/console.h +++ b/src/console.h @@ -92,6 +92,7 @@ struct Console void(*load)(Console*, const char* name); bool(*loadProject)(Console*, const char* data, s32 size, tic_cartridge* dst); + void(*updateProject)(Console*); void(*error)(Console*, const char*); void(*trace)(Console*, const char*, u8 color); void(*tick)(Console*); diff --git a/src/studio.c b/src/studio.c index e03762d..68fce6e 100644 --- a/src/studio.c +++ b/src/studio.c @@ -760,6 +760,8 @@ void exitFromGameMenu() { setStudioMode(TIC_CONSOLE_MODE); } + + studio.console.showGameMenu = false; } void setStudioMode(EditorMode mode) @@ -1680,6 +1682,12 @@ static void processMouseInput() studio.tic->ram.vram.input.gamepad.pressed = studio.mouse.state->down ? 1 : 0; } +static void reloadConfirm(bool yes, void* data) +{ + if(yes) + studio.console.updateProject(&studio.console); +} + SDL_Event* pollEvent() { static SDL_Event event; @@ -1721,6 +1729,25 @@ SDL_Event* pollEvent() { case SDL_WINDOWEVENT_RESIZED: updateGamepadParts(); break; case SDL_WINDOWEVENT_FOCUS_GAINED: + +#if defined(TIC80_PRO) + + if(studio.mode != TIC_START_MODE && studioCartChanged()) + { + static const char* Rows[] = + { + "", + "CART HAS CHANGED!", + "", + "DO YOU WANT", + "TO RELOAD IT?" + }; + + showDialog(Rows, COUNT_OF(Rows), reloadConfirm, NULL); + } + else studio.console.updateProject(&studio.console); + +#endif { studio.console.codeLiveReload.reload(&studio.console,studio.code.data); if(studio.code.update)