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