Skip to content

Commit

Permalink
CPU: Fix overflow bit calculation in SUBFO instruction
Browse files Browse the repository at this point in the history
Since rD can overlap with rA or rB the result needs to be stored in a temporary
  • Loading branch information
Exzap committed Jul 26, 2024
1 parent 47f1dcf commit 5328e9e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Cafe/HW/Espresso/Interpreter/PPCInterpreterALU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,12 @@ static void PPCInterpreter_SUBF(PPCInterpreter_t* hCPU, uint32 opcode)

static void PPCInterpreter_SUBFO(PPCInterpreter_t* hCPU, uint32 opcode)
{
// untested (Don't Starve Giant Edition uses this)
// Seen in Don't Starve Giant Edition and Teslagrad
// also used by DS Virtual Console (Super Mario 64 DS)
PPC_OPC_TEMPL3_XO();
hCPU->gpr[rD] = ~hCPU->gpr[rA] + hCPU->gpr[rB] + 1;
PPCInterpreter_setXerOV(hCPU, checkAdditionOverflow(~hCPU->gpr[rA], hCPU->gpr[rB], hCPU->gpr[rD]));
uint32 result = ~hCPU->gpr[rA] + hCPU->gpr[rB] + 1;
PPCInterpreter_setXerOV(hCPU, checkAdditionOverflow(~hCPU->gpr[rA], hCPU->gpr[rB], result));
hCPU->gpr[rD] = result;
if (opHasRC())
ppc_update_cr0(hCPU, hCPU->gpr[rD]);
PPCInterpreter_nextInstruction(hCPU);
Expand Down

0 comments on commit 5328e9e

Please sign in to comment.