From 15e1258f409062b32369050a516f8b52b34b5bbb Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 19 Aug 2018 00:55:59 +0100 Subject: [PATCH] Rearrange the 6809 code such that I can fire memory events. Signed-off-by: Adrian Conlon --- MC6809/inc/mc6809.h | 32 +++++++++++++++++++++++++------- MC6809/src/mc6809.cpp | 15 ++++++++------- inc/Bus.h | 1 + 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/MC6809/inc/mc6809.h b/MC6809/inc/mc6809.h index 13d2f39..da98da1 100644 --- a/MC6809/inc/mc6809.h +++ b/MC6809/inc/mc6809.h @@ -71,9 +71,10 @@ namespace EightBit { const uint8_t SWI3vector = 0xf2; const uint8_t RESERVEDvector = 0xf0; - uint8_t& AM_direct() { + // + + void Address_direct() { BUS().ADDRESS() = register16_t(fetchByte(), DP()); - return BUS().reference(); } register16_t& RR(int which) { @@ -93,7 +94,7 @@ namespace EightBit { } } - uint8_t& AM_indexed() { + void Address_indexed() { const auto type = fetchByte(); auto& rr = RR(type & (Bit6 | Bit5)); switch (type & Bit7) { @@ -167,16 +168,33 @@ namespace EightBit { default: UNREACHABLE; } - return BUS().reference(); } - uint8_t& AM_extended() { + void Address_extended() { BUS().ADDRESS() = fetchWord(); - return BUS().reference(); } + // + + uint8_t AM_direct() { + Address_direct(); + return BUS().read(); + } + + uint8_t AM_indexed() { + Address_indexed(); + return BUS().read(); + } + + uint8_t AM_extended() { + AM_extended(); + return BUS().read(); + } + + // + void abx(); - void neg(uint8_t& operand); + uint8_t neg(uint8_t operand); register16_t m_d; register16_t m_x; diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index 4374e79..8eac25a 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -31,14 +31,14 @@ int EightBit::mc6809::execute(uint8_t cell) { switch (cell) { // ABX - case 0x3a: addCycles(3); abx(); break; // ABX (inherent) + case 0x3a: addCycles(3); abx(); break; // ABX (inherent) // NEG - case 0x00: addCycles(6); neg(AM_direct()); break; // NEG (direct) - case 0x40: addCycles(2); neg(A()); break; // NEG (NEGA, inherent) - case 0x50: addCycles(2); neg(B()); break; // NEG (NEGB, inherent) - case 0x60: addCycles(6); neg(AM_indexed()); break; // NEG (indexed) - case 0x70: addCycles(7); neg(AM_extended()); break; // NEG (extended) + case 0x00: addCycles(6); BUS().write(neg(AM_direct())); break; // NEG (direct) + case 0x40: addCycles(2); A() = neg(A()); break; // NEG (NEGA, inherent) + case 0x50: addCycles(2); B() = neg(B()); break; // NEG (NEGB, inherent) + case 0x60: addCycles(6); BUS().write(neg(AM_indexed())); break; // NEG (indexed) + case 0x70: addCycles(7); BUS().write(neg(AM_extended())); break; // NEG (extended) default: ASSUME(false); @@ -54,11 +54,12 @@ void EightBit::mc6809::abx() { X() += B(); } -void EightBit::mc6809::neg(uint8_t& operand) { +uint8_t EightBit::mc6809::neg(uint8_t operand) { setFlag(CC(), VF, operand == Bit7); const register16_t result = 0 - operand; operand = result.low; setFlag(CC(), NF, operand & Bit7); setFlag(CC(), ZF, operand == 0); setFlag(CC(), CF, result.word & Bit8); + return operand; } \ No newline at end of file diff --git a/inc/Bus.h b/inc/Bus.h index e613a77..9ee8f56 100644 --- a/inc/Bus.h +++ b/inc/Bus.h @@ -43,6 +43,7 @@ namespace EightBit { write(value); } + protected: virtual uint8_t& reference(uint16_t address) = 0; uint8_t& reference() { return reference(ADDRESS().word); }