]> git.sur5r.net Git - cc65/blob - libsrc/apple2/irq.s
fix merge fxxxup
[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
25         ; Enable interrupts, as old ProDOS versions (i.e. 1.1.1)
26         ; jump to SYS and BIN programs with interrupts disabled.
27         cli
28         rts
29
30         ; Print error message and exit
31 prterr: ldx     #msglen-1
32 :       lda     errmsg,x
33         jsr     $FDED           ; COUT
34         dex
35         bpl     :-
36         jmp     _exit
37
38 errmsg: .ifdef  __APPLE2ENH__
39         .byte   $8D,     't'|$80, 'p'|$80, 'u'|$80, 'r'|$80, 'r'|$80
40         .byte   'e'|$80, 't'|$80, 'n'|$80, 'i'|$80, ' '|$80, 'c'|$80
41         .byte   'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80
42         .byte   't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80
43         .byte   'a'|$80, 'F'|$80, $8D
44         .else
45         .byte   $8D,     'T'|$80, 'P'|$80, 'U'|$80, 'R'|$80, 'R'|$80
46         .byte   'E'|$80, 'T'|$80, 'N'|$80, 'I'|$80, ' '|$80, 'C'|$80
47         .byte   'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80
48         .byte   'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80
49         .byte   'A'|$80, 'F'|$80, $8D
50         .endif
51
52 msglen = * - errmsg
53
54         .code
55
56 doneirq:
57         ; Check for valid interrupt vector table entry number which
58         ; IS necessary as this gets called even if initirq failed.
59         lda     int_num
60         beq     :+
61
62         ; Deallocate interrupt vector table entry
63         dec     i_param         ; Adjust parameter count
64         jsr     $BF00           ; MLI call entry point
65         .byte   $41             ; Dealloc interrupt
66         .addr   i_param
67 :       rts
68
69         .segment        "LOWCODE"
70
71 intptr:
72         ; ProDOS TechRefMan, chapter 6.2:
73         ; "Each installed routine must begin with a CLD instruction."
74         cld
75
76         ; Call interruptors and check for success
77         jsr     callirq
78         bcc     :+
79
80         ; ProDOS TechRefMan, chapter 6.2:
81         ; "When the routine that can process the interrupt is called, it
82         ;  should ... return (via an RTS) with the carry flag clear."
83         clc
84         rts
85
86         ; ProDOS TechRefMan, chapter 6.2:
87         ; "When a routine that cannot process the interrupt is called,
88         ;  it should return (via an RTS) with the cary flag set ..."
89 :       sec
90         rts
91
92         .data
93
94         ; MLI parameter list for (de)alloc interrupt
95 i_param:.byte   $02             ; param_count
96 int_num:.byte   $00             ; int_num
97         .addr   intptr          ; int_code