]> icculus.org git repositories - btb/d2x.git/blob - unused/bios/mouse.asm
replaced by maths.h
[btb/d2x.git] / unused / bios / mouse.asm
1 ; THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
2 ; SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
3 ; END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
4 ; ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
5 ; IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
6 ; SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
7 ; FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
8 ; CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
9 ; AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
10 ; COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
11 ;***************************************************************************
12 ;***************************************************************************
13 ;*****                                                                 *****
14 ;*****                      M O U S E . A S M                          *****
15 ;*****                                                                 *****
16 ;***** Contains routines for a mouse interface.                        *****
17 ;*****                                                                 *****
18 ;*****                                                                 *****
19 ;***** PROCEDURES                                                      *****
20 ;*****                                                                 *****
21 ;***** VARIABLES                                                       *****
22 ;*****                                                                 *****
23 ;*****                                                                 *****
24 ;***** CONSTANTS                                                       *****
25 ;*****                                                                 *****
26 ;*****                                                                 *****
27 ;***************************************************************************
28 ;***************************************************************************
29
30 .386
31
32 ;************************************************************************
33 ;**************** FLAT MODEL DATA SEGMENT STUFF *************************
34 ;************************************************************************
35
36 _DATA   SEGMENT BYTE PUBLIC USE32 'DATA'
37
38 rcsid   db  "$Id: mouse.asm,v 1.1.1.2 2001-01-19 03:33:49 bradleyb Exp $"
39
40                 MOUSE_EVENT STRUCT 2
41                         MouseDX         dw  ?
42                         MouseDY         dw  ?
43                         MouseButtons    dw  ?
44                         MouseFlags      dw  ?
45                 MOUSE_EVENT ENDS
46
47                 NumberOfButtons dw ?
48
49                 MyEvent             MOUSE_EVENT < >
50                 MyEventHandler      dd  0
51
52
53
54 _DATA   ENDS
55
56 DGROUP  GROUP _DATA
57
58
59 ;************************************************************************
60 ;**************** FLAT MODEL CODE SEGMENT STUFF *************************
61 ;************************************************************************
62
63 _TEXT   SEGMENT BYTE PUBLIC USE32 'CODE'
64
65                 ASSUME  ds:_DATA
66                 ASSUME  cs:_TEXT
67
68 PUBLIC  mouse_init_
69
70 mouse_init_:
71
72                 push    bx
73                 xor     ax, ax      ; Reset mouse
74                 int     33h
75                 mov     NumberOfButtons, bx
76                 pop     bx
77                 or      ax, ax
78                 jnz     present
79                 jmp     absent
80
81
82 present:
83                 mov     ax, 0020h   ; Enable driver
84                 int     33h
85
86                 mov     ax, 1
87                 ret
88
89 absent:
90                 mov     ax, 0
91                 ret
92
93
94
95 PUBLIC  mouse_get_pos_
96
97 mouse_get_pos_:
98
99                 push    eax
100                 push    ebx
101                 push    ecx
102                 push    edx
103
104                 push    eax
105
106                 mov     ax, 03h     ; Get Mouse Position and Button Status
107                 int     33h
108                 ; bx = buttons, cx = x, dx = y
109
110                 pop     eax
111                 mov     [eax], cx
112                 pop     eax
113                 mov     [eax], dx
114                 mov     edx, eax
115
116                 pop     ecx
117                 pop     ebx
118                 pop     eax
119
120                 ret
121
122 PUBLIC  mouse_get_delta_
123
124 mouse_get_delta_:
125
126                 push    eax
127                 push    ebx
128                 push    ecx
129                 push    edx
130
131
132                 push    eax
133
134                 mov     eax, 0bh    ; Read Mouse Motion Counters
135                 int     33h
136
137                 pop     eax
138                 mov     [eax], cx
139                 pop     eax
140                 mov     [eax], dx
141                 mov     edx, eax
142
143                 pop     ecx
144                 pop     ebx
145                 pop     eax
146                 ret
147
148
149 PUBLIC  mouse_get_btns_
150
151 mouse_get_btns_:
152
153                 push    ebx
154                 push    ecx
155                 push    edx
156
157                 mov     ax, 03h     ; Get Mouse Position and Button Status
158                 int     33h
159                 ; bx = buttons, cx = x, dx = y
160
161                 movzx   eax, bx
162
163                 pop     edx
164                 pop     ecx
165                 pop     ebx
166
167                 ret
168
169
170 PUBLIC  mouse_close_
171
172 mouse_close_:
173
174                 push    eax
175                 push    ebx
176                 push    es
177
178                 mov     ax, 01fh    ; Disable mouse driver
179                 int     33h
180
181                 pop     es
182                 pop     ebx
183                 pop     eax
184
185                 ret
186
187 MyHandler:
188
189                 pushad
190                 push    ds
191
192                 push    ax
193                 mov     ax, DGROUP
194                 mov     ds, ax
195                 pop     ax
196
197                 mov     MyEvent.MouseDX, cx
198                 mov     MyEvent.MouseDY, dx
199                 mov     MyEvent.MouseButtons, bx
200                 mov     MyEvent.MouseFlags, ax
201
202                 mov     eax, offset MyEvent
203
204                 call    MyEventHandler
205
206                 pop     ds
207                 popad
208
209                 retf
210
211 PUBLIC  mouse_set_handler_
212
213 mouse_set_handler_:
214
215                 push    eax
216                 push    ebx
217                 push    ecx
218                 push    edx
219                 push    es
220
221                 mov     MyEventHandler, edx
222
223                 mov     ecx, eax    ; Event flags
224                 mov     edx, MyHandler
225                 mov     ax, cs
226                 mov     es, ax
227                 mov     ax, 0Ch     ; Set User-defined Mouse Event Handler
228                 int     33h
229
230                 pop     es
231                 pop     edx
232                 pop     ecx
233                 pop     edx
234                 pop     eax
235
236                 ret
237
238 PUBLIC  mouse_clear_handler_
239
240 mouse_clear_handler_:
241
242                 push    eax
243                 push    ebx
244                 push    ecx
245                 push    edx
246                 push    es
247
248                 mov     MyEventHandler, 0
249
250                 mov     ecx, 0    ; Event flags
251                 mov     edx, MyHandler
252                 mov     ax, cs
253                 mov     es, ax
254                 mov     ax, 0Ch     ; Set User-defined Mouse Event Handler
255                 int     33h
256
257                 pop     es
258                 pop     edx
259                 pop     ecx
260                 pop     edx
261                 pop     eax
262
263                 ret
264
265
266 PUBLIC  mouse_set_limits_
267
268 mouse_set_limits_:
269
270                 ; EAX = minx
271                 ; EDX = miny
272                 ; EBX = maxx
273                 ; ECX = maxy
274
275                 push    edx     ; Save Vertical stuff
276                 push    ecx
277
278                 mov     cx, ax
279                 mov     dx, bx
280                 mov     ax, 7
281                 int     33h
282
283                 pop     edx
284                 pop     ecx
285                 mov     ax, 8
286                 int     33h
287
288                 ret
289
290
291 ;extern void mouse_set_pos( short x, short y);
292
293
294 PUBLIC  mouse_set_pos_
295
296 mouse_set_pos_:
297
298                 ; EAX = x
299                 ; EDX = y
300
301                 push    ecx
302
303                 mov     ecx, eax
304                 mov     eax, 04h
305                 int     33h
306                 pop     ecx
307
308
309                 ret
310
311
312
313 _TEXT   ENDS
314
315
316                 END