diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index c21872f..b4a1aa7 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -71,7 +71,7 @@ namespace EightBit { void handleSO(); void handleHALT(); - void interrupt(uint8_t vector); + void interrupt(); virtual void push(uint8_t value) final; virtual uint8_t pop() final; @@ -144,7 +144,6 @@ namespace EightBit { uint8_t andr(uint8_t operand, uint8_t data); uint8_t asl(uint8_t value); void bit(uint8_t operand, uint8_t data); - void brk(); void cmp(uint8_t first, uint8_t second); uint8_t dec(uint8_t value); uint8_t eorr(uint8_t operand, uint8_t data); diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index cabed23..f16f41c 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -48,34 +48,35 @@ void EightBit::MOS6502::handleSO() { void EightBit::MOS6502::handleHALT() { Processor::execute(0xea); // NOP - addCycles(2); } void EightBit::MOS6502::handleRESET() { - LittleEndianProcessor::handleRESET(); jump(getWordPaged(0xff, RSTvector)); - addCycles(4); // ?? TBC + raise(RESET()); } void EightBit::MOS6502::handleNMI() { + raise(HALT()); + interrupt(); raise(NMI()); - interrupt(NMIvector); - addCycles(4); // ?? TBC } void EightBit::MOS6502::handleIRQ() { - LittleEndianProcessor::handleIRQ(); - interrupt(IRQvector); - addCycles(4); // ?? TBC + raise(HALT()); + interrupt(); + raise(INT()); } -void EightBit::MOS6502::interrupt(uint8_t vector) { - raise(HALT()); +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()); + push(P() | (software ? BF : 0)); setFlag(P(), IF); // Disable IRQ - jump(getWordPaged(0xff, vector)); + jump(getWordPaged(0xff, nmi ? NMIvector : IRQvector)); } // @@ -96,7 +97,7 @@ int EightBit::MOS6502::execute() { switch (opcode()) { - case 0x00: fetchByte(); brk(); break; // BRK (implied) + case 0x00: fetchByte(); interrupt(); break; // BRK (implied) case 0x01: A() = orr(A(), AM_IndexedIndirectX()); break; // ORA (indexed indirect X) case 0x02: break; case 0x03: slo(AM_IndexedIndirectX()); break; // *SLO (indexed indirect X) @@ -598,13 +599,6 @@ void EightBit::MOS6502::bit(const uint8_t operand, const uint8_t data) { adjustNegative(data); } -void EightBit::MOS6502::brk() { - pushWord(PC()); - php(); - setFlag(P(), IF); - jump(getWordPaged(0xff, IRQvector)); -} - void EightBit::MOS6502::cmp(const uint8_t first, const uint8_t second) { const register16_t result = first - second; adjustNZ(result.low);