home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / PEN / PENTKT / PENBASE / LOCATOR.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  27KB  |  852 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: LOCATOR.ASM                                */
  18. ;      /*                                                               */
  19. ;      /*  DESCRIPTIVE NAME: Locator handler                            */
  20. ;      /*                                                               */
  21. ;      /*                                                               */
  22. ;      /*  STATUS:  Version 1.0                                         */
  23. ;      /*                                                               */
  24. ;      /*  NOTES: This module provide support for locator logical       */
  25. ;      /*         devices. The device dependent routine calls LOC_ENGINE*/
  26. ;      /*         after filling in the DCB and extended event packet.   */
  27. ;      /*                                                               */
  28. ;      /*         Loc_ProxFilter is provided to filter out proximity    */
  29. ;      /*         points in a positonary position, for example, if the  */
  30. ;      /*         pen is left on the digitizer surface. This routine    */
  31. ;      /*         works inconjunction with Loc_ProxFitlerTC. The        */
  32. ;      /*         device dependent routine must allocate a BOX_FILTER   */
  33. ;      /*         structure and initialize it.                          */
  34. ;      /*                                                               */
  35. ;      /*         The device dependent routine may need to subclass,    */
  36. ;      /*         or replace, the coordinate adjustment routine or the  */
  37. ;      /*         forceClear routine. The latter is called after the    */
  38. ;      /*         proximity or contact time out occurs.                 */
  39. ;      /*                                                               */
  40. ;      /*         The locator module also supports a special IOCTL      */
  41. ;      /*         intended for use by the alignment calibration program */
  42. ;      /*         that returns raw cooridinates.                        */
  43. ;      /*                                                               */
  44. ;      /*  ENTRY POINTS:                                                */
  45. ;      /*      See public statements                                    */
  46. ;      /*  EXTERNAL REFERENCES:                                         */
  47. ;      /*      See extrn statements                                     */
  48. ;      /*                                                               */
  49. ;      /******************* END  OF  SPECIFICATIONS *********************/
  50. .xlist
  51.   include pensegs.inc
  52.   include pen.inc
  53.   include penidc.inc
  54.   include penei.inc
  55.   include penioctl.inc
  56.   include struc.inc
  57.   include devhlp.inc
  58.   include infoseg.inc
  59. .list
  60.  
  61. .286p
  62.  
  63. ;------------------------------------------------------------------------------
  64. ; external data references
  65. ;------------------------------------------------------------------------------
  66.  
  67. extrn Device_Help  : dword
  68.  
  69. ;------------------------------------------------------------------------------
  70. ; external routines
  71. ;------------------------------------------------------------------------------
  72.  
  73. extrn Idc_ReportEvent : near
  74. extrn But_GetButtons : near
  75. extrn But_GetButtonShift : near
  76. extrn Dsp_GetSuppress    : near
  77.  
  78. ;------------------------------------------------------------------------------
  79. ; local equates
  80. ;------------------------------------------------------------------------------
  81.  
  82. TICK_LIMIT equ 4
  83. ;------------------------------------------------------------------------------
  84. ; local data declarations
  85. ;------------------------------------------------------------------------------
  86.  
  87. DSEG   segment
  88. public qlrc_sem
  89. qlrc_sem   db  0     ; reentry semaphore for query locator raw coordinate
  90.  
  91. stateTable label word   ; state transition action table
  92.        dw    clr_clr
  93.        dw    0          ; reserved
  94.        dw    clr_prx
  95.        dw    clr_con
  96.  
  97.        dw    0          ; reserved
  98.        dw    0          ; reserved
  99.        dw    0          ; reserved
  100.        dw    0          ; reserved
  101.  
  102.        dw    prx_clr
  103.        dw    0          ; reserved
  104.        dw    prx_prx
  105.        dw    prx_con
  106.  
  107.        dw    con_clr
  108.        dw    0          ; reserved
  109.        dw    con_prx
  110.        dw    con_con
  111.  
  112. DSEG   ends
  113.  
  114. CSEG SEGMENT
  115.      ASSUME    CS:CGROUP, SS:nothing, ES:nothing, DS:DGROUP
  116.  
  117.  
  118. ;---- ROUTINES TO HANDLE EVENTS -----------------------------------------------
  119. ;
  120. ;------------------------------------------------------------------------------
  121.  
  122. ;------------------------------------------------------------------------------
  123. ; process an event for a device dependent locator device
  124. ;  bx = dcb
  125. ;  di = extended event packet address
  126. ;------------------------------------------------------------------------------
  127. public Loc_Engine
  128. Loc_Engine    proc
  129.  
  130.   mov  [bx].dcb_StateTimeOut,0   ; reset the watchdog timer
  131.  
  132. ; if anyone is waiting on a query locator raw coordinate (QLRC)
  133.  
  134.   .if <bit [bx].dcb_LocFlags nz QLRC_REQUEST> AND
  135.   .if <[bx].dcb_LocNewState eq STATE_CONTACT>
  136.      and  [bx].dcb_LocFlags,not QLRC_REQUEST  ;signals that its our ProcRun that
  137.                                               ;woke up the thread, clean up,
  138.                                               ;and we don't need to ProcRun
  139.                                               ;multiple times if wakeup is slow
  140.      push bx
  141.      lea  bx,qlrc_sem           ; set up block id
  142.      mov  ax,ds
  143.      mov  dl, DevHlp_ProcRun
  144.      call Device_Help           ; Invoke function
  145.      pop  bx
  146.   .endif
  147.  
  148. ; process this coorindate point
  149.  
  150.   call detectMotion
  151.   call [bx].dcb_@Adjust
  152.   call computeStd
  153.   call stateMachine
  154.   call fillEventBuffer
  155.   call Idc_ReportEvent
  156.   call updateValues
  157.  
  158.   ret
  159. Loc_Engine endp
  160.  
  161. ;------------------------------------------------------------------------------
  162. ; see if the location has changed.
  163. ;  bx = dcb
  164. ;------------------------------------------------------------------------------
  165. public detectMotion    ;ddxy
  166. detectMotion proc
  167. .386p
  168.   mov  eax, [bx].dcb_LocNewX      ; check if x has changed
  169.   .if <[bx].dcb_LocLastX eq eax> AND
  170.   mov  eax, [bx].dcb_LocNewY      ; check if y has changed
  171.   .if <[bx].dcb_LocLastY eq eax>
  172.      and  [bx].dcb_LocFlags, not LOC_MOTION
  173.   .else
  174.      or   [bx].dcb_LocFlags, LOC_MOTION
  175.   .endif
  176. .286p
  177.   ret
  178. detectMotion endp
  179.  
  180. ;------------------------------------------------------------------------------
  181. ; adjust the coordinates  - ABSOLUTE
  182. ;  bx = dcb
  183. ;------------------------------------------------------------------------------
  184. public AdjustCoords    ;ddxy
  185. AdjustCoords proc
  186.  
  187. .386p
  188. ; adjust x
  189.   mov  eax, [bx].dcb_LocNewX
  190.   lea  si, [bx].dcb_Xtrans
  191.   call Loc_normalize
  192.   call Loc_slide
  193.   mov  [bx].dcb_LocNDCX,eax
  194.  
  195. ; adjust y
  196.   mov  eax, [bx].dcb_LocNewY
  197.   lea  si, [bx].dcb_Ytrans
  198.   call Loc_normalize
  199.   call Loc_slide
  200.   mov  [bx].dcb_LocNDCY,eax
  201. .286p
  202.   ret
  203. AdjustCoords endp
  204.  
  205. ;------------------------------------------------------------------------------
  206. ; adjust the coordinates  - RELATIVE
  207. ;  bx = dcb
  208. ;------------------------------------------------------------------------------
  209. public AdjustRelCoords  ;ddxy
  210. AdjustRelCoords proc
  211. .386p
  212.   mov  eax, [bx].dcb_LocNewX
  213.   mov  [bx].dcb_LocNDCX,eax
  214.   mov  eax, [bx].dcb_LocNewY
  215.   mov  [bx].dcb_LocNDCY,eax
  216. .286p
  217.   ret
  218. AdjustRelCoords endp
  219.  
  220. ;------------------------------------------------------------------------------
  221. ; convert raw device cooridinate to normalized device cooridinate
  222. ;
  223. ;  1) adjust from raw device coridinate origin to normalized device origin
  224. ;  2) normalized from measured extent to fixed extent
  225. ;  3) clip to fixed extent
  226. ;  4) invert if necessary
  227. ;
  228. ;  eax = coordinate value
  229. ;  si = coordinate transformation structure
  230. ; returns
  231. ;  eax = adjusted coordinate value
  232. ;------------------------------------------------------------------------------
  233. public Loc_normalize        ;ddxy
  234. Loc_normalize proc
  235.  .386p
  236. ; adjust realitive to normalized origin
  237.  
  238.   add  eax, [si].trn_org_adj
  239.   .if  s                                   ; if result is negative
  240.      mov   eax,0                           ; back it up to 0 (but no more)
  241.   .endif
  242.  
  243. ; normalize
  244.  
  245.   mov  edx, [si].trn_ext_max
  246.   imul edx                                 ; eax*edx = EDX:EAX
  247.   mov  ecx, [si].trn_ext_adj
  248.   idiv ecx                                 ; edx:eax / ecx = EAX.EDX
  249.   .if  <nonzero edx>                       ; if remainder
  250.      inc  eax
  251.   .endif
  252.  
  253. ; clip to real extents (max value is extents - 1)
  254.  
  255.   .if  <eax ge [si].trn_ext_max>
  256.      mov    eax,[si].trn_ext_max
  257.      dec    eax
  258.   .endif
  259.  
  260. ; invert if necessary
  261.  
  262.   .if  <bit [si].trn_flags nz INVERTED_COORD>
  263.      inc  eax
  264.      neg  eax
  265.      add  eax, [si].trn_ext_max
  266.   .endif
  267.  
  268. .286p
  269.   ret
  270. Loc_Normalize endp
  271.  
  272. ;------------------------------------------------------------------------------
  273. ; adjust a coordinate using slide algorithm
  274. ;  eax = coordinate value
  275. ;  si = coordinate transformation structure
  276. ; returns
  277. ;  eax = adjusted coordinate value
  278. ;------------------------------------------------------------------------------
  279. public Loc_slide     ;ddxy
  280. Loc_slide proc
  281. .386p
  282.   push eax
  283.   mov  ax, [si].trn_offset
  284.   cwde
  285.   mov  ecx, eax
  286.   pop eax
  287.   .if  <nonzero cx>
  288.      mov  edx, [si].trn_ext_max
  289.      push ebx
  290.      .if <ecx lt 0>            ; negative offset
  291.         mov  ebx,ecx           ; put OFFSET in bx
  292.         add  ebx,eax           ; add coord to offset
  293.         .if  s                 ; if still negative
  294.            mov    eax,0        ; back it up to 0 (but no more)
  295.         .else
  296.            mov    ebx,edx      ; put fixed extent in ebx
  297.            add    ebx,ecx      ; add the OFFSET to fixed extent
  298.            .if  <eax gt ebx>   ; If coord is greater than Offset+FixedExtent
  299.                                ; 2*X - Xm    (when X=Xm, coord=extent)
  300.               add    eax,eax   ; slide area situation, double coord
  301.               sub    eax,edx   ; minus the fixed extent from coord
  302.            .else               ; If coord is less than Offset+FixedExtent
  303.               add    eax,ecx   ; normal area
  304.            .endif
  305.         .endif
  306.      .else                     ; positive (or zero)
  307.         mov    ebx,edx         ; put extent in ebx
  308.         sub    ebx,ecx         ; ecx=OFFSET
  309.         .if  <eax gt ebx>      ; if coord greater than extent-OFFSET
  310.            mov    eax,edx      ; don't adjust past extent
  311.         .else
  312.            .if <eax lt ecx>
  313.              add    eax,eax    ; slide area
  314.            .else
  315.              add    eax,ecx    ; normal area
  316.            .endif
  317.         .endif
  318.      .endif
  319.      pop  ebx
  320.   .endif
  321.   ret
  322. Loc_slide endp
  323.  
  324. ;------------------------------------------------------------------------------
  325. ; comput standard coordinate values
  326. ;  bx = dcb
  327. ;------------------------------------------------------------------------------
  328. public computeStd
  329. computeStd proc
  330.   mov  si,[bx].dcb_@RegCaps
  331.   mov  di, [bx].dcb_@EiEvent
  332.   mov  eax,[si].lcap_std_x_extent
  333.   imul [bx].dcb_LocNDCX
  334.   idiv [si].lcap_dev_x_extent
  335.   mov  [di].lev_std_x,eax
  336.  
  337.   mov  eax,[si].lcap_std_y_extent
  338.   imul [bx].dcb_LocNDCY
  339.   idiv [si].lcap_dev_y_extent
  340.   mov  [di].lev_std_y,eax
  341.   ret
  342. computeStd endp
  343.  
  344. ;------------------------------------------------------------------------------
  345. ; process state transitions. Figure out events and mouse buttons
  346. ;  bx = dcb
  347. ;------------------------------------------------------------------------------
  348. public stateMachine
  349. stateMachine proc
  350.   mov  di,[bx].dcb_@EiEvent
  351.   and  [di].lev_cntrl,LOC_REL+LOC_ABS+LOC_FAKE
  352.   mov  si,[bx].dcb_LocLastState
  353.   sal  si,2
  354.   add  si,[bx].dcb_LocNewState
  355.   jmp  stateTable[si]
  356. stateMachine endp
  357.  
  358.  
  359. ; this is a strange transition and isn't expected, but its OK
  360. public clr_clr
  361. clr_clr proc
  362.   mov  [di].cev_devicebits, EV_MOVE
  363.   ret
  364. clr_clr endp
  365.  
  366. ; valid only for devices that report proximity
  367. public clr_prx
  368. clr_prx proc
  369.   mov  [di].cev_devicebits, EV_MOVE + EV_ENTER_PROX
  370.   or   [di].lev_cntrl,LOC_PROX
  371.   ret
  372. clr_prx endp
  373.  
  374. ; can't tell if this is a device that doesn't support proximity or just
  375. ; a quite touchdown, so we have to check the capabilities before reporting
  376. ; EV_ENTER_PROX
  377. public clr_con
  378. clr_con proc
  379.   call But_GetButtonShift
  380.   mov  [bx].dcb_LocMouBut,al ; save for whole stroke
  381.   or   [di].lev_cntrl,dx     ; returned control information
  382.   call Dsp_GetSuppress
  383.   or   [di].lev_cntrl,dx     ; returned control information
  384.   mov  ah,al
  385.   .if  <bit [bx].dcb_LocFlags nz LOC_MOTION>
  386.      sar  al,1
  387.      or   al,ah
  388.   .endif
  389.   mov  si,[bx].dcb_@regCaps
  390.   .if <bit [si].lcap_caps nz PENCAP_PROXIMITY>
  391.      or ax,EV_ENTER_PROX
  392.   .endif
  393.   mov  [di].cev_devicebits, ax
  394.   or   [di].lev_cntrl,LOC_CONTACT
  395.   ret
  396. clr_con endp
  397.  
  398. public prx_clr
  399. prx_clr proc
  400.   mov  [di].cev_devicebits, EV_MOVE + EV_EXIT_PROX
  401.   ret
  402. prx_clr endp
  403.  
  404. public prx_prx
  405. prx_prx proc
  406.   mov  [di].cev_devicebits, EV_MOVE
  407.   or   [di].lev_cntrl,LOC_PROX
  408.   ret
  409. prx_prx endp
  410.  
  411. public prx_con
  412. prx_con proc
  413.   call But_GetButtonShift
  414.   mov  [bx].dcb_LocMouBut,al ; save for whole stroke
  415.   or   [di].lev_cntrl,dx     ; returned control information
  416.   call Dsp_GetSuppress
  417.   or   [di].lev_cntrl,dx     ; returned control information
  418.   mov  ah,al
  419.   .if  <bit [bx].dcb_LocFlags nz LOC_MOTION>
  420.      sar  al,1
  421.      or   al,ah
  422.   .endif
  423.   mov  [di].cev_devicebits, ax
  424.   or   [di].lev_cntrl,LOC_CONTACT
  425.   ret
  426. prx_con endp
  427.  
  428. ; Could be quick lift off or a device that doesn't support proximity.
  429. public con_clr
  430. con_clr proc
  431.   mov  al, EV_MOVE
  432.   mov  ah,[bx].dcb_LocMouBut
  433.   mov  si,[bx].dcb_@regCaps
  434.   .if <bit [si].lcap_caps nz PENCAP_PROXIMITY>
  435.      or ax,EV_EXIT_PROX
  436.   .endif
  437.   mov  [di].cev_devicebits, ax
  438.   ret
  439. con_clr endp
  440.  
  441. public con_prx
  442. con_prx proc
  443.   mov  al, EV_MOVE
  444.   mov  ah,[bx].dcb_LocMouBut
  445.   mov  [di].cev_devicebits, ax
  446.   or   [di].lev_cntrl,LOC_PROX
  447.   ret
  448. con_prx endp
  449.  
  450. public con_con
  451. con_con proc
  452.   xor  ah,ah
  453.   mov  al,[bx].dcb_LocMouBut
  454.   .if  <bit [bx].dcb_LocFlags nz LOC_MOTION>
  455.      sar  al,1
  456.   .endif
  457.   mov  [di].cev_devicebits, ax
  458.   or   [di].lev_cntrl,LOC_CONTACT
  459.   ret
  460. con_con endp
  461.  
  462. ;------------------------------------------------------------------------------
  463. ; fill in locator event fields
  464. ;  bx = dcb
  465. ;------------------------------------------------------------------------------
  466. public fillEventBuffer
  467. fillEventBuffer  proc
  468.  
  469. ;    fill in EIQ locator position
  470.  
  471.   mov di,[bx].dcb_@EiEvent
  472. .386p
  473.   mov eax,[bx].dcb_LocNDCX
  474.   mov [di].lev_dev_x, eax
  475.   mov eax,[bx].dcb_LocNDCY
  476.   mov [di].lev_dev_y, eax
  477. .286p
  478.   mov ax, [bx].dcb_LocNewZ
  479.   mov [di].lev_dev_z, ax
  480.  
  481. ; finish off extended event packet
  482.  
  483.   call But_GetButtons             ; get buttons
  484.   mov  [di].lev_buttons,ax
  485.  
  486.   TraceAbs
  487.   ret
  488. fillEventBuffer endp
  489.  
  490. ;------------------------------------------------------------------------------
  491. ; update fields for next time
  492. ;  bx = dcb
  493. ;------------------------------------------------------------------------------
  494. public updateValues
  495. updateValues proc
  496.   mov ax, [bx].dcb_LocNewState
  497.   mov [bx].dcb_LocLastState, ax
  498. .386p
  499.   mov eax, [bx].dcb_LocNewX
  500.   mov [bx].dcb_LocLastX,eax
  501.   mov eax, [bx].dcb_LocNewY
  502.   mov [bx].dcb_LocLastY,eax
  503. .286p
  504.   mov ax, [bx].dcb_LocNewZ
  505.   mov [bx].dcb_LocLastZ,ax
  506.   mov di,[bx].dcb_@EiEvent
  507.   mov ax, [di].lev_cntrl
  508.   mov [bx].dcb_LocLastCntrl,ax
  509.   ret
  510. updateValues endp
  511.  
  512. ;---- IOCTL ROUTINES ----------------------------------------------------------
  513. ;
  514. ;------------------------------------------------------------------------------
  515.  
  516. ;------------------------------------------------------------------------------
  517. ; return next raw coordinate (used for calibration)
  518. ;  edx = timeout value
  519. ;  bx = dcb
  520. ; returns
  521. ;  eax = dqlrc.rc
  522. ;  ecx = dqlrc.xRaw
  523. ;  edx = dqlrc.yRaw
  524. ;------------------------------------------------------------------------------
  525. public Loc_qlrc
  526. Loc_qlrc proc
  527.   .386p
  528.  
  529. ; back sure only one guy doing this
  530.  
  531.   xor  al,al
  532.   xchg qlrc_sem,al              ;set semaphore
  533.   or   al,al
  534.   .if  nz
  535.      mov eax,QLRC_BUSY          ;someone already has it
  536.   .else
  537.  
  538. ; wait for coordinates to be saved by interrupt handler in loc_engine
  539.  
  540.      .repeat
  541.         DISABLE
  542.         or   [bx].dcb_LocFlags,QLRC_REQUEST
  543.         push bx
  544.         mov  cx,dx                 ; set up timeout value
  545.         shr  edx,16
  546.         mov  di,dx
  547.         lea  bx,qlrc_sem           ; set up block id
  548.         mov  ax,ds
  549.         mov  dh,0                  ; allow interrupts
  550.         mov  dl, DevHlp_ProcBlock
  551.         call Device_Help           ; Invoke function
  552.         DISABLE
  553.         pop  bx
  554.         .if  c                     ; unusual wake up
  555.            mov  eax, QLRC_TIMEOUT
  556.            and  [bx].dcb_LocFlags,not QLRC_REQUEST
  557.            jmp  short qlrc_done
  558.         .endif
  559.      .until <bit [bx].dcb_LocFlags z QLRC_REQUEST> ;make sure its our wakeup
  560.      mov  eax,QLRC_VALID
  561.  
  562. ; return last coordinates saved by interrupt handler in loc_engine
  563.  
  564. qlrc_done:
  565.      mov  ecx, [bx].dcb_LocNewX
  566.      mov  edx, [bx].dcb_LocNewY
  567.  
  568.      ENABLE
  569.      mov  qlrc_sem,0            ;clear reentry semaphore
  570.   .endif
  571.   ret
  572.   .286p
  573. Loc_qlrc endp
  574.  
  575. ;--- RUNS UNDER TIMER TICK HANDLER --------------------------------------------
  576. ;
  577. ;------------------------------------------------------------------------------
  578.  
  579. ;------------------------------------------------------------------------------
  580. ; See if proximity or contact state has timed out. If so, return to clear.
  581. ;  bx = dcb
  582. ;  si = locator event packet
  583. ;------------------------------------------------------------------------------
  584. public Loc_Tick
  585. Loc_Tick proc
  586.  .if <[bx].dcb_LocLastState ne STATE_CLEAR>
  587.      inc [bx].dcb_StateTimeOut
  588.  
  589.     .if <[bx].dcb_LocLastState eq STATE_PROX>
  590.        mov cx,[bx].dcb_TimeoutLimProx
  591.     .else
  592.        mov cx,[bx].dcb_TimeoutLimCont
  593.     .endif
  594.     .if <nonzero cx>
  595.        .if <[bx].dcb_StateTimeout gt cx>    ;have we timed out waiting
  596.          call [bx].dcb_@Dev_ForceClear          ;for Prox data???
  597.        .endif
  598.     .endif
  599.  .endif
  600.   ret
  601. Loc_Tick endp
  602.  
  603. ;---- DEFAULT DCB@ ROUTINES ---------------------------------------------------
  604. ;
  605. ;------------------------------------------------------------------------------
  606.  
  607. ;------------------------------------------------------------------------------
  608. ; force to clear state after either prox or contact state timed out
  609. ; bx = dcb for this device
  610. ;------------------------------------------------------------------------------
  611. public Loc_ForceClear
  612. Loc_ForceClear proc
  613.   GetCritSec [bx].dcb_Sem1
  614.   .if  z
  615.      mov [bx].dcb_LocNewState, STATE_CLEAR
  616. .386p
  617.      mov eax,[bx].dcb_LocLastX           ;Use last position
  618.      mov [bx].dcb_LocNewX,eax
  619.      mov eax,[bx].dcb_LocLastY
  620.      mov [bx].dcb_LocNewY,eax
  621. .286p
  622.      mov ax,[bx].dcb_LocLastZ
  623.      mov [bx].dcb_LocNewZ,ax
  624.  
  625.      mov di,[bx].dcb_@EiEvent           ; set cntrl
  626.      mov ax,[bx].dcb_LocLastCntrl
  627.      and ax,LOC_ABS+LOC_REL
  628.      or  ax,LOC_FAKE
  629.      mov [di].lev_cntrl, ax
  630.  
  631.      call Loc_Engine                    ; bx = dcb
  632.                                         ; di = event
  633.   .endif
  634.   ClearCritSec [bx].dcb_Sem1
  635.   ret
  636. Loc_ForceClear endp
  637.  
  638. ;---- BOX FILTRER ROUTINES ----------------------------------------------------
  639. ;
  640. ;------------------------------------------------------------------------------
  641. .386p
  642. ;------------------------------------------------------------------------------
  643. ; see if the location has moved out the the 'box', if not, then use old
  644. ; cooridinates. This must be done before coordinate normalization in case we
  645. ; are going to use the last raw coordinates
  646. ;
  647. ; This routine is called directly from the device dependent routine before
  648. ; calling the locator engine.
  649. ;
  650. ; note: box_flags bit BOX_SMOOTH should be ON if calling to smooth contact pts
  651. ;
  652. ;  bx = dcb
  653. ;  di = box struc
  654. ; returns
  655. ;  cx == 0 in the box, New coordinates updated to last values
  656. ;     != 0 out of the box
  657. ;------------------------------------------------------------------------------
  658. public Loc_BoxFilter
  659. Loc_BoxFilter proc
  660.   xor  cx,cx
  661.  
  662.   mov  eax, [bx].dcb_LocNewX      ; check if x is in the box
  663.   sub  eax, [di].box_LocLastX
  664.   .if  s
  665.      neg eax
  666.   .endif
  667.   .if <[di].box_Size lt eax>
  668.      inc  cx
  669.   .endif
  670.  
  671.   mov  eax, [bx].dcb_LocNewY      ; check if y is in the box
  672.   sub  eax, [di].box_LocLastY
  673.   .if  s
  674.      neg eax
  675.   .endif
  676.   .if <[di].box_Size lt eax>
  677.      inc cx
  678.   .endif
  679.  
  680. ; if its out of the box, update the box for the next area
  681.  
  682.   .if <nonzero cx>
  683.      mov  eax, [bx].dcb_LocNewX
  684.      mov  [di].box_LocLastX, eax
  685.      mov  eax, [bx].dcb_LocNewY
  686.      mov  [di].box_LocLastY, eax
  687.  
  688. ; if its in the box, then use the
  689. ; old raw coordinates so the box does not drift.
  690.   .elseif <bit [di].box_flags nz BOX_SMOOTH>
  691.      mov  eax, [di].box_LocLastX
  692.      mov  [bx].dcb_LocNewX, eax
  693.      mov  eax, [di].box_LocLastY
  694.      mov  [bx].dcb_LocNewY, eax
  695.   .endif
  696.   ret
  697. Loc_BoxFilter endp
  698.  
  699. ;------------------------------------------------------------------------------
  700. ; This routine is called directly from the device dependent routine before
  701. ; calling the locator engine. This routine can filters out proximity
  702. ; that do not change, for example, a pen left on the digitizer.
  703. ;
  704. ; note: box_flags bit BOX_SMOOTH should probably be off for filtering prox pts
  705. ;
  706. ; Inorder of this to work right, the caller should be calling Loc_ProxFilterTC
  707. ; on each timer tick from the device dependent tick count routine.
  708. ;
  709. ;  bx = dcb
  710. ;  di = box structure
  711. ; returns
  712. ;  cx == 0 ignore proximity point
  713. ;     != 0 pass on prox point
  714. ;------------------------------------------------------------------------------
  715. public Loc_ProxFilter
  716. Loc_ProxFilter proc
  717.   mov [di].box_ClearCnt, 0             ; used to clear box after prox pts
  718.   call Loc_BoxFilter
  719.   .if <nonzero cx>     ; out of the box
  720.      mov  [di].box_TickCount,0
  721.   .else
  722.      mov  ax,[di].box_TickCount
  723.      .if  <ax lt [di].box_TickLimit>
  724.         inc cx
  725.      .endif
  726.   .endif
  727.   ret
  728. Loc_ProxFilter endp
  729.  
  730. ;------------------------------------------------------------------------------
  731. ; This routine is called directly from the device dependent routine from
  732. ; the device dependent tick routine. It works with Loc_ProxFilter to filter
  733. ; out proximity points that do not change.
  734. ;
  735. ;  bx = dcb
  736. ;  di = box structure
  737. ; returns
  738. ;------------------------------------------------------------------------------
  739. public Loc_ProxFilterTC
  740. Loc_ProxFilterTC proc
  741.   mov cx,[di].box_ClearCnt
  742.   inc cx
  743.   .if <cx lt [bx].dcb_TimeoutLimProx> ; haven't seen a prox latly
  744.      mov  [di].box_ClearCnt,cx
  745.      mov  ax,[di].box_TickCount
  746.      .if  <ax lt [di].box_TickLimit>
  747.         inc [di].box_TickCount
  748.      .endif
  749.   .else
  750.      mov  [di].box_LocLastX, -1     ; make sure next prox is not 'in the box'
  751.   .endif
  752.   ret
  753. Loc_ProxFilterTC endp
  754. .286p
  755.  
  756. CSEG ends
  757. ;---- INITIALIZATION ROUTINES -------------------------------------------------
  758. ;
  759. ; note: this code is truncated from the driver after the INIT command returns
  760. ;       to OS/2
  761. ;------------------------------------------------------------------------------
  762.  
  763. ;------------------------------------------------------------------------------
  764. ; Initialize engine
  765. ;  bx = dcb
  766. ;------------------------------------------------------------------------------
  767. CSEGI segment
  768. public Loc_Init
  769. Loc_Init proc
  770.   mov  [bx].dcb_LocLastState, STATE_CLEAR
  771.   mov  [bx].dcb_StateTimeout,0
  772.   mov  [bx].dcb_@Dev_DTTick,  offset Loc_Tick
  773.  
  774. ; set the following default handlers
  775.  
  776.   .if <[bx].dcb_@Dev_ForceClear eq 0>
  777.      mov  [bx].dcb_@Dev_ForceClear, offset Loc_ForceClear
  778.   .endif
  779.   .if <[bx].dcb_@Adjust eq 0>
  780.      mov  [bx].dcb_@Adjust,         offset AdjustCoords
  781.   .endif
  782.  
  783. ; do some error checking on the device dependent set up
  784.  
  785.   .386p
  786.   mov  si,[bx].dcb_@RegCaps
  787.   lea  di, [bx].dcb_Xtrans          ; check X extents
  788.   call Loc_chk_exts
  789.   .if  <[si].lcap_dev_x_extent eq 0>
  790.      mov   [si].lcap_dev_x_extent, eax
  791.      PANIC PANIC_EXTZERO
  792.   .endif
  793.   lea  di, [bx].dcb_Ytrans          ; check Y extents
  794.   call Loc_chk_exts
  795.   .if  <[si].lcap_dev_y_extent eq 0>
  796.      mov   [si].lcap_dev_y_extent, eax
  797.      PANIC PANIC_EXTZERO
  798.   .endif
  799.  
  800.   mov ax,[si].lcap_sample_rate      ; check rates
  801.   .if <zero ax>
  802.      mov   ax,FAKE_SAMPLE_RATE
  803.      mov   [si].lcap_sample_rate,ax
  804.      PANIC PANIC_RATEZERO
  805.   .endif
  806.   .if <[si].lcap_max_sample_rate eq 0>
  807.      mov   [si].lcap_max_sample_rate,ax
  808.      PANIC PANIC_RATEZERO
  809.   .endif
  810.   .286p
  811.   ret
  812. Loc_Init endp
  813.  
  814. ;------------------------------------------------------------------------------
  815. ; check extents
  816. ;  di = trn
  817. ; returns
  818. ;  eax = default extent
  819. ;------------------------------------------------------------------------------
  820. public Loc_chk_exts
  821. Loc_chk_exts proc
  822.   .386p
  823.   mov eax,[di].trn_ext_max_PM
  824.   .if <zero eax>
  825.      mov   eax, FAKE_EXTENT
  826.      mov   [di].trn_ext_max_PM, eax
  827.      PANIC PANIC_EXTZERO
  828.   .endif
  829.   .if <[di].trn_ext_max eq 0>
  830.      mov   [di].trn_ext_max, eax
  831.      PANIC PANIC_EXTZERO
  832.   .endif
  833.   .if <[di].trn_ext_adj eq 0>
  834.      mov   [di].trn_ext_adj, eax
  835.      PANIC PANIC_EXTZERO
  836.   .endif
  837.   .if <[di].trn_ext_adj_default eq 0>
  838.      mov   [di].trn_ext_adj_default, eax
  839.      PANIC PANIC_EXTZERO
  840.   .endif
  841.   .if <[di].trn_ext_adj_calibrated eq 0>
  842.      mov   [di].trn_ext_adj_calibrated, eax
  843.      PANIC PANIC_EXTZERO
  844.   .endif
  845.   .286p
  846.   ret
  847. Loc_chk_exts endp
  848.  
  849. CSEGI ends
  850.  
  851. end
  852.