From 01175cf9eb219a4eafec72236dafb9afa6e94126 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Tue, 8 Jan 2019 23:55:27 +0000 Subject: [PATCH] Add support for emulated SYNC and RDY lines. Untested, but feel close. Signed-off-by: Adrian Conlon --- M6502/inc/mos6502.h | 10 +++++++--- M6502/src/mos6502.cpp | 15 +++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 34f598d..a07524e 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -43,7 +43,9 @@ namespace EightBit { const auto& P() const { return p; } auto& NMI() { return m_nmiLine; } // In - auto& SO() { return m_soLine; } // In + auto& SO() { return m_soLine; } // In + auto& SYNC() { return m_syncLine; } // Out + auto& RDY() { return m_rdyLine; } // In protected: virtual void handleRESET() final; @@ -185,8 +187,10 @@ namespace EightBit { uint8_t s = 0; // stack pointer uint8_t p = 0; // processor status - PinLevel m_nmiLine = PinLevel::Low; - PinLevel m_soLine = PinLevel::Low; + PinLevel m_nmiLine = PinLevel::Low; // Active low + PinLevel m_soLine = PinLevel::Low; // Active low + PinLevel m_syncLine = PinLevel::Low; // Active high + PinLevel m_rdyLine = PinLevel::Low; // Active high register16_t m_intermediate; diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 54adc3b..40e9a29 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -21,13 +21,12 @@ void EightBit::MOS6502::powerOn() { int EightBit::MOS6502::step() { resetCycles(); ExecutingInstruction.fire(*this); - if (LIKELY(powered())) { + if (LIKELY(powered() && raised(RDY()))) { if (UNLIKELY(lowered(SO()))) handleSO(); + lower(SYNC()); // Instruction fetch beginning opcode() = fetchByte(); - if (UNLIKELY(lowered(HALT()))) - handleHALT(); - else if (UNLIKELY(lowered(RESET()))) + if (UNLIKELY(lowered(RESET()))) handleRESET(); else if (UNLIKELY(lowered(NMI()))) handleNMI(); @@ -46,10 +45,6 @@ void EightBit::MOS6502::handleSO() { P() |= VF; } -void EightBit::MOS6502::handleHALT() { - opcode() = 0xea; // NOP -} - void EightBit::MOS6502::handleRESET() { raise(RESET()); m_handlingRESET = true; @@ -58,14 +53,12 @@ void EightBit::MOS6502::handleRESET() { void EightBit::MOS6502::handleNMI() { - raise(HALT()); raise(NMI()); m_handlingNMI = true; opcode() = 0x00; // BRK } void EightBit::MOS6502::handleIRQ() { - raise(HALT()); raise(INT()); m_handlingIRQ = true; opcode() = 0x00; // BRK @@ -107,6 +100,8 @@ uint8_t EightBit::MOS6502::busRead() { int EightBit::MOS6502::execute() { + raise(SYNC()); // Instruction fetch has now completed + switch (opcode()) { case 0x00: fetchByte(); interrupt(); break; // BRK (implied)