home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / PEN / PENTKT / PENBASE / BUTTON.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  11KB  |  311 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  4. ;
  5. ;    The following IBM OS/2 WARP source code is provided to you solely for
  6. ;    the purpose of assisting you in your development of OS/2 WARP device
  7. ;    drivers. You may use this code in accordance with the IBM License
  8. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  9. ;    Copyright statement may not be removed.;
  10. ;*****************************************************************************/
  11. ;      /*****************************************************************/
  12. ;      /*                                                               */
  13. ;      /*                                                               */
  14. ;      /*****************************************************************/
  15. ;      /******************* START OF SPECIFICATIONS *********************/
  16. ;      /*                                                               */
  17. ;      /*  SOURCE FILE NAME: BUTTON.ASM                                 */
  18. ;      /*                                                               */
  19. ;      /*  DESCRIPTIVE NAME: Button handler                             */
  20. ;      /*                                                               */
  21. ;      /*                                                               */
  22. ;      /*  STATUS:  Version 1.0                                         */
  23. ;      /*                                                               */
  24. ;      /*  NOTES: This module contains routines to manage device        */
  25. ;      /*         buttons. The device dependent routine must call       */
  26. ;      /*         But_Engine to report the position of buttons. It      */
  27. ;      /*         is OK to call the engine multiple times with the      */
  28. ;      /*         same button state, for example, on each sample point  */
  29. ;      /*         for a barrel button.                                  */
  30. ;      /*                                                               */
  31. ;      /*         This module provides button state for the other       */
  32. ;      /*         pen driver components. Assignments are processed      */
  33. ;      /*         from the IOCTL subcomponent.                          */
  34. ;      /*                                                               */
  35. ;      /*  ENTRY POINTS:                                                */
  36. ;      /*      See public statements                                    */
  37. ;      /*  EXTERNAL REFERENCES:                                         */
  38. ;      /*      See extrn statements                                     */
  39. ;      /*                                                               */
  40. ;      /******************* END  OF  SPECIFICATIONS *********************/
  41. .xlist
  42.   include pensegs.inc
  43.   include pen.inc
  44.   include penidc.inc
  45.   include penioctl.inc
  46.   include penei.inc
  47.   include struc.inc
  48. .list
  49.  
  50. .286p
  51.  
  52. ;------------------------------------------------------------------------------
  53. ; external data references
  54. ;------------------------------------------------------------------------------
  55.  
  56. extrn Device_Help  : dword
  57.  
  58. ;------------------------------------------------------------------------------
  59. ; external routines
  60. ;------------------------------------------------------------------------------
  61.  
  62. extrn Idc_ReportEvent : near
  63. extrn Dsp_GetSuppress : near
  64.  
  65. ;------------------------------------------------------------------------------
  66. ; local equates
  67. ;------------------------------------------------------------------------------
  68. FORCEGSTMODE equ -1   ; must be unique with other psba.value values
  69.  
  70. ;------------------------------------------------------------------------------
  71. ; local data declarations
  72. ;------------------------------------------------------------------------------
  73.  
  74. DSEG   segment
  75. public buttons
  76. buttons   dw 0           ; state of buttons, 1=activated, 0=released
  77. @dcbb     dw 0           ; pointer to button dcb
  78.  
  79. DSEG   ends
  80.  
  81.  
  82. CSEG SEGMENT
  83.      ASSUME    CS:CGROUP, SS:nothing, ES:nothing, DS:DGROUP
  84.  
  85.  
  86. ;---- ROUTINES TO HANDLE EVENTS -----------------------------------------------
  87. ;
  88. ;------------------------------------------------------------------------------
  89.  
  90. ;------------------------------------------------------------------------------
  91. ; process an event for a device dependent locator device
  92. ;  dl = 0 released -1=activated
  93. ;  bx = button dcb
  94. ;  cx = button index (0 to 15)
  95. ;
  96. ; The button structure but_mask field is used by But_getButtonShift to form a
  97. ; a button mask. A Shift button will set and clear the the but_mask as the
  98. ; button is activated and released. A One Time Button will set the but_mask
  99. ; on activation, but will not clear it on release. A stroke that uses the
  100. ; shift will clear the One Time but_mask in But_GetButtonShift routine.
  101. ;------------------------------------------------------------------------------
  102.  
  103. butbit     equ word ptr bp-8
  104. newState   equ word ptr bp-6
  105. butEntry   equ word ptr bp-4
  106. newButtons equ word ptr bp-2
  107.  
  108. public But_Engine
  109. But_Engine    proc
  110.   .if  <[bx].dcb_NumButDefs lt cx>
  111.      stc
  112.      ret
  113.   .endif
  114.  
  115.   enter 8,0
  116.  
  117.   mov  ax,1   ; make a bit mask for this button
  118.   sal  ax,cl
  119.   mov  [butbit],ax
  120.  
  121. ; calculate address of button definition
  122.  
  123.   sal  cx,BUT_DEF_SIZE_SHIFT
  124.   mov  si,[bx].dcb_@ButDefArray
  125.   add  si,cx
  126.  
  127. ; see if state has changed
  128. ; ax = button mask for this button
  129. ; dl = new button state
  130. ; si = button entry pointer
  131.  
  132.   cmp  dl,[si].but_state
  133.   .if  nz NEAR                   ; state change
  134.  
  135. ; figure what new button mask will be
  136.  
  137.      mov  [butEntry],si
  138.      mov  [newState],dx
  139.      mov  cx, buttons
  140.      or   cx,ax     ;turn it on
  141.      .if  <zero dl>
  142.         xor cx,ax   ;turn it off
  143.      .endif
  144.      mov  [newButtons], cx
  145.  
  146. ; report event
  147.  
  148.      mov  di,[bx].dcb_@EiEvent   ; Addr of locator event packet
  149.      mov  [di].bev_change,ax     ; show which changed
  150.      mov  [di].bev_state,cx      ; show state of all buttons
  151.      mov  ah,[si].but_value
  152.      mov  [di].bev_value,ah      ; send value (valid for hotkeys)
  153.      mov  al,[si].but_action
  154.      mov  [di].bev_action,al     ; send action
  155.  
  156.      call Dsp_GetSuppress        ; get display suppress control info
  157.                                  ; dx = cntrl info
  158.      mov  [di].bev_cntrl,dx      ; control info
  159.  
  160.      call Idc_ReportEvent
  161.  
  162. ; only process button if not suppressed
  163.  
  164.      .if  <bit [di].bev_cntrl z BEV_SUPPRESSED+BEV_BKLT_OFF>
  165.  
  166.         mov  si,[butEntry]
  167.         mov  dx,[newState]
  168.         mov  [si].but_state,dl  ; save new state
  169.         mov  ax,[newButtons]
  170.         mov  buttons,ax         ; update state of all buttons
  171.         mov  cl,[si].but_action
  172.  
  173. ; do stuff for mouse emulation
  174. ; dl = new button state
  175. ; cl = button action
  176.  
  177.         .if <cl eq SHIFTBUTTON> OR
  178.         .if <cl eq GESTUREMODE>
  179.            mov di,[bx].dcb_@regCaps
  180.            mov ax,[di].bcap_typeMask
  181.            and ax,[butbit]
  182.            .if <zero ax>    ; its a non-barrel button
  183.               mov dh,[si].but_flags
  184.               .if  <nonzero dl>      ; activation
  185.                   and dh,BUT_ONESHOT ; leave one_shot
  186.               .else                  ; release
  187.                  .if <bit dh z BUT_USED> ; button wasn't used, toggle one_time
  188.                     xor dh,BUT_ONESHOT   ; toggle it
  189.                     and dh,BUT_ONESHOT   ; only leave one_time bit
  190.                  .else
  191.                     xor dh,dh        ; clear all bits
  192.                  .endif
  193.               .endif
  194.               mov [si].but_flags,dh
  195.            .endif
  196.         .endif
  197.      .endif
  198.   .endif
  199.   clc
  200.   leave
  201.   ret
  202. But_Engine endp
  203.  
  204. ;------------------------------------------------------------------------------
  205. ; return button emulation
  206. ; returns
  207. ;  al=emulated mouse buttons
  208. ;  dx=loc_cntrl bits to be or'ed in
  209. ;
  210. ; This routine is called at the start of a stroke by the locator engine to
  211. ; latch mouse emulated buttons for the duration of the stroke. One Time shifts
  212. ; can be cleared now.
  213. ;------------------------------------------------------------------------------
  214. public But_GetButtonShift
  215. But_GetButtonShift proc
  216.   push bx
  217.   mov  bx,@dcbb
  218.   xor  al,al            ; initialize button emulation mask to no buttons
  219.   xor  dx,dx            ; initialize loc_cntrl to zero
  220.   mov  si,[bx].dcb_@regCaps
  221.   mov  cx,[si].bcap_num
  222.   mov  si,[bx].dcb_@ButDefArray
  223.   .repeat
  224.      .if <bit [si].but_flags nz BUT_ONESHOT> OR
  225.      .if <[si].but_state ne 0>
  226.         cmp  [si].but_action, SHIFTBUTTON
  227.         je   short gbs_10
  228.         cmp  [si].but_action, GESTUREMODE
  229.         jne  short gbs_19
  230.         or  al,FORCEGSTMODE
  231. gbs_10:
  232.         or  al,[si].but_value
  233.         mov [si].but_flags, BUT_USED  ; indicate used & clear oneshot
  234. gbs_19:
  235.      .endif
  236.      add si, size BUT_DEF
  237.   .loop
  238.   .if <zero al>
  239.      mov al,EV_BUTTON1           ; default to button 1
  240.   .elseif <al eq FORCEGSTMODE>
  241.      mov al,EV_BUTTON1           ; override to force gesture mode
  242.      mov dx,LOC_GSTMODE
  243.   .endif
  244.   pop bx
  245.   ret
  246. But_GetButtonShift endp
  247.  
  248. ;------------------------------------------------------------------------------
  249. ; returns
  250. ;  ax=current button state
  251. ;------------------------------------------------------------------------------
  252. public But_GetButtons
  253. But_GetButtons proc
  254.   mov  ax, buttons
  255.   ret
  256. But_GetButtons endp
  257.  
  258. ;---- MISCELLANEOUS ROUTINES --------------------------------------------------
  259. ; bx = dcb
  260. ;------------------------------------------------------------------------------
  261. public But_CalcCaps
  262. But_CalcCaps proc
  263.   push bx
  264.   mov  di,[bx].dcb_@RegCaps
  265.   mov  [di].bcap_nullMask,0
  266.   mov  [di].bcap_hotKeyMask,0
  267.   mov  [di].bcap_shiftMask,0
  268.   mov  [di].bcap_appKeyMask,0
  269.   mov  [di].bcap_augKeyMask,0
  270.   mov  [di].bcap_gesKeyMask,0
  271.  
  272. ; set bits in caps flag words using action as an index into the caps flag
  273. ; words
  274. ; note: order of caps words MUST match action value
  275.  
  276.   mov  cx,[bx].dcb_NumButDefs
  277.   mov  si,[bx].dcb_@ButDefArray
  278.   lea  di,[di].bcap_nullMask
  279.   xor  bh,bh
  280.   mov  ax,1
  281.   .repeat
  282.      mov  bl, [si].but_action    ; index into masks by action
  283.      sal  bx,1
  284.      or   [bx+di],ax
  285.      sal  ax,1
  286.      add  si, size BUT_DEF
  287.   .loop
  288.   pop  bx
  289.   ret
  290. But_CalcCaps endp
  291.  
  292. CSEG ends
  293. ;---- INITIALIZATION ROUTINES -------------------------------------------------
  294. ;
  295. ; note: this code is truncated from the driver after the INIT command returns
  296. ;       to OS/2
  297. ;------------------------------------------------------------------------------
  298.  
  299. ;------------------------------------------------------------------------------
  300. ; Initialize engine
  301. ;  bx = dcb
  302. ;------------------------------------------------------------------------------
  303. CSEGI segment
  304. public But_Init
  305. But_Init proc
  306.   mov @dcbb,bx                 ; pointer to button dcb
  307.   ret
  308. But_Init endp
  309. CSEGI ends
  310. end
  311.