]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/mcbdefault.s
Merge pull request #207 from greg-king5/random-seed
[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 hide:
31         ldy     #15
32         sty     IndReg
33
34         ldy     #VIC_SPR_ENA
35         lda     (vic),y
36         and     #MOUSE_SPR_NMASK
37         sta     (vic),y
38
39         ldy     ExecReg
40         sty     IndReg
41         rts
42
43 ; --------------------------------------------------------------------------
44 ; Show the mouse pointer. Always called with interrupts disabled.
45
46 show:
47         ldy     #15
48         sty     IndReg
49
50         ldy     #VIC_SPR_ENA
51         lda     (vic),y
52         ora     #MOUSE_SPR_MASK
53         sta     (vic),y
54
55         ldy     ExecReg
56         sty     IndReg
57         ; Fall through
58
59 ; --------------------------------------------------------------------------
60 ; Prepare to move the mouse pointer. Always called with interrupts disabled.
61
62 prep:
63         ; Fall through
64
65 ; --------------------------------------------------------------------------
66 ; Draw the mouse pointer. Always called with interrupts disabled.
67
68 draw:
69         rts
70
71 ; --------------------------------------------------------------------------
72 ; Move the mouse pointer x position to the value in .XA. Always called with
73 ; interrupts disabled.
74
75 movex:
76         ldy     #15
77         sty     IndReg
78
79 ; Add the x correction; and, set the low byte. That frees .A.
80
81         add     #<24                    ; x correction
82         ldy     #VIC_SPR_X
83         sta     (vic),y
84
85 ; Set the high byte
86
87         ldy     #VIC_SPR_HI_X
88         txa
89         adc     #>24
90         bnz     @L1                     ; Branch if high byte not zero
91         lda     (vic),y                 ; Get high x bits of all sprites
92         and     #MOUSE_SPR_NMASK        ; Clear high bit for sprite
93         sta     (vic),y
94
95 @L0:    ldy     ExecReg
96         sty     IndReg
97         rts
98
99 @L1:    lda     (vic),y                 ; Get high x bits of all sprites
100         ora     #MOUSE_SPR_MASK         ; Set high bit for sprite
101         sta     (vic),y
102         bnz     @L0                     ; Branch always
103
104 ; --------------------------------------------------------------------------
105 ; Move the mouse pointer y position to the value in .XA. Always called with
106 ; interrupts disabled.
107
108 movey:
109         ldy     #15
110         sty     IndReg
111
112         add     #50                     ; y correction (first visible line)
113         ldy     #VIC_SPR_Y
114         sta     (vic),y                 ; Set y position
115
116         ldy     ExecReg
117         sty     IndReg
118         rts
119
120 ; --------------------------------------------------------------------------
121 ; Callback structure
122
123 .rodata
124
125 _mouse_def_callbacks:
126         .addr   hide
127         .addr   show
128         .addr   prep
129         .addr   draw
130         .addr   movex
131         .addr   movey