From 7af81018c9b51ca8b930b06399fd0ca4b7ee0303 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 1 Nov 2018 19:47:21 +0000 Subject: [PATCH] Modify rotate and shift instructions to be a little more understandable (6502/6809) Signed-off-by: Adrian Conlon --- M6502/src/mos6502.cpp | 14 ++++++-------- MC6809/src/mc6809.cpp | 25 +++++++++++-------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index f6778ab..ebe66ff 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -613,20 +613,18 @@ void EightBit::MOS6502::plp() { P() = (pop() | RF) & ~BF; } -uint8_t EightBit::MOS6502::rol(uint8_t operand) { +uint8_t EightBit::MOS6502::rol(const uint8_t operand) { const auto carryIn = carry(); setFlag(P(), CF, operand & Bit7); - operand <<= 1; - operand |= carryIn; - return through(operand); + const uint8_t result = (operand << 1) | carryIn; + return through(result); } -uint8_t EightBit::MOS6502::ror(uint8_t operand) { +uint8_t EightBit::MOS6502::ror(const uint8_t operand) { const auto carryIn = carry(); setFlag(P(), CF, operand & Bit0); - operand >>= 1; - operand |= (carryIn << 7); - return through(operand); + const uint8_t result = (operand >> 1) | (carryIn << 7); + return through(result); } void EightBit::MOS6502::rti() { diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index baf48ef..610d5c5 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -787,10 +787,9 @@ uint8_t EightBit::mc6809::asl(uint8_t operand) { uint8_t EightBit::mc6809::asr(uint8_t operand) { setFlag(CC(), CF, operand & Bit0); - operand >>= 1; - operand |= Bit7; - adjustNZ(operand); - return operand; + const uint8_t result = (operand >> 1) | Bit7; + adjustNZ(result); + return result; } void EightBit::mc6809::bit(const uint8_t operand, const uint8_t data) { @@ -1007,23 +1006,21 @@ void EightBit::mc6809::pul(register16_t& stack, const uint8_t data) { } } -uint8_t EightBit::mc6809::rol(uint8_t operand) { +uint8_t EightBit::mc6809::rol(const uint8_t operand) { const auto carryIn = carry(); setFlag(CC(), CF, operand & Bit7); setFlag(CC(), VF, ((operand & Bit7) >> 7) ^ ((operand & Bit6) >> 6)); - operand <<= 1; - operand |= carryIn; - adjustNZ(operand); - return operand; + const uint8_t result = (operand << 1) | carryIn; + adjustNZ(result); + return result; } -uint8_t EightBit::mc6809::ror(uint8_t operand) { +uint8_t EightBit::mc6809::ror(const uint8_t operand) { const auto carryIn = carry(); setFlag(CC(), CF, operand & Bit0); - operand >>= 1; - operand |= (carryIn << 7); - adjustNZ(operand); - return operand; + const uint8_t result = (operand >> 1) | (carryIn << 7); + adjustNZ(result); + return result; } void EightBit::mc6809::rti() {