From 76767110b7c49e78dd0b718f642b28a15bc635e6 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 22 Jun 2022 15:12:08 -0400 Subject: [PATCH] Fix overflow for 8-bit calculations; essentially a revert for ADC. --- .../Implementation/65816Implementation.hpp | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/Processors/65816/Implementation/65816Implementation.hpp b/Processors/65816/Implementation/65816Implementation.hpp index 9f77567c6..d5161e64a 100644 --- a/Processors/65816/Implementation/65816Implementation.hpp +++ b/Processors/65816/Implementation/65816Implementation.hpp @@ -910,33 +910,25 @@ template void Processor> (1 + registers_.m_shift))&0x40); - end_nibble(0x6000, 0x10000); + nibble(0xf000, 0x6000, 0x10000); #undef nibble -#undef begin_nibble -#undef end_nibble + registers_.flags.overflow = (( (partials ^ registers_.a.full) & (partials ^ data_buffer_.value) ) >> (1 + registers_.m_shift))&0x40; registers_.flags.set_nz(uint16_t(result), registers_.m_shift); registers_.flags.carry = (result >> (8 + registers_.m_shift))&1; LDA(result); @@ -945,7 +937,6 @@ template void Processor void Processor= limit) result = ((result + adjustment) & (carry - 1)) + carry; -#define nibble(mask, limit, adjustment, carry) \ - begin_nibble(mask); \ - end_nibble(limit, adjustment, carry) - - result = registers_.flags.carry; nibble(0x000f, 0x000a, 0x0006, 0x00010); nibble(0x00f0, 0x00a0, 0x0060, 0x00100); nibble(0x0f00, 0x0a00, 0x0600, 0x01000); - - begin_nibble(0xf000); - registers_.flags.overflow = (( (uint16_t(result) ^ registers_.a.full) & (uint16_t(result) ^ data_buffer_.value) ) >> (1 + registers_.m_shift))&0x40; - end_nibble(0xa000, 0x6000, 0x10000); + nibble(0xf000, 0xa000, 0x6000, 0x10000); #undef nibble -#undef begin_nibble -#undef end_nibble + registers_.flags.overflow = (( (partials ^ registers_.a.full) & (partials ^ data_buffer_.value) ) >> (1 + registers_.m_shift))&0x40; } else { result = int(a + data_buffer_.value + registers_.flags.carry); registers_.flags.overflow = (( (uint16_t(result) ^ registers_.a.full) & (uint16_t(result) ^ data_buffer_.value) ) >> (1 + registers_.m_shift))&0x40;