Also, when you're considering software, note that the BRK vector is shared with the IRQ vector, so you might want to add some header code at that vector to determine which happened: an actual IRQ or the BRK instruction. I use a short piece of code in the ROM for that... and also for the exit routine via an RTI. The old Vic-20 used a similar routine, albeit had to move the index registers to the accumulator to push on the stack (and inverse when pulling from the stack), so that added more clock cycles and memory to the routines.
Code: Select all
IRQ_VECTOR ;This is the ROM start for the BRK/IRQ handler
PHA ;Save A Reg (3)
PHX ;Save X Reg (3)
PHY ;Save Y Reg (3)
TSX ;Get Stack pointer (2)
LDA $0100+4,X ;Get Status Register (4)
AND #$10 ;Mask for BRK bit set (2)
BNE DO_BRK ;If set, handle BRK (2/3)
JMP (IRQVEC0) ;Jump to Soft vectored IRQ Handler (6)
DO_BRK JMP (BRKVEC0) ;Jump to Soft vectored BRK Handler (6)
NMI_ROM JMP (NMIVEC0) ;Jump to Soft vectored NMI handler (6)
;
;This is the standard return for the IRQ/BRK handler routines
;
IRQ_EXIT0 PLY ;Restore Y Reg (4)
PLX ;Restore X Reg (4)
PLA ;Restore A Reg (4)
RTI ;Return from IRQ/BRK routine (6)