]> git.sur5r.net Git - cc65/blob - libsrc/apple2/irq.s
Fixed gcc compiler warning (#867)
[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         .macpack        apple2
13
14         .segment        "ONCE"
15
16 initirq:
17         ; Check for ProDOS
18         lda     __dos_type
19         beq     prterr
20
21         ; Allocate interrupt vector table entry
22         jsr     $BF00           ; MLI call entry point
23         .byte   $40             ; Alloc interrupt
24         .addr   i_param
25         bcs     prterr
26
27         ; Enable interrupts, as old ProDOS versions (i.e. 1.1.1)
28         ; jump to SYS and BIN programs with interrupts disabled.
29         cli
30         rts
31
32         ; Print error message and exit
33 prterr: ldx     #msglen-1
34 :       lda     errmsg,x
35         jsr     $FDED           ; COUT
36         dex
37         bpl     :-
38         jmp     _exit
39
40 errmsg: .ifdef  __APPLE2ENH__
41         scrcode $0D, "tpurretni colla ot deliaF", $0D
42         .else
43         scrcode $0D, "TPURRETNI COLLA OT DELIAF", $0D
44         .endif
45
46 msglen = * - errmsg
47
48         .code
49
50 doneirq:
51         ; Check for valid interrupt vector table entry number which
52         ; IS necessary as this gets called even if initirq failed.
53         lda     int_num
54         beq     :+
55
56         ; Deallocate interrupt vector table entry
57         dec     i_param         ; Adjust parameter count
58         jsr     $BF00           ; MLI call entry point
59         .byte   $41             ; Dealloc interrupt
60         .addr   i_param
61 :       rts
62
63         .segment        "LOWCODE"
64
65 intptr:
66         ; ProDOS TechRefMan, chapter 6.2:
67         ; "Each installed routine must begin with a CLD instruction."
68         cld
69
70         ; Call interruptors and check for success
71         jsr     callirq
72         bcc     :+
73
74         ; ProDOS TechRefMan, chapter 6.2:
75         ; "When the routine that can process the interrupt is called, it
76         ;  should ... return (via an RTS) with the carry flag clear."
77         clc
78         rts
79
80         ; ProDOS TechRefMan, chapter 6.2:
81         ; "When a routine that cannot process the interrupt is called,
82         ;  it should return (via an RTS) with the cary flag set ..."
83 :       sec
84         rts
85
86         .data
87
88         ; MLI parameter list for (de)alloc interrupt
89 i_param:.byte   $02             ; param_count
90 int_num:.byte   $00             ; int_num
91         .addr   intptr          ; int_code