mirror of https://github.com/mgba-emu/mgba.git
3DS: Allow loading ROM out of romfs if included
This commit is contained in:
parent
981d01134b
commit
73afc7d7f7
|
@ -1,4 +1,4 @@
|
|||
set(USE_VFS_3DS ON CACHE BOOL "Use 3DS-specific file support")
|
||||
set(USE_VFS_3DS OFF CACHE BOOL "Use 3DS-specific file support")
|
||||
mark_as_advanced(USE_VFS_3DS)
|
||||
|
||||
find_program(3DSLINK 3dslink)
|
||||
|
|
|
@ -817,7 +817,43 @@ THREAD_ENTRY _core2Test(void* context) {
|
|||
UNUSED(context);
|
||||
}
|
||||
|
||||
int main() {
|
||||
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) {
|
||||
strncpy(initialPath, argv[1], sizeof(PATH_MAX));
|
||||
} else {
|
||||
u8 hmac[0x20];
|
||||
memset(hmac, 0, sizeof(hmac));
|
||||
APT_ReceiveDeliverArg(initialPath, sizeof(initialPath), hmac, NULL, NULL);
|
||||
}
|
||||
|
||||
rotation.d.sample = _sampleRotation;
|
||||
rotation.d.readTiltX = _readTiltX;
|
||||
rotation.d.readTiltY = _readTiltY;
|
||||
|
@ -1046,9 +1082,32 @@ int main() {
|
|||
_map3DSKey(&runner.params.keyMap, KEY_CSTICK_UP, mGUI_INPUT_INCREASE_BRIGHTNESS);
|
||||
_map3DSKey(&runner.params.keyMap, KEY_CSTICK_DOWN, mGUI_INPUT_DECREASE_BRIGHTNESS);
|
||||
|
||||
mGUIRunloop(&runner);
|
||||
Result res = romfsInit();
|
||||
bool useRomfs = false;
|
||||
if (R_SUCCEEDED(res)) {
|
||||
useRomfs = setupRomfs(initialPath, sizeof(initialPath), &runner);
|
||||
if (!useRomfs) {
|
||||
romfsExit();
|
||||
_cleanup();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (initialPath[0] == '/' || useRomfs) {
|
||||
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);
|
||||
}
|
||||
|
||||
mGUIDeinit(&runner);
|
||||
|
||||
if (useRomfs) {
|
||||
romfsExit();
|
||||
}
|
||||
_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue