mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-03-01 03:29:37 +00:00
Start unifying 6502 interrupt handling. NMI/IRQ/BRK are all doing mostly the same work.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
b7b7c93a77
commit
06e2a5c947
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user