From a3e64cae41dc29cf193c2e9f87cda0528f8f8ef3 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 17 Dec 2019 22:16:02 -0500 Subject: [PATCH] Corrects SBCD carry. --- .../Implementation/68000Implementation.hpp | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Processors/68000/Implementation/68000Implementation.hpp b/Processors/68000/Implementation/68000Implementation.hpp index df3d062d8..d8a23b6d4 100644 --- a/Processors/68000/Implementation/68000Implementation.hpp +++ b/Processors/68000/Implementation/68000Implementation.hpp @@ -390,6 +390,7 @@ template void Proces const uint8_t destination = destination()->halves.low.halves.low; // Perform the BCD add by evaluating the two nibbles separately. + const int unadjusted_result = destination + source + (extend_flag_ ? 1 : 0); int result = (destination & 0xf) + (source & 0xf) + (extend_flag_ ? 1 : 0); if(result > 0x09) result += 0x06; result += (destination & 0xf0) + (source & 0xf0); @@ -399,8 +400,6 @@ template void Proces zero_result_ |= result & 0xff; extend_flag_ = carry_flag_ = uint_fast32_t(result & ~0xff); negative_flag_ = result & 0x80; - - const int unadjusted_result = destination + source + (extend_flag_ ? 1 : 0); overflow_flag_ = ~unadjusted_result & result & 0x80; // Store the result. @@ -1530,21 +1529,21 @@ template void Proces overflow_flag_ = carry_flag_ = 0; break; -#define sbcd() \ - /* Perform the BCD arithmetic by evaluating the two nibbles separately. */ \ - int result = (destination & 0xf) - (source & 0xf) - (extend_flag_ ? 1 : 0); \ - if((result & 0x1f) > 0x09) result -= 0x06; \ - result += (destination & 0xf0) - (source & 0xf0); \ - if((result & 0x1ff) > 0x99) result -= 0x60; \ - \ - /* Set all flags essentially as if this were normal subtraction. */ \ - zero_result_ |= result & 0xff; \ - extend_flag_ = carry_flag_ = decltype(carry_flag_)(result & ~0xff); \ - negative_flag_ = result & 0x80; \ +#define sbcd() \ + /* Perform the BCD arithmetic by evaluating the two nibbles separately. */ \ const int unadjusted_result = destination - source - (extend_flag_ ? 1 : 0); \ - overflow_flag_ = unadjusted_result & ~result & 0x80; \ - \ - /* Store the result. */ \ + int result = (destination & 0xf) - (source & 0xf) - (extend_flag_ ? 1 : 0); \ + if((result & 0x1f) > 0x09) result -= 0x06; \ + result += (destination & 0xf0) - (source & 0xf0); \ + extend_flag_ = carry_flag_ = decltype(carry_flag_)((result & 0x1ff) > 0x99); \ + if(carry_flag_) result -= 0x60; \ + \ + /* Set all flags essentially as if this were normal subtraction. */ \ + zero_result_ |= result & 0xff; \ + negative_flag_ = result & 0x80; \ + overflow_flag_ = unadjusted_result & ~result & 0x80; \ + \ + /* Store the result. */ \ destination()->halves.low.halves.low = uint8_t(result); /*