I'll post a PS2 build once I find out how to load files independently from the place (CD, DVD, HD, MC or MASS) you run the elf.
You can parse the argv[0] path/filename string to figure out from which device your program was started. For the HDD case, the things are trickier, since it's reported as from 'host:'...
There are almost infinite ways of doing this, but if you want to spare some dev time, you can use my solution I implemented for ps2doom (and if you spot some bug, warn me please :) ) :
Code: Select all
void GetElfFilename(const char *argv0, char* deviceName, char* fullPath, char* elfFilename)
{
int i;
int lenght = strlen(argv0);
int doispontosIndex = 0;
int slashIndex = 0;
int isFileOnRoot = 0;
// locate '/' from the end of path
for(i=lenght-1; i>=0; i--)
{
if (argv0[i] == '/')
{
slashIndex = i;
break;
}
}
if (slashIndex == 0)
isFileOnRoot = 1; // elf is located on root of device
// locate ':' from the start of path
for(i=0; i<lenght; i++)
{
if (argv0[i] == ':')
{
doispontosIndex = i;
break;
}
}
// set deviceName to device name (ex: 'mass:', 'host:', 'mc0', etc)
strncpy(deviceName, argv0, doispontosIndex+1);
deviceName[doispontosIndex+1] = 0;
// set fullPath to full path (ex: 'mass:directory/', 'mass:directory1/directory2/', etc (no limit over depth))
if (isFileOnRoot)
strcpy(fullPath, deviceName); // fullPath = deviceName actually
else
{
strncpy(fullPath, argv0, slashIndex+1);
fullPath[slashIndex+1] = 0;
}
// set elfFilename
if (isFileOnRoot)
memcpy(elfFilename, argv0 + doispontosIndex + 1, lenght - doispontosIndex);
else
memcpy(elfFilename, argv0 + slashIndex + 1, lenght - slashIndex);
}
Hope this helps. This should work for every device except HDD.