Skip to content

Commit eb5d5ed

Browse files
Resolve merge conflicts with upstream master
2 parents 2b0cd61 + 39afed2 commit eb5d5ed

6 files changed

Lines changed: 101 additions & 18 deletions

File tree

.github/ISSUE_TEMPLATE/issue-report.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ body:
5959
label: "In which device(s) have you experienced this issue?"
6060
multiple: true
6161
options:
62+
- USB
63+
- SMB
64+
- HDD
65+
- iLink
66+
- MX4SIO
6267
- SD2PSX (DIY)
6368
- MemCardPRO2 (8BitMods)
6469
- PSxMemCard Gen1 (Bitfunx)

include/bdmsupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void bdmEnumerateDevices();
5555

5656
void bdmResolveLBA_UDMA(bdm_device_data_t *pDeviceData);
5757
int bdmWaitForDevice(int deviceId, u32 timeoutMs);
58-
int bdmHDDIsPresent();
58+
int bdmHDDIsPresent(u32 timeoutMs);
5959
int bdmResolveDeviceRoot(char *target, int targetLength, const char *driverName, int massDeviceIndex, int massSlot);
6060

6161
int bdmFindPartition(char *target, const char *name, int write);

include/hddsupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@ item_list_t *hddGetObject(int initOnly);
7373
int hddLoadModules(void);
7474
void hddLoadSupportModules(void);
7575
void hddLaunchGame(item_list_t *itemList, int id, config_set_t *configSet);
76+
int hddIsPresent();
7677

7778
#endif

src/bdmsupport.c

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ int bdmUpdateDeviceData(item_list_t *itemList)
10401040
return 0;
10411041
}
10421042

1043-
int bdmWaitForDevice(int deviceId, u32 timeoutMs)
1043+
static int bdmWaitForDevice(int deviceId, u32 timeoutMs)
10441044
{
10451045
const int RETRY_DELAY = 100;
10461046
char path[16];
@@ -1067,11 +1067,89 @@ int bdmWaitForDevice(int deviceId, u32 timeoutMs)
10671067
}
10681068
}
10691069

1070-
int bdmHDDIsPresent()
1070+
static int bdmDeviceIsPresent(int deviceId)
10711071
{
1072-
// the only thing that currently uses ata_device_identify is ATA_DEVCTL_GET_HIGHEST_UDMA_MODE, so this is the best method to check for presence via xhdd (for now anyways)
1073-
// ideally, we'd only have ata_device_identify
1074-
return fileXioDevctl("xhdd0:", ATA_DEVCTL_GET_HIGHEST_UDMA_MODE, NULL, 0, NULL, 0) >= 0;
1072+
char path[16];
1073+
sprintf(path, "mass%d:/", deviceId);
1074+
int dir = fileXioDopen(path);
1075+
1076+
if (dir >= 0) {
1077+
fileXioDclose(dir);
1078+
return 1; // ready
1079+
}
1080+
1081+
return 0;
1082+
}
1083+
1084+
static int bdmDeviceIsATA(int deviceId)
1085+
{
1086+
char path[16];
1087+
bdm_device_data_t data;
1088+
1089+
sprintf(path, "mass%d:/", deviceId);
1090+
int dir = fileXioDopen(path);
1091+
if (dir < 0)
1092+
return 0;
1093+
1094+
fileXioIoctl2(dir, USBMASS_IOCTL_GET_DRIVERNAME, NULL, 0, &data.bdmDriver, sizeof(data.bdmDriver) - 1);
1095+
fileXioDclose(dir);
1096+
1097+
return (!strcmp(data.bdmDriver, "ata") && strlen(data.bdmDriver) == 3);
1098+
}
1099+
1100+
static int bdmGetATADeviceId()
1101+
{
1102+
for (int i = 0; i < MAX_BDM_DEVICES; i++) {
1103+
if (bdmDeviceIsATA(i)) {
1104+
return i;
1105+
}
1106+
}
1107+
return -1;
1108+
}
1109+
1110+
int bdmHDDIsPresent(u32 timeoutMs)
1111+
{
1112+
int hdd_id = -1;
1113+
int timedout = 0;
1114+
1115+
if (!hddIsPresent())
1116+
return 0;
1117+
1118+
// 1. scan via normal methods first...
1119+
hdd_id = bdmGetATADeviceId();
1120+
if (hdd_id >= 0)
1121+
return 1;
1122+
1123+
// 2. try to scan as fast as possible if the previous scan fails...
1124+
hdd_id = 0;
1125+
1126+
for (int i = 0; i < MAX_BDM_DEVICES; i++) {
1127+
// find the first inaccessible device - this one should be the HDD once it's mounted (we don't have access to device data at this point yet!)
1128+
if (!bdmDeviceIsPresent(i)) {
1129+
hdd_id = i;
1130+
break;
1131+
}
1132+
}
1133+
1134+
if (bdmWaitForDevice(hdd_id, timeoutMs)) {
1135+
// double-check to see if this indeed is the HDD, and if it is, we can exit early without stalling any further
1136+
if (bdmDeviceIsATA(hdd_id)) {
1137+
return 1;
1138+
} else
1139+
LOG("bdmHDDIsPresent: device at id %d is not an ATA HDD...\n", hdd_id);
1140+
} else {
1141+
timedout = 1;
1142+
LOG("bdmHDDIsPresent: waiting for hdd at id %d timed out...\n", hdd_id);
1143+
}
1144+
1145+
// 3. last resort - time out (if needed) and scan again...
1146+
if (!timedout) {
1147+
// if we haven't timed out already, then we need to wait for the devices to wake up... wait for the timeout...
1148+
LOG("bdmHDDIsPresent: waiting for timeout before scanning again...\n", hdd_id);
1149+
DelayThread(timeoutMs * 1000);
1150+
}
1151+
1152+
return bdmGetATADeviceId() >= 0;
10751153
}
10761154

10771155

src/hddsupport.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,13 @@ static int hddUpdateGameListCache(hdl_games_list_t *cache, hdl_games_list_t *gam
818818
return result;
819819
}
820820

821+
int hddIsPresent()
822+
{
823+
// the only thing that currently uses ata_device_identify is ATA_DEVCTL_GET_HIGHEST_UDMA_MODE, so this is the best method to check for presence via xhdd (for now anyways)
824+
// ideally, we'd only have ata_device_identify
825+
return fileXioDevctl("xhdd0:", ATA_DEVCTL_GET_HIGHEST_UDMA_MODE, NULL, 0, NULL, 0) >= 0;
826+
}
827+
821828
static char *hddGetPrefix(item_list_t *itemList)
822829
{
823830
return gHDDPrefix;

src/opl.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -800,12 +800,8 @@ static int checkLoadConfigBDM(int types)
800800
bdm_result = bdmFindPartition(path, "conf_opl.cfg", 0);
801801
// if not on USB, check BDM HDD
802802
if (bdm_result == 0) {
803-
if (hddLoadModules() >= 0 && bdmHDDIsPresent()) {
804-
// we can safely assume mass0 in this instance because this should be the only device if the previous checks failed...
805-
// wait for up to 5 seconds for the HDD to spin up and become accessible...
806-
if (!bdmWaitForDevice(0, 5000))
807-
LOG("checkLoadConfigBDM: HDD check timeout!");
808-
803+
// wait for up to 5 seconds for the HDD to spin up and become accessible...
804+
if (hddLoadModules() >= 0 && bdmHDDIsPresent(5000)) {
809805
bdm_result = bdmFindPartition(path, "conf_opl.cfg", 0);
810806
if (bdm_result)
811807
is_hdd = 1;
@@ -1037,12 +1033,8 @@ static int trySaveConfigBDM(int types)
10371033
bdm_result = bdmFindPartition(path, "conf_opl.cfg", 1);
10381034
// if not on USB, check BDM HDD
10391035
if (bdm_result == 0) {
1040-
if (hddLoadModules() >= 0 && bdmHDDIsPresent()) {
1041-
// we can safely assume mass0 in this instance because this should be the only device if the previous checks failed...
1042-
// wait for up to 5 seconds for the HDD to spin up and become accessible...
1043-
if (!bdmWaitForDevice(0, 5000))
1044-
LOG("trySaveConfigBDM: HDD check timeout!");
1045-
1036+
// wait for up to 5 seconds for the HDD to spin up and become accessible...
1037+
if (hddLoadModules() >= 0 && bdmHDDIsPresent(5000)) {
10461038
bdm_result = bdmFindPartition(path, "conf_opl.cfg", 1);
10471039
}
10481040
}

0 commit comments

Comments
 (0)