From 7296ff7cce0894b4633ddbc5fdec84362d22c30a Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 6 Apr 2020 23:08:11 +0100 Subject: [PATCH] MC6809 tidy a few items and show a "functional" (rather than macro based) rmw routine. --- MC6809/inc/mc6809.h | 31 +++++++++++++++++++++++++++++-- MC6809/src/mc6809.cpp | 32 +++++++++++--------------------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/MC6809/inc/mc6809.h b/MC6809/inc/mc6809.h index 32ca432..36c977d 100644 --- a/MC6809/inc/mc6809.h +++ b/MC6809/inc/mc6809.h @@ -4,6 +4,7 @@ // http://www.cpu-world.com/Arch/6809.html #include +#include #include #include @@ -112,6 +113,7 @@ namespace EightBit { virtual uint8_t busRead() final; virtual void call(register16_t destination) final; + virtual void ret() final; private: const uint8_t RESETvector = 0xfe; // RESET vector @@ -125,7 +127,33 @@ namespace EightBit { void eat(int cycles = 1) { for (int cycle = 0; cycle < cycles; ++cycle) - memoryRead(0xffff); + memoryRead(Mask16); + } + + // Read/Modify/Write + + // Macro version: easy to use + // RMW(AM_direct_byte, asl) + #define RMW(ACCESSOR, OPERATION) \ + { \ + const auto data = ACCESSOR(); \ + const auto address = BUS().ADDRESS(); \ + const auto result = OPERATION(data); \ + eat(); \ + memoryWrite(address, result); \ + } + + typedef std::function accessor_t; + typedef std::function operation_t; + + // C++ 11 version: looks great, but verbose to use + // rmw([this]() { return AM_direct_byte(); }, [this](uint8_t data) { return asl(data); }); + void rmw(accessor_t accessor, operation_t operation) { + const auto data = accessor(); + const auto address = BUS().ADDRESS(); + const auto result = operation(data); + eat(); + memoryWrite(address, result); } // Stack manipulation @@ -363,7 +391,6 @@ namespace EightBit { uint8_t rol(uint8_t operand); uint8_t ror(uint8_t operand); void rti(); - void rts(); uint8_t sbc(uint8_t operand, uint8_t data); uint8_t sub(uint8_t operand, uint8_t data, uint8_t carry = 0); register16_t sub(register16_t operand, register16_t data); diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index 5bb6905..b0d663e 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -4,16 +4,6 @@ #include #include -// Read/Modify/Write -#define RMW(ACCESSOR, OPERATION) \ -{ \ - const auto data = ACCESSOR(); \ - const auto address = BUS().ADDRESS(); \ - const auto result = OPERATION(data); \ - eat(); \ - memoryWrite(address, result); \ -} - EightBit::mc6809::mc6809(Bus& bus) : BigEndianProcessor(bus) { RaisedPOWER.connect([this](EventArgs) { @@ -61,17 +51,17 @@ void EightBit::mc6809::handleHALT() { void EightBit::mc6809::handleRESET() { BigEndianProcessor::handleRESET(); - memoryRead(0xfffe); + memoryRead({ 0xff, RESETvector }); raiseNMI(); lowerBA(); raiseBS(); DP() = 0; CC() = setBit(CC(), IF); // Disable IRQ CC() = setBit(CC(), FF); // Disable FIRQ - memoryRead(0xfffe); - memoryRead(0xfffe); - memoryRead(0xfffe); - jump(getWordPaged(0xff, RESETvector)); + memoryRead(); + memoryRead(); + memoryRead(); + jump(getWord()); eat(); } @@ -142,6 +132,11 @@ void EightBit::mc6809::call(register16_t destination) { jump(destination); } +void EightBit::mc6809::ret() { + BigEndianProcessor::ret(); + eat(); +} + // int EightBit::mc6809::execute() { @@ -421,7 +416,7 @@ void EightBit::mc6809::executeUnprefixed() { case 0x3B: memoryRead(); rti(); break; // RTI (inherent) // RTS - case 0x39: memoryRead(); rts(); break; // RTS (inherent) + case 0x39: memoryRead(); ret(); break; // RTS (inherent) // SBC @@ -1088,11 +1083,6 @@ void EightBit::mc6809::rti() { eat(); } -void EightBit::mc6809::rts() { - ret(); - eat(); -} - void EightBit::mc6809::swi() { eat(); saveEntireRegisterState();