(GX/GameCube) Support SD2SP2 / Serial Port 2 SD adapters

Official GameCube builds link against external devkitPro
libogc/libfat (EXTERNAL_LIBOGC=1), where the GameCube disc
interface table is:

   { "sd",    __io_gcsd2 },  /* Serial Port 2 (SD2SP2 etc.) */
   { "carda", __io_gcsda },
   { "cardb", __io_gcsdb },

so an SD2SP2 card mounts as "sd:" and, being first in the table,
becomes the default device. Two pieces of HW_DOL code predate
this and only knew about SD Gecko slots A/B:

1) frontend_gx_get_env() unconditionally ran
   chdir("carda:/retroarch"), clobbering the launch directory
   that fatInitDefault() had already chdir()'d to from argv[0]
   (as provided by Swiss and other modern loaders) whenever a
   slot A card with a retroarch folder was present. Only fall
   back to a fixed location when the loader supplied no usable
   argv[0], and prefer "sd:/retroarch" over "carda:/retroarch"
   in that fallback, mirroring libfat's own device priority.
   The chdir chain is harmless under the internal libogc, where
   no "sd" device exists and the first chdir simply fails.

2) frontend_gx_parse_drive_list() offered only carda:/ and
   cardb:/ on HW_DOL, so SD2SP2 users could not browse to their
   card's root from Start Directory / Load Content and had to
   hand-edit retroarch.cfg. Append sd:/ as well, guarded by
   EXTERNAL_LIBOGC since the vendored libogc has no SP2 driver.

Reported on Discord: RetroArch launched from Swiss on an SD2SP2
card resolved sd:/ paths fine once typed into the config, but
the directory browser only ever offered carda:/ and cardb:/.
This commit is contained in:
libretroadmin committed 2026-08-16 21:11:05 +02:00
1 parent a804af1265
commit 38414d1336
1 file changed
+23 -1
+23 -1
View File
@@ -176,7 +176,19 @@ static void frontend_gx_get_env(int *argc, char *argv[],
#endif
#ifdef HW_DOL
chdir("carda:/retroarch");
/* If the loader provided a usable argv[0] (e.g. Swiss),
* fatInitDefault() has already chdir()'d to the directory
* RetroArch was launched from, and the defaults derived from
* getcwd() below must be rooted there. Only fall back to a
* fixed location when no launch path is available, preferring
* the Serial Port 2 SD adapter mount ("sd": SD2SP2 and
* similar devices) over an SD Gecko in slot A, mirroring
* libfat's own device priority. */
if (*argc < 1 || !argv || !argv[0] || !strstr(argv[0], ":/"))
{
if (chdir("sd:/retroarch") != 0)
chdir("carda:/retroarch");
}
#endif
getcwd(g_defaults.dirs[DEFAULT_DIR_CORE],
@@ -538,6 +550,16 @@ static int frontend_gx_parse_drive_list(void *data, bool load_content)
msg_hash_to_str(MSG_EXTERNAL_APPLICATION_DIR),
enum_idx,
FILE_TYPE_DIRECTORY, 0, 0, NULL);
#elif defined(EXTERNAL_LIBOGC)
/* Modern libfat mounts a Serial Port 2 SD adapter
* (SD2SP2 and similar devices) as "sd" on GameCube.
* The internal (vendored) libogc has no SP2 driver,
* hence the EXTERNAL_LIBOGC guard. */
menu_entries_append(list,
"sd:/",
msg_hash_to_str(MSG_EXTERNAL_APPLICATION_DIR),
enum_idx,
FILE_TYPE_DIRECTORY, 0, 0, NULL);
#endif
menu_entries_append(list,
"carda:/",