psxbios: Add checks for card_write, card_read
[pcsx_rearmed.git] / libpcsxcore / psxbios.c
index 265dbfd..d4a38e1 100644 (file)
@@ -2146,7 +2146,13 @@ void psxBios__card_write() { // 0x4e
 #ifdef PSXBIOS_LOG
        PSXBIOS_LOG("psxBios_%s: %x,%x,%x\n", biosB0n[0x4e], a0, a1, a2);
 #endif
-
+       /* Function also accepts sector 400h (a bug) */
+       if (!(a1 <= 0x400))
+       {
+               /* Invalid sectors */
+               v0 = 0; pc0 = ra;
+               return;
+       }
        card_active_chan = a0;
        port = a0 >> 4;
 
@@ -2173,7 +2179,13 @@ void psxBios__card_read() { // 0x4f
 #ifdef PSXBIOS_LOG
        PSXBIOS_LOG("psxBios_%s\n", biosB0n[0x4f]);
 #endif
-
+       /* Function also accepts sector 400h (a bug) */
+       if (!(a1 <= 0x400))
+       {
+               /* Invalid sectors */
+               v0 = 0; pc0 = ra;
+               return;
+       }
        card_active_chan = a0;
        port = a0 >> 4;