55 lines
1.7 KiB
Text
55 lines
1.7 KiB
Text
//-----------------------------------------------------------
|
|
// Simple IRQ Handler Demo
|
|
//
|
|
// Installs a custom IRQ handler through the kernal vector at
|
|
// $0314. The kernal has already saved the registers for us
|
|
// before it calls the vector, so our handler does NOT push or
|
|
// pull A/X/Y. When we are done we jump into the kernal so it
|
|
// can finish the IRQ and RTI properly:
|
|
//
|
|
// jmp $ea31 - let the kernal do its full IRQ work
|
|
// (scan keyboard, blink cursor, update jiffy
|
|
// clock, ...) and then RTI
|
|
// jmp $ea81 - skip the kernal work, just restore the
|
|
// registers the kernal saved and RTI
|
|
//
|
|
// This handler chains to $ea31 so the machine stays usable.
|
|
//-----------------------------------------------------------
|
|
|
|
#INCLUDE <c64start.c65>
|
|
#INCLUDE <c64defs.c65>
|
|
|
|
GOTO start
|
|
|
|
WORD CONST IRQ_VECTOR = $0314
|
|
WORD handler = @myIRQ // Address of our IRQ handler
|
|
|
|
FUNC installIRQ
|
|
ASM
|
|
sei // Disable interrupts while we patch
|
|
ENDASM
|
|
|
|
POKEW IRQ_VECTOR, handler // Point the vector at our handler
|
|
|
|
ASM
|
|
cli // Re-enable interrupts
|
|
ENDASM
|
|
FEND
|
|
|
|
|
|
LABEL start
|
|
installIRQ()
|
|
SUBEND //exit back to basic
|
|
|
|
//-----------------------------------------------------------
|
|
// The IRQ handler.
|
|
//
|
|
// No register saving needed - the kernal did it. Do the work,
|
|
// then hand control back to the kernal at $ea31 which restores
|
|
// the registers and returns from the interrupt.
|
|
//-----------------------------------------------------------
|
|
LABEL myIRQ
|
|
ASM
|
|
inc $0400 // Bump the top-left screen character
|
|
jmp $ea31 // Let the kernal finish the IRQ
|
|
ENDASM
|