diff --git a/Makefile.ps2 b/Makefile.ps2 index 0a7b51162a..dadf436ed3 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -66,7 +66,7 @@ endif CFLAGS += $(RARCH_DEFINES) # Missing objecst on the PS2SDK -EE_OBJS += ps2/compat_files/compat_ctype.o ps2/compat_files/time.o +EE_OBJS += ps2/compat_files/compat_ctype.o ps2/compat_files/time.o ps2/compat_files/ps2_devices.o #EE_OBJS = griffin/griffin.o bootstrap/ps2/kernel_functions.o EE_OBJS += griffin/griffin.o diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 9b5b27a816..14a6c77ef7 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -25,18 +25,8 @@ #include #include #include +#include -enum BootDeviceIDs{ - BOOT_DEVICE_UNKNOWN = -1, - BOOT_DEVICE_MC0 = 0, - BOOT_DEVICE_MC1, - BOOT_DEVICE_CDROM, - BOOT_DEVICE_MASS, - BOOT_DEVICE_HDD, - BOOT_DEVICE_HOST, - - BOOT_DEVICE_COUNT, -}; extern unsigned char poweroff_irx_start[]; extern unsigned int poweroff_irx_size; @@ -77,133 +67,25 @@ extern unsigned int mcman_irx_size; extern unsigned char mcserv_irx_start[]; extern unsigned int mcserv_irx_size; -static unsigned char HDDModulesLoaded=0; - char eboot_path[512]; char user_path[512]; static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE; -/* Only paths residing on "basic" devices - * (devices that don't require mounting) - * can be specified here, since this system - * doesn't perform mounting based on the path. - */ -#define DEFAULT_PATH "mass:" - -static int getBootDeviceID(char *path) -{ - if (!strncmp(path, "mc0:", 4)) - return BOOT_DEVICE_MC0; - else if (!strncmp(path, "mc1:", 4)) - return BOOT_DEVICE_MC1; - else if (!strncmp(path, "cdrom0:", 7)) - return BOOT_DEVICE_CDROM; - else if (!strncmp(path, "mass:", 5) || !strncmp(path, "mass0:", 6)) - return BOOT_DEVICE_MASS; - else if (!strncmp(path, "hdd:", 4) || !strncmp(path, "hdd0:", 5)) - return BOOT_DEVICE_HDD; - else if (!strncmp(path, "host", 4) && ((path[4]>='0' && path[4]<='9') || path[4]==':')) - return BOOT_DEVICE_HOST; - else - return BOOT_DEVICE_UNKNOWN; - - return BOOT_DEVICE_HOST; -} - -/* HACK! If booting from a USB device, keep trying to - * open this program again until it succeeds. - * - * This will ensure that the emulator will be able to load its files. - */ - -static void waitUntilDeviceIsReady(const char *path) -{ - FILE *file; - - while((file=fopen(path, "rb"))==NULL) - { - /* Wait for a while first, or the IOP - * will get swamped by requests from the EE. */ - nopdelay(); - nopdelay(); - nopdelay(); - nopdelay(); - nopdelay(); - nopdelay(); - nopdelay(); - nopdelay(); - }; - - fclose(file); -} - -void setPWDOnPFS(const char *FullCWD_path) -{ - int i; - char *path=NULL; - for (i=strlen(FullCWD_path); i>=0; i--) - { - /* Try to seperate the CWD from the path to this ELF. */ - if (FullCWD_path[i]==':') - { - if ((path=malloc(i+6+2))!=NULL) - { - strcpy(path, "pfs0:/"); - strncat(path, FullCWD_path, i+1); - path[i+1+6]='\0'; - } - break; - } - else if ((FullCWD_path[i]=='\\')||(FullCWD_path[i]=='/')) - { - if ((path=malloc(i+6+1))!=NULL) - { - strcpy(path, "pfs0:/"); - strncat(path, FullCWD_path, i); - path[i+6]='\0'; - } - break; - } - } - - if (path!=NULL) - { - chdir(path); - free(path); - } -} - -static const char *getMountParams(const char *command, char *BlockDevice) -{ - int BlockDeviceNameLen; - const char *MountPath=NULL; - - if (strlen(command)>6 && (MountPath=strchr(&command[5], ':'))!=NULL) - { - BlockDeviceNameLen=(unsigned int)MountPath-(unsigned int)command; - strncpy(BlockDevice, command, BlockDeviceNameLen); - BlockDevice[BlockDeviceNameLen]='\0'; - - MountPath++; /* This is the location of the mount path; */ - } - - return MountPath; -} - static void create_path_names(void) { char cwd[FILENAME_MAX]; + int bootDeviceID; + getcwd(cwd, sizeof(cwd)); - if (strncmp(cwd, "mc0:", 4) || strncmp(cwd, "mc1:", 4)) { - /* For now the save and load states just working in MCs */ - strlcpy(cwd, "mc0:/", sizeof(cwd)); - } + bootDeviceID=getBootDeviceID(cwd); + strlcpy(cwd, rootDevicePath(bootDeviceID), sizeof(cwd)); strcat(cwd, "RETROARCH"); strlcpy(eboot_path, cwd, sizeof(eboot_path)); strlcpy(g_defaults.dirs[DEFAULT_DIR_PORT], eboot_path, sizeof(g_defaults.dirs[DEFAULT_DIR_PORT])); strlcpy(user_path, eboot_path, sizeof(user_path)); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], g_defaults.dirs[DEFAULT_DIR_PORT], "CORES", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], g_defaults.dirs[DEFAULT_DIR_PORT], @@ -260,44 +142,6 @@ static void poweroffCallback(void *arg) static void frontend_ps2_get_environment_settings(int *argc, char *argv[], void *args, void *params_data) { - char cwd[FILENAME_MAX], blockDevice[16]; - const char *mountPoint; - int bootDeviceID; - - getcwd(cwd, sizeof(cwd)); - bootDeviceID=getBootDeviceID(cwd); - - /* Mount the HDD partition, if required. */ - if (bootDeviceID==BOOT_DEVICE_HDD) - { - /* Try not to adjust this unless you know what you are doing. The tricky part i keeping the NULL character in the middle of that argument list separated from the number 4. */ - static const char PS2HDD_args[]="-o\0""2"; - static const char PS2FS_args[]="-o\0""8"; - - if (!HDDModulesLoaded) - { - SifExecModuleBuffer(poweroff_irx_start, poweroff_irx_size, 0, NULL, NULL); - SifExecModuleBuffer(ps2dev9_irx_start, ps2dev9_irx_size, 0, NULL, NULL); - SifExecModuleBuffer(ps2atad_irx_start, ps2atad_irx_size, 0, NULL, NULL); - SifExecModuleBuffer(ps2hdd_irx_start, ps2hdd_irx_size, sizeof(PS2HDD_args), PS2HDD_args, NULL); - SifExecModuleBuffer(ps2fs_irx_start, ps2fs_irx_size, sizeof(PS2FS_args), PS2FS_args, NULL); - HDDModulesLoaded=1; - } - - /* Attempt to mount the partition. */ - if ((mountPoint=getMountParams(cwd, blockDevice))!=NULL && !strncmp(mountPoint, "pfs:", 4)) - { - fileXioMount("pfs0:", blockDevice, FIO_MT_RDWR); - - setPWDOnPFS(&mountPoint[4]); - } - } - else if (bootDeviceID==BOOT_DEVICE_CDROM) - chdir(DEFAULT_PATH); - else if (bootDeviceID==BOOT_DEVICE_MASS) - waitUntilDeviceIsReady(argv[0]); - else if (bootDeviceID==BOOT_DEVICE_UNKNOWN) { } - create_path_names(); #ifndef IS_SALAMANDER @@ -335,11 +179,13 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[], if (!string_is_empty(dir_path)) path_mkdir(dir_path); } - } static void frontend_ps2_init(void *data) { + char cwd[FILENAME_MAX]; + int bootDeviceID; + SifInitRpc(0); #if !defined(DEBUG) /* Comment this line if you don't wanna debug the output */ @@ -381,6 +227,11 @@ static void frontend_ps2_init(void *data) RARCH_ERR("padInit library not initalizated\n"); } + /* Prepare device */ + getcwd(cwd, sizeof(cwd)); + bootDeviceID=getBootDeviceID(cwd); + waitUntilDeviceIsReady(bootDeviceID); + #if defined(HAVE_FILE_LOGGER) retro_main_log_file_init("retroarch.log"); verbosity_enable(); @@ -506,35 +357,32 @@ static int frontend_ps2_parse_drive_list(void *data, bool load_content) MSG_UNKNOWN; menu_entries_append_enum(list, - "mc0:/", + rootDevicePath(BOOT_DEVICE_MC0), msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), enum_idx, FILE_TYPE_DIRECTORY, 0, 0); menu_entries_append_enum(list, - "mc1:/", + rootDevicePath(BOOT_DEVICE_MC1), msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), enum_idx, FILE_TYPE_DIRECTORY, 0, 0); menu_entries_append_enum(list, - "mass:/", + rootDevicePath(BOOT_DEVICE_MASS), msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), enum_idx, FILE_TYPE_DIRECTORY, 0, 0); menu_entries_append_enum(list, - "cdfs:/", - msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), - enum_idx, - FILE_TYPE_DIRECTORY, 0, 0); - menu_entries_append_enum(list, - "hdd0:/", + rootDevicePath(BOOT_DEVICE_HOST), msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), enum_idx, FILE_TYPE_DIRECTORY, 0, 0); +#if defined(DEBUG) menu_entries_append_enum(list, "host:", msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), enum_idx, FILE_TYPE_DIRECTORY, 0, 0); +#endif #endif return 0; diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 97eb04c086..d957c9aa7a 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -821,11 +821,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size) if (tmp[len-1] == '/') tmp[len-1] = '\0'; - if (fileXioGetStat(tmp, &buf) < 0) - { - free(tmp); - return 0; - } + fileXioGetStat(tmp, &buf); free(tmp); #elif defined(__CELLOS_LV2__) CellFsStat buf; @@ -880,7 +876,14 @@ int retro_vfs_stat_impl(const char *path, int32_t *size) #if defined(VITA) || defined(PSP) is_dir = FIO_S_ISDIR(buf.st_mode); #elif defined(PS2) - is_dir = FIO_S_ISDIR(buf.mode); + if (!buf.mode) { + // if fileXioGetStat fails + int dir_ret = fileXioDopen(path); + is_dir = dir_ret > 0; + fileXioDclose(dir_ret); + } else { + is_dir = FIO_S_ISDIR(buf.mode); + } #elif defined(__CELLOS_LV2__) is_dir = ((buf.st_mode & S_IFMT) == S_IFDIR); #elif defined(_WIN32) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 8af7e60b82..4f7ef14af0 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -1766,7 +1766,7 @@ static bool menu_init(menu_handle_t *menu_data) configuration_set_bool(settings, settings->bools.menu_show_start_screen, false); -#if !defined(PS2) /* TODO: PS2 IMPROVEMENT */ +#if !(defined(PS2) && defined(DEBUG)) /* TODO: PS2 IMPROVEMENT */ if (settings->bools.config_save_on_exit) command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL); #endif diff --git a/ps2/compat_files/compat_ctype.c b/ps2/compat_files/compat_ctype.c index bb443bac17..a03606a900 100644 --- a/ps2/compat_files/compat_ctype.c +++ b/ps2/compat_files/compat_ctype.c @@ -438,7 +438,10 @@ noconv: return (acc); } -//long strtol(const char *s, char **endptr, int base); FJTRUJY MISSING +float strtof(const char* str, char** endptr) +{ + return (float) strtod(str, endptr); +} //unsigned long strtoul(const char *s, char **endptr, int base); FJTRUJY MISSING int link(const char *oldpath, const char *newpath) diff --git a/ps2/compat_files/ps2_devices.c b/ps2/compat_files/ps2_devices.c new file mode 100644 index 0000000000..74a3412bce --- /dev/null +++ b/ps2/compat_files/ps2_devices.c @@ -0,0 +1,178 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2018 - Francisco Javier Trujillo Mata - fjtrujy + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include + +#include +#include + +#define DEVICE_SLASH "/" + +#define DEVICE_MC0 "mc0:" +#define DEVICE_MC1 "mc1:" +#define DEVICE_CDROM "cdrom0:" +#define DEVICE_MASS "mass:" +#define DEVICE_MASS0 "mass0:" +#define DEVICE_HDD "hdd:" +#define DEVICE_HDD0 "hdd0:" +#define DEVICE_HOST "host:" +#define DEVICE_HOST0 "host0:" +#define DEVICE_HOST1 "host1:" +#define DEVICE_HOST2 "host2:" +#define DEVICE_HOST3 "host3:" +#define DEVICE_HOST4 "host4:" +#define DEVICE_HOST5 "host5:" +#define DEVICE_HOST6 "host6:" +#define DEVICE_HOST7 "host7:" +#define DEVICE_HOST8 "host8:" +#define DEVICE_HOST9 "host9:" + +#define DEVICE_MC0_PATH DEVICE_MC0 DEVICE_SLASH +#define DEVICE_MC1_PATH DEVICE_MC1 DEVICE_SLASH +#define DEVICE_CDROM_PATH DEVICE_CDROM DEVICE_SLASH +#define DEVICE_MASS_PATH DEVICE_MASS DEVICE_SLASH +#define DEVICE_MASS0_PATH DEVICE_MASS0 DEVICE_SLASH +#define DEVICE_HDD_PATH DEVICE_HDD DEVICE_SLASH +#define DEVICE_HDD0_PATH DEVICE_HDD0 DEVICE_SLASH +#define DEVICE_HOST_PATH DEVICE_HOST DEVICE_SLASH +#define DEVICE_HOST0_PATH DEVICE_HOST0 DEVICE_SLASH +#define DEVICE_HOST1_PATH DEVICE_HOST1 DEVICE_SLASH +#define DEVICE_HOST2_PATH DEVICE_HOST2 DEVICE_SLASH +#define DEVICE_HOST3_PATH DEVICE_HOST3 DEVICE_SLASH +#define DEVICE_HOST4_PATH DEVICE_HOST4 DEVICE_SLASH +#define DEVICE_HOST5_PATH DEVICE_HOST5 DEVICE_SLASH +#define DEVICE_HOST6_PATH DEVICE_HOST6 DEVICE_SLASH +#define DEVICE_HOST7_PATH DEVICE_HOST7 DEVICE_SLASH +#define DEVICE_HOST8_PATH DEVICE_HOST8 DEVICE_SLASH +#define DEVICE_HOST9_PATH DEVICE_HOST9 DEVICE_SLASH + +char *rootDevicePath(enum BootDeviceIDs device_id) +{ + switch (device_id) + { + case BOOT_DEVICE_MC0: + return DEVICE_MC0_PATH; + case BOOT_DEVICE_MC1: + return DEVICE_MC1_PATH; + case BOOT_DEVICE_CDROM: + return DEVICE_CDROM_PATH; + case BOOT_DEVICE_MASS: + return DEVICE_MASS_PATH; + case BOOT_DEVICE_MASS0: + return DEVICE_MASS_PATH; + case BOOT_DEVICE_HDD: + return DEVICE_HDD_PATH; + case BOOT_DEVICE_HDD0: + return DEVICE_HDD0_PATH; + case BOOT_DEVICE_HOST: + return DEVICE_HOST_PATH; + case BOOT_DEVICE_HOST0: + return DEVICE_HOST0_PATH; + case BOOT_DEVICE_HOST1: + return DEVICE_HOST1_PATH; + case BOOT_DEVICE_HOST2: + return DEVICE_HOST2_PATH; + case BOOT_DEVICE_HOST3: + return DEVICE_HOST3_PATH; + case BOOT_DEVICE_HOST4: + return DEVICE_HOST4_PATH; + case BOOT_DEVICE_HOST5: + return DEVICE_HOST5_PATH; + case BOOT_DEVICE_HOST6: + return DEVICE_HOST6_PATH; + case BOOT_DEVICE_HOST7: + return DEVICE_HOST7_PATH; + case BOOT_DEVICE_HOST8: + return DEVICE_HOST8_PATH; + case BOOT_DEVICE_HOST9: + return DEVICE_HOST9_PATH; + default: + return ""; + } +} + +enum BootDeviceIDs getBootDeviceID(char *path) +{ + if (!strncmp(path, DEVICE_MC0, 4)) + return BOOT_DEVICE_MC0; + else if (!strncmp(path, DEVICE_MC1, 4)) + return BOOT_DEVICE_MC1; + else if (!strncmp(path, DEVICE_CDROM, 7)) + return BOOT_DEVICE_CDROM; + else if (!strncmp(path, DEVICE_MASS, 5)) + return BOOT_DEVICE_MASS; + else if (!strncmp(path, DEVICE_MASS0, 6)) + return BOOT_DEVICE_MASS0; + else if (!strncmp(path, DEVICE_HDD, 4)) + return BOOT_DEVICE_HDD; + else if (!strncmp(path, DEVICE_HDD0, 5)) + return BOOT_DEVICE_HDD0; + else if (!strncmp(path, DEVICE_HOST, 5)) + return BOOT_DEVICE_HOST; + else if (!strncmp(path, DEVICE_HOST0, 6)) + return BOOT_DEVICE_HOST0; + else if (!strncmp(path, DEVICE_HOST1, 6)) + return BOOT_DEVICE_HOST1; + else if (!strncmp(path, DEVICE_HOST2, 6)) + return BOOT_DEVICE_HOST2; + else if (!strncmp(path, DEVICE_HOST3, 6)) + return BOOT_DEVICE_HOST3; + else if (!strncmp(path, DEVICE_HOST4, 6)) + return BOOT_DEVICE_HOST4; + else if (!strncmp(path, DEVICE_HOST5, 6)) + return BOOT_DEVICE_HOST5; + else if (!strncmp(path, DEVICE_HOST6, 6)) + return BOOT_DEVICE_HOST6; + else if (!strncmp(path, DEVICE_HOST7, 6)) + return BOOT_DEVICE_HOST7; + else if (!strncmp(path, DEVICE_HOST8, 6)) + return BOOT_DEVICE_HOST8; + else if (!strncmp(path, DEVICE_HOST9, 6)) + return BOOT_DEVICE_HOST9; + else + return BOOT_DEVICE_UNKNOWN; +} + +/* HACK! If booting from a USB device, keep trying to + * open this program again until it succeeds. + * + * This will ensure that the emulator will be able to load its files. + */ + +bool waitUntilDeviceIsReady(enum BootDeviceIDs device_id) +{ + int openFile = - 1; + int retries = 3; /* just in case we tried a unit that is not working/connected */ + char *rootDevice = rootDevicePath(device_id); + + while(openFile < 0 && retries > 0) + { + openFile = fioDopen(rootDevice); + /* Wait untill the device is ready */ + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + + retries--; + }; + + fioDclose(openFile); + + return openFile >= 0; +} diff --git a/ps2/include/compat_ctype.h b/ps2/include/compat_ctype.h index cd1b96f543..2a0e17c993 100644 --- a/ps2/include/compat_ctype.h +++ b/ps2/include/compat_ctype.h @@ -22,4 +22,6 @@ unsigned long long strtoull(const char * __restrict nptr, char ** __restrict end int link(const char *oldpath, const char *newpath); int unlink(const char *path); +float strtof (const char* str, char** endptr); + #endif diff --git a/ps2/include/ps2_devices.h b/ps2/include/ps2_devices.h new file mode 100644 index 0000000000..deab4ec0d2 --- /dev/null +++ b/ps2/include/ps2_devices.h @@ -0,0 +1,49 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2018 - Francisco Javier Trujillo Mata - fjtrujy + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef PS2_DEVICES_H +#define PS2_DEVICES_H + +#include + +enum BootDeviceIDs{ + BOOT_DEVICE_UNKNOWN = -1, + BOOT_DEVICE_MC0 = 0, + BOOT_DEVICE_MC1, + BOOT_DEVICE_CDROM, + BOOT_DEVICE_MASS, + BOOT_DEVICE_MASS0, + BOOT_DEVICE_HDD, + BOOT_DEVICE_HDD0, + BOOT_DEVICE_HOST, + BOOT_DEVICE_HOST0, + BOOT_DEVICE_HOST1, + BOOT_DEVICE_HOST2, + BOOT_DEVICE_HOST3, + BOOT_DEVICE_HOST4, + BOOT_DEVICE_HOST5, + BOOT_DEVICE_HOST6, + BOOT_DEVICE_HOST7, + BOOT_DEVICE_HOST8, + BOOT_DEVICE_HOST9, + BOOT_DEVICE_COUNT, +}; + +char *rootDevicePath(enum BootDeviceIDs device_id); + +enum BootDeviceIDs getBootDeviceID(char *path); + +bool waitUntilDeviceIsReady(enum BootDeviceIDs device_id); + +#endif