From 07248972bff3d6c282422c00a7077793c8d42ca4 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Wed, 22 Aug 2018 09:11:02 +0100 Subject: [PATCH] Add implementations of ROL/ROR for the 6809 processor Signed-off-by: Adrian Conlon --- MC6809/inc/mc6809.h | 2 ++ MC6809/src/mc6809.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/MC6809/inc/mc6809.h b/MC6809/inc/mc6809.h index c836e37..bf0835a 100644 --- a/MC6809/inc/mc6809.h +++ b/MC6809/inc/mc6809.h @@ -250,6 +250,8 @@ namespace EightBit { void pshu(uint8_t data); void puls(uint8_t data); void pulu(uint8_t data); + uint8_t rol(uint8_t operand); + uint8_t ror(uint8_t operand); register16_t m_d; register16_t m_x; diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index 4a94c7c..f755f00 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -280,6 +280,20 @@ int EightBit::mc6809::executeUnprefixed(uint8_t opcode) { case 0x35: addCycles(5); puls(AM_immediate_byte()); break; // PUL (PULS immediate) case 0x37: addCycles(5); pulu(AM_immediate_byte()); break; // PUL (PULU immediate) + // ROL + case 0x09: addCycles(6); BUS().write(rol(AM_direct_byte())); break; // ROL (direct) + case 0x49: addCycles(2); A() = rol(A()); break; // ROL (ROLA inherent) + case 0x59: addCycles(2); B() = rol(B()); break; // ROL (ROLB inherent) + case 0x69: addCycles(6); BUS().write(rol(AM_indexed_byte())); break; // ROL (indexed) + case 0x79: addCycles(7); BUS().write(rol(AM_extended_byte())); break; // ROL (extended) + + // ROR + case 0x06: addCycles(6); BUS().write(ror(AM_direct_byte())); break; // ROR (direct) + case 0x46: addCycles(2); A() = ror(A()); break; // ROR (RORA inherent) + case 0x56: addCycles(2); B() = ror(B()); break; // ROR (RORB inherent) + case 0x66: addCycles(6); BUS().write(ror(AM_indexed_byte())); break; // ROR (indexed) + case 0x76: addCycles(7); BUS().write(ror(AM_extended_byte())); break; // ROR (extended) + default: UNREACHABLE; } @@ -857,3 +871,22 @@ void EightBit::mc6809::pulu(uint8_t data) { PC() = popWordU(); } } + +uint8_t EightBit::mc6809::rol(uint8_t operand) { + const auto carry = CC() & CF; + setFlag(CC(), CF, operand & Bit7); + setFlag(CC(), VF, ((operand & Bit7) >> 7) ^ ((operand & Bit6) >> 6)); + operand <<= 1; + operand |= carry; + adjustNZ(operand); + return operand; +} + +uint8_t EightBit::mc6809::ror(uint8_t operand) { + const auto carry = CC() & CF; + setFlag(CC(), CF, operand & Bit0); + operand >>= 1; + operand |= (carry << 7); + adjustNZ(operand); + return operand; +}