home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 26
/
CD_ASCQ_26_1295.iso
/
vrac
/
mouse03g.zip
/
MOUSE0G.ASM
< prev
next >
Wrap
Assembly Source File
|
1995-10-18
|
10KB
|
248 lines
Title TSR Microsoft Mouse Driver - Simple Version
;
;Author: G.B.Gustafson Feb 1992, Oct 1995, gustafson@math.utah.edu
;
;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.
;
; A cursor + copy + paste routine by Juergen Weber and Grant
; Gustafson is available as xPC-Mouse versions 1.0 and 1.1. See
; ftp://oak.oakland.edu/simtel/msdos/screen/ and file name
; "xpcm*.zip". These are production versions with ASM source and
; enough features to keep everyone happy. October 1995.
;
;USE: The importance of the sources is educational value:
;
; 1. A simple, useful TSR that hooks no 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.
; 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.
;
;RELEASE TSR. This TSR contains no code to detect its own presence.
;Furthermore, it contains no code to release it from memory. Code can be
;written following the ideas of Al Williams, "DOS 5: A Developers Guide",
;page 516 (M&T Books 1992). See other sources this package: mouse2g.asm.
;
; 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.
;Znix and Merit 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
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
;
;Press Mouse supplies: BX=button status, CX=X mickeys, DX=Y mickeys
; The signed integers CX, DX measure UP==+, RIGHT==+
; Clears all button counts on each call.
;
test ax,010B ;Left button press?
jz check_rightbutton ;No? Then check right button.
mov cx,retkey ;Yes. Then plug in RETURN key.
jmp short dostuffbuffer
check_rightbutton:
test ax,01000B ;Right button press?
jz checkcursor ;No? Then check cursor keys.
mov cx,esckey ;Yes. Then plug in ESC key.
dostuffbuffer:
call stuffbuffer ;near function call
jmp return ;and outa here
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
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
dec ax
cmp ax,bx
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].
push di ;At segment 40h and offset 01ah is
push bx
mov di,40h ;the offset into the typeahead buffer
mov es,di ;for the character at the head. At
mov bx,es:[1ch] ;segment 40h and offset 01ch is the
mov si,bx ;offset into the typeahead buffer for
add bx,2 ;the last character. The buffer is full
cmp bx,es:[1ah] ;if *[01ch]+2 == *[01ah].
je quit ;Full? Then don't add any more chars
cmp bx,es:[82h] ;Offset less than end of buffer?
jl isroom ;Yes. Then go ahead and stuff it.
mov bx,es:[80h] ;Else wrap around to buffer start
isroom:
mov es:[si],cx ;CX=scan code to be stuffed
mov es:[1ch],bx ;BX=new offset to last buffer character
quit: pop bx
pop di
pop si
pop es
sti ;let other routines stuff the buffer
ret ;near return
stuffbuffer endp
endresident label byte
;
;All resident code is above this point.
;All code below this point gets trashed by TSR exit.
;For simplicity, no unload of 100h PSP area.
;
start:
mov ax,resetmousedriver ;reset mouse driver to defaults
int mouse
cmp ax,0 ;bx=number of buttons, not used yet
je nomouse ;exit if no mouse driver loaded
mov ax,cs ;Hook mouse driver to event handler
mov es,ax ;es=segment of event handler
mov dx,offset mouseeventhandler
mov ax,seteventhandler ;mouse driver function code
mov cx,eventmask ;signal mask for interrupt
int mouse
mov es,cs:[2ch] ;es=environment segment
mov ah,49h ;free DOS alloc memory
int 21h
lea dx,endresident ;save resident code & exit.
int 27h ;outdated TSR method used for simplicity
nomouse:
mov ax,0 ;Failure? Then do normal exit to dos.
int 21h ;don't bother with error message
code ends
end begin