]> git.sur5r.net Git - cc65/blob - libsrc/geos/mousesprite/mouse.s
Remove sprite param to mouse_init
[cc65] / libsrc / geos / mousesprite / mouse.s
1 ;
2 ; Maciej 'YTM/Elysium' Witkowiak
3 ;
4 ; 2.7.2001
5 ;
6 ; Wrapper for GEOS standard input device interface
7 ;
8
9         .export         _mouse_init, _mouse_done
10         .export         _mouse_hide, _mouse_show
11         .export         _mouse_box
12         .export         _mouse_pos, _mouse_info
13         .export         _mouse_move, _mouse_buttons
14
15         .import         popa, popsreg, addysp1
16         .importzp       sp, sreg, ptr1
17
18         .include "../inc/const.inc"
19         .include "../inc/jumptab.inc"
20         .include "../inc/geossym.inc"
21
22
23 .code
24
25 ; --------------------------------------------------------------------------
26 ;
27 ; unsigned char __fastcall__ mouse_init (unsigned char port,
28 ;                                        unsigned char type);
29 ;
30
31 _mouse_init:
32         jsr     popa                    ; ignore all parameters
33
34         jsr     StartMouseMode
35         jsr     MouseOff
36
37         lda     #0
38         sta     mouseTop
39         sta     mouseLeft
40         sta     mouseLeft+1
41         lda     #199
42         sta     mouseBottom
43         lda     #<319
44         sta     mouseRight
45         lda     #>319
46         sta     mouseRight+1
47
48         lda     #0
49 ; --------------------------------------------------------------------------
50 ;
51 ; void mouse_done (void);
52 ;
53 _mouse_done:
54         rts
55
56 ; --------------------------------------------------------------------------
57 ;
58 ; void mouse_hide (void);
59 ;
60
61 _mouse_hide = MouseOff
62
63 ; --------------------------------------------------------------------------
64 ;
65 ; void mouse_show (void);
66 ;
67
68 _mouse_show = MouseUp
69
70 ; --------------------------------------------------------------------------
71 ;
72 ; void __fastcall__ mouse_box (int minx, int miny, int maxx, int maxy);
73 ;
74
75 _mouse_box:
76         ldy     #0                      ; Stack offset
77
78         sta     mouseBottom
79
80         lda     (sp),y
81         sta     mouseRight
82         iny
83         lda     (sp),y
84         sta     mouseRight+1            ; maxx
85
86         iny
87         lda     (sp),y
88         sta     mouseTop
89         iny                             ; Skip high byte
90
91         iny
92         lda     (sp),y
93         sta     mouseLeft
94         iny
95         lda     (sp),y
96         sta     mouseLeft+1             ; minx
97
98         jmp     addysp1                 ; Drop params, return
99
100 ; --------------------------------------------------------------------------
101 ;
102 ; void __fastcall__ mouse_pos (struct mouse_pos* pos);
103 ; /* Return the current mouse position */
104 ;
105
106 _mouse_pos:
107         sta     ptr1
108         stx     ptr1+1                  ; Remember the argument pointer
109
110         ldy     #0                      ; Structure offset
111
112         php
113         sei                             ; Disable interrupts
114
115         lda     mouseXPos               ; Transfer the position
116         sta     (ptr1),y
117         lda     mouseXPos+1
118         iny
119         sta     (ptr1),y
120         lda     mouseYPos
121         iny
122         sta     (ptr1),y
123         lda     #$00
124         iny
125         sta     (ptr1),y
126
127         plp                             ; Reenable interrupts
128         rts                             ; Done
129
130 ; --------------------------------------------------------------------------
131 ;
132 ; void __fastcall__ mouse_info (struct mouse_info* info);
133 ; /* Return the state of the mouse buttons and the position of the mouse */
134 ;
135
136 _mouse_info:
137
138 ; We're cheating here to keep the code smaller: The first fields of the
139 ; mouse_info struct are identical to the mouse_pos struct, so we will just
140 ; call _mouse_pos to initialize the struct pointer and fill the position
141 ; fields.
142
143         jsr     _mouse_pos
144
145 ; Fill in the button state
146
147         jsr     _mouse_buttons          ; Will not touch ptr1
148         iny
149         sta     (ptr1),y
150
151         rts
152
153 ; --------------------------------------------------------------------------
154 ;
155 ; void __fastcall__ mouse_move (int x, int y);
156 ;
157
158 _mouse_move:
159         jsr     popsreg                 ; Get X
160         php
161         sei                             ; Disable interrupts
162         sta     mouseYPos
163         lda     sreg
164         ldx     sreg+1
165         sta     mouseXPos
166         stx     mouseXPos+1
167         plp                             ; Enable interrupts
168         rts
169
170 ; --------------------------------------------------------------------------
171 ;
172 ; unsigned char mouse_buttons (void);
173 ;
174
175 _mouse_buttons:
176         lda     pressFlag
177         and     #SET_MOUSE
178         lsr
179         rts
180