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