psxbios: Do the same for heap_size.
[pcsx_rearmed.git] / libpcsxcore / psxbios.c
index ebb5957..b27d195 100644 (file)
@@ -1,5 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team              *
+ *   Copyright (C) 2019 Ryan Schultz, PCSX-df Team, PCSX team, gameblabla, *
+ *      dmitrysmagin, senquack                                                                                            *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
  ***************************************************************************/
 
+/* Gameblabla 2018-2019 : 
+ * Numerous changes to bios calls as well as improvements in order to conform to nocash's findings
+ * for the PSX bios calls. Thanks senquack for helping out with some of the changes
+ * and helping to spot issues and refine my patches.
+ * */
+
 /*
  * Internal simulated HLE BIOS.
  */
@@ -858,7 +865,6 @@ void psxBios_bcmp() { // 0x29
 
 void psxBios_memcpy() { // 0x2a
        char *p1 = (char *)Ra0, *p2 = (char *)Ra1;
-       s32 n=0;
        v0 = a0;
        if (a0 == 0 || a2 > 0x7FFFFFFF)
        {
@@ -866,7 +872,6 @@ void psxBios_memcpy() { // 0x2a
                return;
        }
        while ((s32)a2-- > 0) {
-               n++;
                *p1++ = *p2++;
        }
        a2 = 0;
@@ -1219,8 +1224,10 @@ void psxBios_InitHeap() { // 0x39
        size &= 0xfffffffc;
 
        heap_addr = (u32 *)Ra0;
-       heap_end = (u32 *)((u8 *)heap_addr + size);
-       *heap_addr = SWAP32(size | 1);
+       heap_size = size;
+       heap_end = (u32 *)((u8 *)heap_addr + heap_size);
+       /* HACKFIX: Commenting out this line fixes GTA2 crash */
+       //*heap_addr = SWAP32(size | 1);
 
        SysPrintf("InitHeap %x,%x : %x %x\n",a0,a1, (int)((uptr)heap_addr-(uptr)psxM), size);
 
@@ -1926,10 +1933,8 @@ void psxBios_StopPAD() { // 14
        PSXBIOS_LOG("psxBios_%s\n", biosB0n[0x14]);
 #endif
        pad_stopped = 1;
-       if (pad_buf == 0){
        pad_buf1 = NULL;
        pad_buf2 = NULL;
-       }
        pc0 = ra;
 }
 
@@ -2209,9 +2214,6 @@ void psxBios_puts() { // 3e/3f
        pc0 = ra;
 }
 
-char ffile[64], *pfile;
-int nfile;
-
 
 /* To avoid any issues with different behaviour when using the libc's own strlen instead.
  * We want to mimic the PSX's behaviour in this case for bufile. */
@@ -2597,6 +2599,15 @@ void psxBios__card_status() { // 5c
        pc0 = ra;
 }
 
+void psxBios__card_wait() { // 5d
+#ifdef PSXBIOS_LOG
+       PSXBIOS_LOG("psxBios_%s: %x\n", biosB0n[0x5d], a0);
+#endif
+
+       v0 = 1;
+       pc0 = ra;
+}
+
 /* System calls C0 */
 
 /*
@@ -2951,7 +2962,7 @@ void psxBiosInit() {
        //biosB0[0x5a] = psxBios_sys_b0_5a;
        biosB0[0x5b] = psxBios_ChangeClearPad;
        biosB0[0x5c] = psxBios__card_status;
-       //biosB0[0x5d] = psxBios__card_wait;
+       biosB0[0x5d] = psxBios__card_wait;
 //*******************C0 CALLS****************************
        //biosC0[0x00] = psxBios_InitRCnt;
        //biosC0[0x01] = psxBios_InitException;
@@ -3277,7 +3288,6 @@ void psxBiosException() {
 void psxBiosFreeze(int Mode) {
        u32 base = 0x40000;
 
-       pad_stopped = 0;
        bfreezepsxMptr(jmp_int, u32);
        bfreezepsxMptr(pad_buf, int);
        bfreezepsxMptr(pad_buf1, char);
@@ -3292,4 +3302,6 @@ void psxBiosFreeze(int Mode) {
        bfreezel(&CurThread);
        bfreezes(FDesc);
        bfreezel(&card_active_chan);
+       bfreezel(&pad_stopped);
+       bfreezel(&heap_size);
 }