]> git.sur5r.net Git - cc65/blob - libsrc/atari/mcbpm.s
- always use page 6 for P/M mouse cursor
[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,7
15
16 ; get mouse shape data
17         .import mouse_pm_bits
18         .import mouse_pm_height
19         .import mouse_pm_hotspot_x
20         .import mouse_pm_hotspot_y
21
22
23 ; P/M definitions. The first value can be changed to adjust the number
24 ; 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 MOUSE_PM_NUM    = 2                             ; P/M used for the mouse
28 MOUSE_PM_BASE   = pm_base                       ; ZP location pointing to the hw area used by the selected P/M
29
30 .if MOUSE_PM_NUM = 4
31 MOUSE_PM_RAW    = 0                             ; MOUSE_PM_RAW is the hardware P/M number for MOUSE_PM_NUM
32 .macro  set_mouse_x
33         ; assume CF = 0
34         sta     HPOSM3
35         adc     #2
36         sta     HPOSM2
37         adc     #2
38         sta     HPOSM1
39         adc     #2
40         sta     HPOSM0
41 .endmacro
42 .else
43 MOUSE_PM_RAW    = MOUSE_PM_NUM + 1
44 .macro  set_mouse_x
45         sta     HPOSP0 + MOUSE_PM_NUM
46 .endmacro
47 .endif
48
49 ; ------------------------------------------------------------------------
50
51         .rodata
52
53         ; Callback structure
54 _mouse_pm_callbacks:
55         .addr   hide
56         .addr   show
57         .addr   prep
58         .addr   draw
59         .addr   movex
60         .addr   movey
61
62 ; ------------------------------------------------------------------------
63
64         .bss
65
66 omy:    .res    1                       ; old Mouse Y position
67 colhlp: .res    1                       ; helper variable to set P/M color
68
69 ; ------------------------------------------------------------------------
70
71         .segment "EXTZP" : zeropage
72
73 pm_base:.res    2
74
75 ; ------------------------------------------------------------------------
76
77         .code
78
79 ; Hide the mouse cursor.
80 hide:   lda     #0
81         sta     GRACTL
82         rts
83
84 ; Show the mouse cursor.
85 show:
86 .if MOUSE_PM_NUM < 4
87         lda     #2
88 .else
89         lda     #1
90 .endif
91         sta     GRACTL
92         ;rts                            ; optimized out
93
94 prep:
95 draw:
96         rts
97
98 ; Move the mouse cursor x position to the value in A/X.
99 movex:  cpx     #1
100         ror     a
101         clc
102         adc     #48
103         sbc     #<(mouse_pm_hotspot_x - 1)
104         set_mouse_x
105         jmp     update_colors
106
107 ; Move the mouse cursor y position to the value in A/X.
108 movey:  clc
109         adc     #32
110         sbc     #<(mouse_pm_hotspot_y - 1)
111         pha
112         lda     omy
113         jsr     clr_pm                  ; remove player at old position
114         jsr     update_colors
115         pla
116         sta     omy
117         ;jmp    set_pm                  ; put player to new position
118         ; fall thru
119
120 ; Set P/M data from 'mouse_pm_bits'
121 set_pm: tay
122         ldx     #0
123 set_l:  lda     mouse_pm_bits,x
124         sta     (MOUSE_PM_BASE),y
125         inx
126         iny
127         beq     set_end
128         cpx     #<mouse_pm_height
129         bcc     set_l
130 set_end:rts
131
132 ; Clear (zero) P/M data
133 clr_pm: ldx     #<mouse_pm_height
134         tay
135         lda     #0
136 clr_l:  sta     (MOUSE_PM_BASE),y
137         iny
138         beq     clr_end
139         dex
140         bne     clr_l
141 clr_end:rts
142
143
144 pm_down = hide
145
146
147 ; this assumes a GRAPHICS 0 screen
148 update_colors:
149         lda     COLOR2                  ; get background color
150         and     #$F0
151         sta     colhlp
152         lda     COLOR1
153         and     #$0F
154         ora     colhlp
155
156 .if MOUSE_PM_NUM = 4
157         sta     PCOLR0
158         sta     PCOLR1
159         sta     PCOLR2
160         sta     PCOLR3
161         sta     SIZEM
162 .else
163         sta     PCOLR0 + MOUSE_PM_NUM
164         sta     SIZEP0 + MOUSE_PM_NUM
165 .endif
166         rts
167
168 ; ------------------------------------------------------------------------
169
170         .segment "INIT"
171
172 pm_init:lda     #0
173         sta     MOUSE_PM_BASE
174         ldx     #6                      ; page 6
175         stx     MOUSE_PM_BASE+1
176         tay
177 @iniloo:sta     (MOUSE_PM_BASE),y
178         iny
179         bne     @iniloo
180
181 .if 0   ; enable if not using page 6 for P/M data
182         lda     MOUSE_PM_BASE+1
183         and     #$F8
184 .endif
185         sta     PMBASE
186
187         lda     #62
188         sta     SDMCTL
189
190         lda     #1 + 16
191         sta     GPRIOR
192
193         jmp     update_colors