Vita: Allow loading ROM out of app0 if included

This commit is contained in:
Vicki Pfau 2022-10-22 23:34:28 -07:00
parent 73afc7d7f7
commit 85e66155f2
4 changed files with 61 additions and 29 deletions

View File

@ -19,6 +19,12 @@
#include <mgba-util/png-io.h>
#include <mgba-util/vfs.h>
#ifdef PSP2
#include <psp2/io/stat.h>
#elif defined(__3DS__)
#include <mgba-util/platform/3ds/3ds-vfs.h>
#endif
#include <sys/time.h>
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;

View File

@ -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

View File

@ -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();

View File

@ -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);