home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / MOUSE / ABS.ASM next >
Assembly Source File  |  1995-04-14  |  19KB  |  571 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT (C) Microsoft Corporation, 1989
  4. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  5. ;
  6. ;    The following IBM OS/2 WARP source code is provided to you solely for
  7. ;    the purpose of assisting you in your development of OS/2 WARP device
  8. ;    drivers. You may use this code in accordance with the IBM License
  9. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  10. ;    Copyright statement may not be removed.;
  11. ;*****************************************************************************/
  12.  
  13. ;/*************************************************************************
  14. ;*
  15. ;* SOURCE FILE NAME = ABS.ASM
  16. ;*
  17. ;* DESCRIPTIVE NAME = Absolute event processing routines.
  18. ;*
  19. ;*
  20. ;* VERSION      V2.0
  21. ;*
  22. ;* DATE         01/18/92
  23. ;*
  24. ;* DESCRIPTION  Absolute event processing routines.
  25. ;*
  26. ;* FUNCTIONS Process_Absolute() Process an absolute mouse event packet.
  27. ;*           ABSProtEvent()     Process absolute event for protect mode.
  28. ;*           ABSVDMEvent()      Process absolute event for a VDM session.
  29. ;*           MapXY2RowCol()     Map an (x,y) coordinate to the current mode.
  30. ;*           CalcRelative()     Converts absolute points into a relative
  31. ;*                              motion equivalent.
  32. ;*
  33. ;* NOTES        This file contains the mouse device independent
  34. ;*              absolute event processing routines.  See the linker
  35. ;*              control file for location in link list
  36. ;*
  37. ;*
  38. ;* STRUCTURES   NONE
  39. ;*
  40. ;* EXTERNAL REFERENCES   Ptr Draw DD, Device Dep DD
  41. ;*                       Update_Ptr, IntrSetup, ReportEvent.
  42. ;*
  43. ;*
  44. ;* EXTERNAL FUNCTIONS
  45. ;*
  46. ;*              NONE
  47. ;*
  48. ;* CHANGE ACTIVITY =
  49. ;*   DATE      FLAG        APAR   CHANGE DESCRIPTION
  50. ;*   --------  ----------  -----  --------------------------------------
  51. ;*   mm/dd/yy  @Vr.mpppxx  xxxxx  xxxxxxx
  52. ;*   01/18/92              DCR 1555
  53. ;*   01/18/92              60273  Fixed typo in code
  54. ;*   07/15/93  RAR2        68850  Added additional check for Xclusive Mode
  55. ;*
  56. ;*
  57. ;*
  58. ;*
  59. ;**************************************************************************
  60.  
  61.  
  62. .386p
  63.  
  64. .xlist
  65.         include mouse.inc
  66. .list
  67.  
  68. ;*
  69. ;*  External Mouse Module Data References
  70. ;*
  71.  
  72.        extrn  FgndSessn            : byte
  73.        extrn  MEvent               : byte
  74.        extrn  VEvent               : byte
  75.        extrn  DeviceData           : byte
  76.        extrn  Int_Packet           : byte
  77.        extrn  Num_Grps             : byte
  78.  
  79.        extrn  IntEntry             : word
  80.        extrn  VDM_Flags            : word
  81.        extrn  VDM_Cols             : word
  82.        extrn  VDM_Rows             : word
  83.  
  84.        extrn  MSEVDDEntry          : fword
  85.  
  86.        extrn  Calc_Num             : near
  87.        extrn  IntrSetup            : near
  88.        extrn  Update_Ptr           : near
  89.        extrn  ReportProtectEvent   : near
  90.  
  91.  
  92. CSEG     SEGMENT   WORD  PUBLIC  USE16 'CODE'
  93.          ASSUME    CS:CSEG, SS:nothing, ES:nothing, DS:nothing
  94.  
  95. ;*
  96. ;*   Module Procs made Public for other Mouse Modules
  97. ;*
  98.  
  99.        public  Process_Absolute
  100.        public  MapXY2RowCol
  101.        public  CalcRelative
  102.        public  ABSProtEvent
  103.        public  ABSVDMEvent
  104.        public  Security_Hook2                ;           
  105.        public  Security_End2                 ;           
  106.  
  107.  
  108. ;***********************************************************************
  109. ;*
  110. ;*  FUNCTION NAME  :  Process_Absolute
  111. ;*
  112. ;*  DESCRIPTION    :  Process an absolute mouse event packet.
  113. ;*
  114. ;*               This routine processes absolute event data from
  115. ;*               the attached pointing device.
  116. ;*
  117. ;*  INPUT          :  The packet pointed to by SInt_Packet should contain
  118. ;*                    the new absolute event. The packet format is
  119. ;*
  120. ;*                        Abs_Event    dw
  121. ;*                        Y_Pos        dw
  122. ;*                        X_Pos        dw
  123. ;*                        Y_Size       dw
  124. ;*                        X_Size       dw
  125. ;*
  126. ;*                    DS - MOUSE$ data selector
  127. ;*
  128. ;*  OUTPUT         :  None.
  129. ;*
  130. ;*  RETURN-NORMAL  :  Always.
  131. ;*
  132. ;*  RETURN-ERROR   :  Never.
  133. ;*
  134. ;*  EFFECTS        :  Pointer position updated and event saved.
  135. ;*
  136. ;*  INTERNAL REFERENCES:
  137. ;*     ROUTINES:  Update_Ptr, CalcNewPtrPos, IntrSetup,
  138. ;*                ReportEvent.
  139. ;*
  140. ;*  EXTERNAL REFERENCES:
  141. ;*     ROUTINES:  NONE.
  142. ;*     DevHelps:  NONE.
  143. ;*
  144. ;***********************************************************************
  145. ;* PSEUDOCODE :
  146. ;*
  147. ;*     BeginSub  Process_Absolute
  148. ;*
  149. ;*      IF <fullscreen session>
  150. ;*
  151. ;*         call IntrSetup to do common event processing setup
  152. ;*         IF <session has support>
  153. ;*            call ABSProtEvent to process a fullscreen event
  154. ;*         ENDIF          /* Ignore event if no support available  */
  155. ;*
  156. ;*      ELSEIF<VMSE ready to accept events>
  157. ;*         call ABSVDMEvent to process this FS VDM event
  158. ;*      ENDIF
  159. ;*
  160. ;*      return
  161. ;*
  162. ;*     EndSub  Process_Absolute
  163. ;*
  164. ;************************************************************************
  165.  
  166. Process_Absolute  proc  near
  167.  
  168. ;*
  169. ;*     First increment the entry flag for use in debugging to see if we are
  170. ;*     servicing a mouse event.  Then check if this event is for a full screen
  171. ;*     session. If it is a full screen session then call IntrSetup to setup
  172. ;*     everything needed to process a protect mode full screen mouse event.
  173. ;*     IntrSetup puts the sel:off of the mouse CB affected in DS:SI and
  174. ;*     leaves the mouse data selector in FS.  DS should be reset to
  175. ;*     the mouse data selector before exiting.
  176. ;*
  177.  
  178. Security_Hook2:                      ;           
  179.  
  180.        inc  IntEntry
  181.        mov  al, Num_Grps             ; Get number of full screen sessions
  182.  
  183. Security_End2:                       ;           
  184.  
  185.        .if <FgndSessn lt al> AND     ; If this is a full screen session
  186.        .if <bit VDM_Flags z VDMXMOUSEMODE> ; A windowed VDM does NOT have ;RAR2
  187.                                            ; Exclusive mouse access!      ;RAR2
  188.  
  189.           push ds
  190.           push fs
  191.           call IntrSetup             ; do common event processing setup
  192.  
  193. ;*
  194. ;* If carry is clear then it is OK to process the event.
  195. ;*
  196.           .if <nc>                   ; and session has open mse support
  197.              call ABSProtEvent       ; process a fullscreen event
  198.           .endif
  199.           pop  fs                    ; restore fs to entry value
  200.           pop  ds                    ; restore our ds
  201.  
  202.        .else
  203.           call ABSVDMEvent           ; process VDM event
  204.        .endif
  205.  
  206.        dec  IntEntry                 ; decrement entry count
  207.  
  208.        ret                           ; return to IDC router
  209.  
  210. Process_Absolute  Endp
  211.  
  212.  
  213. ;******************************************************************
  214. ;*
  215. ;* FUNCTION NAME : ABSProtEvent
  216. ;*
  217. ;* DESCRIPTION   : Process absolute event for protect mode.
  218. ;*
  219. ;*  INPUT        : The packet pointed to by SInt_Packet should contain
  220. ;*                 the new absolute event. The packet format is
  221. ;*
  222. ;*                        Abs_Event    dw
  223. ;*                        Y_Pos        dw
  224. ;*                        X_Pos        dw
  225. ;*                        Y_Size       dw
  226. ;*                        X_Size       dw
  227. ;*
  228. ;*                  DS - MOUSE$ data selector
  229. ;*                  SI - pointer to the SGCB
  230. ;*
  231. ;* OUTPUT        : Absolute event processed.
  232. ;*
  233. ;* SIDE EFFECTS  : No registers preserved.
  234. ;*
  235. ;*******************************************************************
  236. ;* PSEUDOCODE    :
  237. ;*
  238. ;*           BeginSub  ABSProtEvent
  239. ;*
  240. ;*            return
  241. ;*
  242. ;*           EndSub  ABSProtEvent
  243. ;*
  244. ;***********************************************************************
  245.  
  246. ABSProtEvent  proc  near
  247.  
  248. NewRow     equ   <(word ptr [bp-4])>   ; local var for new row coord
  249. NewCol     equ   <(word ptr [bp-6])>   ; local var for new col coord
  250.  
  251.        enter 4,0                       ; reserve space for vars
  252.  
  253.        test [SI].MType, Graphics       ; IF mode is a graphics mode
  254.        .if  nz                         ; then
  255.           push [si].GCol_Res           ; push the graphics resolutions
  256.           push [si].GRow_Res           ; on stack
  257.        .else                           ; else push the text resolutions
  258.           push [si].TCol_Res           ; on stack
  259.           push [si].TRow_Res           ; 
  260.        .endif                          ; end display mode type test
  261.  
  262.        call MapXY2RowCol               ; map the absolute data.
  263.  
  264.        mov  NewRow, ax
  265.        mov  NewCol, bx
  266.  
  267.        test [SI].D_Status, MickeyData    ; check to see if mickey data
  268.        .if  nz                           ; to be reported.  If so
  269.  
  270.           push NewCol                    ; put new column on stack
  271.           push NewRow                    ; and new row
  272.           call CalcRelative              ; go calculate a relative event
  273.           add  sp, 4                     ; clear local variables
  274.           push 1                         ; report event no matter what.
  275.        .else                             ; Else report type pointer pos.
  276.           mov  ax, NewRow                ; get new row
  277.           mov  cx, NewCol                ; get new col
  278.           mov  fs:MEvent.Mon_Row_Pos, ax ; put in event record
  279.           mov  fs:MEvent.Mon_Col_Pos, cx
  280.           push 0                         ; report event if not a duplicate
  281.        .endif                            ; Mickey Data Report Test
  282.  
  283.        push NewRow
  284.        push NewCol
  285.        call ReportProtectEvent              ; go report the event
  286.        add  sp, 6
  287.  
  288. ;*
  289. ;* call update_ptr to update the pointer image.  cx is the new col position
  290. ;* and dx is the new row position.  If a VDM is active the device status
  291. ;* will be set to disable calling pointer draw.
  292.  
  293.        mov  cx, NewCol
  294.        mov  dx, NewRow
  295.        call Update_Ptr                 ; update the pointer image
  296.  
  297.        leave
  298.        ret                             ; return to entry routine
  299.  
  300.  
  301. ABSProtEvent  endp
  302.  
  303.  
  304. ;*******************************************************************
  305. ;*
  306. ;* FUNCTION NAME  : ABSVDMEvent
  307. ;*
  308. ;* DESCRIPTION    : Process absolute event for a VDM session.
  309. ;*
  310. ;*  Now map the (x,y) point to the current (row,col) coordinate.
  311. ;*
  312. ;*  This is done using the following formula:
  313. ;*
  314. ;*             Row = (YPos * Row_Res) / YSize
  315. ;*
  316. ;*  Where
  317. ;*        Row is the display row
  318. ;*        YPos is the absolute y position
  319. ;*        Row_Res is the display mode row resolution
  320. ;*        YSize is the Y axis size of the absolute device.
  321. ;*
  322. ;*        The Column calculation is the same using the X
  323. ;*        and column values.
  324. ;*
  325. ;*  INPUT         : The packet pointed to by SInt_Packet should contain
  326. ;*                  the new absolute event. The packet format is
  327. ;*
  328. ;*                             Abs_Event    dw
  329. ;*                             Y_Pos        dw
  330. ;*                             X_Pos        dw
  331. ;*                             Y_Size       dw
  332. ;*                             X_Size       dw
  333. ;*
  334. ;*                       DS - MOUSE$ data selector
  335. ;*
  336. ;* OUTPUT         : Absolute event processed.
  337. ;*
  338. ;* SIDE EFFECTS   : No registers preserved.
  339. ;*
  340. ;**********************************************************************
  341. ;*  PSEUDOCODE :
  342. ;*
  343. ;*   BeginSub  ABSVDMEvent
  344. ;*
  345. ;*    Get X position
  346. ;*    Get the number of columns in the X plane
  347. ;*    Get X size
  348. ;*    Call Calc_Num the get the actual column
  349. ;*    Store new column in packet to VMSE
  350. ;*
  351. ;*    Get Y position
  352. ;*    Get the number of rows in the Y plane
  353. ;*    Get Y size
  354. ;*    Call Calc_Num the get the actual row
  355. ;*    Store new row in packet to VMSE
  356. ;*
  357. ;*    Store current SGID in packet to VMSE
  358. ;*    Store current event in packet to VMSE
  359. ;*    Turn on bit in event field indicating (ABS event)
  360. ;*
  361. ;*    IF <VMSE ready for events>
  362. ;*       Send VMSE this event
  363. ;*    ENDIF
  364. ;*
  365. ;*    return
  366. ;*
  367. ;*   EndSub  ABSVDMEvent
  368. ;*
  369. ;************************************************************************/
  370.  
  371. ABSVDMEvent  proc  near
  372.  
  373.        mov  ax, Int_Packet.X_Pos        ; get the X position
  374.        mov  bx, VDM_Cols                ; Columns in the X plane.
  375.        mov  cx, Int_Packet.X_Size       ; get the X size
  376.        call Calc_Num                    ; do (ax * bx)/cx
  377.        mov VEvent.ve_X, ax              ; New absolute col position.
  378.  
  379.        mov  ax, Int_Packet.Y_Pos        ; get the Y position
  380.        mov  bx, VDM_Rows                ; Rows in the Y plane.
  381.        mov  cx, Int_Packet.Y_Size       ; get the Y size
  382.        call Calc_Num                    ; do (ax * bx)/cx
  383.        mov VEvent.ve_Y, ax              ; New absolute row position.
  384.  
  385. ;*                                                                   ;RAR2
  386. ;* If excluse mouse access mode is ON, then the VEvent.ve_SGID field ;RAR2
  387. ;* has already been updated when the VMSE called PDDCMD_XMouseMode.  ;RAR2
  388. ;*                                                                   ;RAR2
  389.        .if <bit VDM_Flags z VDMXMOUSEMODE>                           ;RAR2
  390.           mov  al, fgndsessn            ; Foreground FS VDM SGID
  391.           cbw                           ; Make into a word
  392.           mov  VEvent.ve_SGID, ax       ; Update input packet.
  393.        .endif                                                        ;RAR2
  394.  
  395.        mov  ax, Int_Packet.Event        ; Motion/button status.
  396.        mov  VEvent.ve_Event, ax         ; Update input packet.
  397.        or   VEvent.ve_Event, ABSPIXEVENT; This is an ABS event.
  398.  
  399.        .if <bit VDM_Flags nz VDMREGISTERED>  ; if VDM interface enabled
  400.           push 0                             ; push a 32 bit 1 for
  401.           push VMSE_EVENT                    ; event notify function
  402.           push ds                            ; selector of input packet
  403.           push offset VEvent                 ; offset of input packet
  404.           push 0                             ; output packet selector (N/A)
  405.           push 0                             ; output packet offset (N/A)
  406.           call MSEVDDEntry                   ; go notify the VDD
  407.        .endif
  408.  
  409.        ret                                   ; return to entry routine
  410.  
  411. ABSVDMEvent  endp
  412.  
  413.  
  414. ;***********************************************************************
  415. ;*
  416. ;* FUNCTION NAME : MapXY2RowCol
  417. ;*
  418. ;* DESCRIPTION   : Map an (x,y) coordinate to the current mode.
  419. ;*
  420. ;* INPUT         :  stack frame  top ->  return address
  421. ;*                               row resolution
  422. ;*                               col resolution
  423. ;*
  424. ;*           SInt_Packet has the latest event data below;
  425. ;*
  426. ;*                Abs_Event    dw
  427. ;*                Y_Pos        dw
  428. ;*                X_Pos        dw
  429. ;*                Y_Size       dw
  430. ;*                X_Size       dw
  431. ;*
  432. ;*          DS - MOUSE$ data selector
  433. ;*
  434. ;* OUTPUT        : ax = new row, bx = new col
  435. ;*
  436. ;* SIDE EFFECTS  : No registers preserved.
  437. ;*
  438. ;**********************************************************************
  439. ;*
  440. ;*  PSEUDOCODE :
  441. ;*
  442. ;*             BeginSub  MapXY2RowCol
  443. ;*
  444. ;*              return
  445. ;*
  446. ;*             EndSub  MapXY2RowCol
  447. ;*
  448. ;***********************************************************************
  449.  
  450.  
  451. MapXY2RowCol  Proc  Near
  452.  
  453. RowRes        equ     <(word ptr [bp+4])>
  454. ColRes        equ     <(word ptr [bp+6])>
  455.  
  456.        ENTER 0,0
  457.  
  458.        push RowRes
  459.        push ColRes
  460.  
  461. ;*
  462. ;* Now map the (x,y) point to the current display mode space.  This is done
  463. ;* using the following formula:
  464. ;*
  465. ;*                   Row = (YPos * Row_Res) / YSize
  466. ;*
  467. ;* Where Row is the display row, YPos is the absolute y position, Col_Res
  468. ;* is the display mode row resolution and YSize is the Y axis size of
  469. ;* the absolute pointing device.  The Column calculation is the same using
  470. ;* the X and column values.
  471. ;*
  472.  
  473.  
  474.        mov  ax, fs:Int_Packet.X_Pos      ; get the x position
  475.        mov  cx, fs:Int_Packet.X_Size     ; get the x size
  476.        pop  bx                           ; get the col resolution
  477.        .if <cx a 0>
  478.          call Calc_Num                  ; do (ax * bx)/cx
  479.          dec  bx                        ; convert col resolution to 0 base
  480.          .if <ax a bx>                  ; if new point out of range somehow
  481.             mov  ax, bx                 ; then use the max 0 based resolution
  482.          .endif                         ; 
  483.          pop  bx                        ; get the row resolution
  484.          push ax                        ; save the new point
  485.  
  486.          mov  ax, fs:Int_Packet.Y_Pos   ; get the y position
  487.          mov  cx, fs:Int_Packet.Y_Size  ; get the y size
  488.          .if <cx a 0>
  489.            call Calc_Num                ; do (ax * bx)/cx
  490.            dec  bx                      ; convert col resolution to 0 base
  491.            .if <ax a bx>                ; if new point out of range somehow
  492.               mov  ax, bx               ; then use the max 0 based resolution
  493.            .endif                       ; leave new row in ax
  494.            pop  bx
  495.            clc                          ; indicate NO_ERROR
  496.          .else
  497.            pop  bx                      ; reset stack
  498.            stc                          ; set error condition
  499.            jmp  exit_err                ; leave
  500.          .endif
  501.        .else
  502.          pop  bx                        ; reset stack
  503.          stc                            ; set error condition
  504.        .endif
  505.  
  506. exit_err:
  507.        LEAVE
  508.        ret
  509.  
  510. MapXY2RowCol  EndP
  511.  
  512.  
  513. ;**********************************************************************
  514. ;*
  515. ;* FUNCTION NAME : CalcRelative
  516. ;*
  517. ;* DESCRIPTION   : Converts absolute points into a relative motion
  518. ;*                 equivalent.
  519. ;*
  520. ;* INPUT         :  stack frame   top -> return address
  521. ;*                                       Row position
  522. ;*                                       Col position
  523. ;*
  524. ;* OUTPUT        : relative motion in mickeys put in the mouse event pkt
  525. ;*
  526. ;* SIDE EFFECTS  : No registers preserved.
  527. ;*
  528. ;************************************************************************
  529. ;* PSEUDOCODE    :
  530. ;*
  531. ;*               BeginSub  CalcRelative
  532. ;*
  533. ;*                return
  534. ;*
  535. ;*               EndSub  CalcRelative
  536. ;*
  537. ;************************************************************************/
  538.  
  539. CalcRelative  Proc  Near
  540.  
  541. RowPos        equ     <(word ptr [bp+4])>
  542. ColPos        equ     <(word ptr [bp+6])>
  543.  
  544.        ENTER 0,0
  545.  
  546.        mov  ax, RowPos
  547.        sub  ax, [si].Ptr_Row_Pos
  548.        imul [si].Row_Cell_Size
  549.        imul [si].RowScale_Fact
  550.        mov  cx, 8
  551.        idiv cx
  552.        mov  fs:MEvent.Mon_Row_Pos, ax
  553.  
  554. ;*     mov  ax, NewCol                          ;           
  555.        mov  ax, ColPos                          ;           
  556.        sub  ax, [si].Ptr_Col_Pos
  557.        imul [si].Col_Cell_Size
  558.        imul [si].ColScale_Fact
  559.        mov  cx, 8
  560.        idiv cx
  561.        mov  fs:MEvent.Mon_Col_Pos, ax
  562.  
  563.        LEAVE
  564.  
  565.        ret
  566.  
  567. CalcRelative  EndP
  568.  
  569. CSEG     ENDS
  570.          END
  571.