From 4ed3b21bf37a6b6d319bfcfb048ef020b4c819e3 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 23 Jun 2022 21:58:09 -0400 Subject: [PATCH] Decimal SBC tweak: negative partial results don't cause carry. --- .../65816/Implementation/65816Implementation.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Processors/65816/Implementation/65816Implementation.hpp b/Processors/65816/Implementation/65816Implementation.hpp index ec7c73ba6..4e542236f 100644 --- a/Processors/65816/Implementation/65816Implementation.hpp +++ b/Processors/65816/Implementation/65816Implementation.hpp @@ -918,14 +918,22 @@ template void Processor> 16) & adjustment; \ + result &= (carry & ~(result >> 31)) | (carry - 1); + + // i.e. add the next nibble to that in the accumulator, with carry, and + // store it to result. Keep a copy for the partials. + // + // If result is less than carry, subtract adjustment. + // + // Allow onward carry if the bit immediately above this nibble is 1, and + // the current partial result is positive. nibble(0x000f, 0x0006, 0x00010); nibble(0x00f0, 0x0060, 0x00100);