]> git.sur5r.net Git - cc65/blob - libsrc/geos/mousesprite/mouse.s
Added new mouse functions
[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         popax, 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 sprite,
29 ;                                        unsigned char type);
30 ;
31
32 _mouse_init:
33         jsr     popax                   ; ignore all parameters
34
35         jsr     StartMouseMode
36         jsr     MouseOff
37
38         lda     #0
39         sta     mouseTop
40         sta     mouseLeft
41         sta     mouseLeft+1
42         lda     #199
43         sta     mouseBottom
44         lda     #<319
45         sta     mouseRight
46         lda     #>319
47         sta     mouseRight+1
48
49         lda     #0
50 ; --------------------------------------------------------------------------
51 ;
52 ; void mouse_done (void);
53 ;
54 _mouse_done:
55         rts
56
57 ; --------------------------------------------------------------------------
58 ;
59 ; void mouse_hide (void);
60 ;
61
62 _mouse_hide = MouseOff
63
64 ; --------------------------------------------------------------------------
65 ;
66 ; void mouse_show (void);
67 ;
68
69 _mouse_show = MouseUp
70
71 ; --------------------------------------------------------------------------
72 ;
73 ; void __fastcall__ mouse_box (int minx, int miny, int maxx, int maxy);
74 ;
75
76 _mouse_box:
77         ldy     #0                      ; Stack offset
78
79         sta     mouseBottom
80
81         lda     (sp),y
82         sta     mouseRight
83         iny
84         lda     (sp),y
85         sta     mouseRight+1            ; maxx
86
87         iny
88         lda     (sp),y
89         sta     mouseTop
90         iny                             ; Skip high byte
91
92         iny
93         lda     (sp),y
94         sta     mouseLeft
95         iny
96         lda     (sp),y
97         sta     mouseLeft+1             ; minx
98
99         jmp     addysp1                 ; Drop params, return
100
101 ; --------------------------------------------------------------------------
102 ;
103 ; void __fastcall__ mouse_pos (struct mouse_pos* pos);
104 ; /* Return the current mouse position */
105 ;
106
107 _mouse_pos:
108         sta     ptr1
109         stx     ptr1+1                  ; Remember the argument pointer
110
111         ldy     #0                      ; Structure offset
112
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         cli                             ; 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         sei                             ; Disable interrupts
161         sta     mouseYPos
162         lda     sreg
163         ldx     sreg+1
164         sta     mouseXPos
165         stx     mouseXPos+1
166         cli                             ; Enable interrupts
167         rts
168
169 ; --------------------------------------------------------------------------
170 ;
171 ; unsigned char mouse_buttons (void);
172 ;
173
174 _mouse_buttons:
175         lda     pressFlag
176         and     #SET_MOUSE
177         lsr
178         rts
179