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
33 .import __INTERRUPTOR_TABLE__, __INTERRUPTOR_COUNT__
37 ; --------------------------------------------------------------------------
38 ; Call all IRQ routines. The function needs to use self modifying code and
39 ; is thereforce placed in the data segment. It will return carry set if the
40 ; interrupt was handled and carry clear if not. The caller may choose to
41 ; ignore this at will.
42 ; NOTE: The routine must not be called if the table is empty!
47 ldy #.lobyte(__INTERRUPTOR_COUNT__*2)
49 clc ; Preset carry flag
51 lda __INTERRUPTOR_TABLE__,y
52 sta jmpvec+2 ; Modify code below
54 lda __INTERRUPTOR_TABLE__,y
55 sta jmpvec+1 ; Modify code below
56 sty index+1 ; Modify code below
57 jmpvec: jsr $FFFF ; Patched at runtime
58 bcs done ; Bail out if interrupt handled
59 index: ldy #$FF ; Patched at runtime