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