emulate pending irq bit somewhat
[pcsx_rearmed.git] / libpcsxcore / r3000a.c
index 2127358..0be8a53 100644 (file)
@@ -61,8 +61,10 @@ void psxReset() {
 
        psxRegs.CP0.n.SR   = 0x10600000; // COP0 enabled | BEV = 1 | TS = 1
        psxRegs.CP0.n.PRid = 0x00000002; // PRevID = Revision ID, same as R3000A
-       if (Config.HLE)
-               psxRegs.CP0.n.SR |= 1u << 30; // COP2 enabled
+       if (Config.HLE) {
+               psxRegs.CP0.n.SR |= 1u << 30;    // COP2 enabled
+               psxRegs.CP0.n.SR &= ~(1u << 22); // RAM exception vector
+       }
 
        psxCpu->ApplyConfig();
        psxCpu->Reset();
@@ -96,7 +98,7 @@ void psxShutdown() {
 void psxException(u32 cause, enum R3000Abdt bdt, psxCP0Regs *cp0) {
        u32 opcode = intFakeFetch(psxRegs.pc);
        
-       if (unlikely(!Config.HLE && ((((opcode) >> 24) & 0xfe) == 0x4a))) {
+       if (unlikely(!Config.HLE && (opcode >> 25) == 0x25)) {
                // "hokuto no ken" / "Crash Bandicot 2" ...
                // BIOS does not allow to return to GTE instructions
                // (just skips it, supposedly because it's scheduled already)
@@ -107,7 +109,7 @@ void psxException(u32 cause, enum R3000Abdt bdt, psxCP0Regs *cp0) {
        }
 
        // Set the Cause
-       cp0->n.Cause = (bdt << 30) | (cp0->n.Cause & 0x300) | cause;
+       cp0->n.Cause = (bdt << 30) | (cp0->n.Cause & 0x700) | cause;
 
        // Set the EPC & PC
        cp0->n.EPC = bdt ? psxRegs.pc - 4 : psxRegs.pc;
@@ -119,8 +121,6 @@ void psxException(u32 cause, enum R3000Abdt bdt, psxCP0Regs *cp0) {
 
        // Set the SR
        cp0->n.SR = (cp0->n.SR & ~0x3f) | ((cp0->n.SR & 0x0f) << 2);
-
-       if (Config.HLE) psxBiosException();
 }
 
 void psxBranchTest() {
@@ -196,15 +196,11 @@ void psxBranchTest() {
                }
        }
 
-       if (psxHu32(0x1070) & psxHu32(0x1074)) {
-               if ((psxRegs.CP0.n.SR & 0x401) == 0x401) {
-#ifdef PSXCPU_LOG
-                       PSXCPU_LOG("Interrupt: %x %x\n", psxHu32(0x1070), psxHu32(0x1074));
-#endif
-//                     SysPrintf("Interrupt (%x): %x %x\n", psxRegs.cycle, psxHu32(0x1070), psxHu32(0x1074));
-                       psxException(0x400, 0, &psxRegs.CP0);
-               }
-       }
+       psxRegs.CP0.n.Cause &= ~0x400;
+       if (psxHu32(0x1070) & psxHu32(0x1074))
+               psxRegs.CP0.n.Cause |= 0x400;
+       if (((psxRegs.CP0.n.Cause | 1) & psxRegs.CP0.n.SR & 0x401) == 0x401)
+               psxException(0, 0, &psxRegs.CP0);
 }
 
 void psxJumpTest() {