From 48387285211aaf3989bb19685b0e926a4e4d703b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 9 Oct 2024 21:04:32 -0400 Subject: [PATCH] Eliminate `nibble` macros. --- InstructionSets/M50740/Executor.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/InstructionSets/M50740/Executor.cpp b/InstructionSets/M50740/Executor.cpp index 48d1d12a5..944b8280d 100644 --- a/InstructionSets/M50740/Executor.cpp +++ b/InstructionSets/M50740/Executor.cpp @@ -724,16 +724,15 @@ template void Executor::perform(uint8_t *operand [[maybe_u uint16_t partials = 0; int result = carry_flag_; -#define nibble(mask, limit, adjustment, carry) \ - result += (a & mask) + (*operand & mask); \ - partials += result & mask; \ - if(result >= limit) result = ((result + (adjustment)) & (carry - 1)) + carry; + const auto nibble = [&](uint16_t mask, uint16_t limit, uint16_t adjustment, uint16_t carry) { + result += (a & mask) + (*operand & mask); + partials += result & mask; + if(result >= limit) result = ((result + (adjustment)) & (carry - 1)) + carry; + }; nibble(0x000f, 0x000a, 0x0006, 0x00010); nibble(0x00f0, 0x00a0, 0x0060, 0x00100); -#undef nibble - overflow_result_ = uint8_t((partials ^ a) & (partials ^ *operand)); set_nz(uint8_t(result)); carry_flag_ = (result >> 8) & 1; @@ -742,17 +741,16 @@ template void Executor::perform(uint8_t *operand [[maybe_u unsigned int borrow = carry_flag_ ^ 1; const uint16_t decimal_result = uint16_t(a - *operand - borrow); -#define nibble(mask, adjustment, carry) \ - result += (a & mask) - (*operand & mask) - borrow; \ - if(result > mask) result -= adjustment; \ - borrow = (result > mask) ? carry : 0; \ - result &= (carry - 1); + const auto nibble = [&](uint16_t mask, uint16_t adjustment, uint16_t carry) { + result += (a & mask) - (*operand & mask) - borrow; + if(result > mask) result -= adjustment; + borrow = (result > mask) ? carry : 0; + result &= (carry - 1); + }; nibble(0x000f, 0x0006, 0x00010); nibble(0x00f0, 0x0060, 0x00100); -#undef nibble - overflow_result_ = uint8_t((decimal_result ^ a) & (~decimal_result ^ *operand)); set_nz(uint8_t(result)); carry_flag_ = ((borrow >> 8)&1)^1;