Skip to content

Commit 5328e9e

Browse files
committed
CPU: Fix overflow bit calculation in SUBFO instruction
Since rD can overlap with rA or rB the result needs to be stored in a temporary
1 parent 47f1dcf commit 5328e9e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Cafe/HW/Espresso/Interpreter/PPCInterpreterALU.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,12 @@ static void PPCInterpreter_SUBF(PPCInterpreter_t* hCPU, uint32 opcode)
212212

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

0 commit comments

Comments
 (0)