]> git.sur5r.net Git - cc65/blob - libsrc/atari/mcbdefault.s
Change display logic of mouse cursor (hide and show functions).
[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
25 ; ------------------------------------------------------------------------
26
27         .segment        "EXTZP" : zeropage
28 scrptr: .res    2
29
30 ; ------------------------------------------------------------------------
31
32
33         .rodata
34
35         ; Callback structure
36 _mouse_def_callbacks:
37         .addr   hide
38         .addr   show
39         .addr   movex
40         .addr   movey
41
42 ; ------------------------------------------------------------------------
43
44         .data
45
46 cursor = 11                     ; '+' screen code'
47
48 ; setcursor
49
50 getcursor:
51 column: ldy     #$00            ; Patched at runtime
52         lda     (scrptr),y
53         rts
54
55 setcursor:
56 column2:ldy     #$00            ; Patched at runtime
57         sta     (scrptr),y
58         rts
59
60 ; ------------------------------------------------------------------------
61
62         .code
63
64 done:
65         rts
66
67 ; Hide the mouse cursor.
68 hide:
69         jsr     getcursor       ; Get character at cursor position
70         cmp     #cursor         ; "mouse" character
71         bne     overwr          ; no, probably program has overwritten it
72         lda     backup          ; 
73         jmp     setcursor       ; Draw character
74 overwr: sta     backup
75         rts
76
77 ; Show the mouse cursor.
78 show:
79         jsr     getcursor       ; Cursor visible at current position?
80         sta     backup          ; Save character at cursor position
81         lda     #cursor
82         jmp     setcursor       ; Draw cursor
83
84
85 ; Move the mouse cursor x position to the value in A/X.
86 movex:
87         cpx     #1
88         ror     a
89         lsr     a               ; convert to character position
90         lsr     a
91         sta     column+1
92         sta     column2+1
93         rts
94
95 ; Move the mouse cursor y position to the value in A/X.
96 movey:
97         tax
98         ldy     tmp4            ; mul40 uses tmp4
99         lda     loc_tmp         ; and this local variable
100         pha
101         txa                     ; get parameter back
102         lsr     a               ; convert y position to character line
103         lsr     a
104         lsr     a
105         jsr     mul40
106         clc
107         adc     SAVMSC
108         sta     scrptr
109         txa
110         adc     SAVMSC+1
111         sta     scrptr+1
112         pla
113         sta     loc_tmp
114         sty     tmp4
115         rts