]> git.sur5r.net Git - cc65/blob - libsrc/apple2/mcbdefault.s
Simplify code generated for the ?: operator when type conversion code for the
[cc65] / libsrc / apple2 / mcbdefault.s
1 ;
2 ; Default mouse callbacks for the Apple II
3 ;
4 ; Oliver Schmidt, 22.09.2005
5 ;
6 ; All functions in this module should be interrupt safe, because they may
7 ; be called from an interrupt handler
8 ;
9
10         .ifdef  __APPLE2ENH__
11         .constructor    initmcb
12         .endif
13         .export         _mouse_def_callbacks
14         
15         .include        "apple2.inc"
16
17 ; ------------------------------------------------------------------------
18
19         .bss
20         
21 backup: .res    1
22
23 ; ------------------------------------------------------------------------
24
25         .rodata
26
27         ; Callback structure
28 _mouse_def_callbacks:
29         .addr   hide
30         .addr   show
31         .addr   movex
32         .addr   movey
33
34 ; ------------------------------------------------------------------------
35
36         .segment        "INIT"
37
38         .ifdef  __APPLE2ENH__
39 initmcb:
40         lda     ALTCHARSET      ; Alternate charset switched in?
41         bpl     :+              ; No, normal charset
42         lda     #'B'            ; MouseText character
43         sta     cmpcur+1
44         sta     getcur+1
45 :       rts
46         .endif
47
48 ; ------------------------------------------------------------------------
49
50         .data
51
52 getcursor:
53         .ifdef  __APPLE2ENH__
54         bit     RD80VID         ; In 80 column mode?
55         bpl     column          ; No, skip bank switching
56 switch: bit     LOWSCR          ; Patched at runtime
57         .endif
58 column: ldx     #$00            ; Patched at runtime
59 getscr: lda     $0400,x         ; Patched at runtime
60 cmpcur: cmp     #'+' | $40      ; Possibly patched by initialization
61         rts
62
63 setcursor:
64 getcur: lda     #'+' | $40      ; Possibly patched by initialization
65 setscr: sta     $0400,x         ; Patched at runtime
66         .ifdef  __APPLE2ENH__
67         bit     LOWSCR          ; Doesn't hurt in 40 column mode
68         .endif
69         rts
70
71 ; ------------------------------------------------------------------------
72
73         .code
74
75 done:
76         .ifdef  __APPLE2ENH__
77         bit     LOWSCR          ; Doesn't hurt in 40 column mode
78         .endif
79         rts
80
81 ; Hide the mouse cursor.
82 hide:
83         jsr     getcursor       ; Cursor visible at current position?
84         bne     done            ; No, we're done
85         lda     backup          ; Get character at cursor position
86         jmp     setscr          ; Draw character
87
88 ; Show the mouse cursor.
89 show:
90         jsr     getcursor       ; Cursor visible at current position?
91         beq     done            ; Yes, we're done
92         sta     backup          ; Save character at cursor position
93         jmp     setcursor       ; Draw cursor
94
95 ; Move the mouse cursor x position to the value in A/X.
96 movex:
97         dex                     ; Is position [256..279]?
98         bmi     :+              ; No, start with column 0
99         clc
100         adc     #$0100 .MOD 7   ; Bias position
101         ldx     #$0100 / 7 - 1  ; Bias column
102 :       sec
103 :       sbc     #7              ; 280 positions / 40 columns
104         inx
105         bcs     :-
106         stx     column+1
107         .ifdef  __APPLE2ENH__
108         adc     #7 / 2          ; Left or right half of 40-col column?
109         ldx     #<LOWSCR        ; Columns 1,3,5..79
110         bcs     :+
111         .assert LOWSCR + 1 = HISCR, error
112         inx                     ; Columns 0,2,4..78
113 :       stx     switch+1
114         .endif
115         rts
116
117 ; Move the mouse cursor y position to the value in A/X.
118 movey:
119         tax                     ; ABCDExxx
120         lsr                     ; 0ABCDExx
121         lsr                     ; 00ABCDEx
122         lsr                     ; 000ABCDE
123         sta     getscr+1
124         lsr                     ; 0000ABCD
125         and     #%00000011      ; 000000CD
126         ora     #>$0400         ; 000001CD
127         sta     getscr+2
128         sta     setscr+2
129         txa                     ; ABCDExxx
130         ror                     ; EABCDExx
131         and     #%11100000      ; EAB00000
132         ora     getscr+1        ; EABABCDE
133         and     #%11111000      ; EABAB000
134         sta     getscr+1
135         sta     setscr+1
136         rts