From 00eac312fe9ed070e9d4ca7569eb8ac4853cd4c8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 2 Sep 2024 19:27:43 +1000 Subject: [PATCH] NDS: Try to fix mounting SD card failing --- src/MenuOptions.c | 1 + src/Platform_NDS.c | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/MenuOptions.c b/src/MenuOptions.c index 73b646fb3..2a76c6671 100644 --- a/src/MenuOptions.c +++ b/src/MenuOptions.c @@ -474,6 +474,7 @@ static void MenuOptionsScreen_Free(void* screen) { struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen; Event_Unregister_(&UserEvents.HackPermsChanged, screen, MenuOptionsScreen_OnHacksChanged); Event_Unregister_(&WorldEvents.LightingModeChanged, screen, MenuOptionsScreen_OnLightingModeServerChanged); + MenuInputOverlay_Close(false); } static void MenuOptionsScreen_Layout(void* screen) { diff --git a/src/Platform_NDS.c b/src/Platform_NDS.c index 353b0c0fb..8831cc758 100644 --- a/src/Platform_NDS.c +++ b/src/Platform_NDS.c @@ -232,7 +232,7 @@ static int LoadFatFilesystem(void* arg) { return 0; } -static void InitFilesystem(void) { +static void MountFilesystem(void) { cothread_t thread = cothread_create(LoadFatFilesystem, NULL, 0, 0); // If running with DSi mode in melonDS and the internal SD card is enabled, then // fatInitDefault gets stuck in sdmmc_ReadSectors - because the fifoWaitValue32Async will never return @@ -241,22 +241,28 @@ static void InitFilesystem(void) { // and then giving up if it takes too long.. not the most elegant solution, but it does work if (thread == -1) { LoadFatFilesystem(NULL); - } else { - for (int i = 0; i < 100; i++) - { - cothread_yield(); - if (cothread_has_joined(thread)) break; - - swiDelay(2000); - } + return; } + + for (int i = 0; i < 100; i++) + { + cothread_yield(); + if (cothread_has_joined(thread)) break; + + swiDelay(20000); + } + Platform_LogConst("Gave up after 100 tries"); +} - char* dir = fatGetDefaultCwd(); - if (dir) { +static void InitFilesystem(void) { + MountFilesystem(); + char* dir = fatGetDefaultCwd(); + + if (dir) { Platform_Log1("CWD: %c", dir); - root_path.buffer = dir; - root_path.length = String_Length(dir); - } + root_path.buffer = dir; + root_path.length = String_Length(dir); + } Platform_ReadonlyFilesystem = !fat_available; if (fat_available) return;