]> git.sur5r.net Git - cc65/blob - libsrc/runtime/callirq.s
Add interrupt handling code from Stefan Haubenthal
[cc65] / libsrc / runtime / callirq.s
1 ;
2 ; Ullrich von Bassewitz, 2004-04-04
3 ;
4 ; CC65 runtime: Support for calling special irq routines declared as condes
5 ; type 2.
6 ;
7 ; There are two reasons, why this is a separate routine, and the generic
8 ; condes routine in condes.s is not used:
9 ;
10 ;   1. Speed. Having several things hardcoded makes it faster. This is
11 ;      important if it is called in each interrupt.
12 ;
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.
18 ;
19 ; As the normal condes routine, this one has the limitation of 127 table
20 ; entries.
21 ;
22
23         .export callirq
24         .export callirq_y       ; Same but with Y preloaded
25
26         .import __INTERRUPTOR_TABLE__, __INTERRUPTOR_COUNT__
27
28 .code
29
30 ; --------------------------------------------------------------------------
31 ; Call all IRQ routines. The function needs to use self modifying code and
32 ; is thereforce placed in the data segment.
33 ; NOTE: The routine must not be called if the table is empty!
34
35 .data
36
37 callirq:
38         ldy     #.lobyte(__INTERRUPTOR_COUNT__*2)
39 callirq_y:
40         dey
41         lda     __INTERRUPTOR_TABLE__,y
42         sta     jmpvec+2                ; Modify code below
43         dey
44         lda     __INTERRUPTOR_TABLE__,y
45         sta     jmpvec+1                ; Modify code below
46         sty     index+1                 ; Modify code below
47 jmpvec: jsr     $FFFF                   ; Patched at runtime
48 index:  ldy     #$FF                    ; Patched at runtime
49         bne     callirq_y
50         rts
51
52
53