From ec72160f395671a6dbc665b2e657219754151947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Peri=C4=87?= Date: Wed, 21 Oct 2020 22:05:26 +0200 Subject: [PATCH 1/2] Added support for loading ROM files from Lua script on Linux --- src/drivers/Qt/fceuWrapper.cpp | 6 ++++++ src/drivers/sdl/sdl.cpp | 6 ++++++ src/lua-engine.cpp | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index ddc1b0e2..cdc27dd7 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -206,6 +206,12 @@ DriverKill() inited=0; } +int reloadLastGame() { + std::string lastRom; + g_config->getOption(std::string("SDL.LastOpenFile"), &lastRom); + return LoadGame(lastRom.c_str()); +} + /** * Loads a game, given a full path/filename. The driver code must be * initialized after the game is loaded, because the emulator code diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 25f7f0aa..ce9482fc 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -189,6 +189,12 @@ static void ShowUsage(char *prog) } +int reloadLastGame() { + std::string lastRom; + g_config->getOption(std::string("SDL.LastOpenFile"), &lastRom); + return LoadGame(lastRom.c_str()); +} + /** * Loads a game, given a full path/filename. The driver code must be * initialized after the game is loaded, because the emulator code diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 42344162..74ded2ab 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -545,6 +545,17 @@ static int emu_loadrom(lua_State *L) { } else { return 1; } +#else + const char *nameo2 = luaL_checkstring(L,1); + char nameo[2048]; + strncpy(nameo, nameo2, sizeof(nameo)); + if(!FCEUI_LoadGame(nameo, 0, true)) { + extern void reloadLastGame(); + reloadLastGame(); + return 0; + } else { + return 1; + } #endif return 1; } From 432ffeeec251384924df8df6b6668effe69c00cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Peri=C4=87?= Date: Thu, 22 Oct 2020 01:20:48 +0200 Subject: [PATCH 2/2] Use LoadGame instead of FCEUI_LoadGame --- src/attic/pc/dface.h | 2 +- src/attic/pc/main.c | 4 ++-- src/drivers/Qt/dface.h | 2 +- src/drivers/Qt/fceuWrapper.cpp | 9 ++++++--- src/drivers/Qt/fceuWrapper.h | 2 +- src/drivers/Qt/sdl.h | 2 +- src/drivers/sdl/dface.h | 2 +- src/drivers/sdl/sdl.cpp | 7 +++++-- src/drivers/sdl/sdl.h | 2 +- src/lua-engine.cpp | 3 ++- 10 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/attic/pc/dface.h b/src/attic/pc/dface.h index 9981bd08..55fe169a 100644 --- a/src/attic/pc/dface.h +++ b/src/attic/pc/dface.h @@ -44,7 +44,7 @@ void LockConsole(void); void UnlockConsole(void); void ToggleFS(); /* SDL */ -int LoadGame(const char *path); +int LoadGame(const char *path, bool silent = false); int CloseGame(void); int GUI_Init(int argc, char **argv, int (*dofunc)(void)); int GUI_Idle(void); diff --git a/src/attic/pc/main.c b/src/attic/pc/main.c index 6bdd7ce7..1e4bef03 100644 --- a/src/attic/pc/main.c +++ b/src/attic/pc/main.c @@ -275,12 +275,12 @@ static void DoArgs(int argc, char *argv[]) provides data necessary for the driver code(number of scanlines to render, what virtual input devices to use, etc.). */ -int LoadGame(const char *path) +int LoadGame(const char *path, bool silent) { FCEUGI *tmp; CloseGame(); - if(!(tmp=FCEUI_LoadGame(path,1))) + if(!(tmp=FCEUI_LoadGame(path,1,silent))) return 0; CurGame=tmp; ParseGI(tmp); diff --git a/src/drivers/Qt/dface.h b/src/drivers/Qt/dface.h index 12c515ee..16de524b 100644 --- a/src/drivers/Qt/dface.h +++ b/src/drivers/Qt/dface.h @@ -29,7 +29,7 @@ void LockConsole(void); void UnlockConsole(void); void ToggleFS(); /* SDL */ -int LoadGame(const char *path); +int LoadGame(const char *path, bool silent); //int CloseGame(void); void Giggles(int); diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index cdc27dd7..e833c8be 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -206,10 +206,13 @@ DriverKill() inited=0; } +/** + * Reloads last game + */ int reloadLastGame() { std::string lastRom; g_config->getOption(std::string("SDL.LastOpenFile"), &lastRom); - return LoadGame(lastRom.c_str()); + return LoadGame(lastRom.c_str(), false); } /** @@ -218,7 +221,7 @@ int reloadLastGame() { * provides data necessary for the driver code(number of scanlines to * render, what virtual input devices to use, etc.). */ -int LoadGame(const char *path) +int LoadGame(const char *path, bool silent) { int gg_enabled, autoLoadDebug, autoOpenDebugger; @@ -233,7 +236,7 @@ int LoadGame(const char *path) FCEUI_SetGameGenie (gg_enabled); - if(!FCEUI_LoadGame(path, 1)) { + if(!FCEUI_LoadGame(path, 1, silent)) { return 0; } diff --git a/src/drivers/Qt/fceuWrapper.h b/src/drivers/Qt/fceuWrapper.h index e0928e09..6b196856 100644 --- a/src/drivers/Qt/fceuWrapper.h +++ b/src/drivers/Qt/fceuWrapper.h @@ -19,7 +19,7 @@ extern unsigned int gui_draw_area_height; // global configuration object extern Config *g_config; -int LoadGame(const char *path); +int LoadGame(const char *path, bool silent = false); int CloseGame(void); int fceuWrapperInit( int argc, char *argv[] ); diff --git a/src/drivers/Qt/sdl.h b/src/drivers/Qt/sdl.h index 82870040..20c5c58f 100644 --- a/src/drivers/Qt/sdl.h +++ b/src/drivers/Qt/sdl.h @@ -24,7 +24,7 @@ extern int dendy; extern int pal_emulation; extern bool swapDuty; -int LoadGame(const char *path); +int LoadGame(const char *path, bool silent); int CloseGame(void); void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); uint64 FCEUD_GetTime(); diff --git a/src/drivers/sdl/dface.h b/src/drivers/sdl/dface.h index 827bbfaf..e92be90d 100644 --- a/src/drivers/sdl/dface.h +++ b/src/drivers/sdl/dface.h @@ -29,7 +29,7 @@ void LockConsole(void); void UnlockConsole(void); void ToggleFS(); /* SDL */ -int LoadGame(const char *path); +int LoadGame(const char *path, bool silent); //int CloseGame(void); void Giggles(int); diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index ce9482fc..424dc53c 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -189,6 +189,9 @@ static void ShowUsage(char *prog) } +/** + * Reloads last game. + */ int reloadLastGame() { std::string lastRom; g_config->getOption(std::string("SDL.LastOpenFile"), &lastRom); @@ -201,12 +204,12 @@ int reloadLastGame() { * provides data necessary for the driver code(number of scanlines to * render, what virtual input devices to use, etc.). */ -int LoadGame(const char *path) +int LoadGame(const char *path, bool silent) { if (isloaded){ CloseGame(); } - if(!FCEUI_LoadGame(path, 1)) { + if(!FCEUI_LoadGame(path, 1, silent)) { return 0; } diff --git a/src/drivers/sdl/sdl.h b/src/drivers/sdl/sdl.h index 91c6414d..e667da25 100644 --- a/src/drivers/sdl/sdl.h +++ b/src/drivers/sdl/sdl.h @@ -24,7 +24,7 @@ extern int dendy; extern int pal_emulation; extern bool swapDuty; -int LoadGame(const char *path); +int LoadGame(const char *path, bool silent = false); int CloseGame(void); void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); uint64 FCEUD_GetTime(); diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 74ded2ab..6f8d90f7 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -520,6 +520,7 @@ static int emu_getdir(lua_State *L) { extern void ReloadRom(void); +extern int LoadGame(const char*, bool); // emu.loadrom(string filename) // @@ -549,7 +550,7 @@ static int emu_loadrom(lua_State *L) { const char *nameo2 = luaL_checkstring(L,1); char nameo[2048]; strncpy(nameo, nameo2, sizeof(nameo)); - if(!FCEUI_LoadGame(nameo, 0, true)) { + if(!LoadGame(nameo, true)) { extern void reloadLastGame(); reloadLastGame(); return 0;