[PS2] Improvements with the device detection and different folder to save config

This commit is contained in:
Francisco Javier Trujillo Mata 2019-02-28 20:55:21 +01:00
parent 43ff843757
commit 6d2bba220f
8 changed files with 259 additions and 165 deletions

View File

@ -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

View File

@ -25,17 +25,8 @@
#include <libpwroff.h>
#include <audsrv.h>
#include <libpad.h>
#include <ps2_devices.h>
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;
@ -76,126 +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;
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 bool waitUntilDeviceIsReady(const char *device_path)
{
int openFile = - 1;
int retries = 10; /* just in case we tried a unit that is not working/ready */
while(openFile < 0 && retries > 0)
{
openFile = fioDopen(device_path);
/* Wait untill the device is ready */
nopdelay();
nopdelay();
nopdelay();
nopdelay();
nopdelay();
nopdelay();
nopdelay();
nopdelay();
};
fioDclose(openFile);
return openFile >= 0;
}
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));
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],
@ -252,40 +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);
waitUntilDeviceIsReady(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]);
}
}
create_path_names();
#ifndef IS_SALAMANDER
@ -323,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 */
@ -369,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();
@ -494,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;

View File

@ -876,9 +876,11 @@ 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)
if (!strncmp(path, "host", 4) && ((path[4]>='0' && path[4]<='9') || path[4]==':')) {
// fileXioGetStat is not working for host
is_dir = fioDopen(path);
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);
}

View File

@ -1762,7 +1762,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

View File

@ -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)

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <ps2_devices.h>
#include <stdio.h>
#include <kernel.h>
#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;
}

View File

@ -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

49
ps2/include/ps2_devices.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef PS2_DEVICES_H
#define PS2_DEVICES_H
#include <stdbool.h>
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