home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
util
/
mous
/
007
/
mouse2g.asm
< prev
next >
Wrap
Assembly Source File
|
1992-05-04
|
15KB
|
356 lines
Title TSR Microsoft Mouse Driver - Full Version
;
;Author: G.B.Gustafson Feb 1992, gustafson@math.utah.edu.Internet.
;
;REFERENCE: Two similar mouse TSR programs exist:
;
; A similar but different TSR is in MENUMOUS.ASM sources from
; jmbj@whuts.ATT.COM (BITTMAN). It is located in archive MENUMOUS.ARC;
; see below for source directory on Internet.
;
; The MENUMOUS sources break when used with the BUF160_5.ZIP device
; driver that expands the keyboard buffer (it does work with the
; default keyboard buffer of length 17). The source below for the
; keyboard buffer stuffer works with the BUF160_5.ZIP driver.
;
; A shareware product called ARRMOUSE.ZIP is available on Internet
; anonymous FTP to wuarchive.wustl.edu in directory ~/mirrors/msdos.
; The author is Seth W. Comstock (Version 1.0, March 1990). It has
; some good features and should be investigated.
;
;USE: The importance of the sources is educational value:
;
; 1. A simple, useful TSR that hooks the 2fh interrupt vector.
; 2. A keyboard buffer routine for stuffing keys. It will work
; even if the keyboard buffer has been expanded.
; 3. Mouse driver example. Safe initialization and shutdown.
; See notes below on the event handler.
;
;MOUSE SENSITIVITY. A curious feature in mouse code is sensitivity to
;movement: settling down on a character is subject to much error. In the
;code below this problem is attacked.
;
; Ideally, the cursor should lock onto a line and not be bumped off
; easily as the cursor scans left and right. Further, up and down
; motion should lock the cursor onto a column. I should like to scan
; up and down columns of numbers with the mouse exactly as I do with
; the cursor keys. The code below is an attempt to realize these
; features that falls short of perfection.
;
;MOUSE DRIVER DEFAULTS. The TSR resets the mouse driver and but sets no
;defaults for the mouse controls: X,Y sensitivity, doubler. If the TSR
;is unloaded, then the mouse driver is again reset to disable the event
;handler hook.
;
;RELEASE TSR. This TSR contains code to detect its own presence.
;Furthermore, it contains code to release it from memory. The code was
;written following the ideas of Al Williams, "DOS 5: A Developers Guide",
;page 516 (M&T Books 1992).
;
; It is not safe to simply delete this TSR because of the mouse driver
; event handler initialization. However, you can issue a mouse driver
; reset and then it can be safely deleted by mark/release or resdel.
;
;WARRANTY. This source code carries no warranty. Its intended use is
;information. If you use it, then it was worth writing down: no
;permission is needed to copy and use this source. I repeat: this is not
;a software product, and it is serendipity if it happens to be useful.
;-GBG
;
;=========================Mouse Functions================================
;Mouse movement is mapped to cursor keys: up,down,left,right.
;Right button ==> Esc Key (ctrl-[, 27)
;Left button ==> Enter Key (ctrl-M, 13)
;Settings here are for Znix mouse with ballistics /m2 /fdefault.pro
;Other ballistics tried and all are acceptable: /m1, /m3, /m4.
;Also tested on Merit Mouse Z-1000 (like Znix /m4 no ballistics).
;========================================================================
;
code segment
org 100h
assume cs:code,ds:code,es:code
begin: jmp start
leftkey equ 4b00h
rightkey equ 4d00h
upkey equ 4800h
downkey equ 5000h
retkey equ 1c0dh
esckey equ 011bh
mouse equ 51 ;interrupt 33h
resetmousedriver equ 0 ;reset mouse driver
pressmouse equ 5 ;mouse button press status
mousemotion equ 11 ;mouse cursor motion
seteventhandler equ 12 ;set mask and event handler
setsensitivity equ 15 ;set horiz & vert sensitivity
setdoublespeed equ 19 ;set double-speed threshold
eventmask equ 0000000000001011b
;evenmask bits 0,1,4: movement, left & right press
horizontalsensitivity dw 8 ;8=default mickeys/8 pixels
verticalsensitivity dw 16 ;16=default mickeys/8 pixels
;
;Mouse driver resets to 8 and 16 respectively with function 00h.
;Merit and Znix both worked well with settings 8,16.
;
horizposition dw 0 ;store mouse cursor position X
vertposition dw 0 ;store mouse cursor position Y
;
mouseeventhandler proc far
sti
push ax
push bx
push cx
push dx
push di
push ds ;ds=mouse driver data segment
push cs
pop ds ;cs=ds=TSR data segment
cld
;
;Press Mouse supplies: BX=button status, CX=X mickeys, DX=Y mickeys.
; CX and DX are signed integers: up==+, right==+.
; Clears all button counts on each call.
;
mov ax,pressmouse ;get status of button press
mov bx,0 ;for left button
int mouse
and ax,1 ;Press left button?
jz check_rightbutton ;No? Then check right button.
mov cx,retkey ;Yes. Then plug in RETURN key.
call stuffbuffer ;near function call
check_rightbutton:
mov ax,pressmouse ;get status of button press
mov bx,2 ;for right button
int mouse
and ax,2 ;press right button?
jz checkcursor ;No? Then check cursor keys.
mov cx,esckey ;Yes. Then plug in ESC key.
call stuffbuffer ;near function call
checkcursor:
mov ax,mousemotion ;Has the mouse cursor moved?
int mouse
mov ax,horizposition ;save new horizontal position
add ax,cx ;cx=X coord supplied by mouse driver
mov horizposition,ax
cmp ax,0 ;Has the mouse cursor moved?
je motionvertical ;No change, then check vertical
jg motionhorizontal ;Make positive
not ax
motionhorizontal:
mov bx,horizontalsensitivity
cmp ax,bx
jl motionvertical ;didn't move enough for a change
cmp horizposition,0
mov cx,rightkey
jg stuffit1 ;If positive, then stuff cursor Right
mov cx,leftkey
stuffit1:
jmp stuffit2 ;Forget about vertical motion!
motionvertical:
mov ax,vertposition ;save new vertical position
add ax,dx ;dx=Y coord supplied by mouse driver
mov vertposition,ax
cmp ax,0
je return ;no change, all done
jg testvertsens ;If positive, then stuff cursor Up
not ax
testvertsens:
mov bx,verticalsensitivity
cmp ax,bx
jl return ;didn't move enough for a change
cmp vertposition,0
mov cx,downkey
jg stuffit2
mov cx,upkey
stuffit2:
call manystuffbuffer ;stuff key CX into keyboard buffer
mov vertposition,0 ;reset vertical saved position
mov horizposition,0 ;reset horizontal saved position
return:
pop ds
pop di
pop dx
pop cx
pop bx
pop ax
ret
mouseeventhandler endp
manystuffbuffer proc near
; AX=amount in mickeys mouse cursor has moved.
; BX=sensitivity in mickeys
; CX=key scan code to stuff into keyboard buffer
manyloop:
call stuffbuffer
sub ax,bx
cmp ax,bx ;Full moves only
jge manyloop
ret
manystuffbuffer endp
stuffbuffer proc near
cli ;Prevent interrupts from stuffing buffer
push es ;typeahead buffer start at *[0040:0080]
push si ;and end at *[0040:0082].