]> git.sur5r.net Git - cc65/blob - libsrc/c64/mcbdefault.s
atari5200: fix COLOR defines' names
[cc65] / libsrc / c64 / mcbdefault.s
1 ;
2 ; Default mouse callbacks for the C64
3 ;
4 ; Ullrich von Bassewitz, 2004-03-20
5 ;
6 ; All functions in this module should be interrupt safe, because they may
7 ; be called from an interrupt handler
8 ;
9
10         .constructor    initmcb
11         .export         _mouse_def_callbacks
12         .import         _mouse_def_pointershape
13         .import         _mouse_def_pointercolor
14         .import         mcb_spritememory
15         .import         mcb_spritepointer
16
17         .include        "mouse-kernel.inc"
18         .include        "c64.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 this value.
24 MOUSE_SPR       = 0                             ; Sprite used for the mouse
25 MOUSE_SPR_MASK  = $01 .shl MOUSE_SPR            ; Positive mask
26 MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK)  ; Negative mask
27 VIC_SPR_X       = (VIC_SPR0_X + 2*MOUSE_SPR)    ; Sprite X register
28 VIC_SPR_Y       = (VIC_SPR0_Y + 2*MOUSE_SPR)    ; Sprite Y register
29
30 ; --------------------------------------------------------------------------
31 ; Initialize the mouse sprite.
32
33 .segment        "ONCE"
34
35 initmcb:
36
37 ; Make all RAM accessible
38
39         lda     #$30
40         ldy     $01
41         sei
42         sta     $01
43
44 ; Copy the mouse sprite data
45
46         ldx     #64 - 1
47 @L0:    lda     _mouse_def_pointershape,x
48         sta     mcb_spritememory,x
49         dex
50         bpl     @L0
51
52 ; Set the mouse sprite pointer
53
54         lda     #<(mcb_spritememory / 64)
55         sta     mcb_spritepointer + MOUSE_SPR
56
57 ; Restore memory configuration
58
59         sty     $01
60         cli
61
62 ; Set the mouse sprite color
63
64         lda     _mouse_def_pointercolor
65         sta     VIC_SPR0_COLOR + MOUSE_SPR
66         rts
67
68 ; --------------------------------------------------------------------------
69 ; Hide the mouse pointer. Always called with interrupts disabled.
70
71 .code
72
73 hide:
74         lda     #MOUSE_SPR_NMASK
75         and     VIC_SPR_ENA
76         sta     VIC_SPR_ENA
77         rts
78
79 ; --------------------------------------------------------------------------
80 ; Show the mouse pointer. Always called with interrupts disabled.
81
82 show:
83         lda     #MOUSE_SPR_MASK
84         ora     VIC_SPR_ENA
85         sta     VIC_SPR_ENA
86         ; Fall through
87
88 ; --------------------------------------------------------------------------
89 ; Prepare to move the mouse pointer. Always called with interrupts disabled.
90
91 prep:
92         ; Fall through
93
94 ; --------------------------------------------------------------------------
95 ; Draw the mouse pointer. Always called with interrupts disabled.
96
97 draw:
98         rts
99
100 ; --------------------------------------------------------------------------
101 ; Move the mouse pointer X position to the value in a/x. Always called with
102 ; interrupts disabled.
103
104 movex:
105
106 ; Add the X correction and set the low byte. This frees A.
107
108         add     #24                     ; X correction
109         sta     VIC_SPR_X
110
111 ; Set the high byte
112
113         txa
114         adc     #0
115         bne     @L1                     ; Branch if high byte not zero
116         lda     VIC_SPR_HI_X            ; Get high X bits of all sprites
117         and     #MOUSE_SPR_NMASK        ; Clear high bit for sprite
118         sta     VIC_SPR_HI_X
119         rts
120
121 @L1:    lda     VIC_SPR_HI_X            ; Get high X bits of all sprites
122         ora     #MOUSE_SPR_MASK         ; Set high bit for sprite
123         sta     VIC_SPR_HI_X
124         rts
125
126 ; --------------------------------------------------------------------------
127 ; Move the mouse pointer Y position to the value in a/x. Always called with
128 ; interrupts disabled.
129
130 movey:
131         add     #50                     ; Y correction (first visible line)
132         sta     VIC_SPR_Y               ; Set Y position
133         rts
134
135 ; --------------------------------------------------------------------------
136 ; Callback structure
137
138 .rodata
139
140 _mouse_def_callbacks:
141         .addr   hide
142         .addr   show
143         .addr   prep
144         .addr   draw
145         .addr   movex
146         .addr   movey