}
void psxBios_calloc() { // 0x37
+ void *pv0;
#ifdef PSXBIOS_LOG
PSXBIOS_LOG("psxBios_%s\n", biosA0n[0x37]);
#endif
a0 = a0 * a1;
psxBios_malloc();
- memset(Rv0, 0, a0);
+ pv0 = Rv0;
+ if (pv0)
+ memset(pv0, 0, a0);
}
void psxBios_realloc() { // 0x38
u32 save[4];
char *ptmp = tmp;
int n=1, i=0, j;
-
- memcpy(save, (char*)PSXM(sp), 4 * 4);
- psxMu32ref(sp) = SWAP32((u32)a0);
- psxMu32ref(sp + 4) = SWAP32((u32)a1);
- psxMu32ref(sp + 8) = SWAP32((u32)a2);
- psxMu32ref(sp + 12) = SWAP32((u32)a3);
+ void *psp;
+
+ psp = PSXM(sp);
+ if (psp) {
+ memcpy(save, psp, 4 * 4);
+ psxMu32ref(sp) = SWAP32((u32)a0);
+ psxMu32ref(sp + 4) = SWAP32((u32)a1);
+ psxMu32ref(sp + 8) = SWAP32((u32)a2);
+ psxMu32ref(sp + 12) = SWAP32((u32)a3);
+ }
while (Ra0[i]) {
switch (Ra0[i]) {
}
*ptmp = 0;
- memcpy((char*)PSXM(sp), save, 4 * 4);
+ if (psp)
+ memcpy(psp, save, 4 * 4);
SysPrintf("%s", tmp);
void psxBios_Load() { // 0x42
EXE_HEADER eheader;
+ void *pa1;
#ifdef PSXBIOS_LOG
PSXBIOS_LOG("psxBios_%s: %s, %x\n", biosA0n[0x42], Ra0, a1);
#endif
- if (LoadCdromFile(Ra0, &eheader) == 0) {
- memcpy(Ra1, ((char*)&eheader)+16, sizeof(EXEC));
+ pa1 = Ra1;
+ if (pa1 && LoadCdromFile(Ra0, &eheader) == 0) {
+ memcpy(pa1, ((char*)&eheader)+16, sizeof(EXEC));
v0 = 1;
} else v0 = 0;
void psxBios_open() { // 0x32
int i;
char *ptr;
+ void *pa0 = Ra0;
#ifdef PSXBIOS_LOG
PSXBIOS_LOG("psxBios_%s: %s,%x\n", biosB0n[0x32], Ra0, a1);
v0 = -1;
- if (!strncmp(Ra0, "bu00", 4)) {
- buopen(1);
- }
+ if (pa0) {
+ if (!strncmp(pa0, "bu00", 4)) {
+ buopen(1);
+ }
- if (!strncmp(Ra0, "bu10", 4)) {
- buopen(2);
+ if (!strncmp(pa0, "bu10", 4)) {
+ buopen(2);
+ }
}
pc0 = ra;
pc0 = ra;
}
-#define buread(mcd) { \
+#define buread(Ra1, mcd) { \
SysPrintf("read %d: %x,%x (%s)\n", FDesc[1 + mcd].mcfile, FDesc[1 + mcd].offset, a2, Mcd##mcd##Data + 128 * FDesc[1 + mcd].mcfile + 0xa); \
ptr = Mcd##mcd##Data + 8192 * FDesc[1 + mcd].mcfile + FDesc[1 + mcd].offset; \
memcpy(Ra1, ptr, a2); \
void psxBios_read() { // 0x34
char *ptr;
+ void *pa1 = Ra1;
#ifdef PSXBIOS_LOG
PSXBIOS_LOG("psxBios_%s: %x, %x, %x\n", biosB0n[0x34], a0, a1, a2);
v0 = -1;
- switch (a0) {
- case 2: buread(1); break;
- case 3: buread(2); break;
+ if (pa1) {
+ switch (a0) {
+ case 2: buread(pa1, 1); break;
+ case 3: buread(pa1, 2); break;
+ }
}
pc0 = ra;
}
-#define buwrite(mcd) { \
+#define buwrite(Ra1, mcd) { \
u32 offset = + 8192 * FDesc[1 + mcd].mcfile + FDesc[1 + mcd].offset; \
SysPrintf("write %d: %x,%x\n", FDesc[1 + mcd].mcfile, FDesc[1 + mcd].offset, a2); \
ptr = Mcd##mcd##Data + offset; \
void psxBios_write() { // 0x35/0x03
char *ptr;
+ void *pa1 = Ra1;
+
+#ifdef PSXBIOS_LOG
+ PSXBIOS_LOG("psxBios_%s: %x,%x,%x\n", biosB0n[0x35], a0, a1, a2);
+#endif
+
+ v0 = -1;
+ if (!pa1) {
+ pc0 = ra;
+ return;
+ }
if (a0 == 1) { // stdout
- char *ptr = Ra1;
+ char *ptr = pa1;
+ v0 = a2;
while (a2 > 0) {
SysPrintf("%c", *ptr++); a2--;
}
pc0 = ra; return;
}
-#ifdef PSXBIOS_LOG
- PSXBIOS_LOG("psxBios_%s: %x,%x,%x\n", biosB0n[0x35], a0, a1, a2);
-#endif
-
- v0 = -1;
switch (a0) {
- case 2: buwrite(1); break;
- case 3: buwrite(2); break;
+ case 2: buwrite(pa1, 1); break;
+ case 3: buwrite(pa1, 2); break;
}
pc0 = ra;
void psxBios_firstfile() { // 42
struct DIRENTRY *dir = (struct DIRENTRY *)Ra1;
+ void *pa0 = Ra0;
u32 _dir = a1;
char *ptr;
int i;
v0 = 0;
- strcpy(ffile, Ra0);
- pfile = ffile+5;
- nfile = 1;
- if (!strncmp(Ra0, "bu00", 4)) {
- bufile(1);
- } else if (!strncmp(Ra0, "bu10", 4)) {
- bufile(2);
+ if (pa0) {
+ strcpy(ffile, pa0);
+ pfile = ffile+5;
+ nfile = 1;
+ if (!strncmp(pa0, "bu00", 4)) {
+ bufile(1);
+ } else if (!strncmp(pa0, "bu10", 4)) {
+ bufile(2);
+ }
}
// firstfile() calls _card_read() internally, so deliver it's event
*/
void psxBios_rename() { // 44
+ void *pa0 = Ra0;
+ void *pa1 = Ra1;
char *ptr;
int i;
v0 = 0;
- if (!strncmp(Ra0, "bu00", 4) && !strncmp(Ra1, "bu00", 4)) {
- burename(1);
- }
+ if (pa0 && pa1) {
+ if (!strncmp(pa0, "bu00", 4) && !strncmp(pa1, "bu00", 4)) {
+ burename(1);
+ }
- if (!strncmp(Ra0, "bu10", 4) && !strncmp(Ra1, "bu10", 4)) {
- burename(2);
+ if (!strncmp(pa0, "bu10", 4) && !strncmp(pa1, "bu10", 4)) {
+ burename(2);
+ }
}
pc0 = ra;
*/
void psxBios_delete() { // 45
+ void *pa0 = Ra0;
char *ptr;
int i;
v0 = 0;
- if (!strncmp(Ra0, "bu00", 4)) {
- budelete(1);
- }
+ if (pa0) {
+ if (!strncmp(pa0, "bu00", 4)) {
+ budelete(1);
+ }
- if (!strncmp(Ra0, "bu10", 4)) {
- budelete(2);
+ if (!strncmp(pa0, "bu10", 4)) {
+ budelete(2);
+ }
}
pc0 = ra;
}
void psxBios__card_write() { // 0x4e
+ void *pa2 = Ra2;
int port;
#ifdef PSXBIOS_LOG
card_active_chan = a0;
port = a0 >> 4;
- if (port == 0) {
- memcpy(Mcd1Data + a1 * 128, Ra2, 128);
- SaveMcd(Config.Mcd1, Mcd1Data, a1 * 128, 128);
- } else {
- memcpy(Mcd2Data + a1 * 128, Ra2, 128);
- SaveMcd(Config.Mcd2, Mcd2Data, a1 * 128, 128);
+ if (pa2) {
+ if (port == 0) {
+ memcpy(Mcd1Data + a1 * 128, pa2, 128);
+ SaveMcd(Config.Mcd1, Mcd1Data, a1 * 128, 128);
+ } else {
+ memcpy(Mcd2Data + a1 * 128, pa2, 128);
+ SaveMcd(Config.Mcd2, Mcd2Data, a1 * 128, 128);
+ }
}
DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004
}
void psxBios__card_read() { // 0x4f
+ void *pa2 = Ra2;
int port;
#ifdef PSXBIOS_LOG
card_active_chan = a0;
port = a0 >> 4;
- if (port == 0) {
- memcpy(Ra2, Mcd1Data + a1 * 128, 128);
- } else {
- memcpy(Ra2, Mcd2Data + a1 * 128, 128);
+ if (pa2) {
+ if (port == 0) {
+ memcpy(pa2, Mcd1Data + a1 * 128, 128);
+ } else {
+ memcpy(pa2, Mcd2Data + a1 * 128, 128);
+ }
}
DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004