]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/mcbdefault.s
Added SER_ prefix. Whitespace cleanup
[cc65] / libsrc / cbm510 / mcbdefault.s
1 ;
2 ; Default mouse callbacks for the CBM510 (P128)
3 ;
4 ; 2004-03-20, Ullrich von Bassewitz2
5 ; 2013-06-25, Greg King
6 ;
7 ; All functions in this module should be interrupt-safe because they might
8 ; be called from an interrupt handler.
9 ;
10
11         .constructor    initmcb
12         .export         _mouse_def_callbacks
13         .import         _mouse_def_pointershape
14         .import         _mouse_def_pointercolor
15         .import         vic:zp
16
17         .include        "mouse-kernel.inc"
18         .include        "cbm510.inc"
19
20         .macpack        generic
21
22 ; Sprite definitions. The first value can be changed to adjust the number
23 ; of the sprite used for the mouse. All others depend on that value.
24 MOUSE_SPR       = 0                             ; Sprite used for the mouse
25 MOUSE_SPR_MEM   = $F400                         ; Memory location
26 MOUSE_SPR_MASK  = $01 .shl MOUSE_SPR            ; Positive mask
27 MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK)  ; Negative mask
28 VIC_SPR_X       = (VIC_SPR0_X + 2*MOUSE_SPR)    ; Sprite X register
29 VIC_SPR_Y       = (VIC_SPR0_Y + 2*MOUSE_SPR)    ; Sprite Y register
30
31 ; --------------------------------------------------------------------------
32 ; Initialize the mouse sprite.
33
34 .segment        "ONCE"
35
36 initmcb:
37
38 ; Copy the mouse sprite data
39
40         ldx     #64 - 1
41 @L0:    lda     _mouse_def_pointershape,x
42         sta     MOUSE_SPR_MEM,x
43         dex
44         bpl     @L0
45
46 ; Set the mouse sprite pointer
47
48         lda     #<(MOUSE_SPR_MEM / 64)
49         sta     $F3F8 + MOUSE_SPR
50
51 ; Set the mouse sprite color
52
53         ldx     IndReg
54         lda     #15
55         sta     IndReg
56
57         lda     _mouse_def_pointercolor
58         ldy     #VIC_SPR0_COLOR + MOUSE_SPR
59         sta     (vic),y
60
61         stx     IndReg
62         rts
63
64 ; --------------------------------------------------------------------------
65 ; Hide the mouse pointer. Always called with interrupts disabled.
66
67 .code
68
69 hide:
70         ldy     #15
71         sty     IndReg
72
73         ldy     #VIC_SPR_ENA
74         lda     (vic),y
75         and     #MOUSE_SPR_NMASK
76         sta     (vic),y
77
78         ldy     ExecReg
79         sty     IndReg
80         rts
81
82 ; --------------------------------------------------------------------------
83 ; Show the mouse pointer. Always called with interrupts disabled.
84
85 show:
86         ldy     #15
87         sty     IndReg
88
89         ldy     #VIC_SPR_ENA
90         lda     (vic),y
91         ora     #MOUSE_SPR_MASK
92         sta     (vic),y
93
94         ldy     ExecReg
95         sty     IndReg
96         ; Fall through
97
98 ; --------------------------------------------------------------------------
99 ; Prepare to move the mouse pointer. Always called with interrupts disabled.
100
101 prep:
102         ; Fall through
103
104 ; --------------------------------------------------------------------------
105 ; Draw the mouse pointer. Always called with interrupts disabled.
106
107 draw:
108         rts
109
110 ; --------------------------------------------------------------------------
111 ; Move the mouse pointer x position to the value in .XA. Always called with
112 ; interrupts disabled.
113
114 movex:
115         ldy     #15
116         sty     IndReg
117
118 ; Add the x correction; and, set the low byte. That frees .A.
119
120         add     #<24                    ; x correction
121         ldy     #VIC_SPR_X
122         sta     (vic),y
123
124 ; Set the high byte
125
126         ldy     #VIC_SPR_HI_X
127         txa
128         adc     #>24
129         bnz     @L1                     ; Branch if high byte not zero
130         lda     (vic),y                 ; Get high x bits of all sprites
131         and     #MOUSE_SPR_NMASK        ; Clear high bit for sprite
132         sta     (vic),y
133
134 @L0:    ldy     ExecReg
135         sty     IndReg
136         rts
137
138 @L1:    lda     (vic),y                 ; Get high x bits of all sprites
139         ora     #MOUSE_SPR_MASK         ; Set high bit for sprite
140         sta     (vic),y
141         bnz     @L0                     ; Branch always
142
143 ; --------------------------------------------------------------------------
144 ; Move the mouse pointer y position to the value in .XA. Always called with
145 ; interrupts disabled.
146
147 movey:
148         ldy     #15
149         sty     IndReg
150
151         add     #50                     ; y correction (first visible line)
152         ldy     #VIC_SPR_Y
153         sta     (vic),y                 ; Set y position
154
155         ldy     ExecReg
156         sty     IndReg
157         rts
158
159 ; --------------------------------------------------------------------------
160 ; Callback structure
161
162 .rodata
163
164 _mouse_def_callbacks:
165         .addr   hide
166         .addr   show
167         .addr   prep
168         .addr   draw
169         .addr   movex
170         .addr   movey