(PS2) Cleanups

This commit is contained in:
twinaphex 2020-02-14 17:43:00 +01:00
parent d6e7ae3769
commit c4f69b1eb7
3 changed files with 181 additions and 177 deletions

View File

@ -33,14 +33,14 @@ int islower(int c)
if ((c < 'a') || (c > 'z')) if ((c < 'a') || (c > 'z'))
return 0; return 0;
// passed both criteria, so it /* passed both criteria, so it
// is a lower case alpha char * is a lower case alpha char */
return 1; return 1;
} }
int tolower(int ch) int tolower(int ch)
{ {
if(ch >= 'A' && ch <= 'Z') if (ch >= 'A' && ch <= 'Z')
return ('a' + ch - 'A'); return ('a' + ch - 'A');
return ch; return ch;
} }
@ -58,7 +58,8 @@ int memcmp(const void *s1, const void *s2, unsigned int length)
const char *a = s1; const char *a = s1;
const char *b = s2; const char *b = s2;
while (length--) { while (length--)
{
if (*a++ != *b++) if (*a++ != *b++)
return 1; return 1;
} }

View File

@ -19,11 +19,13 @@ static int comp_entries_by_filename(const void *elem1, const void *elem2)
return strcmp(((entries*)elem1)->filename, ((entries*)elem2)->filename); 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(); int cdmode = sceCdGetDiskType();
switch (cdmode) { switch (cdmode)
{
case SCECdPSCD: case SCECdPSCD:
case SCECdPSCDDA: case SCECdPSCDDA:
case SCECdPS2CD: case SCECdPS2CD:
@ -60,15 +62,18 @@ static int prepareCDVD(void)
u64 wait_start; u64 wait_start;
int cdmode = sceCdGetDiskType(); int cdmode = sceCdGetDiskType();
if (sceCdGetDiskType() <= SCECdUNKNOWN) { if (sceCdGetDiskType() <= SCECdUNKNOWN)
{
wait_start = cd_Timer(); wait_start = cd_Timer();
while ((cd_Timer() < wait_start + 500) && !ps2_cdDiscValid()) { while ((cd_Timer() < wait_start + 500) && !ps2_cdDiscValid())
{
if (cdmode == SCECdNODISC) if (cdmode == SCECdNODISC)
return 0; return 0;
} }
if (cdmode == SCECdNODISC) if (cdmode == SCECdNODISC)
return 0; return 0;
if ((cdmode < SCECdPSCD) || (cdmode > SCECdPS2DVD)) { if ((cdmode < SCECdPSCD) || (cdmode > SCECdPS2DVD))
{
ps2_cdStop(); ps2_cdStop();
return 0; return 0;
} }
@ -86,50 +91,55 @@ static int listcdvd(const char *path, entries *FileEntry)
int first_file_index; int first_file_index;
strcpy(dir, &path[5]); strcpy(dir, &path[5]);
// Directories first...
/* Directories first... */
CDVD_FlushCache(); 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( if (TocEntryList[i].fileProperties & 0x02 && (!strcmp(
TocEntryList[i].filename, ".") || !strcmp( TocEntryList[i].filename, ".") || !strcmp(
TocEntryList[i].filename, ".."))) TocEntryList[i].filename, "..")))
continue; // Skip pseudopaths "." and ".." continue;
FileEntry[t].dircheck = 1; FileEntry[t].dircheck = 1;
strcpy(FileEntry[t].filename, TocEntryList[i].filename); strcpy(FileEntry[t].filename, TocEntryList[i].filename);
t++; t++;
if (t >= FILEENTRY_SIZE - 2) { if (t >= FILEENTRY_SIZE - 2)
break; break;
} }
}
qsort(FileEntry, t, sizeof(entries), comp_entries_by_filename); qsort(FileEntry, t, sizeof(entries), comp_entries_by_filename);
first_file_index = t; first_file_index = t;
// Now files only /* Now files only */
CDVD_FlushCache(); CDVD_FlushCache();
n = CDVD_GetDir(dir, NULL, CDVD_GET_FILES_ONLY, TocEntryList, FILEENTRY_SIZE, dir); 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( if (TocEntryList[i].fileProperties & 0x02 && (!strcmp(
TocEntryList[i].filename, ".") || !strcmp( TocEntryList[i].filename, ".") || !strcmp(
TocEntryList[i].filename, ".."))) TocEntryList[i].filename, "..")))
continue; // Skip pseudopaths "." and ".." continue;
FileEntry[t].dircheck = 0; FileEntry[t].dircheck = 0;
strcpy(FileEntry[t].filename, TocEntryList[i].filename); strcpy(FileEntry[t].filename, TocEntryList[i].filename);
t++; t++;
if (t >= FILEENTRY_SIZE - 2) { if (t >= FILEENTRY_SIZE - 2)
break; 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; return t;
} }
@ -138,15 +148,17 @@ static int fileXioCDDread(int fd, iox_dirent_t *dirent)
{ {
DescriptorTranslation *descriptor = __ps2_fd_grab(fd); 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); 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; dirent->stat.mode = FIO_S_IFDIR;
} else { else
dirent->stat.mode = FIO_S_IFREG; dirent->stat.mode = FIO_S_IFREG;
}
descriptor->current_folder_position++; descriptor->current_folder_position++;
} else { }
else
{
descriptor->current_folder_position = 0; descriptor->current_folder_position = 0;
return 0; return 0;
} }
@ -156,47 +168,38 @@ static int fileXioCDDread(int fd, iox_dirent_t *dirent)
static int fileXioCDDopen(const char *name) static int fileXioCDDopen(const char *name)
{ {
int fd = -1; if (prepareCDVD())
if (prepareCDVD()){ {
fd = __ps2_acquire_descriptor(); int fd = __ps2_acquire_descriptor();
DescriptorTranslation *descriptor = __ps2_fd_grab(fd); DescriptorTranslation *descriptor = __ps2_fd_grab(fd);
descriptor->current_folder_position = 0; descriptor->current_folder_position = 0;
descriptor->items = listcdvd(name, descriptor->FileEntry); descriptor->items = listcdvd(name, descriptor->FileEntry);
}
return fd; return fd;
}
return -1;
} }
int ps2fileXioDopen(const char *name) int ps2fileXioDopen(const char *name)
{ {
enum BootDeviceIDs deviceID = getBootDeviceID((char *)name); enum BootDeviceIDs deviceID = getBootDeviceID((char *)name);
int fd = -1; if (deviceID == BOOT_DEVICE_CDFS)
if (deviceID == BOOT_DEVICE_CDFS) { return fileXioCDDopen(name);
fd = fileXioCDDopen(name); return fileXioDopen(name);
} else {
fd = fileXioDopen(name);
}
return fd;
} }
int ps2fileXioDread(int fd, iox_dirent_t *dirent) int ps2fileXioDread(int fd, iox_dirent_t *dirent)
{ {
if (is_fd_valid(fd)) { if (is_fd_valid(fd))
return fileXioCDDread(fd, dirent); return fileXioCDDread(fd, dirent);
} else {
return fileXioDread(fd, dirent); return fileXioDread(fd, dirent);
}
} }
int ps2fileXioDclose(int fd) int ps2fileXioDclose(int fd)
{ {
int ret = -19; if (is_fd_valid(fd))
if (is_fd_valid(fd)) { return __ps2_release_descriptor(fd);
ret = __ps2_release_descriptor(fd); else if (fd > 0)
} else if (fd > 0) { return fileXioDclose(fd);
ret = fileXioDclose(fd); return -19;
}
return ret;
} }

View File

@ -49,20 +49,20 @@ static time_t _gmtotime_t (
int sc int sc
) )
{ {
int passed_years;
long passed_days;
long passed_seconds_current_day;
time_t seconds_from_1970 = -1; time_t seconds_from_1970 = -1;
if ((yr >= MIN_SUPPORTED_YEAR) || (yr <= MAX_SUPPORTED_YEAR)) 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 */ /* 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 += (passed_years >> 2) * (DAYS_YEAR + 1); /* passed leap years */
passed_days += dy + _days[mo - 1]; /* passed days in the year */ passed_days += dy + _days[mo - 1]; /* passed days in the year */
if ( !(yr & 3) && (mo > 2) )
if (!(yr & 3) && (mo > 2))
passed_days++; /* if current year, is a leap year */ passed_days++; /* if current year, is a leap year */
passed_seconds_current_day = (((hr * MINS_HOUR) + mn) * SECS_MIN) + sc; 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; seconds_from_1970 = (passed_days * HOURS_DAY * MINS_HOUR * SECS_MIN) + passed_seconds_current_day;
} }