2 ; Ullrich von Bassewitz, 2004-04-04
4 ; CC65 runtime: Support for calling special irq routines declared as condes
7 ; There are two reasons, why this is a separate routine, and the generic
8 ; condes routine in condes.s is not used:
10 ; 1. Speed. Having several things hardcoded makes it faster. This is
11 ; important if it is called in each interrupt.
13 ; 2. Reentrancy. The condes routines must use self modyfiying code, which
14 ; means it is not reentrant. An IRQ using condes, that interrupts
15 ; another use of condes will cause unpredicatble behaviour. The current
16 ; code avoids this by using locking mechanisms, but it's complex and
17 ; has a size and performance penalty.
19 ; 3. Special semantics: An interruptor called by callirq must tell by
20 ; setting or resetting the carry flag if the interrupt has been handled
21 ; (which means that the interrupt is no longer active at the interrupt
22 ; source). callirq will call no other interruptors if this happens. To
23 ; simplify code, all interrupt routines will be called with carry clear
26 ; As the normal condes routine, this one has the limitation of 127 table
31 .export callirq_y ; Same but with Y preloaded
32 .export __CALLIRQ__ : absolute = 1
33 .constructor irq_init, 10
34 .destructor irq_done, 10
36 .import __INTERRUPTOR_TABLE__, __INTERRUPTOR_COUNT__
43 ; --------------------------------------------------------------------------
44 ; Call all IRQ routines. The function needs to use self modifying code and
45 ; is thereforce placed in the data segment. It will return carry set if the
46 ; interrupt was handled and carry clear if not. The caller may choose to
47 ; ignore this at will.
48 ; NOTE: The routine must not be called if the table is empty!
53 ldy #.lobyte(__INTERRUPTOR_COUNT__*2)
55 clc ; Preset carry flag
57 lda __INTERRUPTOR_TABLE__,y
58 sta jmpvec+2 ; Modify code below
60 lda __INTERRUPTOR_TABLE__,y
61 sta jmpvec+1 ; Modify code below
62 sty index+1 ; Modify code below
63 jmpvec: jsr $FFFF ; Patched at runtime
64 bcs done ; Bail out if interrupt handled
65 index: ldy #$FF ; Patched at runtime