Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. void psxException(u32 code, u32 bd) {
  2.     // Set the Cause, preserving R/W 'interrupt pending field' bits 8,9
  3.     // (From Notaz's PCSX Rearmed)
  4.     psxRegs.CP0.n.Cause = (psxRegs.CP0.n.Cause & 0x300) | code;
  5.  
  6.     // Set the EPC & PC
  7.     if (bd) {
  8.         psxRegs.CP0.n.Cause|= 0x80000000;
  9.         psxRegs.CP0.n.EPC = (psxRegs.pc - 4);
  10.     } else
  11.         psxRegs.CP0.n.EPC = (psxRegs.pc);
  12.  
  13.     if (psxRegs.CP0.n.Status & 0x400000)
  14.         psxRegs.pc = 0xbfc00180;
  15.     else
  16.         psxRegs.pc = 0x80000080;
  17.  
  18.     // Set the Status
  19.     psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status &~0x3f) |
  20.                           ((psxRegs.CP0.n.Status & 0xf) << 2);
  21.  
  22.     // PS1 exceptions have a quirk regarding GTE instructions:
  23.     //  When an exception happens at a GTE instruction, the instruction
  24.     //  executes before entry to the handler. This means that the GTE
  25.     //  instruction would execute a second time upon return from handler.
  26.     //  Before returning, most handlers prevent this by incrementng EPC by 4
  27.     //  if they see a GTE opcode at EPC location. In an emulator, this is not
  28.     //  helpful and actually prevents the GTE instruction from ever being
  29.     //  executed.
  30.     if (!Config.HLE && (((PSXMu32(psxRegs.CP0.n.EPC) >> 24) & 0xfe) == 0x4a)) {
  31.         // Fix for graphics glitches in:
  32.         // "hokuto no ken" / "Crash Bandicoot 2" / "Crash Team Racing"
  33.  
  34.         // Subtly alter the GTE opcode in PS1 RAM so exception handlers won't
  35.         //  recognize it and try to skip it upon return.
  36.         PSXMu32ref(psxRegs.CP0.n.EPC) &= SWAPu32(~0x02000000);
  37.     }
  38.  
  39.     if (Config.HLE) {
  40.         psxBiosException();
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement