]> git.sur5r.net Git - cc65/blob - libsrc/c128/mcbdefault.s
Fixed gcc compiler warning (#867)
[cc65] / libsrc / c128 / mcbdefault.s
1 ;
2 ; Default mouse callbacks for the C128
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
15         .include        "mouse-kernel.inc"
16         .include        "c128.inc"
17
18         .macpack        generic
19
20 ; Sprite definitions. The first value can be changed to adjust the number
21 ; of the sprite used for the mouse. All others depend on this value.
22 MOUSE_SPR       = 0                             ; Sprite used for the mouse
23 MOUSE_SPR_MEM   = $0E00                         ; Memory location
24 MOUSE_SPR_MASK  = $01 .shl MOUSE_SPR            ; Positive mask
25 MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK)  ; Negative mask
26 VIC_SPR_X       = (VIC_SPR0_X + 2*MOUSE_SPR)    ; Sprite X register
27 VIC_SPR_Y       = (VIC_SPR0_Y + 2*MOUSE_SPR)    ; Sprite Y register
28
29 ; --------------------------------------------------------------------------
30 ; Initialize the mouse sprite.
31
32 .segment        "ONCE"
33
34 initmcb:
35
36 ; Copy the mouse sprite data
37
38         ldx     #64 - 1
39 @L0:    lda     _mouse_def_pointershape,x
40         sta     MOUSE_SPR_MEM,x
41         dex
42         bpl     @L0
43
44 ; Set the mouse sprite pointer
45
46         lda     #<(MOUSE_SPR_MEM / 64)
47         sta     $07F8 + MOUSE_SPR
48
49 ; Set the mouse sprite color
50
51         lda     _mouse_def_pointercolor
52         sta     VIC_SPR0_COLOR + MOUSE_SPR
53         rts
54
55 ; --------------------------------------------------------------------------
56 ; Hide the mouse pointer. Always called with interrupts disabled.
57
58 .code
59
60 hide:
61         lda     #MOUSE_SPR_NMASK
62         and     VIC_SPR_ENA
63         sta     VIC_SPR_ENA
64         rts
65
66 ; --------------------------------------------------------------------------
67 ; Show the mouse pointer. Always called with interrupts disabled.
68
69 show:
70         lda     #MOUSE_SPR_MASK
71         ora     VIC_SPR_ENA
72         sta     VIC_SPR_ENA
73         ; Fall through
74
75 ; --------------------------------------------------------------------------
76 ; Prepare to move the mouse pointer. Always called with interrupts disabled.
77
78 prep:
79         ; Fall through
80
81 ; --------------------------------------------------------------------------
82 ; Draw the mouse pointer. Always called with interrupts disabled.
83
84 draw:
85         rts
86
87 ; --------------------------------------------------------------------------
88 ; Move the mouse pointer X position to the value in a/x. Always called with
89 ; interrupts disabled.
90
91 movex:
92
93 ; Add the X correction and set the low byte. This frees A.
94
95         add     #24                     ; X correction
96         sta     VIC_SPR_X
97
98 ; Set the high byte
99
100         txa
101         adc     #0
102         bne     @L1                     ; Branch if high byte not zero
103         lda     VIC_SPR_HI_X            ; Get high X bits of all sprites
104         and     #MOUSE_SPR_NMASK        ; Clear high bit for sprite
105         sta     VIC_SPR_HI_X
106         rts
107
108 @L1:    lda     VIC_SPR_HI_X            ; Get high X bits of all sprites
109         ora     #MOUSE_SPR_MASK         ; Set high bit for sprite
110         sta     VIC_SPR_HI_X
111         rts
112
113 ; --------------------------------------------------------------------------
114 ; Move the mouse pointer Y position to the value in a/x. Always called with
115 ; interrupts disabled.
116
117 movey:
118         clc
119         ldx     PALFLAG
120         bne     @L2
121         adc     #50                     ; FIXME: Should be NTSC, is PAL value
122         sta     VIC_SPR_Y               ; Set Y position
123         rts
124
125 @L2:    adc     #50                     ; Add PAL correction
126         sta     VIC_SPR_Y               ; Set Y position
127         rts
128
129 ; --------------------------------------------------------------------------
130 ; Callback structure
131
132 .rodata
133
134 _mouse_def_callbacks:
135         .addr   hide
136         .addr   show
137         .addr   prep
138         .addr   draw
139         .addr   movex
140         .addr   movey