home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / KMOUSE10.ZIP / KEYMOUS.ASM < prev    next >
Assembly Source File  |  1989-10-02  |  8KB  |  239 lines

  1. ;KeyMous.ASM
  2. ; mouse driver for Turbo Pascal
  3. ;Copyright 1989
  4. ;by Kenneth A. Hill, P.E.
  5.  
  6. MouseInt    Equ    33h        ;Mouse interrupt
  7.  
  8. MoveRight    Equ    01h        ;right motion byte mask
  9. MoveLeft    Equ    02h        ;left motion mask
  10. MoveDown    Equ    04h        ;down motion mask
  11. MoveUp        Equ    08h        ;up motion mask
  12.  
  13. Bios_Data    Equ    40h        ;Bios data Segment
  14. Buffer_Head    Equ    1Ah        ;offset to keyboard buffer head
  15. Buffer_Tail    Equ    Buffer_Head+2    ;offset to buffer tail
  16. Buffer_Start    Equ    80h        ;starting keyboard buffer address offset
  17. Buffer_End    Equ    Buffer_Start+2    ;ending Kb Buffer addr offset
  18.  
  19. data        segment byte public    ;Pascal variables
  20.         Extrn    LKey:Word
  21.         Extrn    RKey:Word
  22.         Extrn    DKey:Word
  23.         Extrn    UKey:Word
  24.         Extrn    LBKey:Word
  25.         Extrn    RBKey:Word
  26.                 Extrn   MBKey:Word
  27.         Extrn    VDly:Word
  28.                 Extrn   HDly:Word
  29.                 Extrn    Msk : Word
  30.                 Extrn    MouseMotion:Byte
  31.         Extrn    VCount : Word
  32.         Extrn    HCount : Word
  33.  
  34.     VFlag    DW    0        ;Word for +/- V. movem't flag
  35.     HFlag    DW    0        ;Word for +/- H. Movem't flag
  36.     Evnts    DW    ?        ;Event storage (AX)
  37.     Btns    DW    ?        ;Button storage (BX)
  38.     XCoord    DW    ?        ;X-coord storage (CX)
  39.     YCoord    DW    ?        ;Y-coord storage (DX)
  40.     VMicks    DW    ?        ;V Mickey count (SI)
  41.     HMicks    DW    ?        ;H Mickey count (DI)
  42.     MousDat DW    ?        ;Mouse DS
  43.  
  44. Data        Ends
  45.  
  46. code        segment byte public
  47.          assume cs:code,DS:DATA
  48.         PUBLIC MousKey
  49. ;
  50. ;
  51. ;--------------------------------------------------------------------------
  52. ;MousKey subroutine is handed control by the mouse driver when its mask matches
  53. ;a mouse action.
  54. ;  At Entry Registers are:
  55. ;    AX     Event Flags (same format as mask)
  56. ;    BX    Button State
  57. ;    CX    X pointer coordinate
  58. ;    DX    Y pointer coordinate
  59. ;    SI    last raw vertical mickey count
  60. ;    DI    last raw horizontal mickey count
  61. ;    DS    mouse driver data segment! (Mouse.Com's or Mouse.Sys's)
  62. ;--------------------------------------------------------------------------
  63. MousKey        proc far                ;Must be far proc for Mouse driver.
  64. ;
  65. ;Set up our data segment & save mouse environ for genius mouse
  66. ;
  67.         Mov  Evnts,AX        ;save AX
  68.         Mov  Btns,BX        ;Save BX
  69.         Mov  XCoord,CX        ;Save CX
  70.         Mov  YCoord,DX        ;SAve DX
  71.         Mov  VMicks,SI        ;Save SI
  72.         Mov  HMicks,DI        ;Save DI
  73.         Mov  MousDat,DS        ;Save DS
  74.         mov  BX,Seg Data    ;Set up our data segment
  75.         mov  DS,BX        ;in DS
  76.         Mov  BX,Btns        ;Restore BX
  77. ;
  78. ;Determine which event occurred and branch accordingly
  79. ;
  80.          And  AX,Msk        ;clear unused bits
  81.         test AX,1        ;was there movement?
  82.         Jnz  Moved        ;yes, then branch
  83.         Jmp  CheckButtons    ;no, check for button action
  84. ;
  85. ;Respond to motion
  86. ;
  87. Moved:
  88.         Mov HFlag,0        ;0 flag registers
  89.         Mov VFlag,0        ;
  90.         mov ax,11        ;function 11 (read motion counters)
  91.         int MouseInt        ;read motion counters
  92.                     ;CX = mickeys moved horiz
  93.                     ;DX = mickeys moved vertically
  94.                     ;positive if right or DOWN!
  95.         cmp cx,0        ;horizontal motion positive?
  96.         jge  Moved1        ;yes, then jump
  97.         Inc  HFlag        ;no, set hflag
  98.         Neg  CX            ;set CX to positive count
  99. Moved1:        Cmp  DX,0        ;Vertical motion positive?
  100.         JGE    Moved2        ;Yes, then jump
  101.         Inc    VFlag        ;No, then set VFlag
  102.         Neg    DX        ;and set DX to positive count
  103. Moved2:        Cmp    CX,DX        ;which motion was it?
  104.         JAE    MovedH        ;  Jump if horizontal
  105.                 Jmp  MovedV             ; Else process vert.
  106. MovedH:                                 ;yes, process horiz.
  107.                 Mov BX,HCount        ;check H Delay
  108.                 Dec BX            ;decrement the counter
  109.                 Mov HCount,BX        ;save the counter
  110.                 JZ MovedH0        ;continue if 0
  111.                 Ret            ;if not
  112. MovedH0:        Mov BX,HDly        ;get Horiz delay
  113.         Mov HCount,BX        ;in Hcount
  114.         cmp HFlag,0        ;was motion positive?
  115.         JZ  MovedH1             ;yes, then branch
  116.         Mov Al,MouseMotion    ;get motion byte
  117.         Test Al,MoveLeft    ;is movement authorized?
  118.          Jz MoveExit        ;no, then exit
  119.         mov AX,LKey        ;yes, load ax with left keycode
  120.         jmp insert        ;and stuff it
  121. MovedH1:
  122.         Mov AL,MouseMotion    ;get motion byte
  123.         Test AL,MoveRight    ;is movement authorized?
  124.         Jz MoveExit        ;no, then exit
  125.         mov AX,RKey        ;load AX with Right keycode
  126.         jmp insert        ;and insert that in keybuffer
  127. MovedV:        
  128. ; DX = Mickeys of vertical motion
  129.                 Mov BX,VCount        ;check delay
  130.                 dec BX            ;decrement the counter
  131.         Mov VCount,Bx        ;save the counter
  132.                 Jz  MovedV0        ;branch if 0
  133.                 Ret            ;return if not
  134. MovedV0:    Mov BX,VDly        ;get delay
  135.         mov VCount,BX        ;restore count        
  136.         cmp VFlag,0        ;was motion Down?
  137.         JZ  MovedV1        ;yes then branch
  138.         Mov Al,MouseMotion    ;get motion byte
  139.         Test Al,MoveUp        ;was motion authorized?
  140.         Jz MoveExit        ; no then exit
  141.         mov AX,UKey        ;load ax with up keycode
  142.         jmp insert        ; and stuff it
  143. MovedV1:
  144.         Mov AL,MouseMotion    ;get motion byte
  145.         Test AL,MoveDown    ;was motion authorized?
  146.         Jz    MoveExit    ;no then exit
  147.         mov AX,DKey        ;load ax with Dn keycode
  148.         jmp insert        ; and stuff it
  149.  
  150. MoveExit:    Jmp KeyMousExit        ;exit if motion attempt invalid
  151.  
  152. CheckButtons:
  153.         test ax,2        ;was the left button pressed?
  154.         jnz  LBtn               ;yes, then branch
  155.         test ax,4        ;was left button released?
  156.         jnz  LBtn        ;yes, then branch
  157.         test ax,8        ;was the right button pressed?
  158.         jnz  RBtn               ;yes, then branch
  159.         test ax,10h        ;was right button released?
  160.         jnz  RBtn        ;yes, then branch
  161.         test ax,20h        ;was mid button pressed?
  162.         jnz  MBtn        ;yes then branch
  163.         test ax,40h        ;was mid button released?
  164.         jnz  MBtn               ;yes, then branch
  165.                 Jmp  KeyMousExit       ;we get here by a glitch
  166.  
  167. ;
  168. ;The left button was pressed/released.  Load AX with keycode for left button.
  169. ;
  170. LBtn:        Mov AX,05h        ;get button Press inf function
  171.         Mov BX,0        ;LBtn stats
  172.         Int MouseInt        ;clear counters
  173.         Mov Ax,06H        ;get button release inf
  174.         Mov Bx,0        ;LBtn stats
  175.         Int MouseInt        ;clear counters
  176.         mov ax,LBKey        ;load keycode
  177.         jmp insert        ;insert it in the keyboard buffer
  178. ;
  179. ;The right button was pressed.  Load AX with the keycode for right button.
  180. ;
  181. RBtn:        Mov Ax,05h        ;get button inf
  182.         Mov Bx,1        ;RBtn stats
  183.         Int MouseInt        ;clear counters
  184.         Mov Ax,06H        ;get button release inf
  185.         Mov Bx,1        ;Rbtn stats
  186.         Int MouseInt        ;clear counters        
  187.         mov ax,RBKey        ;load keycode
  188.         Jmp Insert        ;and insert
  189. ;
  190. ;The mid button was pressed.  Load AX with keycode for mid button.
  191. ;
  192. MBtn:        Mov AX,05h        ;get button inf
  193.         Mov BX,02        ;Mid button stats
  194.         Int MouseInt        ;and clear counters
  195.         Mov Ax,06h        ;get button inf
  196.         Mov Bx,2        ;MBtn stats
  197.         Int MouseInt        ;clear counters
  198.         mov ax,MBKey        ;load keycode
  199.                     ;fall through to insert
  200.  
  201. ;
  202. ;Insert the keycode in AX into the keyboard buffer.
  203. ;
  204. insert:        mov bx,bios_data    ;point DS to BIOS data area
  205.         mov DS,bx
  206.         cli            ;disable interrupts
  207. Insert0:
  208.         mov bx,DS:Word Ptr [buffer_tail]
  209.                     ;get buffer tail address
  210.         mov dx,bx        ;transfer it to DX
  211.         add dx,2        ;calculate next buffer position
  212.         cmp dx,DS:Word Ptr [buffer_end]    
  213.                     ;did we overshoot the end?
  214.         jne insert1        ;no, then continue
  215.         mov dx,DS:Word Ptr [buffer_start]
  216.                     ;yes, then wrap around
  217. insert1:    cmp dx,DS: Word Ptr [buffer_head]
  218.                     ;is the buffer full?
  219.         je insert2        ;yes then end now
  220.         mov DS:[bx],ax        ;insert the keycode
  221.         mov bx,dx        ;advance the tail
  222.         mov DS:Word Ptr [buffer_tail],bx
  223.                     ;record its new position
  224. insert2:    sti            ;enable interrupts
  225. KeyMousExit:                ;Restore regs and ret
  226.         Mov ax,Evnts        ;restore AX
  227.         Mov Bx,Btns        ;restore BX
  228.         Mov CX,XCoord        ;Restore CX
  229.         Mov DX,Ycoord        ;Restore DX
  230.         Mov SI,VMicks        ;Restore SI
  231.         Mov DI,HMicks        ;Restore DI
  232.         Mov DS,MousDat        ;Restore DS
  233.         ret            ;exit user defined subroutine
  234. MousKey        endp
  235. ;
  236. ;
  237. code        ends
  238.         END
  239.