psxbios: Some games read from address 0, fix that.
[pcsx_rearmed.git] / libpcsxcore / psxbios.c
index ee307e3..7b2c05f 100644 (file)
@@ -1557,6 +1557,13 @@ void psxBios_SetMem() { // 9f
        pc0 = ra;
 }
 
+/* TODO FIXME : Not compliant. -1 indicates failure but using 1 for now. */
+void psxBios_get_cd_status(void) //a6
+{
+       v0 = 1;
+       pc0 = ra;
+}
+
 void psxBios__card_info() { // ab
 #ifdef PSXBIOS_LOG
        PSXBIOS_LOG("psxBios_%s: %x\n", biosA0n[0xab], a0);
@@ -2278,7 +2285,7 @@ void psxBios_firstfile() { // 42
        if (pa0) {
                strcpy(ffile, pa0);
                pfile = ffile+5;
-               nfile = 1;
+               nfile = 0;
                if (!strncmp(pa0, "bu00", 4)) {
                        // firstfile() calls _card_read() internally, so deliver it's event
                        DeliverEvent(0x11, 0x2);
@@ -2858,7 +2865,7 @@ void psxBiosInit() {
        //biosA0[0xa3] = psxBios_DequeueCdIntr;
        //biosA0[0xa4] = psxBios_sys_a0_a4;
        //biosA0[0xa5] = psxBios_ReadSector;
-       //biosA0[0xa6] = psxBios_get_cd_status;
+       biosA0[0xa6] = psxBios_get_cd_status;
        //biosA0[0xa7] = psxBios_bufs_cb_0;
        //biosA0[0xa8] = psxBios_bufs_cb_1;
        //biosA0[0xa9] = psxBios_bufs_cb_2;
@@ -3045,7 +3052,9 @@ void psxBiosInit() {
 */
        // opcode HLE
        psxRu32ref(0x0000) = SWAPu32((0x3b << 26) | 4);
-       psxMu32ref(0x0000) = SWAPu32((0x3b << 26) | 0);
+       /* Whatever this does, it actually breaks CTR, even without the uninitiliazed memory patch. 
+       Normally games shouldn't read from address 0 yet they do. See explanation below in details. */
+       //psxMu32ref(0x0000) = SWAPu32((0x3b << 26) | 0);
        psxMu32ref(0x00a0) = SWAPu32((0x3b << 26) | 1);
        psxMu32ref(0x00b0) = SWAPu32((0x3b << 26) | 2);
        psxMu32ref(0x00c0) = SWAPu32((0x3b << 26) | 3);
@@ -3071,6 +3080,21 @@ void psxBiosInit() {
        psxHu32ref(0x1060) = SWAPu32(0x00000b88);
 
        hleSoftCall = FALSE;
+       
+       /*      Some games like R-Types, CTR, Fade to Black read from adress 0x00000000 due to uninitialized pointers.
+               See Garbage Area at Address 00000000h in Nocash PSX Specfications for more information.
+               R-type will work if PsxM[0] is non-zero. (Meaning that it should not be 00000003h as he implies).
+               Crash Team Racing will refuse to boot if psxM[2] and psx[3] are not set to 0.
+               Fade to Black can crash upon memory card access if byte 5 is set to the wrong value.
+       */
+       psxM[0] = SWAPu32(0x3C);
+       psxM[1] = SWAPu32(0x1A);
+       psxM[2] = SWAPu32(0x00);
+       psxM[3] = SWAPu32(0x00);
+       psxM[4] = SWAPu32(0x27);
+       psxM[5] = SWAPu32(0x5A);
+       psxM[6] = SWAPu32(0x0C);
+       psxM[7] = SWAPu32(0x80);
 }
 
 void psxBiosShutdown() {