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 <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-01-08 01:32:43 +00:00
parent 3faec680b0
commit 25321e78e7
2 changed files with 26 additions and 14 deletions

View File

@ -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;
};
}

View File

@ -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;
}
//