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