From: Francisco Javier Trujillo Mata Date: Wed, 15 Nov 2023 18:36:26 +0000 (+0100) Subject: Use posix functions for PSP X-Git-Tag: v2.00~165 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b2223986c32856d0affe27c386ec87e7a906e18;p=picodrive.git Use posix functions for PSP --- diff --git a/platform/psp/plat.c b/platform/psp/plat.c index cd4df5a6..d15b1b5e 100644 --- a/platform/psp/plat.c +++ b/platform/psp/plat.c @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "../common/emu.h" #include "../libpicofe/menu.h" @@ -137,42 +140,61 @@ int plat_get_data_dir(char *dst, int len) /* check if path is a directory */ int plat_is_dir(const char *path) { - SceIoStat st; - int ret = sceIoGetstat(path, &st); - return (ret >= 0 && (st.st_mode & FIO_S_IFDIR)); + DIR *dir; + if ((dir = opendir(path))) { + closedir(dir); + return 1; + } + return 0; } /* current time in ms */ unsigned int plat_get_ticks_ms(void) { + struct timeval tv; + unsigned int ret; + + gettimeofday(&tv, NULL); + + ret = (unsigned)tv.tv_sec * 1000; /* approximate /= 1000 */ - unsigned long long v64; - v64 = (unsigned long long)plat_get_ticks_us() * 4294968; - return v64 >> 32; + ret += ((unsigned)tv.tv_usec * 4195) >> 22; + + return ret; } /* current time in us */ unsigned int plat_get_ticks_us(void) { - return sceKernelGetSystemTimeLow(); + struct timeval tv; + unsigned int ret; + + gettimeofday(&tv, NULL); + + ret = (unsigned)tv.tv_sec * 1000000; + ret += (unsigned)tv.tv_usec; + + return ret; } /* sleep for some time in ms */ void plat_sleep_ms(int ms) { - psp_msleep(ms); + usleep(ms * 1000); } /* sleep for some time in us */ void plat_wait_till_us(unsigned int us_to) { - unsigned int tval; - int diff; + unsigned int now; + + now = plat_get_ticks_us(); - tval = sceKernelGetSystemTimeLow(); - diff = (int)us_to - (int)tval; - if (diff >= 512 && diff < 100*1024) - sceKernelDelayThread(diff); + while ((signed int)(us_to - now) > 512) + { + usleep(1024); + now = plat_get_ticks_us(); + } } /* wait until some event occurs, or timeout */ @@ -237,110 +259,17 @@ struct plat_target plat_target = { // .hwfilters = plat_hwfilters, }; -#ifndef DT_DIR -/* replacement libc stuff */ - -int alphasort(const struct dirent **a, const struct dirent **b) -{ - return strcoll ((*a)->d_name, (*b)->d_name); -} - -int scandir(const char *dir, struct dirent ***namelist_out, - int(*filter)(const struct dirent *), - int(*compar)(const struct dirent **, const struct dirent **)) +int _flush_cache (char *addr, const int size, const int op) { - int ret = -1, dir_uid = -1, name_alloc = 4, name_count = 0; - struct dirent **namelist = NULL, *ent; - SceIoDirent sce_ent; - - namelist = malloc(sizeof(*namelist) * name_alloc); - if (namelist == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } - - // try to read first.. - dir_uid = sceIoDopen(dir); - if (dir_uid >= 0) - { - /* it is very important to clear SceIoDirent to be passed to sceIoDread(), */ - /* or else it may crash, probably misinterpreting something in it. */ - memset(&sce_ent, 0, sizeof(sce_ent)); - ret = sceIoDread(dir_uid, &sce_ent); - if (ret < 0) - { - lprintf("sceIoDread(\"%s\") failed with %i\n", dir, ret); - goto fail; - } - } - else - lprintf("sceIoDopen(\"%s\") failed with %i\n", dir, dir_uid); - - while (ret > 0) - { - ent = malloc(sizeof(*ent)); - if (ent == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } - ent->d_stat = sce_ent.d_stat; - ent->d_stat.st_attr &= FIO_SO_IFMT; // serves as d_type - strncpy(ent->d_name, sce_ent.d_name, sizeof(ent->d_name)); - ent->d_name[sizeof(ent->d_name)-1] = 0; - if (filter == NULL || filter(ent)) - namelist[name_count++] = ent; - else free(ent); - - if (name_count >= name_alloc) - { - void *tmp; - name_alloc *= 2; - tmp = realloc(namelist, sizeof(*namelist) * name_alloc); - if (tmp == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } - namelist = tmp; - } - - memset(&sce_ent, 0, sizeof(sce_ent)); - ret = sceIoDread(dir_uid, &sce_ent); - } - - // sort - if (compar != NULL && name_count > 3) - qsort(&namelist[2], name_count - 2, sizeof(namelist[0]), (int (*)()) compar); - - // all done. - ret = name_count; - *namelist_out = namelist; - goto end; - -fail: - if (namelist != NULL) - { - while (name_count--) - free(namelist[name_count]); - free(namelist); - } -end: - if (dir_uid >= 0) sceIoDclose(dir_uid); - return ret; + //sceKernelDcacheWritebackAll(); + sceKernelDcacheWritebackRange(addr, size); + sceKernelIcacheInvalidateRange(addr, size); + return 0; } -/* stubs for libflac (embedded in libchdr) */ -#include - -int chown(const char *pathname, uid_t owner, gid_t group) { return -1; } -int chmod(const char *pathname, mode_t mode) { return -1; } -int utime(const char *filename, const struct utimbuf *times) { return -1; } -#endif - -#include -#include - int posix_memalign(void **p, size_t align, size_t size) { if (p) *p = memalign(align, size); return (p ? *p ? 0 : ENOMEM : EINVAL); -} - -int _flush_cache (char *addr, const int size, const int op) -{ - //sceKernelDcacheWritebackAll(); - sceKernelDcacheWritebackRange(addr, size); - sceKernelIcacheInvalidateRange(addr, size); - return 0; -} +} \ No newline at end of file diff --git a/platform/psp/psp.c b/platform/psp/psp.c index 4e884879..e719e469 100644 --- a/platform/psp/psp.c +++ b/platform/psp/psp.c @@ -31,7 +31,6 @@ extern int pico_main(int argc, char *argv[]); #ifndef FW15 PSP_MODULE_INFO("PicoDrive", 0, 1, 97); -PSP_HEAP_SIZE_MAX(); int main(int argc, char *argv[]) { return pico_main(argc, argv); } /* just a wrapper */