]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/kirq.s
Small size optimizations
[cc65] / libsrc / cbm510 / kirq.s
1 ;
2 ; Ullrich von Bassewitz, 28.09.1998
3 ;
4 ; IRQ routine for the 510.
5 ;
6
7         .export         irq, nmi, k_irq, k_nmi
8         .import         SCNKEY, UDTIM, k_rs232
9         .import         condes
10         .import         __IRQFUNC_TABLE__, __IRQFUNC_COUNT__
11         .importzp       tpi1
12
13         .include        "cbm510.inc"
14
15
16 ; -------------------------------------------------------------------------
17 ; This is the mapping of the active irq register of the 6525 (tpi1):
18 ;
19 ; Bit   7       6       5       4       3       2       1       0
20 ;                               |       |       |       |       ^ 50 Hz
21 ;                               |       |       |       ^ SRQ IEEE 488
22 ;                               |       |       ^ cia2
23 ;                               |       ^ cia1 IRQB ext. Port
24 ;                               ^ acia
25
26
27
28 ; -------------------------------------------------------------------------
29 ; IRQ entry point
30
31 .proc   irq
32
33         pha
34         txa
35         pha
36         tya
37         pha
38         tsx
39         lda     $104,x                  ; Get the flags from the stack
40         and     #$10                    ; Test break flag
41         bne     L1
42         jmp     (IRQVec)
43 L1:     jmp     (BRKVec)
44
45 .endproc
46
47 ; -------------------------------------------------------------------------
48 ; NMI entry point
49
50 .proc   nmi
51
52         jmp     (NMIVec)
53
54 .endproc
55
56
57 ; -------------------------------------------------------------------------
58 ; Kernal irq entry point. The IRQvec points here (usually).
59
60 k_irq:
61         lda     IndReg                  ; Ind. Segment retten
62         pha
63         cld
64         lda     #$0F
65         sta     IndReg
66         ldy     #tpiActIntReg
67         lda     (tpi1),y                ; Interrupt Register 6525
68         beq     noirq
69
70 ; -------------------------------------------------------------------------
71 ; 50/60Hz interrupt
72
73         cmp     #%00000001              ; ticker irq?
74         bne     irq1
75
76 ; Call user IRQ handlers if we have any
77
78         ldy     #<(__IRQFUNC_COUNT__*2)
79         beq     @L1
80         lda     #<__IRQFUNC_TABLE__
81         ldx     #>__IRQFUNC_TABLE__
82         jsr     condes                  ; Call the functions
83
84 ; Call replacement kernal IRQ routines
85
86 @L1:    jsr     SCNKEY                  ; Poll the keyboard
87         jsr     UDTIM                   ; Bump the time
88
89 ; -------------------------------------------------------------------------
90 ; UART interrupt
91
92 irq1:   cmp     #%00010000              ; interrupt from uart?
93         bne     irqend
94         jsr     k_rs232                 ; Read character from uart
95
96 ; -------------------------------------------------------------------------
97 ; Done
98
99 irqend: ldy     #tpiActIntReg
100         sta     (tpi1),y                ; Clear interrupt
101
102 noirq:  pla
103         sta     IndReg
104         pla
105         tay
106         pla
107         tax
108         pla
109 k_nmi:  rti
110
111