home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / mouse03g.zip / MOUSE0G.ASM < prev    next >
Assembly Source File  |  1995-10-18  |  10KB  |  248 lines

  1.         Title   TSR Microsoft Mouse Driver - Simple Version
  2. ;
  3. ;Author: G.B.Gustafson Feb 1992, Oct 1995, gustafson@math.utah.edu
  4. ;
  5. ;REFERENCE: Two similar mouse TSR programs exist:
  6. ;
  7. ;    A similar but different TSR is in MENUMOUS.ASM sources from
  8. ;    jmbj@whuts.ATT.COM (BITTMAN). It is located in archive MENUMOUS.ARC;
  9. ;    see below for source directory on Internet.
  10. ;
  11. ;    The MENUMOUS sources break when used with the BUF160_5.ZIP device
  12. ;    driver that expands the keyboard buffer (it does work with the
  13. ;    default keyboard buffer of length 17). The source below for the
  14. ;    keyboard buffer stuffer works with the BUF160_5.ZIP driver.
  15. ;
  16. ;    A shareware product called ARRMOUSE.ZIP is available on Internet
  17. ;    anonymous FTP to wuarchive.wustl.edu in directory ~/mirrors/msdos.
  18. ;    The author is Seth W. Comstock (Version 1.0, March 1990). It has
  19. ;    some good features and should be investigated.
  20. ;
  21. ;    A cursor + copy + paste routine by Juergen Weber and Grant
  22. ;    Gustafson is available as xPC-Mouse versions 1.0 and 1.1. See
  23. ;    ftp://oak.oakland.edu/simtel/msdos/screen/ and file name
  24. ;    "xpcm*.zip". These are production versions with ASM source and
  25. ;    enough features to keep everyone happy. October 1995.
  26. ;
  27. ;USE: The importance of the sources is educational value:
  28. ;
  29. ;     1. A simple, useful TSR that hooks no interrupt vector.
  30. ;     2. A keyboard buffer routine for stuffing keys. It will work
  31. ;        even if the keyboard buffer has been expanded.
  32. ;     3. Mouse driver example. Safe initialization.
  33. ;        See notes below on the event handler.
  34. ;
  35. ;MOUSE SENSITIVITY. A curious feature in mouse code is sensitivity to
  36. ;movement: settling down on a character is subject to much error. In the
  37. ;code below this problem is attacked.
  38. ;
  39. ;    Ideally, the cursor should lock onto a line and not be bumped off
  40. ;    easily as the cursor scans left and right. Further, up and down
  41. ;    motion should lock the cursor onto a column. I should like to scan
  42. ;    up and down columns of numbers with the mouse exactly as I do with
  43. ;    the cursor keys. The code below is an attempt to realize these
  44. ;    features that falls short of perfection.
  45. ;
  46. ;MOUSE DRIVER DEFAULTS. The TSR resets the mouse driver and but sets no
  47. ;defaults for the mouse controls: X,Y sensitivity, doubler.
  48. ;
  49. ;RELEASE TSR. This TSR contains no code to detect its own presence.
  50. ;Furthermore, it contains no code to release it from memory. Code can be
  51. ;written following the ideas of Al Williams, "DOS 5: A Developers Guide",
  52. ;page 516 (M&T Books 1992). See other sources this package: mouse2g.asm.
  53. ;
  54. ;    It is not safe to simply delete this TSR because of the mouse driver
  55. ;    event handler initialization. However, you can issue a mouse driver
  56. ;    reset and then it can be safely deleted by mark/release or resdel.
  57. ;
  58. ;WARRANTY. This source code carries no warranty. Its intended use is
  59. ;information. If you use it, then it was worth writing down: no
  60. ;permission is needed to copy and use this source. I repeat: this is not
  61. ;a software product, and it is serendipity if it happens to be useful.
  62. ;-GBG
  63. ;
  64. ;=========================Mouse Functions================================
  65. ;Mouse movement is mapped to cursor keys: up,down,left,right.
  66. ;Right button  ==> Esc Key   (ctrl-[, 27)
  67. ;Left button   ==> Enter Key (ctrl-M, 13)
  68. ;Settings here are for Znix mouse with ballistics /m2 /fdefault.pro
  69. ;Other ballistics tried and all are acceptable: /m1, /m3, /m4.
  70. ;Also tested on Merit Mouse Z-1000 (like Znix /m4 no ballistics).
  71. ;========================================================================
  72. ;
  73. code segment
  74.         org 100h
  75.         assume cs:code,ds:code,es:code
  76. begin:  jmp start
  77.  
  78. leftkey                 equ  4b00h
  79. rightkey                equ  4d00h
  80. upkey                   equ  4800h
  81. downkey                 equ  5000h
  82. retkey                  equ  1c0dh
  83. esckey                  equ  011bh
  84.  
  85. mouse                   equ  51         ;interrupt 33h
  86. resetmousedriver        equ   0         ;reset mouse driver
  87. pressmouse              equ   5         ;mouse button press status
  88. mousemotion             equ  11         ;mouse cursor motion
  89. seteventhandler         equ  12         ;set mask and event handler
  90. setsensitivity          equ  15         ;set horiz & vert sensitivity
  91. setdoublespeed          equ  19         ;set double-speed threshold
  92. eventmask               equ  0000000000001011b
  93. ;evenmask bits 0,1,4: movement, left & right press
  94.  
  95. horizontalsensitivity   dw   8          ;8=default mickeys/8 pixels
  96. verticalsensitivity     dw  16          ;16=default mickeys/8 pixels
  97. ;
  98. ;Mouse driver resets to 8 and 16 respectively with function 00h.
  99. ;Znix and Merit both worked well with settings 8/16.
  100. ;
  101.  
  102. horizposition           dw   0          ;store mouse cursor position X
  103. vertposition            dw   0          ;store mouse cursor position Y
  104.  
  105. mouseeventhandler proc far
  106.         push ax
  107.         push bx
  108.         push cx
  109.         push dx
  110.         push di
  111.         push ds                 ;ds=mouse driver data segment
  112.  
  113.         push cs
  114.         pop ds                  ;cs=ds=TSR data segment
  115. ;
  116. ;Press Mouse supplies: BX=button status, CX=X mickeys, DX=Y mickeys
  117. ;                      The signed integers CX, DX measure UP==+, RIGHT==+
  118. ;                      Clears all button counts on each call.
  119. ;
  120.         test ax,010B            ;Left button press?
  121.         jz check_rightbutton    ;No? Then check right button.
  122.         mov cx,retkey           ;Yes. Then plug in RETURN key.
  123.         jmp short dostuffbuffer
  124. check_rightbutton:
  125.         test ax,01000B          ;Right button press?
  126.         jz checkcursor          ;No? Then check cursor keys.
  127.         mov cx,esckey           ;Yes. Then plug in ESC key.
  128. dostuffbuffer:
  129.         call stuffbuffer        ;near function call
  130.         jmp return              ;and outa here
  131. checkcursor:
  132.         mov ax,mousemotion      ;Has the mouse cursor moved?
  133.         int mouse
  134.         mov ax,horizposition    ;save new horizontal position
  135.         add ax,cx               ;cx=X coord supplied by mouse driver
  136.         mov horizposition,ax
  137.         cmp ax,0                ;Has the mouse cursor moved?
  138.         je  motionvertical      ;No change, then check vertical
  139.         jg motionhorizontal     ;Make positive
  140.         not ax
  141. motionhorizontal:
  142.         mov bx,horizontalsensitivity
  143.         cmp ax,bx
  144.         jl motionvertical       ;didn't move enough for a change
  145.         cmp horizposition,0
  146.         mov cx,rightkey
  147.         jg  stuffit1            ;If positive, then stuff cursor Right
  148.         mov cx,leftkey
  149. stuffit1:
  150.         jmp stuffit2
  151. motionvertical:
  152.         mov ax,vertposition     ;save new vertical position
  153.         add ax,dx               ;dx=Y coord supplied by mouse driver
  154.         mov vertposition,ax
  155.         cmp ax,0
  156.         je return               ;no change, all done
  157.         jg testvertsens         ;If positive, then stuff cursor Up
  158.         not ax
  159. testvertsens:
  160.         mov bx,verticalsensitivity
  161.         cmp ax,bx
  162.         jl return               ;didn't move enough for a change
  163.         cmp vertposition,0
  164.         mov cx,downkey
  165.         jg stuffit2
  166.         mov cx,upkey
  167. stuffit2:
  168.         call manystuffbuffer    ;stuff key CX into keyboard buffer
  169.         mov vertposition,0      ;reset vertical saved position
  170.         mov horizposition,0     ;reset horizontal saved position
  171. return:
  172.         pop ds
  173.         pop di
  174.         pop dx
  175.         pop cx
  176.         pop bx
  177.         pop ax
  178.         ret
  179. mouseeventhandler endp
  180.  
  181. manystuffbuffer proc near
  182. ; AX=amount in mickeys mouse cursor has moved.
  183. ; BX=sensitivity in mickeys
  184. ; CX=key scan code to stuff into keyboard buffer
  185. manyloop:
  186.         call stuffbuffer
  187.         sub ax,bx
  188.         dec ax
  189.         cmp ax,bx
  190.         jge manyloop
  191.         ret
  192. manystuffbuffer endp
  193.  
  194. stuffbuffer proc near
  195.         cli                     ;Prevent interrupts from stuffing buffer
  196.         push es                 ;typeahead buffer start at *[0040:0080]
  197.         push si                 ;and end at *[0040:0082].
  198.         push di                 ;At segment 40h and offset 01ah is
  199.         push bx
  200.         mov di,40h              ;the offset into the typeahead buffer
  201.         mov es,di               ;for the character at the head. At
  202.         mov bx,es:[1ch]         ;segment 40h and offset 01ch is the
  203.         mov si,bx               ;offset into the typeahead buffer for
  204.         add bx,2                ;the last character. The buffer is full
  205.         cmp bx,es:[1ah]         ;if *[01ch]+2 == *[01ah].
  206.         je quit                 ;Full? Then don't add any more chars
  207.         cmp bx,es:[82h]         ;Offset less than end of buffer?
  208.         jl isroom               ;Yes. Then go ahead and stuff it.
  209.         mov bx,es:[80h]         ;Else wrap around to buffer start
  210. isroom:
  211.         mov es:[si],cx          ;CX=scan code to be stuffed
  212.         mov es:[1ch],bx         ;BX=new offset to last buffer character
  213. quit:   pop bx
  214.         pop di
  215.         pop si
  216.         pop es
  217.         sti                     ;let other routines stuff the buffer
  218.         ret                     ;near return
  219. stuffbuffer endp
  220.  
  221. endresident label byte
  222. ;
  223. ;All resident code is above this point.
  224. ;All code below this point gets trashed by TSR exit.
  225. ;For simplicity, no unload of 100h PSP area.
  226. ;
  227. start:
  228.         mov ax,resetmousedriver ;reset mouse driver to defaults
  229.         int mouse
  230.         cmp ax,0                ;bx=number of buttons, not used yet
  231.         je nomouse              ;exit if no mouse driver loaded
  232.         mov ax,cs               ;Hook mouse driver to event handler
  233.         mov es,ax               ;es=segment of event handler
  234.         mov dx,offset mouseeventhandler
  235.         mov ax,seteventhandler  ;mouse driver function code
  236.         mov cx,eventmask        ;signal mask for interrupt
  237.         int mouse
  238.         mov es,cs:[2ch]         ;es=environment segment
  239.         mov ah,49h              ;free DOS alloc memory
  240.         int 21h
  241.         lea dx,endresident      ;save resident code & exit.
  242.         int 27h                 ;outdated TSR method used for simplicity
  243. nomouse:
  244.         mov ax,0                ;Failure? Then do normal exit to dos.
  245.         int 21h                 ;don't bother with error message
  246. code    ends
  247.         end begin
  248.