home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / MOCATCH.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-03-31  |  7.6 KB  |  315 lines

  1. ;
  2. ; Name        mocatch -- Catch mouse button presses and releases.
  3. ;
  4. ; Synopsis    (Special mouse interrupt subroutine -- not to be called
  5. ;        directly from C.)
  6. ;
  7. ;        Register values on entry:
  8. ;
  9. ;          AX  Condition mask bits:
  10. ;            0001h  Mouse movement.
  11. ;            0002h  MO_L_PRESS    Left   button pressed.
  12. ;            0004h  MO_L_RELEASE  Left   button released.
  13. ;            0008h  MO_R_PRESS    Right  button pressed.
  14. ;            0010h  MO_R_RELEASE  Right  button released.
  15. ;            0020h  MO_M_PRESS    Center button pressed.
  16. ;            0040h  MO_M_RELEASE  Center button released.
  17. ;          BX  Button state bits:
  18. ;            0001h  MO_LEFT
  19. ;            0002h  MO_RIGHT
  20. ;            0004h  MO_MIDDLE
  21. ;          CX  Horizontal cursor position in pixels.
  22. ;          DX  Vertical     cursor position in pixels.
  23. ;          DI  Horizontal mouse    position in mickeys.
  24. ;          SI  Vertical     mouse    position in mickeys.
  25. ;
  26. ;        Register values on exit:
  27. ;
  28. ;          (All unchanged including flags.)
  29. ;
  30. ; Description    This function receives control from certain mouse
  31. ;        events.  It keeps a history (b_mohist[]) of the
  32. ;        locations and times of mouse button presses and releases
  33. ;        and the shift key states at the time of those events.
  34. ;
  35. ;        If a user interrupt handler is also installed (see
  36. ;        MOHANDLR.C), this function may also pass control to the
  37. ;        dispatcher routine inside MOHANDLR.  It passes control
  38. ;        only if the mouse event matches the user function's
  39. ;        "call mask".
  40. ;
  41. ; Returns    b_mohist    Updated array of recent mouse events.
  42. ;
  43. ; Version    6.00  (C)Copyright Blaise Computing Inc. 1989
  44. ;
  45.  
  46.     include beginasm.mac
  47.  
  48.     beginMod mocatch
  49.  
  50. MO_EVENT struc                ; MO_EVENT:  One mouse button
  51.                     ; event.  This must match
  52.                     ; definition in BMOUSE.H.
  53.                     ;
  54.     MO_EV_EVENT       dw  0        ; MO_PRESS or MO_RELEASE.
  55.     MO_EV_TIME          dd  0ffffffffh    ; BIOS clock ticks since midnight.
  56.     MO_EV_C_VERT      dw  0        ; Cursor location in pixels.
  57.     MO_EV_C_HORIZ     dw  0
  58.     MO_EV_VERT          dw  0        ; Mouse location in mickeys.
  59.     MO_EV_HORIZ       dw  0
  60.     MO_EV_KSTAT       dw  0
  61.     MO_EV_RELEVANT    dw  0        ; Newness bits:
  62.                     ;   MO_CLICK, MO_DCLICK, MO_PRESS,
  63.                     ;   and MO_RELEASE
  64.                     ;   indicating whether this event
  65. MO_EVENT ends                ;   has been read & cleared.
  66.  
  67. MO_LEFT         equ 0001h        ; Event symbols.
  68. MO_RIGHT        equ 0002h        ; Must match BMOUSE.H!
  69. MO_MIDDLE        equ 0004h
  70. MO_PRESS        equ 0008h
  71. MO_RELEASE        equ 0010h
  72. MO_CLICK        equ 0040h
  73. MO_DCLICK        equ 0080h
  74.  
  75. MO_HIST_LIMIT        equ 5        ; Number of events recorded.
  76.                     ; Must match BMOUSE.H!
  77.  
  78. MO_L_PRESS        equ  0002h        ; Condition mask bits in AX.
  79. MO_L_RELEASE        equ  0004h
  80. MO_R_PRESS        equ  0008h
  81. MO_R_RELEASE        equ  0010h
  82. MO_M_PRESS        equ  0020h
  83. MO_M_RELEASE        equ  0040h
  84.  
  85.  
  86. REG_INPUT struc             ; Saved copy of register
  87.     REG_AX    dw  ?            ;  values, pushed on entry.
  88.     REG_BX    dw  ?
  89.     REG_CX    dw  ?
  90.     REG_DX    dw  ?
  91.     REG_DI    dw  ?
  92.     REG_SI    dw  ?
  93. REG_INPUT ends
  94.  
  95.     ; External variables defined elsewhere.
  96.  
  97.     beginDSeg
  98.  
  99.     extSym    b_modispat,dword    ; Address of dispatcher that
  100.                     ;  calls user interrupt handler.
  101.  
  102.     extSym    b_mohanmask,word    ; Mask value (if any) for user
  103.                     ;  mouse interrupt handler.
  104.  
  105.     ; Define & initialize global variables.
  106.  
  107.     pubSym    b_mohist,<MO_EVENT (3 * MO_HIST_LIMIT) dup (<>)>
  108.     endDSeg
  109.  
  110.     beginCSeg mocatch
  111.  
  112. temp_vector    dd  ?            ; Temporary vector in code
  113.                     ;  segment
  114.  
  115. ;********************************************************************
  116. ;
  117. ;   Internal routine DO_ONE_BUTTON:
  118. ;
  119. ;    Entry registers:
  120. ;
  121. ;        DX:AX   32-bit BIOS time of day (clock ticks).
  122. ;        DI        Copy of BIOS keyboard shift status word.
  123. ;        DS:BX   Address of first MO_EVENT structure for this button.
  124. ;        ES        Duplicate copy of DS.
  125. ;        SS:BP   Address of REG_INPUT structure containing register
  126. ;              values on entry to MOCATCH.
  127. ;        CX        Mask to capture button state (MO_LEFT, MO_RIGHT, or
  128. ;              MO_MIDDLE)
  129. ;        DF        (Direction Flag) = 1 (downward)
  130. ;
  131. ;    Exit registers:
  132. ;
  133. ;        CX,SI              Undefined
  134. ;        AX,BX,DX,DS,ES,DF,SS,BP,DI      Unchanged
  135.  
  136. do_one_button    proc    near
  137.         assume    ds:nothing,es:nothing
  138.  
  139. ;   Copy button's history backward one event to make room for new event.
  140.  
  141.     push    di
  142.     push    cx
  143.     mov    si,bx
  144.     add    si,((MO_HIST_LIMIT - 1) * type b_mohist@) - 2
  145.     mov    di,si
  146.     add    di,type b_mohist@
  147.     mov    cx,((MO_HIST_LIMIT - 1) * type b_mohist@) / 2
  148.     rep    movsw
  149.     pop    cx
  150.     pop    di
  151.  
  152. ;   Record event type:    press or release.
  153.  
  154.     test    [bp].REG_BX,cx
  155.     jnz    button_down
  156.  
  157.     mov    [bx].MO_EV_EVENT,   MO_RELEASE
  158.     mov    [bx].MO_EV_RELEVANT,MO_RELEASE or MO_CLICK or MO_DCLICK
  159.     jmp    short state_done
  160. button_down:
  161.     mov    [bx].MO_EV_EVENT,   MO_PRESS
  162.     mov    [bx].MO_EV_RELEVANT,MO_PRESS or MO_CLICK or MO_DCLICK
  163. state_done:
  164.  
  165. ;   Record other details of this event.
  166.  
  167.     mov    [bx].MO_EV_KSTAT,di        ; Keyboard status.
  168.     mov    word ptr [bx].MO_EV_TIME  ,ax    ; Time of day.
  169.     mov    word ptr [bx].MO_EV_TIME+2,dx
  170.  
  171.     mov    cx,[bp].REG_CX            ; Mouse cursor location.
  172.     mov    [bx].MO_EV_C_HORIZ,cx
  173.     mov    cx,[bp].REG_DX
  174.     mov    [bx].MO_EV_C_VERT,cx
  175.     mov    cx,[bp].REG_DI            ; Mouse location.
  176.     mov    [bx].MO_EV_HORIZ,cx
  177.     mov    cx,[bp].REG_SI
  178.     mov    [bx].MO_EV_VERT,cx
  179.  
  180.     ret
  181.  
  182. do_one_button    endp
  183.  
  184. ;********************************************************************
  185. ;
  186. ;   Actual entry point for MOCATCH.
  187.  
  188.     beginProc mocatch        ; Will exit via far RETurn.
  189.  
  190.     push    bp
  191.     mov    bp,sp
  192.  
  193.     push    ds
  194.     push    es
  195.     pushf
  196.  
  197.     push    si            ; Save entry register values.
  198.     push    di
  199.     push    dx
  200.     push    cx
  201.     push    bx
  202.     push    ax
  203.  
  204. ;   Load registers with values that apply to all buttons.
  205.  
  206.     mov    bp,sp            ; SS:BP -> set of input registers.
  207.  
  208.     xor    ax,ax            ; Fetch BIOS time of day.
  209.     mov    ds,ax
  210.     assume    ds:nothing
  211.     les    ax,ds:[046ch]
  212.     assume    es:nothing
  213.     mov    dx,es            ; DX:AX = time of day.
  214.  
  215.     mov    di,ds:[0417h]        ; Shift key status word.
  216.  
  217.     mov    bx,seg b_mohist@
  218.     mov    ds,bx            ; DS -> default data segment.
  219.     assume    ds:nothing
  220.     mov    es,bx
  221.     assume    es:nothing
  222.     lea    bx,b_mohist@
  223.                     ; DS:BX -> history for this button
  224.                     ; ES == DS
  225.  
  226.     std
  227.  
  228. ;   Record left button event if it was pressed or released.
  229.  
  230.     test    [bp].REG_AX,MO_L_PRESS or MO_L_RELEASE
  231.     jz    did_left
  232.  
  233.     mov    cx,MO_LEFT
  234.     call    do_one_button
  235. did_left:
  236.     add    bx,(MO_HIST_LIMIT * type b_mohist@)
  237.  
  238. ;   Record right button event if it was pressed or released.
  239.  
  240.     test    [bp].REG_AX,MO_R_PRESS or MO_R_RELEASE
  241.     jz    did_right
  242.  
  243.     mov    cx,MO_RIGHT
  244.     call    do_one_button
  245. did_right:
  246.  
  247. ;   Record middle button event if it was pressed or released.
  248.  
  249.     test    [bp].REG_AX,MO_M_PRESS or MO_M_RELEASE
  250.     jz    did_middle
  251.  
  252.     add    bx,(MO_HIST_LIMIT * type b_mohist@)
  253.     mov    cx,MO_MIDDLE
  254.     call    do_one_button
  255. did_middle:
  256.  
  257. ;   All done.
  258.  
  259. ;   Check whether to pass control to user's interrupt handler also.
  260.  
  261.                     ; DS -> default data segment.
  262.  
  263.     mov    ax,ds:b_mohanmask@  ; User   event bits.
  264.     test    [bp].REG_AX,ax        ; Actual event bits.
  265.     jz    straight_exit        ; Zero implies user handler isn't
  266.                     ;  interested in this event.
  267.  
  268. ;   Jump to user's interrupt handler.
  269.  
  270.     les    ax,ds:b_modispat@   ; Set up copy of vector in
  271.     assume    es:nothing        ;  code segment.
  272.     mov    word ptr temp_vector  ,ax
  273.     mov    word ptr temp_vector+2,es
  274.  
  275.     pop    ax            ; Restore registers.
  276.     pop    bx
  277.     pop    cx
  278.     pop    dx
  279.     pop    di
  280.     pop    si
  281.  
  282.     popff
  283.     pop    es
  284.     assume    es:nothing
  285.     pop    ds
  286.     assume    ds:nothing
  287.  
  288.     pop    bp
  289.     jmp    temp_vector        ; Jump to user's handler.
  290.  
  291. ;   Return directly to mouse driver.
  292.  
  293. straight_exit:
  294.     pop    ax            ; Restore registers and exit.
  295.     pop    bx
  296.     pop    cx
  297.     pop    dx
  298.     pop    di
  299.     pop    si
  300.  
  301.     popff
  302.     pop    es
  303.     assume    es:nothing
  304.     pop    ds
  305.     assume    ds:nothing
  306.  
  307.     pop    bp
  308.     db    0cbh            ; Far return.
  309.  
  310.     endProc mocatch
  311.     endCseg mocatch
  312.     endMod    mocatch
  313.  
  314.     end
  315.