From a009f43e8356896efd80330f68f24d3b0d308bfb Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Wed, 12 Jun 2024 17:09:07 +0100 Subject: [PATCH] Fixed overflow calculation to account for signed numbers w/ S --- src/emulator/execute.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/emulator/execute.c b/src/emulator/execute.c index fddd50f..2aec368 100644 --- a/src/emulator/execute.c +++ b/src/emulator/execute.c @@ -49,12 +49,12 @@ static void executeDPImmediate(Machine *state, a64inst_instruction *inst) { dword result; case(a64inst_ADDS): - result = srcVal + arithmImm; + result = truncateValue(srcVal + arithmImm, regType); writeRegister(state, dest, regType, result); updateCondNZ(state, result, regType); - state->conditionCodes.Overflow = max(srcVal, arithmImm) > result; - state->conditionCodes.Carry = state->conditionCodes.Overflow; + state->conditionCodes.Overflow = getMSB(srcVal, regType) == getMSB(arithmImm, regType) && getMSB(result, regType) != getMSB(srcVal, regType); + state->conditionCodes.Carry = max(truncateValue(srcVal, regType), truncateValue(arithmImm, regType)) > result; break; case(a64inst_ADD): @@ -177,12 +177,12 @@ static void executeDPRegister(Machine *state, a64inst_instruction *inst) { switch(inst->data.DPRegisterData.processOp) { case(a64inst_ADDS): - result = src1Val + src2Val; + result = truncateValue(src1Val + src2Val, regType); writeRegister(state, dest, regType, result); updateCondNZ(state, result, regType); - state->conditionCodes.Overflow = max(src1Val, src2Val) > result; - state->conditionCodes.Carry = state->conditionCodes.Overflow; + state->conditionCodes.Overflow = getMSB(src1Val, regType) == getMSB(src2Val, regType) && getMSB(result, regType) != getMSB(src1Val, regType); + state->conditionCodes.Carry = max(truncateValue(src1Val, regType), truncateValue(src2Val, regType)) > result; break; case(a64inst_ADD):