From 25321e78e7667f62dd05f938a86efec5c6ee6b58 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Tue, 8 Jan 2019 01:32:43 +0000 Subject: [PATCH] Now that HALT/RESET/NMI/IRQ and BRK have a unified architecture, I think this wraps up the instruction handler of the 6502. Signed-off-by: Adrian Conlon --- M6502/inc/mos6502.h | 4 ++++ M6502/src/mos6502.cpp | 36 ++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index b4a1aa7..97d82a1 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -186,5 +186,9 @@ namespace EightBit { PinLevel m_soLine = PinLevel::Low; register16_t m_intermediate; + + bool m_handlingRESET = false; + bool m_handlingNMI = false; + bool m_handlingIRQ = false; }; } \ No newline at end of file diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 9b7f966..d41c0de 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -24,6 +24,7 @@ int EightBit::MOS6502::step() { if (LIKELY(powered())) { if (UNLIKELY(lowered(SO()))) handleSO(); + opcode() = fetchByte(); if (UNLIKELY(lowered(HALT()))) handleHALT(); else if (UNLIKELY(lowered(RESET()))) @@ -32,8 +33,7 @@ int EightBit::MOS6502::step() { handleNMI(); else if (UNLIKELY(lowered(IRQ()) && !interruptMasked())) handleIRQ(); - else - Processor::execute(fetchByte()); + execute(); } ExecutedInstruction.fire(*this); return cycles(); @@ -47,36 +47,44 @@ void EightBit::MOS6502::handleSO() { } void EightBit::MOS6502::handleHALT() { - Processor::execute(0xea); // NOP + opcode() = 0xea; // NOP } void EightBit::MOS6502::handleRESET() { - jump(getWordPaged(0xff, RSTvector)); raise(RESET()); + m_handlingRESET = true; + opcode() = 0x00; // BRK } void EightBit::MOS6502::handleNMI() { raise(HALT()); - Processor::execute(0); raise(NMI()); + m_handlingNMI = true; + opcode() = 0x00; // BRK } void EightBit::MOS6502::handleIRQ() { raise(HALT()); - Processor::execute(0); raise(INT()); + m_handlingIRQ = true; + opcode() = 0x00; // BRK } void EightBit::MOS6502::interrupt() { - const bool nmi = lowered(NMI()); - const bool irq = lowered(IRQ()); - const bool hardware = nmi || irq; - const bool software = !hardware; - pushWord(PC()); - push(P() | (software ? BF : 0)); - setFlag(P(), IF); // Disable IRQ - jump(getWordPaged(0xff, nmi ? NMIvector : IRQvector)); + uint8_t vector = RSTvector; + if (!m_handlingRESET) { + const bool nmi = m_handlingNMI; + const bool irq = m_handlingIRQ; + const bool hardware = nmi || irq; + const bool software = !hardware; + pushWord(PC()); + push(P() | (software ? BF : 0)); + setFlag(P(), IF); // Disable IRQ + vector = nmi ? NMIvector : IRQvector; + } + jump(getWordPaged(0xff, vector)); + m_handlingRESET = m_handlingNMI = m_handlingIRQ = false; } //