From ce3a9f0b4c4a90c59fcfc35169bfc7dfe563b312 Mon Sep 17 00:00:00 2001 From: CosmicScale Date: Wed, 1 Jan 2025 15:04:40 +0000 Subject: [PATCH 1/2] Fixed BDM Auto-Launch --- src/opl.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/opl.c b/src/opl.c index 4b138bb17..c7b1cdc5a 100644 --- a/src/opl.c +++ b/src/opl.c @@ -1850,7 +1850,7 @@ static void miniInit(int mode) gEnableMX4SIO = 1; gEnableBdmHDD = 1; bdmLoadModules(); - delay(6); // Wait for the device to be detected. + } else if (mode == HDD_MODE) { hddLoadModules(); hddLoadSupportModules(); @@ -1953,26 +1953,48 @@ static void autoLaunchBDMGame(char *argv[]) gAutoLaunchDeviceData = malloc(sizeof(bdm_device_data_t)); memset(gAutoLaunchDeviceData, 0, sizeof(bdm_device_data_t)); - snprintf(path, sizeof(path), "mass0:"); - int dir = fileXioDopen(path); - if (dir >= 0) { - fileXioIoctl2(dir, USBMASS_IOCTL_GET_DRIVERNAME, NULL, 0, &gAutoLaunchDeviceData->bdmDriver, sizeof(gAutoLaunchDeviceData->bdmDriver) - 1); - fileXioIoctl2(dir, USBMASS_IOCTL_GET_DEVICE_NUMBER, NULL, 0, &gAutoLaunchDeviceData->massDeviceIndex, sizeof(gAutoLaunchDeviceData->massDeviceIndex)); - - if (!strcmp(gAutoLaunchDeviceData->bdmDriver, "ata") && strlen(gAutoLaunchDeviceData->bdmDriver) == 3) - bdmResolveLBA_UDMA(gAutoLaunchDeviceData); + int dir = -1; + char apaDevicePrefix[8] = {0}; + delay(8); + snprintf(apaDevicePrefix, sizeof(apaDevicePrefix), "mass0:"); + // Loop through mass0: to mass4: + for (int i = 0; i <= 4; i++) { + snprintf(path, sizeof(path), "mass%d:", i); + dir = fileXioDopen(path); + + if (dir >= 0) { + fileXioIoctl2(dir, USBMASS_IOCTL_GET_DRIVERNAME, NULL, 0, &gAutoLaunchDeviceData->bdmDriver, sizeof(gAutoLaunchDeviceData->bdmDriver) - 1); + fileXioIoctl2(dir, USBMASS_IOCTL_GET_DEVICE_NUMBER, NULL, 0, &gAutoLaunchDeviceData->massDeviceIndex, sizeof(gAutoLaunchDeviceData->massDeviceIndex)); + + if (!strcmp(gAutoLaunchDeviceData->bdmDriver, "ata") && strlen(gAutoLaunchDeviceData->bdmDriver) == 3) { + bdmResolveLBA_UDMA(gAutoLaunchDeviceData); + snprintf(apaDevicePrefix, sizeof(apaDevicePrefix), "mass%d:", i); + fileXioDclose(dir); + break; // Exit the loop if "ata" device is found + } - fileXioDclose(dir); + fileXioDclose(dir); + } else { + // Retry for mass0: only + if (i == 0) { + delay(6); + i--; + } else { + break; + } + } + delay(6); } if (gBDMPrefix[0] != '\0') { - snprintf(path, sizeof(path), "mass0:%s/CFG/%s.cfg", gBDMPrefix, gAutoLaunchBDMGame->startup); - snprintf(gAutoLaunchDeviceData->bdmPrefix, sizeof(gAutoLaunchDeviceData->bdmPrefix), "mass0:%s/", gBDMPrefix); + snprintf(path, sizeof(path), "%s%s/CFG/%s.cfg", apaDevicePrefix, gBDMPrefix, gAutoLaunchBDMGame->startup); + snprintf(gAutoLaunchDeviceData->bdmPrefix, sizeof(gAutoLaunchDeviceData->bdmPrefix), "%s%s/", apaDevicePrefix, gBDMPrefix); } else { - snprintf(path, sizeof(path), "mass0:CFG/%s.cfg", gAutoLaunchBDMGame->startup); - snprintf(gAutoLaunchDeviceData->bdmPrefix, sizeof(gAutoLaunchDeviceData->bdmPrefix), "mass0:"); + snprintf(path, sizeof(path), "%sCFG/%s.cfg", apaDevicePrefix, gAutoLaunchBDMGame->startup); + snprintf(gAutoLaunchDeviceData->bdmPrefix, sizeof(gAutoLaunchDeviceData->bdmPrefix), "%s", apaDevicePrefix); } + configSet = configAlloc(0, NULL, path); configRead(configSet); From 7d54d56261a39776bbeee74b955873bf6d4f5e41 Mon Sep 17 00:00:00 2001 From: CosmicScale <60739760+CosmicScale@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:55:56 +0000 Subject: [PATCH 2/2] Moved `dir` declaration inside loop --- src/opl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/opl.c b/src/opl.c index c7b1cdc5a..792745eb0 100644 --- a/src/opl.c +++ b/src/opl.c @@ -1953,14 +1953,13 @@ static void autoLaunchBDMGame(char *argv[]) gAutoLaunchDeviceData = malloc(sizeof(bdm_device_data_t)); memset(gAutoLaunchDeviceData, 0, sizeof(bdm_device_data_t)); - int dir = -1; char apaDevicePrefix[8] = {0}; delay(8); snprintf(apaDevicePrefix, sizeof(apaDevicePrefix), "mass0:"); // Loop through mass0: to mass4: for (int i = 0; i <= 4; i++) { snprintf(path, sizeof(path), "mass%d:", i); - dir = fileXioDopen(path); + int dir = fileXioDopen(path); if (dir >= 0) { fileXioIoctl2(dir, USBMASS_IOCTL_GET_DRIVERNAME, NULL, 0, &gAutoLaunchDeviceData->bdmDriver, sizeof(gAutoLaunchDeviceData->bdmDriver) - 1);