From 047babbe7c0ac4ae793516cd035c99d6e97b3777 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Tue, 8 Jan 2019 23:09:52 +0000 Subject: [PATCH] Rearrange the RESET handler for cycle accuracy. Use more of the general interrupt handler, but with "dummy" stack write access. Signed-off-by: Adrian Conlon --- M6502/inc/mos6502.h | 3 +++ M6502/src/mos6502.cpp | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 97d82a1..34f598d 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -76,6 +76,9 @@ namespace EightBit { virtual void push(uint8_t value) final; virtual uint8_t pop() final; + // Dummy stack push, used during RESET + void dummyPush(uint8_t value); + // Addressing modes register16_t Address_Absolute(); diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index d41c0de..54adc3b 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -72,17 +72,21 @@ void EightBit::MOS6502::handleIRQ() { } void EightBit::MOS6502::interrupt() { - 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; + const bool reset = m_handlingRESET; + const bool nmi = m_handlingNMI; + const bool irq = m_handlingIRQ; + const bool hardware = nmi || irq || reset; + const bool software = !hardware; + if (reset) { + dummyPush(PC().high); + dummyPush(PC().low); + dummyPush(P()); + } else { pushWord(PC()); push(P() | (software ? BF : 0)); - setFlag(P(), IF); // Disable IRQ - vector = nmi ? NMIvector : IRQvector; } + setFlag(P(), IF); // Disable IRQ + const uint8_t vector = reset ? RSTvector : (nmi ? NMIvector : IRQvector); jump(getWordPaged(0xff, vector)); m_handlingRESET = m_handlingNMI = m_handlingIRQ = false; } @@ -392,6 +396,12 @@ uint8_t EightBit::MOS6502::pop() { return getBytePaged(1, ++S()); } +void EightBit::MOS6502::dummyPush(const uint8_t value) { + addCycle(); + BUS().DATA() = value; + BUS().ADDRESS() = register16_t(S()--, 1); +} + //// EightBit::register16_t EightBit::MOS6502::Address_Absolute() {