]> git.sur5r.net Git - cc65/blob - libsrc/atari/mcbdefault.s
Adapt to new mouse driver interface ('prep' and 'draw')
[cc65] / libsrc / atari / mcbdefault.s
1 ;
2 ; Default mouse callbacks for the Ataris
3 ;
4 ; Christian Groessler, 03.01.2014
5 ;
6 ; derived from Apple2 version by
7 ; Oliver Schmidt, 22.09.2005
8 ;
9 ; All functions in this module should be interrupt safe, because they may
10 ; be called from an interrupt handler
11 ;
12
13         .export         _mouse_def_callbacks
14         .importzp       tmp4
15         .import         mul40,loc_tmp
16
17         .include        "atari.inc"
18
19 ; ------------------------------------------------------------------------
20
21         .bss
22
23 backup: .res    1
24 visible:.res    1
25
26 ; ------------------------------------------------------------------------
27
28         .segment        "EXTZP" : zeropage
29 scrptr: .res    2
30
31 ; ------------------------------------------------------------------------
32
33
34         .rodata
35
36         ; Callback structure
37 _mouse_def_callbacks:
38         .addr   hide
39         .addr   show
40         .addr   prep
41         .addr   draw
42         .addr   movex
43         .addr   movey
44
45 ; ------------------------------------------------------------------------
46
47         .data
48
49 cursor = 11                     ; '+' screen code'
50
51 ; setcursor
52
53 getcursor:
54 column: ldy     #$00            ; Patched at runtime
55         lda     (scrptr),y
56         rts
57
58 setcursor:
59 column2:ldy     #$00            ; Patched at runtime
60         sta     (scrptr),y
61         rts
62
63 ; ------------------------------------------------------------------------
64
65         .code
66
67 done:
68         rts
69
70 ; Hide the mouse cursor.
71 hide:
72         dec     visible
73
74 prep:
75         jsr     getcursor       ; Get character at cursor position
76         cmp     #cursor         ; "mouse" character
77         bne     overwr          ; no, probably program has overwritten it
78         lda     backup          ; 
79         jmp     setcursor       ; Draw character
80 overwr: sta     backup
81         rts
82
83 ; Show the mouse cursor.
84 show:
85         inc     visible
86
87 draw:
88         lda     visible
89         beq     done
90         jsr     getcursor       ; Cursor visible at current position?
91         sta     backup          ; Save character at cursor position
92         lda     #cursor
93         jmp     setcursor       ; Draw cursor
94
95
96 ; Move the mouse cursor x position to the value in A/X.
97 movex:
98         cpx     #1
99         ror     a
100         lsr     a               ; convert to character position
101         lsr     a
102         sta     column+1
103         sta     column2+1
104         rts
105
106 ; Move the mouse cursor y position to the value in A/X.
107 movey:
108         tax
109         ldy     tmp4            ; mul40 uses tmp4
110         lda     loc_tmp         ; and this local variable
111         pha
112         txa                     ; get parameter back
113         lsr     a               ; convert y position to character line
114         lsr     a
115         lsr     a
116         jsr     mul40
117         clc
118         adc     SAVMSC
119         sta     scrptr
120         txa
121         adc     SAVMSC+1
122         sta     scrptr+1
123         pla
124         sta     loc_tmp
125         sty     tmp4
126         rts