]> git.sur5r.net Git - cc65/blob - libsrc/atari/mcbdefault.s
another small cleanup
[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         ; Patched at runtime
53         cmp     #cursor
54         rts
55
56 setcursor:
57         lda     #cursor
58 setscr: sta     (scrptr),y         ; Patched at runtime
59         rts
60
61 ; ------------------------------------------------------------------------
62
63         .code
64
65 done:
66         rts
67
68 ; Hide the mouse cursor.
69 hide:
70         jsr     getcursor       ; Cursor visible at current position?
71         bne     done            ; No, we're done
72         lda     backup          ; Get character at cursor position
73         jmp     setscr          ; Draw character
74
75 ; Show the mouse cursor.
76 show:
77         jsr     getcursor       ; Cursor visible at current position?
78         beq     done            ; Yes, we're done
79         sta     backup          ; Save character at cursor position
80         jmp     setcursor       ; Draw cursor
81
82
83 ; Move the mouse cursor x position to the value in A/X.
84 movex:
85         cpx     #1
86         ror     a
87         lsr     a               ; convert to character position
88         lsr     a
89         sta     column+1
90         rts
91
92 ; Move the mouse cursor y position to the value in A/X.
93 movey:
94         tax
95         ldy     tmp4            ; mul40 uses tmp4
96         lda     loc_tmp         ; and this local variable
97         pha
98         txa                     ; get parameter back
99         lsr     a               ; convert y position to character line
100         lsr     a
101         lsr     a
102         jsr     mul40
103         clc
104         adc     SAVMSC
105         sta     scrptr
106         txa
107         adc     SAVMSC+1
108         sta     scrptr+1
109         pla
110         sta     loc_tmp
111         sty     tmp4
112         rts