Skip to content

Commit

Permalink
Use PSX.EXE if SYSTEM.CNF file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
socram8888 committed Mar 20, 2021
1 parent 2ae9121 commit a2b4e19
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 23 deletions.
55 changes: 55 additions & 0 deletions bios.h
Expand Up @@ -55,6 +55,61 @@ void ExitCriticalSection();
*/
#define FILE_SIZE(blocks) ((blocks) << 16)

/**
* No error.
*/
#define FILEERR_OK 0x00

/**
* File not found
*/
#define FILEERR_NOT_FOUND 0x02

/**
* Bad device port number (tty2 and up)
*/
#define FILEERR_BAD_DEVICE 0x06

/**
* Invalid or unused file handle
*/
#define FILEERR_UNUSED_HANDLE 0x09

/**
* General error (physical I/O error, unformatted, disk changed for old fcb)
*/
#define FILEERR_GENERAL 0x10

/**
* File already exists
*/
#define FILEERR_ALREADY_EXISTS 0x11

/**
* Cross device rename
*/
#define FILEERR_CROSS_DEV_RENAME 0x12

/**
* Unknown device name
*/
#define FILEERR_UNKNOWN_DEV 0x13

/**
* Alignment error
*/
#define FILEERR_ALIGN 0x16

/**
* Too many open files
*/
#define FILEERR_TOO_MANY_HANDLES 0x18

/**
* Device full
*/
#define FILEERR_DEV_FULL 0x1C

/**
* Opens a file on the target device for I/O.
*
Expand Down
61 changes: 38 additions & 23 deletions secondary.c
Expand Up @@ -322,40 +322,55 @@ void try_boot_cd() {
debug_write("Initializing CD");
CdInit();

// Defaults if no SYSTEM.CNF file exists
uint32_t tcb = 4;
uint32_t event = 16;
uint32_t stacktop = 0x801FFF00;
const char * bootfile = "cdrom:PSX.EXE;1";

char bootfilebuf[32];
debug_write("Loading SYSTEM.CNF");
int32_t fd = FileOpen("cdrom:SYSTEM.CNF;1", FILE_READ);
if (fd == -1) {
debug_write("Open error %x", GetLastError());
return;
}
int32_t cfg_fd = FileOpen("cdrom:SYSTEM.CNF;1", FILE_READ);
if (cfg_fd > 0) {
int32_t read = FileRead(cfg_fd, data_buffer, 2048);
FileClose(cfg_fd);

if (read == -1) {
debug_write("Read error %x", GetLastError());
return;
}

int32_t read = FileRead(fd, data_buffer, 2048);
FileClose(fd);
// Null terminate
data_buffer[read] = '\0';

if (read == -1) {
debug_write("Read error %x", GetLastError());
return;
}
if (
!config_get_hex((char *) data_buffer, "TCB", &tcb) ||
!config_get_hex((char *) data_buffer, "EVENT", &event) ||
!config_get_hex((char *) data_buffer, "STACK", &stacktop) ||
!config_get_string((char *) data_buffer, "BOOT", bootfilebuf)
) {
return;
}

// Null terminate
data_buffer[read] = '\0';
bootfile = bootfilebuf;
} else {
uint32_t errorCode = GetLastError();
if (errorCode != FILEERR_NOT_FOUND) {
debug_write("Open error %x", GetLastError());
return;
}

uint32_t tcb, event, stacktop;
char bootfile[32];
if (
!config_get_hex((char *) data_buffer, "TCB", &tcb) ||
!config_get_hex((char *) data_buffer, "EVENT", &event) ||
!config_get_hex((char *) data_buffer, "STACK", &stacktop) ||
!config_get_string((char *) data_buffer, "BOOT", bootfile)
) {
return;
debug_write("Not found. Using PSX.EXE");
}

debug_write("Configuring kernel");
SetConf(event, tcb, stacktop);

debug_write("Loading executable");
LoadExeFile(bootfile, data_buffer);
if (!LoadExeFile(bootfile, data_buffer)) {
debug_write("Loading failed");
return;
}

debug_write("Starting");
DoExecute(data_buffer, 0, 0);
Expand Down

0 comments on commit a2b4e19

Please sign in to comment.