Skill: Interrupts, Reset, IRQ, NMI, BRK, and Vectors
Use this skill when
The task involves IRQ/NMI handlers, raster interrupts, STOP+RESTORE, reset behavior, BRK, vector patching, or safe interrupt disabling.
Core concepts
- RESET loads the CPU program counter from vector
$FFFC-$FFFD.
- IRQ/BRK loads from
$FFFE-$FFFF after pushing PC/status to stack.
- NMI loads from
$FFFA-$FFFB and cannot be masked by the I flag.
- C64 RAM vectors allow patching system behavior without changing ROM.
Important RAM vectors
| Decimal |
Hex |
Meaning |
| 788-789 |
$0314-$0315 |
IRQ vector |
| 790-791 |
$0316-$0317 |
BRK vector |
| 792-793 |
$0318-$0319 |
NMI vector |
| 768-779 |
$0300-$030B |
BASIC vectors: error, main loop, tokenize, list, execute, evaluate |
Safe IRQ hook pattern
SEI.
- Save old vector.
- Store new low/high bytes to
$0314/$0315.
CLI.
- Handler saves registers.
- Handler acknowledges its interrupt source.
- Handler restores registers.
- Handler jumps to old IRQ or normal KERNAL IRQ path.
Minimal handler skeleton
irq: pha
txa
pha
tya
pha
; acknowledge source here, e.g. VIC raster IRQ:
lda #$01
sta $d019
; do short, deterministic work
pla
tay
pla
tax
pla
jmp $ea31 ; normal KERNAL IRQ continuation on C64
Warnings
- Do not leave IRQ disabled unless building a controlled loader/demo effect.
- NMI is used by RESTORE and CIA #2; avoid breaking STOP+RESTORE recovery unless intentional.
- Raster IRQ code must be short and cycle-aware.
- Always acknowledge the hardware source or the interrupt will immediately retrigger.
Agent checklist
- State interrupt source: VIC-II, CIA #1, CIA #2, BRK, RESTORE/NMI.
- Show vector write low byte then high byte while IRQ disabled.
- Save/restore A, X, Y unless deliberately not needed.
- Acknowledge interrupt flags.
- Chain to old handler or document full replacement.