]> git.sur5r.net Git - cc65/blob - libsrc/apple2/irq.s
Included a header that defines NULL.
[cc65] / libsrc / apple2 / irq.s
1 ;
2 ; Oliver Schmidt, 2012-11-17
3 ;
4 ; IRQ handling (Apple2 version)
5 ;
6
7         .export         initirq, doneirq
8         .import         callirq, __dos_type, _exit
9
10         .include        "apple2.inc"
11
12         .segment        "INIT"
13
14 initirq:
15         ; Check for ProDOS
16         lda     __dos_type
17         beq     prterr
18
19         ; Allocate interrupt vector table entry
20         jsr     $BF00           ; MLI call entry point
21         .byte   $40             ; Alloc interrupt
22         .addr   i_param
23         bcs     prterr
24         rts
25
26         ; Print error message and exit
27 prterr: ldx     #msglen-1
28 :       lda     errmsg,x
29         jsr     $FDED           ; COUT
30         dex
31         bpl     :-
32         jmp     _exit
33
34 errmsg: .ifdef  __APPLE2ENH__
35         .byte   $8D,     't'|$80, 'p'|$80, 'u'|$80, 'r'|$80, 'r'|$80
36         .byte   'e'|$80, 't'|$80, 'n'|$80, 'i'|$80, ' '|$80, 'c'|$80
37         .byte   'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80
38         .byte   't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80
39         .byte   'a'|$80, 'F'|$80, $8D
40         .else
41         .byte   $8D,     'T'|$80, 'P'|$80, 'U'|$80, 'R'|$80, 'R'|$80
42         .byte   'E'|$80, 'T'|$80, 'N'|$80, 'I'|$80, ' '|$80, 'C'|$80
43         .byte   'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80
44         .byte   'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80
45         .byte   'A'|$80, 'F'|$80, $8D
46         .endif
47
48 msglen = * - errmsg
49
50         .code
51
52 doneirq:
53         ; Check for valid interrupt vector table entry number which
54         ; IS necessary as this gets called even if initirq failed.
55         lda     int_num
56         beq     :+
57
58         ; Deallocate interrupt vector table entry
59         dec     i_param         ; Adjust parameter count
60         jsr     $BF00           ; MLI call entry point
61         .byte   $41             ; Dealloc interrupt
62         .addr   i_param
63 :       rts
64
65         .segment        "LOWCODE"
66
67 intptr:
68         ; ProDOS TechRefMan, chapter 6.2:
69         ; "Each installed routine must begin with a CLD instruction."
70         cld
71
72         ; Call interruptors and check for success
73         jsr     callirq
74         bcc     :+
75
76         ; ProDOS TechRefMan, chapter 6.2:
77         ; "When the routine that can process the interrupt is called, it
78         ;  should ... return (via an RTS) with the carry flag clear."
79         clc
80         rts
81
82         ; ProDOS TechRefMan, chapter 6.2:
83         ; "When a routine that cannot process the interrupt is called,
84         ;  it should return (via an RTS) with the cary flag set ..."
85 :       sec
86         rts
87
88         .data
89
90         ; MLI parameter list for (de)alloc interrupt
91 i_param:.byte   $02             ; param_count
92 int_num:.byte   $00             ; int_num
93         .addr   intptr          ; int_code