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