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