-
Notifications
You must be signed in to change notification settings - Fork 2
/
MOUSE.ASM
589 lines (458 loc) · 22.1 KB
/
MOUSE.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
;
; Mouse.asm - general mouse routines.
; Copyright (C) 2000, 2001 Imre Leber
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; If you have any questions, comments, suggestions, or fixes please
; email me at: [email protected]
;
;**************************************************************************
;*** ToTextCos ***
;***++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++***
;*** Convert to text coordinates. ***
;*** ***
;*** Parameter: %1: coordinate to convert to text coordinate. ***
;**************************************************************************
%macro ToTextCos 1
shr %1, 1
shr %1, 1
shr %1, 1
inc %1
%endmacro
;**************************************************************************
;*** FromTextCos ***
;***++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++***
;*** Convert from text coordinates. ***
;*** ***
;*** Parameter: %1: coordinate to convert to text coordinate. ***
;**************************************************************************
%macro FromTextCos 1
shl %1, 1
shl %1, 1
shl %1, 1
dec %1
%endmacro
;--------------------------------- DATA ----------------------------------
segment _DATA class=DATA
before db 0 ;Remembers wether any of these routines have been
;called before.
mousepresent db 0 ;Remembers wether a mouse driver is present.
;--------------------------------- CODE ----------------------------------
segment _TEXT class=CODE
;=========================================================================
;=== InitMouse ===
;===-------------------------------------------------------------------===
;=== Initialises the mouse driver. ===
;=== ===
;=== int InitMouse (void); ===
;=== ===
;=== Returns: 0 if mouse driver not installed. ===
;=== 1 if mouse driver installed. ===
;=========================================================================
global _CloseMouse
global _InitMouse
_CloseMouse:
_InitMouse:
push es
mov ax, 3533h ; Get vector address of int 33h.
int 21h
xor ax, ax ; AX = 0 for:
; a) false if handler not installed.
; b) to make the init call to int 33h.
mov dx, es
cmp dx, 0 ; Check to be sure that the vector is
jne .installed ; not 0000:0000.
cmp bx, 0
jne .installed
jmp short .EndOfProc ; Exit if 0000:000, return value
; already in ax.
.installed:
int 33h ; Initialise mouse driver.
neg ax
mov [mousepresent], al ; and return wether initialisation
; worked.
.EndOfProc:
pop es
ret
;=========================================================================
;=== MousePresent ===
;===-------------------------------------------------------------------===
;=== Returns wether a mouse driver is installed and if any of these ===
;=== routines haven't been called before initialises the driver. ===
;=== ===
;=== int MousePresent (void); ===
;=== ===
;=== Returns: 0 if mouse not installed (assembly: zf == 1). ===
;=== 1 if mouse installed(assembly: zf == 0). ===
;=========================================================================
global _MousePresent
_MousePresent:
cmp [before], byte 0 ; Check wether we already have
jne .gotit ; initialised.
mov [before], byte 1
call _InitMouse ; Initialise if we haven't done this
; before.
.gotit:
mov al, [mousepresent] ; return wether mouse available.
xor ah, ah
cmp ax, 0
ret
%if 0
;=========================================================================
;=== ShowMouse ===
;===-------------------------------------------------------------------===
;=== Makes the mouse cursor visible. ===
;=== ===
;=== void ShowMouse (void); ===
;=========================================================================
global _ShowMouse
_ShowMouse:
call _MousePresent
jz .EndOfProc ; If mouse available
mov ax, 1 ; show mouse cursor.
int 33h
.EndOfProc:
ret
%endif
%if 0
;=========================================================================
;=== HideMouse ===
;===-------------------------------------------------------------------===
;=== Makes the mouse cursor invisible. ===
;=== ===
;=== void HideMouse (void); ===
;=========================================================================
global _HideMouse
_HideMouse:
call _MousePresent
jz .EndOfProc ; If Mouse available.
mov ax, 2 ; Hide mouse cursor.
int 33h
.EndOfProc:
ret
%endif
%if 0
;=========================================================================
;=== WhereMouse ===
;===-------------------------------------------------------------------===
;=== Returns the status of the buttons and the position of the mouse. ===
;=== ===
;=== int WhereMouse (int* x, int* y); ===
;=== ===
;=== Returns: in x: x position. ===
;=== in y: y position. ===
;=== + status mouse buttons. ===
;=========================================================================
global _WhereMouse
_WhereMouse:
push bp
mov bp, sp
call _MousePresent ; If mouse is not available:
jnz .available
mov bx, [bp+04h] ; Return:
mov [bx], word 0 ; *x = 0
mov bx, [bp+06h]
mov [bx], word 0 ; *y = 0
jmp short .EndOfProc
.available: ; If mouse is available
mov ax, 3 ; Get Mouse cursor position.
int 33h
ToTextCos cx ; Convert to screen coordinates.
ToTextCos dx
mov ax, bx ; Return *x
mov bx, [bp+04h]
mov [bx], cx
mov bx, [bp+06h] ; and *y.
mov [bx], dx
.EndOfProc:
pop bp
ret
%endif
%if 0
;=========================================================================
;=== MouseGotoXY ===
;===-------------------------------------------------------------------===
;=== Sets the position of the mouse cursor. ===
;=== ===
;=== void MouseGotoXY (int x, int y); ===
;=== ===
;=== Parameters: x: x position. ===
;=== y: y position. ===
;=========================================================================
global _MouseGotoXY
_MouseGotoXY:
push bp
mov bp, sp
call _MousePresent ; Exit if mouse not available.
jz .EndOfProc
mov ax, 4
mov cx, [bp+4] ; Get x and y coordinates.
mov dx, [bp+6]
FromTextCos cx ; Convert to mouse coordinates.
FromTextCos dx
int 33h ; Set mouse cursor.
.EndOfProc:
pop bp
ret
%endif
%if 1
;=========================================================================
;=== CountButtonPresses ===
;===-------------------------------------------------------------------===
;=== Returns the number of mouse presses of a certain button and ===
;=== the position of the last press. ===
;=== ===
;=== int CountButtonPresses (int button, int* presses, ===
;=== int* x, int* y); ===
;=== ===
;=== Returns: in x: x position. ===
;=== in y: y position. ===
;=== + status mouse buttons. ===
;=========================================================================
global _CountButtonPresses
_CountButtonPresses:
push bp
mov bp, sp
call _MousePresent ; If mouse not available.
jnz .available
mov ax, 0 ; Return:
mov bx, [bp+06h]
mov [bx], word 0 ; *presses = 0
mov bx, [bp+08h]
mov [bx], word 0 ; *x = 0
mov bx, [bp+0Ah]
mov [bx], word 0 ; *y = 0
jmp short .EndOfProc
.available:
push di
mov ax, 5
mov bx, [bp+04h] ; Count for given button.
int 33h
ToTextCos cx ; Convert return coordinates
ToTextCos dx ; to screen coordinates.
mov di, [bp+06h]
mov [di], bx ; Return press count.
mov di, [bp+08h]
mov [di], cx ; Return x.
mov di, [bp+0Ah]
mov [di], dx ; Return y.
pop di
.EndOfProc:
pop bp
ret
%endif
%if 0
;=========================================================================
;=== CountButtonReleases ===
;===-------------------------------------------------------------------===
;=== Returns the number of mouse releases of a certain button and ===
;=== the position of the last release. ===
;=== ===
;=== int CountButtonReleases (int button, int* releases, ===
;=== int* x, int* y); ===
;=== ===
;=== Returns: in x: x position. ===
;=== in y: y position. ===
;=== + status mouse buttons. ===
;=========================================================================
global _CountButtonReleases
_CountButtonReleases:
push bp
mov bp, sp
call _MousePresent ; If mouse not available.
jnz .available
mov ax, 0 ;Return:
mov bx, [bp+06h] ; *presses = 0
mov [bx], word 0
mov bx, [bp+08h] ; *x = 0
mov [bx], word 0
mov bx, [bp+0Ah] ; *y = 0
mov [bx], word 0
jmp short .EndOfProc
.available:
push di
mov bx, [bp+04h] ; Count for given button.
mov ax, 6
int 33h
ToTextCos cx ; Convert the returned coordinates
ToTextCos dx ; to screen coordinates.
mov di, [bp+06h]
mov [di], bx ; Return release count.
mov di, [bp+08h]
mov [di], cx ; Return x count.
mov di, [bp+0Ah]
mov [di], dx ; Return y count.
pop di
.EndOfProc:
pop bp
ret
%endif
%if 0
;=========================================================================
;=== MouseWindow ===
;===-------------------------------------------------------------------===
;=== Defines the mouse window. ===
;=== ===
;=== void MouseWindow (int x1, int y1, int x2, int y2); ===
;=========================================================================
global _MouseWindow
_MouseWindow:
push bp
mov bp, sp
call _MousePresent ; Exit if mouse is not available.
jz .EndOfProc
mov ax, 7
mov cx, [bp+04h] ; Get x1.
mov dx, [bp+08h] ; Get x2.
FromTextCos cx ; Convert to mouse coordinates.
FromTextCos dx
int 33h ; Set horizontal range.
mov ax, 8
mov cx, [bp+06h] ; Get y1.
mov dx, [bp+0Ah] ; Get y2.
FromTextCos cx ; Convert to mouse coordinates.
FromTextCos dx
int 33h ; Set vertical range.
.EndOfProc:
pop bp
ret
%endif
%if 0
;=========================================================================
;=== DefineTextMouseCursor ===
;===-------------------------------------------------------------------===
;=== Defines the form of the text mouse cursor. ===
;=== ===
;=== void DefineTextMouseCursor(int type, int andmask, int ormask); ===
;=== ===
;=== Parameters: type: software(0), then ===
;=== andmask: AND mask. ===
;=== ormask : OR mask. ===
;=== ===
;=== hardware(1), then ===
;=== andmask: first screen line. ===
;=== ormask: last screen line. ===
;=========================================================================
global _DefineTextMouseCursor
_DefineTextMouseCursor:
push bp
mov bp, sp
call _MousePresent ; Exit if mouse not available.
jz .EndOfProc
mov ax, 0Ah ; Set:
mov bx, [bp+04h] ; type of cursor.
mov cx, [bp+06h] ; and mask.
mov dx, [bp+08h] ; or mask.
int 33h
.EndOfProc:
pop bp
ret
%endif
%if 0
;=========================================================================
;=== GetMouseMoved ===
;===-------------------------------------------------------------------===
;=== Returns the distance between the actual mouse position and the ===
;=== previous position on the screen. ===
;=== ===
;=== void GetMouseMoved (int* distx, int* disty); ===
;=== ===
;=== Returns: in distx: horizontal distance. ===
;=== in disty: vertical distance. ===
;=========================================================================
global _GetMouseMoved
_GetMouseMoved:
push bp
mov bp, sp
call _MousePresent ; If mouse not available
jnz .available
; Return:
mov bx, [bp+04h]
mov [bx], word 0 ; distx = 0
mov bx, [bp+06h]
mov [bx], word 0 ; disty = 0
jmp short .EndOfProc
.available:
mov ax, 0Bh
int 33h
; Return:
mov bx, [bp+04h]
mov [bx], cx ; horizontal distance.
mov bx, [bp+06h]
mov [bx], dx ; vertical distance.
.EndOfProc:
pop bp
ret
%endif
%if 0
;=========================================================================
;=== SetLightPenOn ===
;===-------------------------------------------------------------------===
;=== Turns light pen emulation on. ===
;=== ===
;=== void SetLightPenOn(void); ===
;=========================================================================
global _SetLightPenOn
_SetLightPenOn:
call _MousePresent
jz .EndOfProc ; If it is available,
mov ax, 0Dh ; then turn on pen emulation.
int 33h
.EndOfProc:
ret
%endif
%if 0
;=========================================================================
;=== SetLightPenOff ===
;===-------------------------------------------------------------------===
;=== Turns light pen emulation off. ===
;=== ===
;=== void SetLightPenOff(void); ===
;=========================================================================
global _SetLightPenOff
_SetLightPenOff:
call _MousePresent ; If it is available,
jz .EndOfProc
mov ax, 0Eh ; then turn off pen emulation.
int 33h
.EndOfProc:
ret
%endif
%if 0
;=========================================================================
;=== SetMickey ===
;===-------------------------------------------------------------------===
;=== Sets the speed of the mouse cursor. ===
;=== ===
;=== void SetMickey (int hm, int vm); ===
;=== ===
;=== Parameters: hm: horizontal mickeys. ===
;=== vm: vertical mickeys. ===
;=========================================================================
global _SetMickey
_SetMickey:
push bp
mov bp, sp
call _MousePresent ; If the mouse is available.
jz .EndOfProc
mov cx, [bp+04h] ; Set vertical and
mov dx, [bp+06h] ; horizontal mickey's.
mov ax, 0fh
int 33h
.EndOfProc:
pop bp
ret
%endif