Skip to content

Commit

Permalink
attempt to fix autolaunch bdm hdd
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Nov 3, 2024
1 parent 989eab5 commit 3d94b0a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 2 additions & 0 deletions include/bdmsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ void bdmLaunchGame(item_list_t *itemList, int id, config_set_t *configSet);
void bdmInitSemaphore();
void bdmEnumerateDevices();

void bdmResolveLBA_UDMA(bdm_device_data_t *pDeviceData);

#endif
43 changes: 25 additions & 18 deletions src/bdmsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,30 @@ void bdmEnumerateDevices()
LOG("bdmEnumerateDevices done\n");
}

void bdmResolveLBA_UDMA(bdm_device_data_t *pDeviceData)
{
// If atad is loaded then xhdd is also loaded, query the hdd to see if it supports LBA48 or not.
pDeviceData->bdmHddIsLBA48 = fileXioDevctl("xhdd0:", ATA_DEVCTL_IS_48BIT, NULL, 0, NULL, 0);
if (pDeviceData->bdmHddIsLBA48 < 0) {
// Failed to query the LBA limit of the device, fail safe to LBA28.
LOG("Mass device %d is backed by ATA but failed to get LBA limit %d\n", pDeviceData->massDeviceIndex, pDeviceData->bdmHddIsLBA48);
pDeviceData->bdmHddIsLBA48 = 0;
}

// Query the drive for the highest UDMA mode.
pDeviceData->ataHighestUDMAMode = fileXioDevctl("xhdd0:", ATA_DEVCTL_GET_HIGHEST_UDMA_MODE, NULL, 0, NULL, 0);
if (pDeviceData->ataHighestUDMAMode < 0 || pDeviceData->ataHighestUDMAMode > 7) {
// Failed to query highest UDMA mode supported.
LOG("Mass device %d is backed by ATA but failed to get highest UDMA mode %d\n", pDeviceData->ataHighestUDMAMode);
pDeviceData->ataHighestUDMAMode = 4;
}

#ifdef ATA_UDMA_PLUS
// Set the UDMA mode to highest available.
hddSetTransferMode(0x40, pDeviceData->ataHighestUDMAMode);
#endif
}

int bdmUpdateDeviceData(item_list_t *itemList)
{
char path[16] = {0};
Expand Down Expand Up @@ -802,24 +826,7 @@ int bdmUpdateDeviceData(item_list_t *itemList)

// If the device is backed by the ATA driver then get the supported LBA size for the drive.
if (pDeviceData->bdmDeviceType == BDM_TYPE_ATA) {
// If atad is loaded then xhdd is also loaded, query the hdd to see if it supports LBA48 or not.
pDeviceData->bdmHddIsLBA48 = fileXioDevctl("xhdd0:", ATA_DEVCTL_IS_48BIT, NULL, 0, NULL, 0);
if (pDeviceData->bdmHddIsLBA48 < 0) {
// Failed to query the LBA limit of the device, fail safe to LBA28.
LOG("Mass device %d is backed by ATA but failed to get LBA limit %d\n", pDeviceData->massDeviceIndex, pDeviceData->bdmHddIsLBA48);
pDeviceData->bdmHddIsLBA48 = 0;
}
// Query the drive for the highest UDMA mode.
pDeviceData->ataHighestUDMAMode = fileXioDevctl("xhdd0:", ATA_DEVCTL_GET_HIGHEST_UDMA_MODE, NULL, 0, NULL, 0);
if (pDeviceData->ataHighestUDMAMode < 0 || pDeviceData->ataHighestUDMAMode > 7) {
// Failed to query highest UDMA mode supported.
LOG("Mass device %d is backed by ATA but failed to get highest UDMA mode %d\n", pDeviceData->ataHighestUDMAMode);
pDeviceData->ataHighestUDMAMode = 4;
}
#ifdef ATA_UDMA_PLUS
// Set the UDMA mode to highest available.
hddSetTransferMode(0x40, pDeviceData->ataHighestUDMAMode);
#endif
bdmResolveLBA_UDMA(pDeviceData);
LOG("Mass device: %d (%d LBA%d UDMA%d) %s -> %s\n", itemList->mode, pDeviceData->massDeviceIndex, (pDeviceData->bdmHddIsLBA48 == 1 ? 48 : 28), pDeviceData->ataHighestUDMAMode, pDeviceData->bdmPrefix, pDeviceData->bdmDriver);
} else
LOG("Mass device: %d (%d) %s -> %s\n", itemList->mode, pDeviceData->massDeviceIndex, pDeviceData->bdmPrefix, pDeviceData->bdmDriver);
Expand Down
5 changes: 5 additions & 0 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,8 @@ static void miniInit(int mode)
LOG_ENABLE();

if (mode == BDM_MODE) {
bdmInitSemaphore();

// Force load iLink & mx4sio modules.. we aren't using the gui so this is fine.
gEnableILK = 1; // iLink will break pcsx2 however.
gEnableMX4SIO = 1;
Expand Down Expand Up @@ -1948,6 +1950,9 @@ static void autoLaunchBDMGame(char *argv[])
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);

fileXioDclose(dir);
}

Expand Down

0 comments on commit 3d94b0a

Please sign in to comment.