mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
(PS2) Cleanups
This commit is contained in:
parent
d6e7ae3769
commit
c4f69b1eb7
@ -33,8 +33,8 @@ int islower(int c)
|
||||
if ((c < 'a') || (c > 'z'))
|
||||
return 0;
|
||||
|
||||
// passed both criteria, so it
|
||||
// is a lower case alpha char
|
||||
/* passed both criteria, so it
|
||||
* is a lower case alpha char */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -58,7 +58,8 @@ int memcmp(const void *s1, const void *s2, unsigned int length)
|
||||
const char *a = s1;
|
||||
const char *b = s2;
|
||||
|
||||
while (length--) {
|
||||
while (length--)
|
||||
{
|
||||
if (*a++ != *b++)
|
||||
return 1;
|
||||
}
|
||||
|
@ -19,11 +19,13 @@ static int comp_entries_by_filename(const void *elem1, const void *elem2)
|
||||
return strcmp(((entries*)elem1)->filename, ((entries*)elem2)->filename);
|
||||
}
|
||||
|
||||
static int ps2_cdDiscValid(void) //returns 1 if disc valid, else returns 0
|
||||
/* returns 1 if disc valid, else returns 0 */
|
||||
static int ps2_cdDiscValid(void)
|
||||
{
|
||||
int cdmode = sceCdGetDiskType();
|
||||
|
||||
switch (cdmode) {
|
||||
switch (cdmode)
|
||||
{
|
||||
case SCECdPSCD:
|
||||
case SCECdPSCDDA:
|
||||
case SCECdPS2CD:
|
||||
@ -60,15 +62,18 @@ static int prepareCDVD(void)
|
||||
u64 wait_start;
|
||||
int cdmode = sceCdGetDiskType();
|
||||
|
||||
if (sceCdGetDiskType() <= SCECdUNKNOWN) {
|
||||
if (sceCdGetDiskType() <= SCECdUNKNOWN)
|
||||
{
|
||||
wait_start = cd_Timer();
|
||||
while ((cd_Timer() < wait_start + 500) && !ps2_cdDiscValid()) {
|
||||
while ((cd_Timer() < wait_start + 500) && !ps2_cdDiscValid())
|
||||
{
|
||||
if (cdmode == SCECdNODISC)
|
||||
return 0;
|
||||
}
|
||||
if (cdmode == SCECdNODISC)
|
||||
return 0;
|
||||
if ((cdmode < SCECdPSCD) || (cdmode > SCECdPS2DVD)) {
|
||||
if ((cdmode < SCECdPSCD) || (cdmode > SCECdPS2DVD))
|
||||
{
|
||||
ps2_cdStop();
|
||||
return 0;
|
||||
}
|
||||
@ -86,50 +91,55 @@ static int listcdvd(const char *path, entries *FileEntry)
|
||||
int first_file_index;
|
||||
|
||||
strcpy(dir, &path[5]);
|
||||
// Directories first...
|
||||
|
||||
/* Directories first... */
|
||||
|
||||
CDVD_FlushCache();
|
||||
n = CDVD_GetDir(dir, NULL, CDVD_GET_DIRS_ONLY, TocEntryList, FILEENTRY_SIZE, dir);
|
||||
n = CDVD_GetDir(dir, NULL, CDVD_GET_DIRS_ONLY,
|
||||
TocEntryList, FILEENTRY_SIZE, dir);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
/* Skip pseudopaths "." and ".." */
|
||||
if (TocEntryList[i].fileProperties & 0x02 && (!strcmp(
|
||||
TocEntryList[i].filename, ".") || !strcmp(
|
||||
TocEntryList[i].filename, "..")))
|
||||
continue; // Skip pseudopaths "." and ".."
|
||||
continue;
|
||||
|
||||
FileEntry[t].dircheck = 1;
|
||||
strcpy(FileEntry[t].filename, TocEntryList[i].filename);
|
||||
t++;
|
||||
|
||||
if (t >= FILEENTRY_SIZE - 2) {
|
||||
if (t >= FILEENTRY_SIZE - 2)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qsort(FileEntry, t, sizeof(entries), comp_entries_by_filename);
|
||||
first_file_index = t;
|
||||
|
||||
// Now files only
|
||||
/* Now files only */
|
||||
|
||||
CDVD_FlushCache();
|
||||
n = CDVD_GetDir(dir, NULL, CDVD_GET_FILES_ONLY, TocEntryList, FILEENTRY_SIZE, dir);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
/* Skip pseudopaths "." and ".." */
|
||||
if (TocEntryList[i].fileProperties & 0x02 && (!strcmp(
|
||||
TocEntryList[i].filename, ".") || !strcmp(
|
||||
TocEntryList[i].filename, "..")))
|
||||
continue; // Skip pseudopaths "." and ".."
|
||||
continue;
|
||||
|
||||
FileEntry[t].dircheck = 0;
|
||||
strcpy(FileEntry[t].filename, TocEntryList[i].filename);
|
||||
t++;
|
||||
|
||||
if (t >= FILEENTRY_SIZE - 2) {
|
||||
if (t >= FILEENTRY_SIZE - 2)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qsort(FileEntry + first_file_index, t - first_file_index, sizeof(entries), comp_entries_by_filename);
|
||||
qsort(FileEntry + first_file_index, t - first_file_index,
|
||||
sizeof(entries), comp_entries_by_filename);
|
||||
|
||||
return t;
|
||||
}
|
||||
@ -138,15 +148,17 @@ static int fileXioCDDread(int fd, iox_dirent_t *dirent)
|
||||
{
|
||||
DescriptorTranslation *descriptor = __ps2_fd_grab(fd);
|
||||
|
||||
if (descriptor && descriptor->current_folder_position < descriptor->items) {
|
||||
if (descriptor && descriptor->current_folder_position < descriptor->items)
|
||||
{
|
||||
strcpy(dirent->name, descriptor->FileEntry[descriptor->current_folder_position].filename);
|
||||
if (descriptor->FileEntry[descriptor->current_folder_position].dircheck) {
|
||||
if (descriptor->FileEntry[descriptor->current_folder_position].dircheck)
|
||||
dirent->stat.mode = FIO_S_IFDIR;
|
||||
} else {
|
||||
else
|
||||
dirent->stat.mode = FIO_S_IFREG;
|
||||
}
|
||||
descriptor->current_folder_position++;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
descriptor->current_folder_position = 0;
|
||||
return 0;
|
||||
}
|
||||
@ -156,47 +168,38 @@ static int fileXioCDDread(int fd, iox_dirent_t *dirent)
|
||||
|
||||
static int fileXioCDDopen(const char *name)
|
||||
{
|
||||
int fd = -1;
|
||||
if (prepareCDVD()){
|
||||
fd = __ps2_acquire_descriptor();
|
||||
if (prepareCDVD())
|
||||
{
|
||||
int fd = __ps2_acquire_descriptor();
|
||||
DescriptorTranslation *descriptor = __ps2_fd_grab(fd);
|
||||
descriptor->current_folder_position = 0;
|
||||
descriptor->items = listcdvd(name, descriptor->FileEntry);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int ps2fileXioDopen(const char *name)
|
||||
{
|
||||
enum BootDeviceIDs deviceID = getBootDeviceID((char *)name);
|
||||
int fd = -1;
|
||||
if (deviceID == BOOT_DEVICE_CDFS) {
|
||||
fd = fileXioCDDopen(name);
|
||||
} else {
|
||||
fd = fileXioDopen(name);
|
||||
}
|
||||
|
||||
return fd;
|
||||
if (deviceID == BOOT_DEVICE_CDFS)
|
||||
return fileXioCDDopen(name);
|
||||
return fileXioDopen(name);
|
||||
}
|
||||
|
||||
int ps2fileXioDread(int fd, iox_dirent_t *dirent)
|
||||
{
|
||||
if (is_fd_valid(fd)) {
|
||||
if (is_fd_valid(fd))
|
||||
return fileXioCDDread(fd, dirent);
|
||||
} else {
|
||||
return fileXioDread(fd, dirent);
|
||||
}
|
||||
}
|
||||
|
||||
int ps2fileXioDclose(int fd)
|
||||
{
|
||||
int ret = -19;
|
||||
if (is_fd_valid(fd)) {
|
||||
ret = __ps2_release_descriptor(fd);
|
||||
} else if (fd > 0) {
|
||||
ret = fileXioDclose(fd);
|
||||
}
|
||||
|
||||
return ret;
|
||||
if (is_fd_valid(fd))
|
||||
return __ps2_release_descriptor(fd);
|
||||
else if (fd > 0)
|
||||
return fileXioDclose(fd);
|
||||
return -19;
|
||||
}
|
||||
|
@ -49,20 +49,20 @@ static time_t _gmtotime_t (
|
||||
int sc
|
||||
)
|
||||
{
|
||||
int passed_years;
|
||||
long passed_days;
|
||||
long passed_seconds_current_day;
|
||||
time_t seconds_from_1970 = -1;
|
||||
|
||||
if ((yr >= MIN_SUPPORTED_YEAR) || (yr <= MAX_SUPPORTED_YEAR))
|
||||
{
|
||||
passed_years = (long)yr - MIN_SUPPORTED_YEAR; /* Years after 1970 */
|
||||
long passed_seconds_current_day;
|
||||
int passed_years = (long)yr - MIN_SUPPORTED_YEAR; /* Years after 1970 */
|
||||
/* Calculate days for these years */
|
||||
passed_days = passed_years * DAYS_YEAR;
|
||||
long passed_days = passed_years * DAYS_YEAR;
|
||||
passed_days += (passed_years >> 2) * (DAYS_YEAR + 1); /* passed leap years */
|
||||
passed_days += dy + _days[mo - 1]; /* passed days in the year */
|
||||
|
||||
if (!(yr & 3) && (mo > 2))
|
||||
passed_days++; /* if current year, is a leap year */
|
||||
|
||||
passed_seconds_current_day = (((hr * MINS_HOUR) + mn) * SECS_MIN) + sc;
|
||||
seconds_from_1970 = (passed_days * HOURS_DAY * MINS_HOUR * SECS_MIN) + passed_seconds_current_day;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user