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