Skip to content

Commit

Permalink
OSD Initialization Libraries
Browse files Browse the repository at this point in the history
Example (2019/12/07)
  • Loading branch information
AKuHAK committed Mar 21, 2022
1 parent 3afe4c2 commit 85244f3
Show file tree
Hide file tree
Showing 28 changed files with 423 additions and 144 deletions.
27 changes: 21 additions & 6 deletions osd/Makefile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ PROHBIT_DVD_0100 = 0
#Enable to enable the newer sceCdReadKey checks, which are only supported by a newer CDVDMAN module.
XCDVD_READKEY = 0

#Enable to build the PSX example.
PSX=0

EE_BIN = example.elf

IOP_OBJS = sio2man_irx.o mcman_irx.o mcserv_irx.o
ICONS = icon_sys_A.o icon_sys_J.o icon_sys_C.o
ICONS_TEMP = icon_sys_A.c icon_sys_J.c icon_sys_C.c sio2man_irx.c mcman_irx.c mcserv_irx.c
EE_OBJS = main.o libcdvd_add.o OSDConfig.o OSDInit.o OSDHistory.o dvdplayer.o ps1.o ps2.o modelname.o $(ICONS) $(IOP_OBJS)
IOPRP_TEMP = ioprp.c
EE_OBJS = main.o common/libcdvd_add.o common/OSDConfig.o common/OSDInit.o common/OSDHistory.o common/dvdplayer.o common/ps1.o common/ps2.o common/modelname.o $(ICONS) $(IOP_OBJS)

EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I.
EE_LDFLAGS := -L$(PS2SDK)/ee/lib -nostartfiles
EE_LIBS := -lmc -lcdvd -lpatches -lc -lkernel
EE_CFLAGS += -mgpopt -G8192 -Os -Wall
EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I. -Iinclude -Ipsx
EE_LDFLAGS := -L$(PS2SDK)/ee/lib -nostartfiles -Tlinkfile
EE_LIBS := -lmc -ldebug -lpatches -lc -lkernel
EE_CFLAGS += -mno-gpopt -G0 -Os -Wall

ifeq ($(WRITE_ICOBYSYS),1)
ICONS += icobysys_icn.o
Expand All @@ -35,6 +39,14 @@ ifeq ($(PROHBIT_DVD_0100),1)
EE_CFLAGS += -DPROHBIT_DVD_0100=1
endif

ifeq ($(PSX),1)
EE_CFLAGS += -DPSX=1
EE_OBJS += psx/scmd_add.o ioprp.o
EE_LIBS += -lxcdvd -liopreboot
else
EE_LIBS += -lcdvd
endif

%.o : %.c
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@

Expand All @@ -49,7 +61,7 @@ $(EE_BIN) : $(EE_OBJS)
-o $(EE_BIN) $(EE_OBJS) $(PS2SDK)/ee/startup/crt0.o $(EE_LIBS)

clean:
rm -f $(EE_BIN) $(EE_OBJS) $(ICONS_TEMP)
rm -f $(EE_BIN) $(EE_OBJS) $(ICONS_TEMP) $(IOPRP_TEMP)

icon_sys_A.c : icons/icon_A.sys
bin2c $< $@ icon_sys_A
Expand All @@ -72,4 +84,7 @@ mcman_irx.c : $(PS2SDK)/iop/irx/mcman.irx
mcserv_irx.c : $(PS2SDK)/iop/irx/mcserv.irx
bin2c $< $@ mcserv_irx

ioprp.c : psx/ioprp.img
bin2c $< $@ psx_ioprp

include $(PS2SDK)/Defs.make
38 changes: 27 additions & 11 deletions osd/README.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
OSD libary v1.03 - 2018/08/25
OSD libary v1.04 - 2019/12/07
-----------------------------

The package contains various OSD-related files:
dvdplayer.c: Contains DVD Player management selection and booting code.
libcdvd_add.c: Contains add-on functions for the ancient libcdvd libraries that we use.
main.c: Contains the main function, which shows how the various library functions are to be used.
OSDConfig.c: Contains OSD configuration management functions.
OSDInit.c: Contains low-level OSD configuration-management functions.
OSDHistory.c: Contains functions for loading and updating the user's play history.
ps1.c Contains functions for booting PlayStation game discs
ps2.c Contains functions for booting PlayStation 2 game discs
modelname.c Contains functions for retrieving the PlayStation 2 console's model name (i.e. SCPH-77006).
main.c: Contains the main function, which shows how the various library functions are to be used.
linkfile linkfile for this example.
Exists mainly for the sake of the PSX example, whereby the stack pointer must be within the first 32MB during the EE RAM capacity switch.
psx/ioprp.img: Contains an IOPRP image that contains a custom IOP BooT CONFiguration (IOPBTCONF) file.
This is necessary to load PCDVDMAN and PCDVDFSV from the PSX's boot ROM, to deal with the PSX-specific hardware.
psx/scmd_add.c Contains add-on functions for linking up with the PCDVDFSV module. Only for the PSX.
common/dvdplayer.c: Contains DVD Player management selection and booting code.
common/libcdvd_add.c: Contains add-on functions for the ancient libcdvd libraries that we use.
common/OSDConfig.c: Contains OSD configuration management functions.
common/OSDInit.c: Contains low-level OSD configuration-management functions.
common/OSDHistory.c: Contains functions for loading and updating the user's play history.
common/ps1.c Contains functions for booting PlayStation game discs
common/ps2.c Contains functions for booting PlayStation 2 game discs
common/modelname.c Contains functions for retrieving the PlayStation 2 console's model name (i.e. SCPH-77006).

As of now, the files were based on the OSD from ROM v2.20, which has a late design.
Most of files were based on the OSD from ROM v2.20, which has a late design.

Notes regarding the PSX example:
The PSX's OSDSYS differs from the standard PS2's, whereby it isn't a fully-function dashboard on its own.
It will also perform the boot certification step, which is why it is not necessary.
The PSX's EE has 64MB and its IOP has 8MB. Similar to the TOOL, the memory capacity can be limited to 32MB with the TLB.
It also has a dual-mode CD/DVD drive - by default, it starts up in writer ("Rainbow") mode. In this mode, the usual registers do not work.
The PSX also has a "QUIT GAME" button, which must be enabled by "notifying" the MECHACON of the game mode with sceCdNotifyGameStart().

To build the PSX example, set the PSX variable in the Makefile to 1.

Notes regarding disc-booting:
The example shows how the browser boots PlayStation and PlayStation 2 game discs.
Expand Down Expand Up @@ -59,6 +73,8 @@ Known limitations:
*Remote Control management does not actually do anything (sceCdBypassCtl not implemented).
sceCdBypassCtl() must be implemented on the IOP. CDVDMAN does a check against the IOP PRId, and acts according to the IOP revision.
Revisions before 2.3 will involve a S-command, while later revisions will involve other registers.
The only true way would be to execute code on the IOP. An easy way would be to use XCDVDMAN+XCDVDFSV from the target PS2.
However, this is a board-specific function that might not exist in the XCDVDMAN module versions from all PS2s.
*The actual purpose of OSDConfigGetRcEnabled & OSDConfigSetRcEnabled is not clear.
I am not entirely sure what this is.
In ROM v2.20, it seems to have a relationship to a menu that is labeled "Console" and has the text "Remote Control,Off,On".
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 10 additions & 15 deletions osd/OSDInit.c → osd/common/OSDInit.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ static u8 ConsoleRegionData[16] = {0, 0, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//Perhaps it once used to read more configuration blocks (original capacity was 7 blocks).
static u8 OSDConfigBuffer[CONFIG_BLOCK_SIZE * 2];

//As our homebrew SDK can be linked against any either fileio or fileXio
extern int (*_ps2sdk_close)(int) __attribute__((section("data")));
extern int (*_ps2sdk_open)(const char*, int) __attribute__((section("data")));
extern int (*_ps2sdk_read)(int, void*, int) __attribute__((section("data")));

//Local function prototypes
static int InitMGRegion(void);
static int ConsoleInitRegion(void);
Expand Down Expand Up @@ -63,7 +58,7 @@ static int InitMGRegion(void)
if(ConsoleRegionParamInitStatus == 0)
{
do{
if((result = sceCdAltReadRegionParams(ConsoleRegionData, &stat)) == 0)
if((result = sceCdReadRegionParams(ConsoleRegionData, &stat)) == 0)
{ //Failed.
ConsoleRegionParamInitStatus=1;
}
Expand Down Expand Up @@ -178,10 +173,10 @@ static int GetConsoleRegion(void)

if((result=ConsoleRegion)<0)
{
if((fd = _ps2sdk_open("rom0:ROMVER", O_RDONLY)) >= 0)
if((fd = open("rom0:ROMVER", O_RDONLY)) >= 0)
{
_ps2sdk_read(fd, romver, sizeof(romver));
_ps2sdk_close(fd);
read(fd, romver, sizeof(romver));
close(fd);
ConsoleRegionParamsInitPS1DRV(romver);

switch(romver[4])
Expand Down Expand Up @@ -239,10 +234,10 @@ static int GetOSDRegion(void)
if(ConsoleOSDRegionInitStatus == 0 || ConsoleOSDRegion == -1)
{
ConsoleOSDRegionInitStatus = 1;
if((fd = _ps2sdk_open("rom0:OSDVER", O_RDONLY)) >= 0)
if((fd = open("rom0:OSDVER", O_RDONLY)) >= 0)
{
_ps2sdk_read(fd, OSDVer, sizeof(OSDVer));
_ps2sdk_close(fd);
read(fd, OSDVer, sizeof(OSDVer));
close(fd);
CdReadOSDRegionParams(OSDVer);
switch(OSDVer[4])
{
Expand Down Expand Up @@ -579,10 +574,10 @@ int OSDInitROMVER(void)
int fd;

memset(ConsoleROMVER, 0, ROMVER_MAX_LEN);
if((fd = _ps2sdk_open("rom0:ROMVER", O_RDONLY)) >= 0)
if((fd = open("rom0:ROMVER", O_RDONLY)) >= 0)
{
_ps2sdk_read(fd, ConsoleROMVER, ROMVER_MAX_LEN);
_ps2sdk_close(fd);
read(fd, ConsoleROMVER, ROMVER_MAX_LEN);
close(fd);
}

return 0;
Expand Down
27 changes: 11 additions & 16 deletions osd/dvdplayer.c → osd/common/dvdplayer.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ static char dvdver[] = "rom1:DVDVER?";
static char eromdrvCMD[] = "-k rom1:EROMDRV?";
static char dvdelfCMD[] = "-x erom0:DVDELF";

//As our homebrew SDK can be linked against any either fileio or fileXio
extern int (*_ps2sdk_close)(int) __attribute__((section("data")));
extern int (*_ps2sdk_open)(const char*, int) __attribute__((section("data")));
extern int (*_ps2sdk_read)(int, void*, int) __attribute__((section("data")));

static int readMCFile(int fd, void *buffer, int len);
static int ReadFileFromMC(int port, int slot, const char *file, void *buffer, int len);
static int getStatMC(int port, int slot, int *type, int *free, int *format);
Expand Down Expand Up @@ -256,12 +251,12 @@ static int CheckDVDPlayerUpdate(void)
}
else
{
if(OSDGetDVDPlayerRegion(&dvdid[10]) == 0 || (fd = _ps2sdk_open(dvdid, O_RDONLY)) < 0)
fd = _ps2sdk_open("rom1:DVDID", O_RDONLY);
if(OSDGetDVDPlayerRegion(&dvdid[10]) == 0 || (fd = open(dvdid, O_RDONLY)) < 0)
fd = open("rom1:DVDID", O_RDONLY);

if(fd < 0)
return -1;
_ps2sdk_close(fd);
close(fd);

return 2;
}
Expand Down Expand Up @@ -331,8 +326,8 @@ int DVDPlayerInit(void)
ROMDVDPlayer.major = -1;
ROMDVDPlayer.region = -1;

if(OSDGetDVDPlayerRegion(&dvdid[10]) == 0 || (fd = _ps2sdk_open(dvdid, O_RDONLY)) < 0)
fd = _ps2sdk_open("rom1:DVDID", O_RDONLY);
if(OSDGetDVDPlayerRegion(&dvdid[10]) == 0 || (fd = open(dvdid, O_RDONLY)) < 0)
fd = open("rom1:DVDID", O_RDONLY);

if(fd < 0)
{ //Not having a DVD player is not an error.
Expand All @@ -346,8 +341,8 @@ int DVDPlayerInit(void)
return 0;
}

_ps2sdk_read(fd, id, sizeof(id));
_ps2sdk_close(fd);
read(fd, id, sizeof(id));
close(fd);

ROMDVDPlayer.major = atoi(id);

Expand All @@ -374,13 +369,13 @@ int DVDPlayerInit(void)

if(result == 0)
{
if(OSDGetDVDPlayerRegion(&dvdver[11]) == 0 || (fd = _ps2sdk_open(dvdver, O_RDONLY)) < 0)
fd = _ps2sdk_open("rom1:DVDVER", O_RDONLY);
if(OSDGetDVDPlayerRegion(&dvdver[11]) == 0 || (fd = open(dvdver, O_RDONLY)) < 0)
fd = open("rom1:DVDVER", O_RDONLY);

if(fd >= 0)
{
result = _ps2sdk_read(fd, ROMDVDPlayer.ver, sizeof(ROMDVDPlayer.ver));
_ps2sdk_close(fd);
result = read(fd, ROMDVDPlayer.ver, sizeof(ROMDVDPlayer.ver));
close(fd);

//NULL-terminate, only if non-error
ROMDVDPlayer.ver[result >= 0 ? result : 0] = '\0';
Expand Down
36 changes: 27 additions & 9 deletions osd/libcdvd_add.c → osd/common/libcdvd_add.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "libcdvd_add.h"

static unsigned char MECHACON_CMD_S36_supported = 0, MECHACON_CMD_S27_supported = 0;
static unsigned char MECHACON_CMD_S36_supported = 0, MECHACON_CMD_S27_supported = 0, MECHACON_CMD_S24_supported = 0;

//Initialize add-on functions. Currently only retrieves the MECHACON's version to determine what sceCdAltGetRegionParams() should do.
int cdInitAdd(void)
Expand All @@ -23,6 +23,7 @@ int cdInitAdd(void)
MECHA_version = MECHA_version_data[2] | ((unsigned int)MECHA_version_data[1] << 8) | ((unsigned int)MECHA_version_data[0] << 16);
MECHACON_CMD_S36_supported = (0x5FFFF < MECHA_version); //v6.0 and later
MECHACON_CMD_S27_supported = (0x501FF < MECHA_version); //v5.2 and later
MECHACON_CMD_S24_supported = (0x4FFFF < MECHA_version); //v5.0 and later
return 0;
}
}
Expand All @@ -36,7 +37,7 @@ int cdInitAdd(void)
This function provides an equivalent of the sceCdGetRegionParams function from the newer CDVDMAN modules. The old CDVDFSV and CDVDMAN modules don't support this S-command.
It's supported by only slimline consoles, and returns regional information (e.g. MECHACON version, MG region mask, DVD player region letter etc.).
*/
int sceCdAltReadRegionParams(u8 *data, u32 *stat)
int sceCdReadRegionParams(u8 *data, u32 *stat)
{
unsigned char RegionData[15];
int result;
Expand All @@ -60,7 +61,7 @@ int sceCdAltReadRegionParams(u8 *data, u32 *stat)
}

// This function provides an equivalent of the sceCdBootCertify function from the newer CDVDMAN modules. The old CDVDFSV and CDVDMAN modules don't support this S-command.
int sceCdAltBootCertify(const u8* data)
int sceCdBootCertify(const u8* data)
{
int result;
unsigned char CmdResult;
Expand All @@ -73,7 +74,7 @@ int sceCdAltBootCertify(const u8* data)
return result;
}

int sceCdAltRM(char *ModelName, u32 *stat)
int sceCdRM(char *ModelName, u32 *stat)
{
unsigned char rdata[9];
unsigned char sdata;
Expand All @@ -98,7 +99,7 @@ int sceCdAltRM(char *ModelName, u32 *stat)
This function provides an equivalent of the sceCdReadPS1BootParam function from the newer CDVDMAN modules. The old CDVDFSV and CDVDMAN modules don't support this S-command.
It's supported by only slimline consoles, and returns the boot path for the inserted PlayStation disc.
*/
int sceCdAltReadPS1BootParam(char *param, u32 *stat)
int sceCdReadPS1BootParam(char *param, u32 *stat)
{
u8 out[16];
int result;
Expand All @@ -121,9 +122,26 @@ int sceCdAltReadPS1BootParam(char *param, u32 *stat)
return result;
}

int sceCdAltRcBypassCtl(int bypass, u32 *stat)
int sceCdRcBypassCtl(int bypass, u32 *stat)
{ //TODO: not implemented.
printf("FIXME: sceCdAltRcBypassCtl() not implemented!\n");
*stat = 0;
return 1;
u8 in[16], out[16];
int result;

memset(in, 0, 11);
if(MECHACON_CMD_S24_supported)
{
// TODO
if((result = sceCdApplySCmd(0x24, &bypass, 4, out, 13)) != 0)
{
*stat = out[0];
}
}
else
{
*stat = 0x100;
result = 1;
}

return result;
}

6 changes: 6 additions & 0 deletions osd/common/libcdvd_add.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int cdInitAdd(void);
int sceCdReadRegionParams(u8 *data, u32 *stat);
int sceCdReadPS1BootParam(char *param, u32 *stat);
int sceCdBootCertify(const u8* data);
int sceCdRM(char *ModelName, u32 *stat);
int sceCdRcBypassCtl(int bypass, u32 *stat); //TODO: Not implemented.
16 changes: 5 additions & 11 deletions osd/modelname.c → osd/common/modelname.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#include "main.h"
#include "modelname.h"

//As our homebrew SDK can be linked against any either fileio or fileXio
extern int (*_ps2sdk_close)(int) __attribute__((section("data")));
extern int (*_ps2sdk_open)(const char*, int) __attribute__((section("data")));
extern int (*_ps2sdk_read)(int, void*, int) __attribute__((section("data")));
extern int (*_ps2sdk_lseek)(int, int, int) __attribute__((section("data")));

#define MODEL_NAME_MAX_LEN 17
static char ModelName[MODEL_NAME_MAX_LEN];

Expand Down Expand Up @@ -45,11 +39,11 @@ static int ReadModelName(char *name)
strcpy(name, "SCPH-10000");
else
{ //For ROM v1.01 (Late SCPH-10000, and all SCPH-15000 units).
if((fd = _ps2sdk_open("rom0:OSDSYS", O_RDONLY)) >= 0)
if((fd = open("rom0:OSDSYS", O_RDONLY)) >= 0)
{ //The model name is located at this address.
_ps2sdk_lseek(fd, 0x8C808, SEEK_SET);
_ps2sdk_read(fd, name, MODEL_NAME_MAX_LEN);
_ps2sdk_close(fd);
lseek(fd, 0x8C808, SEEK_SET);
read(fd, name, MODEL_NAME_MAX_LEN);
close(fd);
}
else
strcpy(name, "Unknown");
Expand All @@ -58,7 +52,7 @@ static int ReadModelName(char *name)
return 0; //Original returned -1
}
else{
if((result = sceCdAltRM(name, &stat)) == 1)
if((result = sceCdRM(name, &stat)) == 1)
{ //Command issued successfully.
if(stat & 0x80)
return -2;
Expand Down
Loading

0 comments on commit 85244f3

Please sign in to comment.