Skip to content

Commit

Permalink
Merge pull request #1443 from CosmicScale/autoLaunchBDMGame
Browse files Browse the repository at this point in the history
Fixed BDM Auto-Launch
  • Loading branch information
uyjulian authored Jan 2, 2025
2 parents a626d98 + 7d54d56 commit d5e0998
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1953,26 +1953,47 @@ 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);
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);
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);
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);

Expand Down

0 comments on commit d5e0998

Please sign in to comment.