diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index 64488dcb8..820f1cb07 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -19,6 +19,12 @@ #include #include +#ifdef PSP2 +#include +#elif defined(__3DS__) +#include +#endif + #include mLOG_DECLARE_CATEGORY(GUI_RUNNER); @@ -770,6 +776,44 @@ void mGUIRunloop(struct mGUIRunner* runner) { } } +#if defined(__3DS__) || defined(PSP2) +bool mGUIGetRom(struct mGUIRunner* runner, char* out, size_t outLength) { +#ifdef PSP2 + int fd = open("app0:/filename", O_RDONLY); + strcpy(out, "app0:/"); +#elif defined(__3DS__) + int fd = open("romfs:/filename", O_RDONLY); + strcpy(out, "romfs:/"); +#endif + if (fd < 0) { + return false; + } + size_t len = strlen(out); + ssize_t size = read(fd, out + len, outLength - len); + if (size > 0 && out[len + size - 1] == '\n') { + out[len + size - 1] = '\0'; + } + close(fd); + if (size <= 0) { + return false; + } + char basedir[64]; + mCoreConfigDirectory(basedir, sizeof(basedir)); + strlcat(basedir, "/forwarders", sizeof(basedir)); +#ifdef PSP2 + sceIoMkdir(basedir, 0777); +#elif defined(__3DS__) + FSUSER_CreateDirectory(sdmcArchive, fsMakePath(PATH_ASCII, basedir), 0); +#endif + + mCoreConfigSetValue(&runner->config, "savegamePath", basedir); + mCoreConfigSetValue(&runner->config, "savestatePath", basedir); + mCoreConfigSetValue(&runner->config, "screenshotPath", basedir); + mCoreConfigSetValue(&runner->config, "cheatsPath", basedir); + return true; +} +#endif + #ifndef DISABLE_THREADING THREAD_ENTRY mGUIAutosaveThread(void* context) { struct mGUIAutosaveContext* autosave = context; diff --git a/src/feature/gui/gui-runner.h b/src/feature/gui/gui-runner.h index ea18cc5b8..860b96b99 100644 --- a/src/feature/gui/gui-runner.h +++ b/src/feature/gui/gui-runner.h @@ -98,6 +98,10 @@ void mGUIDeinit(struct mGUIRunner*); void mGUIRun(struct mGUIRunner*, const char* path); void mGUIRunloop(struct mGUIRunner*); +#if defined(__3DS__) || defined(PSP2) +bool mGUIGetRom(struct mGUIRunner* runner, char* out, size_t outLength); +#endif + #ifndef DISABLE_THREADING THREAD_ENTRY mGUIAutosaveThread(void* context); #endif diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index fad2fd96b..b19a0ca2f 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -817,33 +817,6 @@ THREAD_ENTRY _core2Test(void* context) { UNUSED(context); } -bool setupRomfs(char* initialPath, size_t outLength, struct mGUIRunner* runner) { - int fd = open("romfs:/filename", O_RDONLY); - strcpy(initialPath, "romfs:/"); - if (fd < 0) { - return false; - } - size_t len = strlen(initialPath); - ssize_t size = read(fd, initialPath + len, outLength - len); - if (size > 0 && initialPath[len + size - 1] == '\n') { - initialPath[len + size - 1] = '\0'; - } - close(fd); - if (size <= 0) { - return false; - } - char basedir[64]; - mCoreConfigDirectory(basedir, sizeof(basedir)); - strlcat(basedir, "/forwarders", sizeof(basedir)); - FSUSER_CreateDirectory(sdmcArchive, fsMakePath(PATH_ASCII, basedir), 0); - - mCoreConfigSetValue(&runner->config, "savegamePath", basedir); - mCoreConfigSetValue(&runner->config, "savestatePath", basedir); - mCoreConfigSetValue(&runner->config, "screenshotPath", basedir); - mCoreConfigSetValue(&runner->config, "cheatsPath", basedir); - return true; -} - int main(int argc, char* argv[]) { char initialPath[PATH_MAX] = { 0 }; if (argc > 1) { @@ -1085,7 +1058,7 @@ int main(int argc, char* argv[]) { Result res = romfsInit(); bool useRomfs = false; if (R_SUCCEEDED(res)) { - useRomfs = setupRomfs(initialPath, sizeof(initialPath), &runner); + useRomfs = mGUIGetRom(&runner, initialPath, sizeof(initialPath)); if (!useRomfs) { romfsExit(); _cleanup(); diff --git a/src/platform/psp2/main.c b/src/platform/psp2/main.c index c474d9d85..d66ba8494 100644 --- a/src/platform/psp2/main.c +++ b/src/platform/psp2/main.c @@ -153,6 +153,8 @@ static enum GUIKeyboardStatus _keyboardRun(struct GUIKeyboardParams* keyboard) { } int main() { + char initialPath[PATH_MAX] = { 0 }; + vita2d_init(); struct GUIFont* font = GUIFontCreate(); struct mGUIRunner runner = { @@ -278,7 +280,16 @@ int main() { mPSP2MapKey(&runner.params.keyMap, SCE_CTRL_SQUARE, mGUI_INPUT_SCREEN_MODE); scePowerSetArmClockFrequency(444); - mGUIRunloop(&runner); + + if (mGUIGetRom(&runner, initialPath, sizeof(initialPath))) { + size_t i; + for (i = 0; runner.keySources[i].id; ++i) { + mInputMapLoad(&runner.params.keyMap, runner.keySources[i].id, mCoreConfigGetInput(&runner.config)); + } + mGUIRun(&runner, initialPath); + } else { + mGUIRunloop(&runner); + } vita2d_fini(); mGUIDeinit(&runner);