(PS2) platform_ps2.c - style nits

This commit is contained in:
twinaphex 2019-01-03 13:34:12 +01:00
parent 24ef966ca3
commit e53ac5b38b
2 changed files with 124 additions and 91 deletions

View File

@ -85,30 +85,47 @@ char user_path[512];
static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE; static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE;
//Only paths residing on "basic" devices (devices that don't require mounting) /* Only paths residing on "basic" devices
//can be specified here, since this system doesn't perform mounting based on the path. * (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:" #define DEFAULT_PATH "mass:"
static int getBootDeviceID(char *path) { static int getBootDeviceID(char *path)
int result = BOOT_DEVICE_HOST; {
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;
if(!strncmp(path, "mc0:", 4)) result=BOOT_DEVICE_MC0; return BOOT_DEVICE_HOST;
else if(!strncmp(path, "mc1:", 4)) result=BOOT_DEVICE_MC1;
else if(!strncmp(path, "cdrom0:", 7)) result=BOOT_DEVICE_CDROM;
else if(!strncmp(path, "mass:", 5) || !strncmp(path, "mass0:", 6)) result=BOOT_DEVICE_MASS;
else if(!strncmp(path, "hdd:", 4) || !strncmp(path, "hdd0:", 5)) result=BOOT_DEVICE_HDD;
else if(!strncmp(path, "host", 4) && ((path[4]>='0' && path[4]<='9') || path[4]==':')) result=BOOT_DEVICE_HOST;
else result=BOOT_DEVICE_UNKNOWN;
return result;
} }
//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. /* HACK! If booting from a USB device, keep trying to
static void waitUntilDeviceIsReady(const char *path) { * 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; FILE *file;
while((file=fopen(path, "rb"))==NULL){ while((file=fopen(path, "rb"))==NULL)
//Wait for a while first, or the IOP will get swamped by requests from the EE. {
/* Wait for a while first, or the IOP
* will get swamped by requests from the EE. */
nopdelay(); nopdelay();
nopdelay(); nopdelay();
nopdelay(); nopdelay();
@ -122,47 +139,54 @@ static void waitUntilDeviceIsReady(const char *path) {
fclose(file); fclose(file);
} }
void setPWDOnPFS(const char *FullCWD_path) { void setPWDOnPFS(const char *FullCWD_path)
int i; {
char *path; int i;
char *path=NULL;
path=NULL; for (i=strlen(FullCWD_path); i>=0; i--)
for(i=strlen(FullCWD_path); i>=0; i--){ /* Try to seperate the CWD from the path to this ELF. */ {
if(FullCWD_path[i]==':'){ /* Try to seperate the CWD from the path to this ELF. */
if((path=malloc(i+6+2))!=NULL){ if (FullCWD_path[i]==':')
strcpy(path, "pfs0:/"); {
strncat(path, FullCWD_path, i+1); if ((path=malloc(i+6+2))!=NULL)
path[i+1+6]='\0'; {
} strcpy(path, "pfs0:/");
break; strncat(path, FullCWD_path, i+1);
} path[i+1+6]='\0';
else if((FullCWD_path[i]=='\\')||(FullCWD_path[i]=='/')){ }
if((path=malloc(i+6+1))!=NULL){ break;
strcpy(path, "pfs0:/"); }
strncat(path, FullCWD_path, i); else if ((FullCWD_path[i]=='\\')||(FullCWD_path[i]=='/'))
path[i+6]='\0'; {
} if ((path=malloc(i+6+1))!=NULL)
break; {
} strcpy(path, "pfs0:/");
} strncat(path, FullCWD_path, i);
path[i+6]='\0';
if(path!=NULL){ }
chdir(path); break;
free(path); }
} }
if (path!=NULL)
{
chdir(path);
free(path);
}
} }
static const char *getMountParams(const char *command, char *BlockDevice) { static const char *getMountParams(const char *command, char *BlockDevice)
const char *MountPath; {
int BlockDeviceNameLen; int BlockDeviceNameLen;
const char *MountPath=NULL;
MountPath=NULL; if (strlen(command)>6 && (MountPath=strchr(&command[5], ':'))!=NULL)
if(strlen(command)>6 && (MountPath=strchr(&command[5], ':'))!=NULL){ {
BlockDeviceNameLen=(unsigned int)MountPath-(unsigned int)command; BlockDeviceNameLen=(unsigned int)MountPath-(unsigned int)command;
strncpy(BlockDevice, command, BlockDeviceNameLen); strncpy(BlockDevice, command, BlockDeviceNameLen);
BlockDevice[BlockDeviceNameLen]='\0'; BlockDevice[BlockDeviceNameLen]='\0';
MountPath++; //This is the location of the mount path; MountPath++; /* This is the location of the mount path; */
} }
return MountPath; return MountPath;
@ -209,14 +233,16 @@ static void create_path_names(void)
static void poweroffCallback(void *arg) static void poweroffCallback(void *arg)
{ {
//Close all files and unmount all partitions. #if 0
//close(fd); /* Close all files and unmount all partitions. */
close(fd);
//If you use PFS, close all files and unmount all partitions. /* If you use PFS, close all files and unmount all partitions. */
//fileXioDevctl("pfs:", PDIOC_CLOSEALL, NULL, 0, NULL, 0) fileXioDevctl("pfs:", PDIOC_CLOSEALL, NULL, 0, NULL, 0)
//Shut down DEV9, if you used it. /* Shut down DEV9, if you used it. */
//while(fileXioDevctl("dev9x:", DDIOC_OFF, NULL, 0, NULL, 0) < 0){}; while(fileXioDevctl("dev9x:", DDIOC_OFF, NULL, 0, NULL, 0) < 0){};
#endif
printf("Shutdown!"); printf("Shutdown!");
poweroffShutdown(); poweroffShutdown();
@ -231,34 +257,37 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[],
getcwd(cwd, sizeof(cwd)); getcwd(cwd, sizeof(cwd));
bootDeviceID=getBootDeviceID(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){ /* Mount the HDD partition, if required. */
SifExecModuleBuffer(poweroff_irx_start, poweroff_irx_size, 0, NULL, NULL); if (bootDeviceID==BOOT_DEVICE_HDD)
SifExecModuleBuffer(ps2dev9_irx_start, ps2dev9_irx_size, 0, NULL, NULL); {
SifExecModuleBuffer(ps2atad_irx_start, ps2atad_irx_size, 0, NULL, NULL); /* 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. */
SifExecModuleBuffer(ps2hdd_irx_start, ps2hdd_irx_size, sizeof(PS2HDD_args), PS2HDD_args, NULL); static const char PS2HDD_args[]="-o\0""2";
SifExecModuleBuffer(ps2fs_irx_start, ps2fs_irx_size, sizeof(PS2FS_args), PS2FS_args, NULL); static const char PS2FS_args[]="-o\0""8";
HDDModulesLoaded=1;
} if (!HDDModulesLoaded)
{
//Attempt to mount the partition. SifExecModuleBuffer(poweroff_irx_start, poweroff_irx_size, 0, NULL, NULL);
if((mountPoint=getMountParams(cwd, blockDevice))!=NULL && !strncmp(mountPoint, "pfs:", 4)){ 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); fileXioMount("pfs0:", blockDevice, FIO_MT_RDWR);
setPWDOnPFS(&mountPoint[4]); 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) {
} }
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(); create_path_names();
@ -304,37 +333,39 @@ static void frontend_ps2_init(void *data)
{ {
SifInitRpc(0); SifInitRpc(0);
#if !defined(DEBUG) #if !defined(DEBUG)
while(!SifIopReset(NULL, 0)){}; // Comment this line if you don't wanna debug the output /* Comment this line if you don't wanna debug the output */
while(!SifIopReset(NULL, 0)){};
#endif #endif
while(!SifIopSync()){}; while(!SifIopSync()){};
SifInitRpc(0); SifInitRpc(0);
sbv_patch_enable_lmb(); sbv_patch_enable_lmb();
// Controllers /* Controllers */
SifLoadModule("rom0:SIO2MAN", 0, NULL); SifLoadModule("rom0:SIO2MAN", 0, NULL);
SifLoadModule("rom0:PADMAN", 0, NULL); SifLoadModule("rom0:PADMAN", 0, NULL);
// I/O Files /* I/O Files */
SifExecModuleBuffer(iomanX_irx_start, iomanX_irx_size, 0, NULL, NULL); SifExecModuleBuffer(iomanX_irx_start, iomanX_irx_size, 0, NULL, NULL);
SifExecModuleBuffer(fileXio_irx_start, fileXio_irx_size, 0, NULL, NULL); SifExecModuleBuffer(fileXio_irx_start, fileXio_irx_size, 0, NULL, NULL);
// Memory Card /* Memory Card */
SifExecModuleBuffer(mcman_irx_start, mcman_irx_size, 0, NULL, NULL); SifExecModuleBuffer(mcman_irx_start, mcman_irx_size, 0, NULL, NULL);
SifExecModuleBuffer(mcserv_irx_start, mcserv_irx_size, 0, NULL, NULL); SifExecModuleBuffer(mcserv_irx_start, mcserv_irx_size, 0, NULL, NULL);
// USB /* USB */
SifExecModuleBuffer(usbd_irx_start, usbd_irx_size, 0, NULL, NULL); SifExecModuleBuffer(usbd_irx_start, usbd_irx_size, 0, NULL, NULL);
SifExecModuleBuffer(usbhdfsd_irx_start, usbhdfsd_irx_size, 0, NULL, NULL); SifExecModuleBuffer(usbhdfsd_irx_start, usbhdfsd_irx_size, 0, NULL, NULL);
// Audio /* Audio */
SifExecModuleBuffer(freesd_irx_start, freesd_irx_size, 0, NULL, NULL); SifExecModuleBuffer(freesd_irx_start, freesd_irx_size, 0, NULL, NULL);
SifExecModuleBuffer(audsrv_irx_start, audsrv_irx_size, 0, NULL, NULL); SifExecModuleBuffer(audsrv_irx_start, audsrv_irx_size, 0, NULL, NULL);
SDL_Init(SDL_INIT_TIMER); SDL_Init(SDL_INIT_TIMER);
//Initializes audsrv library /* Initializes audsrv library */
if(audsrv_init()) { if (audsrv_init())
{
RARCH_ERR("audsrv library not initalizated\n"); RARCH_ERR("audsrv library not initalizated\n");
} }
@ -380,7 +411,9 @@ static void frontend_ps2_exec(const char *path, bool should_load_game)
#endif #endif
RARCH_LOG("Attempt to load executable: [%s].\n", path); RARCH_LOG("Attempt to load executable: [%s].\n", path);
// exitspawn_kernel(path, args, argp); // I don't know what this is doing #if 0
exitspawn_kernel(path, args, argp); /* I don't know what this is doing */
#endif
#endif #endif
} }
@ -435,7 +468,7 @@ static void frontend_ps2_exitspawn(char *core_path, size_t core_path_size)
static void frontend_ps2_shutdown(bool unused) static void frontend_ps2_shutdown(bool unused)
{ {
poweroffInit(); poweroffInit();
//Set callback function /* Set callback function */
poweroffSetCallback(&poweroffCallback, NULL); poweroffSetCallback(&poweroffCallback, NULL);
} }

View File

@ -294,7 +294,7 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns
*/ */
/* TODO: this is only useful for a few platforms, find which and add ifdef */ /* TODO: this is only useful for a few platforms, find which and add ifdef */
stream->fp = fp; stream->fp = fp;
#if !defined(PS2) // TODO: PS2 IMPROVEMENT #if !defined(PS2) /* TODO: PS2 IMPROVEMENT */
stream->buf = (char*)calloc(1, 0x4000); stream->buf = (char*)calloc(1, 0x4000);
setvbuf(stream->fp, stream->buf, _IOFBF, 0x4000); setvbuf(stream->fp, stream->buf, _IOFBF, 0x4000);
#endif #endif