]> git.sur5r.net Git - cc65/blob - libsrc/c128/mcbdefault.s
Merge https://github.com/cc65/cc65 into c1p
[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 ; --------------------------------------------------------------------------
26 ; Hide the mouse pointer. Always called with interrupts disabled.
27
28 hide:
29         lda     #MOUSE_SPR_NMASK
30         and     VIC_SPR_ENA
31         sta     VIC_SPR_ENA
32         rts
33
34 ; --------------------------------------------------------------------------
35 ; Show the mouse pointer. Always called with interrupts disabled.
36
37 show:
38         lda     #MOUSE_SPR_MASK
39         ora     VIC_SPR_ENA
40         sta     VIC_SPR_ENA
41         ; Fall through
42
43 ; --------------------------------------------------------------------------
44 ; Prepare to move the mouse pointer. Always called with interrupts disabled.
45
46 prep:
47         ; Fall through
48
49 ; --------------------------------------------------------------------------
50 ; Draw the mouse pointer. Always called with interrupts disabled.
51
52 draw:
53         rts
54
55 ; --------------------------------------------------------------------------
56 ; Move the mouse pointer X position to the value in a/x. Always called with
57 ; interrupts disabled.
58
59 movex:
60
61 ; Add the X correction and set the low byte. This frees A.
62
63         add     #24                     ; X correction
64         sta     VIC_SPR_X
65
66 ; Set the high byte
67
68         txa
69         adc     #0
70         bne     @L1                     ; Branch if high byte not zero
71         lda     VIC_SPR_HI_X            ; Get high X bits of all sprites
72         and     #MOUSE_SPR_NMASK        ; Clear high bit for sprite
73         sta     VIC_SPR_HI_X
74         rts
75
76 @L1:    lda     VIC_SPR_HI_X            ; Get high X bits of all sprites
77         ora     #MOUSE_SPR_MASK         ; Set high bit for sprite
78         sta     VIC_SPR_HI_X
79         rts
80
81 ; --------------------------------------------------------------------------
82 ; Move the mouse pointer Y position to the value in a/x. Always called with
83 ; interrupts disabled.
84
85 movey:
86         clc
87         ldx     PALFLAG
88         bne     @L2
89         adc     #50                     ; FIXME: Should be NTSC, is PAL value
90         sta     VIC_SPR_Y               ; Set Y position
91         rts
92
93 @L2:    adc     #50                     ; Add PAL correction
94         sta     VIC_SPR_Y               ; Set Y position
95         rts
96
97 ; --------------------------------------------------------------------------
98 ; Callback structure
99
100 .rodata
101
102 _mouse_def_callbacks:
103         .addr   hide
104         .addr   show
105         .addr   prep
106         .addr   draw
107         .addr   movex
108         .addr   movey