Skip to content

Commit

Permalink
PS2: modular IRX drivers loading
Browse files Browse the repository at this point in the history
  • Loading branch information
sunmax committed Jan 18, 2014
1 parent fb69d8e commit 1cbb90d
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 76 deletions.
5 changes: 3 additions & 2 deletions backends/fs/ps2/ps2-fs.cpp
Expand Up @@ -333,15 +333,16 @@ bool Ps2FilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hi
return false;

if (_isRoot) {
list.push_back(new Ps2FilesystemNode("cdfs:"));
if (g_systemPs2->cdPresent())
list.push_back(new Ps2FilesystemNode("cdfs:"));

if (g_systemPs2->hddPresent())
list.push_back(new Ps2FilesystemNode("pfs0:"));

if (g_systemPs2->usbMassPresent())
list.push_back(new Ps2FilesystemNode("mass:"));

if (g_systemPs2->getBootDevice()==HOST_DEV || g_systemPs2->netPresent())
if (g_systemPs2->netPresent())
list.push_back(new Ps2FilesystemNode("host:"));

if (g_systemPs2->mcPresent())
Expand Down
81 changes: 58 additions & 23 deletions backends/platform/ps2/irxboot.cpp
Expand Up @@ -34,37 +34,65 @@

static const char hddArg[] = "-o" "\0" "8" "\0" "-n" "\0" "20";
static const char pfsArg[] = "-m" "\0" "2" "\0" "-o" "\0" "32" "\0" "-n" "\0" "72"; // "\0" "-debug";
static const char netArg[] = "192.168.0.10" "\0" "255.255.255.0" "\0" "192.168.0.1";

IrxFile irxFiles[] = {
{ "SIO2MAN", BIOS, NOTHING, NULL, 0 },
{ "MCMAN", BIOS, NOTHING, NULL, 0 },
{ "MCSERV", BIOS, NOTHING, NULL, 0 },
{ "PADMAN", BIOS, NOTHING, NULL, 0 },
{ "LIBSD", BIOS, NOTHING, NULL, 0 },

{ "IOMANX.IRX", SYSTEM, NOTHING, NULL, 0 },
{ "FILEXIO.IRX", SYSTEM, NOTHING, NULL, 0 },
{ "CODYVDFS.IRX", SYSTEM, NOTHING, NULL, 0 },
static const char netArg[] = "192.168.1.20" "\0" "255.255.255.0" "\0" "192.168.1.1"; // TODO: set in ScummVM.ini

IrxFile irxCore[] = { // core modules
// Memory Card
{ "SIO2MAN", BIOS, NOTHING, NULL, 0 },
{ "MCMAN", BIOS, NOTHING, NULL, 0 },
{ "MCSERV", BIOS, NOTHING, NULL, 0 },
// Joypad
{ "PADMAN", BIOS, NOTHING, NULL, 0 },
// Sound
{ "LIBSD", BIOS, NOTHING, NULL, 0 },
{ "SJPCM.IRX", SYSTEM, NOTHING, NULL, 0 },
// Files I/O
{ "IOMANX.IRX", SYSTEM, NOTHING, NULL, 0 },
{ "FILEXIO.IRX", SYSTEM, NOTHING, NULL, 0 }
};

IrxFile irxCdrom[] = { // cdrom modules
// CD-Rom FS
{ "CODYVDFS.IRX", SYSTEM, CD_DRIVER, NULL, 0 }
};

IrxFile irxUSB[] = { // USB mass
// USB drv & key
{ "USBD.IRX", USB | OPTIONAL | DEPENDANCY, USB_DRIVER, NULL, 0 },
{ "USB_MASS.IRX", USB | OPTIONAL, MASS_DRIVER, NULL, 0 },
{ "USB_MASS.IRX", USB | OPTIONAL, MASS_DRIVER, NULL, 0 }
};

IrxFile irxInput[] = { // USB input
// USB mouse & kbd
{ "PS2MOUSE.IRX", USB | OPTIONAL, MOUSE_DRIVER, NULL, 0 },
{ "RPCKBD.IRX", USB | OPTIONAL, KBD_DRIVER, NULL, 0 },
#ifndef NO_ADAPTOR
{ "RPCKBD.IRX", USB | OPTIONAL, KBD_DRIVER, NULL, 0 }
};

IrxFile irxHDD[] = { // modules to support HDD
// hdd modules
{ "POWEROFF.IRX", HDD | OPTIONAL | NOT_HOST | DEPENDANCY, HDD_DRIVER, NULL, 0 },
{ "PS2DEV9.IRX", HDD | OPTIONAL | NOT_HOST | DEPENDANCY, HDD_DRIVER, NULL, 0 },
{ "PS2ATAD.IRX", HDD | OPTIONAL | DEPENDANCY, HDD_DRIVER, NULL, 0 },
{ "PS2HDD.IRX", HDD | OPTIONAL | DEPENDANCY, HDD_DRIVER, hddArg, sizeof(hddArg) },
{ "PS2FS.IRX", HDD | OPTIONAL | DEPENDANCY, HDD_DRIVER, pfsArg, sizeof(pfsArg) },
{ "PS2FS.IRX", HDD | OPTIONAL | DEPENDANCY, HDD_DRIVER, pfsArg, sizeof(pfsArg) }
};

IrxFile irxNet[] = { // modules to support NET
// net modules
{ "PS2IP.IRX", NET | OPTIONAL | NOT_HOST | DEPENDANCY, NET_DRIVER, NULL, 0 },
{ "PS2SMAP.IRX", NET | OPTIONAL | NOT_HOST | DEPENDANCY, NET_DRIVER, netArg, sizeof(netArg) },
{ "PS2HOST.IRX", NET | OPTIONAL | NOT_HOST | DEPENDANCY, NET_DRIVER, NULL, 0 }
#endif
};

static const int numIrxFiles = sizeof(irxFiles) / sizeof(irxFiles[0]);
IrxFile *irxType[IRX_MAX] = { irxCore, irxCdrom, irxUSB, irxInput, irxHDD, irxNet };

static const int numIrx[IRX_MAX] = { sizeof(irxCore) / sizeof(IrxFile),
sizeof(irxCdrom) / sizeof(IrxFile),
sizeof(irxUSB) / sizeof(IrxFile),
sizeof(irxInput) / sizeof(IrxFile),
sizeof(irxHDD) / sizeof(IrxFile),
sizeof(irxNet) / sizeof(IrxFile)
};

PS2Device detectBootPath(const char *elfPath, char *bootPath) {

Expand Down Expand Up @@ -113,12 +141,19 @@ PS2Device detectBootPath(const char *elfPath, char *bootPath) {
return device;
}

int loadIrxModules(int device, const char *irxPath, IrxReference **modules) {
int loadIrxModules(int device, const char *irxPath, IrxReference **modules, IrxType type) {

IrxReference *resModules;
IrxReference *curModule;
IrxFile *irxFiles;
int numFiles;

IrxReference *resModules = (IrxReference *)malloc(numIrxFiles * sizeof(IrxReference));
IrxReference *curModule = resModules;
irxFiles = irxType[type];
numFiles = numIrx[type];
resModules = (IrxReference *)malloc(numFiles * sizeof(IrxReference));
curModule = resModules;

for (int i = 0; i < numIrxFiles; i++) {
for (int i = 0; i < numFiles; i++) {
curModule->fileRef = irxFiles + i;
if ((device == HOST_DEV) && (irxFiles[i].flags & NOT_HOST))
continue;
Expand Down Expand Up @@ -191,7 +226,7 @@ int loadIrxModules(int device, const char *irxPath, IrxReference **modules) {
pos++;
}
// and skip any remaining modules that depend on the missing one, too.
while ((i < numIrxFiles - 1) && ((irxFiles[i + 1].flags & TYPEMASK) == (curModule->fileRef->flags & TYPEMASK)))
while ((i < numFiles - 1) && ((irxFiles[i + 1].flags & TYPEMASK) == (curModule->fileRef->flags & TYPEMASK)))
i++;
// the module that actually failed (curModule) is kept in the array for displaying an error message
}
Expand Down
13 changes: 12 additions & 1 deletion backends/platform/ps2/irxboot.h
Expand Up @@ -25,6 +25,16 @@

#include "common/scummsys.h"

enum IrxType {
IRX_CORE = 0,
IRX_CDROM,
IRX_USB,
IRX_INPUT,
IRX_HDD,
IRX_NET,
IRX_MAX
};

enum IrxFlags {
BIOS = 0,
SYSTEM = 1,
Expand All @@ -40,6 +50,7 @@ enum IrxFlags {

enum IrxPurpose {
NOTHING,
CD_DRIVER,
HDD_DRIVER,
USB_DRIVER,
MOUSE_DRIVER,
Expand Down Expand Up @@ -81,6 +92,6 @@ struct IrxReference {
int errorCode;
};

int loadIrxModules(int device, const char *irxPath, IrxReference **modules);
int loadIrxModules(int device, const char *irxPath, IrxReference **modules, IrxType type);

#endif // __IRXBOOT_H__
133 changes: 84 additions & 49 deletions backends/platform/ps2/systemps2.cpp
Expand Up @@ -50,7 +50,6 @@
#include "backends/platform/ps2/cd.h"
#include "backends/platform/ps2/fileio.h"
#include "backends/platform/ps2/Gs2dScreen.h"
#include "backends/platform/ps2/irxboot.h"
#include "backends/platform/ps2/ps2debug.h"
#include "backends/platform/ps2/ps2input.h"
#include "backends/platform/ps2/savefilemgr.h"
Expand Down Expand Up @@ -189,8 +188,6 @@ void gluePowerOffCallback(void *system) {

void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) {

_usbMassLoaded = _useMouse = _useKbd = _useHdd = _useNet = false;

int res = 0, rv = 0;
for (int i = 0; i < numModules; i++) {
if (modules[i].loc == IRX_FILE) {
Expand All @@ -216,6 +213,9 @@ void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) {
case KBD_DRIVER:
_useKbd = true;
break;
case CD_DRIVER:
_useCd = true;
break;
case HDD_DRIVER:
_useHdd = true;
break;
Expand Down Expand Up @@ -252,16 +252,75 @@ void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) {
sioprintf("UsbMass: %sloaded\n", _usbMassLoaded ? "" : "not ");
sioprintf("Mouse: %sloaded\n", _useMouse ? "" : "not ");
sioprintf("Kbd: %sloaded\n", _useKbd ? "" : "not ");
sioprintf("Cd: %sloaded\n", _useCd ? "" : "not ");
sioprintf("Hdd: %sloaded\n", _useHdd ? "" : "not ");
}

bool OSystem_PS2::loadDrivers(IrxType type)
{
IrxReference *modules;
int numModules;
int res;

numModules = loadIrxModules(_bootDevice, _bootPath, &modules, type);
startIrxModules(numModules, modules);

switch (type) {
case IRX_CORE:
/* Init I/O */
if ((res = fileXioInit()) < 0) {
msgPrintf(FOREVER, "FXIO init failed: %d", res);
quit();
}
/* Init sound */
if ((res = SjPCM_Init(0)) < 0) {
msgPrintf(FOREVER, "SjPCM bind failed: %d\n", res);
quit();
}
break;

case IRX_CDROM:
/* Init CDROM & RTC Clock */
if ((res = initCdvdFs()) < 0) {
msgPrintf(FOREVER, "CoDyVDfs bind failed: %d", res);
quit();
}
sioprintf("Reading RTC\n");
readRtcTime(); /* depends on CDROM driver! */
break;

case IRX_HDD:
/* Check HD is available and formatted */
if ((hddCheckPresent() < 0) || (hddCheckFormatted() < 0)) {
_useHdd = false;
}
else {
poweroffInit();
poweroffSetCallback(gluePowerOffCallback, this);

if (fio.mount("pfs0:", "hdd0:+ScummVM", 0) >= 0)
printf("Successfully mounted!\n");
else
_useHdd = false;
}
break;

default:
/* zzz */
break;
}

return true;
}

OSystem_PS2::OSystem_PS2(const char *elfPath) {
_soundStack = _timerStack = NULL;
_printY = 0;
_msgClearTime = 0;
_systemQuit = false;
_modeChanged = false;
_screenChangeCount = 0;
_mouseVisible = false;

_screen = new Gs2dScreen(320, 200, TV_DONT_CARE);

Expand All @@ -272,10 +331,8 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) {
_bootPath = (char *)malloc(128);
_bootDevice = detectBootPath(elfPath, _bootPath);

IrxReference *modules;
int numModules = loadIrxModules(_bootDevice, _bootPath, &modules);

if (_bootDevice != HOST_DEV) {
// TODO: reset funx
sioprintf("Resetting IOP.\n");
cdvdInit(CDVD_EXIT);
cdvdExit();
Expand All @@ -298,50 +355,20 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) {
// TODO: ps2link 1.46 will stall on "poweroff" init / cb
}

startIrxModules(numModules, modules);
_usbMassLoaded = _useMouse = _useKbd = _useCd = _useHdd = _useNet = false;

int res;
if ((res = fileXioInit()) < 0) {
msgPrintf(FOREVER, "FXIO Init failed: %d", res);
quit();
}

if ((res = initCdvdFs()) < 0) {
msgPrintf(FOREVER, "CoDyVDfs bind failed: %d", res);
quit();
}

if ((res = SjPCM_Init(0)) < 0) {
msgPrintf(FOREVER, "SjPCM Bind failed: %d\n", res);
quit();
}

if (_useHdd) {
if ((hddCheckPresent() < 0) || (hddCheckFormatted() < 0))
_useHdd = false;

//hddPreparePoweroff();
poweroffInit();

//hddSetUserPoweroffCallback(gluePowerOffCallback, this);
poweroffSetCallback(gluePowerOffCallback, this);
}
loadDrivers(IRX_CORE);
loadDrivers(IRX_CDROM);
// loadDrivers(IRX_USB); // why they only load correctly post HDD ?
// loadDrivers(IRX_INPUT);
#ifndef NO_ADAPTOR
loadDrivers(IRX_HDD);
loadDrivers(IRX_NET);
#endif
loadDrivers(IRX_USB);
loadDrivers(IRX_INPUT);

fileXioSetBlockMode(FXIO_NOWAIT);

_mouseVisible = false;

sioprintf("reading RTC\n");
readRtcTime();

if (_useHdd) {
// TODO : make partition path configurable
if (fio.mount("pfs0:", "hdd0:+ScummVM", 0) >= 0)
printf("Successfully mounted!\n");
else
_useHdd = false;
}

initMutexes();
}

Expand Down Expand Up @@ -510,6 +537,10 @@ bool OSystem_PS2::mcPresent(void) {
return false;
}

bool OSystem_PS2::cdPresent(void) {
return _useCd;
}

bool OSystem_PS2::hddPresent(void) {
return _useHdd;
}
Expand All @@ -528,7 +559,11 @@ bool OSystem_PS2::usbMassPresent(void) {
}

bool OSystem_PS2::netPresent(void) {
return _useNet;
if (_bootDevice == HOST_DEV || _useNet) {
return true;
}

return false;
}

void OSystem_PS2::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
Expand Down Expand Up @@ -829,7 +864,7 @@ void OSystem_PS2::quit(void) {
" li $3, 0x04;"
" syscall;"
" nop;"
);
);
*/

/*
Expand Down

0 comments on commit 1cbb90d

Please sign in to comment.