Fix regression caused by #9361a5aa4fef73e06bc78b7c462eb28a7d12e3d0
[pcsx_rearmed.git] / libpcsxcore / psxinterpreter.c
index d3e42e9..6c19f06 100644 (file)
@@ -39,7 +39,9 @@ static u32 branchPC;
 #define debugI()
 #endif
 
-#ifdef NDEBUG
+#ifndef NDEBUG
+#include "debug.h"
+#else
 void StartDebugger() {}
 void ProcessDebug() {}
 void StopDebugger() {}
@@ -507,14 +509,20 @@ void psxSLTU()    { if (!_Rd_) return; _rRd_ = _u32(_rRs_) < _u32(_rRt_); }       // Rd
 * Format:  OP rs, rt                                     *
 *********************************************************/
 void psxDIV() {
-       if (_i32(_rRt_) != 0) {
-               _i32(_rLo_) = _i32(_rRs_) / _i32(_rRt_);
-               _i32(_rHi_) = _i32(_rRs_) % _i32(_rRt_);
-       }
-       else {
-               _i32(_rLo_) = _i32(_rRs_) >= 0 ? 0xffffffff : 1;
-               _i32(_rHi_) = _i32(_rRs_);
-       }
+    if (!_i32(_rRt_)) {
+        _i32(_rHi_) = _i32(_rRs_);
+        if (_i32(_rRs_) & 0x80000000) {
+            _i32(_rLo_) = 1;
+        } else {
+            _i32(_rLo_) = 0xFFFFFFFF;
+        }
+    } else if (_i32(_rRs_) == 0x80000000 && _i32(_rRt_) == 0xFFFFFFFF) {
+        _i32(_rLo_) = 0x80000000;
+        _i32(_rHi_) = 0;
+    } else {
+        _i32(_rLo_) = _i32(_rRs_) / _i32(_rRt_);
+        _i32(_rHi_) = _i32(_rRs_) % _i32(_rRt_);
+    }
 }
 
 void psxDIVU() {
@@ -848,7 +856,13 @@ void psxBASIC(struct psxCP2Regs *regs) {
 
 void psxHLE() {
 //     psxHLEt[psxRegs.code & 0xffff]();
-       psxHLEt[psxRegs.code & 0x07]();         // HDHOSHY experimental patch
+//     psxHLEt[psxRegs.code & 0x07]();         // HDHOSHY experimental patch
+    uint32_t hleCode = psxRegs.code & 0x03ffffff;
+    if (hleCode >= (sizeof(psxHLEt) / sizeof(psxHLEt[0]))) {
+        psxNULL();
+    } else {
+        psxHLEt[hleCode]();
+    }
 }
 
 void (*psxBSC[64])() = {