]> git.sur5r.net Git - cc65/blob - libsrc/atari/mcbpm.s
Fixed _textcolor definition.
[cc65] / libsrc / atari / mcbpm.s
1 ;
2 ; P/M mouse callbacks for the Ataris
3 ;
4 ; Christian Groessler, 11.04.2014
5 ;
6 ; All functions in this module should be interrupt safe, because they may
7 ; be called from an interrupt handler
8 ;
9
10         .include        "atari.inc"
11         .importzp       sp
12         .export         _mouse_pm_callbacks
13         .constructor    pm_init, 27
14         .destructor     pm_down
15
16 ; get mouse shape data
17         .import   mouse_pm_bits
18         .importzp mouse_pm_height
19         .importzp mouse_pm_hotspot_x
20         .importzp mouse_pm_hotspot_y
21
22
23 ; P/M definitions. The MOUSE_PM_NUM value can be changed to adjust the
24 ; number of the P/M used for the mouse. All others depend on this value.
25 ; Valid P/M numbers are 0 to 4. When 4 is used, the missiles are used
26 ; as a player.
27 .ifdef USE_PAGE6
28 MOUSE_PM_NUM    = 2                             ; P/M used for the mouse
29                                                 ; This cannot be changed since only player #2 uses the memory at $600.
30 .else
31 MOUSE_PM_NUM    = 4                             ; P/M used for the mouse
32                                                 ; Using player #4 (missiles) wastes the least amount of memory on the
33                                                 ; atari target, since top of memory is typically at $xC20, and the
34                                                 ; missiles use the space at $xB00-$xBFF.
35                                                 ; On the atarixl target this configuration (not using page 6) is not
36                                                 ; really satisfying since the top of memory typically lies beneath
37                                                 ; the ROM and there is flickering visible while the ROM is banked in.
38 .endif
39 MOUSE_PM_BASE   = pm_base                       ; ZP location pointing to the hw area used by the selected P/M
40
41 .if MOUSE_PM_NUM = 4
42 MOUSE_PM_RAW    = 0                             ; MOUSE_PM_RAW is the hardware P/M number for MOUSE_PM_NUM
43 .macro  set_mouse_x
44         ; assume CF = 0
45         sta     HPOSM3
46         adc     #2
47         sta     HPOSM2
48         adc     #2
49         sta     HPOSM1
50         adc     #2
51         sta     HPOSM0
52 .endmacro
53 .else
54 MOUSE_PM_RAW    = MOUSE_PM_NUM + 1
55 .macro  set_mouse_x
56         sta     HPOSP0 + MOUSE_PM_NUM
57 .endmacro
58 .endif
59
60 ; ------------------------------------------------------------------------
61
62         .rodata
63
64         ; Callback structure
65 _mouse_pm_callbacks:
66         .addr   hide
67         .addr   show
68         .addr   prep
69         .addr   draw
70         .addr   movex
71         .addr   movey
72
73 ; ------------------------------------------------------------------------
74
75         .bss
76
77 omy:    .res    1                       ; old Mouse Y position
78 colhlp: .res    1                       ; helper variable to set P/M color
79
80 ; ------------------------------------------------------------------------
81
82         .segment "EXTZP" : zeropage
83
84 pm_base:.res    2
85
86 ; ------------------------------------------------------------------------
87
88         .code
89
90 ; Hide the mouse cursor.
91 hide:   lda     #0
92         sta     GRACTL
93         rts
94
95 ; Show the mouse cursor.
96 show:
97 .if MOUSE_PM_NUM < 4
98         lda     #2
99 .else
100         lda     #1
101 .endif
102         sta     GRACTL
103         jmp     update_colors
104
105 prep:
106 draw:
107         rts
108
109 ; Move the mouse cursor x position to the value in A/X.
110 movex:  cpx     #1
111         ror     a
112         clc
113         adc     #48
114         sbc     #(mouse_pm_hotspot_x - 1) & $FF
115         set_mouse_x
116         jmp     update_colors
117
118 ; Move the mouse cursor y position to the value in A/X.
119 movey:  clc
120         adc     #32
121         sbc     #(mouse_pm_hotspot_y - 1) & $FF
122         pha
123         lda     omy
124         jsr     clr_pm                  ; remove player at old position
125         jsr     update_colors
126         pla
127         sta     omy
128         ;jmp    set_pm                  ; put player to new position
129         ; fall thru
130
131 ; Set P/M data from 'mouse_pm_bits'
132 set_pm: tay
133         ldx     #0
134 set_l:  lda     mouse_pm_bits,x
135         sta     (MOUSE_PM_BASE),y
136         inx
137         iny
138         beq     set_end
139         cpx     #mouse_pm_height
140         bcc     set_l
141 set_end:rts
142
143 ; Clear (zero) P/M data
144 clr_pm: ldx     #mouse_pm_height
145         tay
146         lda     #0
147 clr_l:  sta     (MOUSE_PM_BASE),y
148         iny
149         beq     clr_end
150         dex
151         bne     clr_l
152 clr_end:rts
153
154
155 pm_down = hide
156
157
158 ; this assumes a GRAPHICS 0 screen
159 update_colors:
160         lda     COLOR2                  ; get background color
161         and     #$F0
162         sta     colhlp
163         lda     COLOR1
164         and     #$0F
165         ora     colhlp
166
167 .if MOUSE_PM_NUM = 4
168         sta     PCOLR0
169         sta     PCOLR1
170         sta     PCOLR2
171         sta     PCOLR3
172         lda     #0
173         sta     SIZEM
174 .else
175         sta     PCOLR0 + MOUSE_PM_NUM
176         lda     #0
177         sta     SIZEP0 + MOUSE_PM_NUM
178 .endif
179         rts
180
181 ; ------------------------------------------------------------------------
182
183         .segment "ONCE"
184
185 pm_init:
186         lda     #0
187
188 .ifdef USE_PAGE6
189
190         sta     MOUSE_PM_BASE
191         ldx     #6                      ; page 6
192         stx     MOUSE_PM_BASE+1
193
194 .else
195
196 ; use top of memory and lower sp accordingly
197         sta     sp
198         sta     MOUSE_PM_BASE
199         lda     sp+1
200         and     #7                      ; offset within 2K
201         cmp     #3 + MOUSE_PM_RAW + 1   ; can we use it?
202         bcc     @decr                   ; no
203
204         lda     sp+1
205         and     #$F8
206 @set:   adc     #3 + MOUSE_PM_RAW - 1   ; CF is set, so adding MOUSE_PM_RAW + 3
207         sta     MOUSE_PM_BASE+1
208         sta     sp+1
209         bne     @cont                   ; jump always
210
211 @decr:  lda     sp+1
212         and     #$F8
213         sbc     #8 - 1                  ; CF is clear, subtracts 8
214         bcs     @set                    ; jump always
215
216 @cont:  lda     #0
217
218 .endif
219
220         tay
221 @iniloo:sta     (MOUSE_PM_BASE),y
222         iny
223         bne     @iniloo
224
225 .ifndef USE_PAGE6
226         lda     MOUSE_PM_BASE+1
227         and     #$F8
228 .endif
229         sta     PMBASE
230
231         lda     #62
232         sta     SDMCTL
233
234         lda     #1
235         sta     GPRIOR
236
237         jmp     update_colors