]> git.sur5r.net Git - cc65/blob - libsrc/runtime/callirq.s
Do not try to dump an expression that has errors (circular references in this
[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 ;   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
24 ;      on entry.
25 ;
26 ; As the normal condes routine, this one has the limitation of 127 table
27 ; entries.
28 ;
29
30         .export callirq
31         .export callirq_y       ; Same but with Y preloaded
32
33         .import __INTERRUPTOR_TABLE__, __INTERRUPTOR_COUNT__
34
35 .code
36
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!
43
44 .data
45
46 callirq:
47         ldy     #.lobyte(__INTERRUPTOR_COUNT__*2)
48 callirq_y:
49         clc                             ; Preset carry flag
50 loop:   dey
51         lda     __INTERRUPTOR_TABLE__,y
52         sta     jmpvec+2                ; Modify code below
53         dey
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
60         bne     loop
61 done:   rts
62
63