home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / MOUSE / STRAT.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  56KB  |  1,370 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. ;* SOURCE FILE NAME = STRAT.ASM
  15. ;*
  16. ;* DESCRIPTIVE NAME = Strategy routine, Request routines, and
  17. ;*                    IOCtl support.
  18. ;*
  19. ;*
  20. ;* VERSION      V2.0
  21. ;*
  22. ;* DATE         08/30/91
  23. ;*
  24. ;* DESCRIPTION  This file contains the mouse strategy routine,
  25. ;*              request routines, and IOCtl support routines.  See
  26. ;*              the linker control file for the location in the link
  27. ;*              list.
  28. ;*
  29. ;* FUNCTIONS
  30. ;*              Request_Handler   Mouse Device Driver Request Handler
  31. ;*              Req_Err           Request block Error handler routine.
  32. ;*              Flush             Input Flush Request handler routine.
  33. ;*              Open              Device Open Request handler routine.
  34. ;*              Close             Device Close Request handler routine
  35. ;*              IOCtl             Generic IOCTL Request handler routine.
  36. ;*              DEINS             Deinstallation Request handler routine.
  37. ;*
  38. ;* STRUCTURES   NONE
  39. ;*
  40. ;* EXTERNAL REFERENCES
  41. ;*
  42. ;*              Ptr Draw DD, INIT, IOMW_MM, Device
  43. ;*                               Dependent DD, Monitor_Handler,
  44. ;*                               CollisionChk.
  45. ;*              SemRequest, GetDOSVar, SemClear,
  46. ;*                               DevDone, DeRegister, MonitorCreate.
  47. ;*
  48. ;* CHANGE ACTIVITY =
  49. ;*   DATE      FLAG        APAR   CHANGE DESCRIPTION
  50. ;*   --------  ----------  -----  --------------------------------------
  51. ;*   04/21/93              67424  Loose mouse when coming back from suspend
  52. ;*                                mode on Dell 325nc laptop.
  53. ;*   06/03/93              69671  Lose pointing stick when coming back from
  54. ;*                                suspend mode on IBM 700 series laptops.
  55. ;**************************************************************************
  56.  
  57.  
  58.  
  59. .xlist
  60.         include mouse.inc
  61.         include infoseg.inc
  62.         include filemode.inc
  63.         include basemaca.inc
  64.         include osmaca.inc
  65.         include emiidc.inc                              ;emi
  66. .list
  67.  
  68. CPUMODE 386
  69.  
  70. ;*
  71. ;*    External Mouse Module Data References
  72. ;*
  73.  
  74.        extrn  Num_Grps                              : byte
  75.        extrn  CallSessn                             : byte
  76.        extrn  FgndSessn                             : byte
  77.        extrn  Ptr_Overide                           : byte
  78.        extrn  DeInstall                             : byte
  79.        extrn  Detach_Proc                           : byte
  80.        extrn  DeviceData                            : byte
  81.        extrn  CurCommand                            : byte
  82.        extrn  CurRequest                            : byte
  83.        extrn  AccessTbl                             : byte
  84.        extrn  TypeOverRider                         : byte
  85.        extrn  SType                                 : byte
  86.        extrn  EmiFlags                              : byte  ; emi
  87.        extrn  APMDD                                 : byte  ;           
  88.        extrn  APMIDCDereg                           : byte  ;           
  89.  
  90.        extrn  RBlk_Tbl                              : word
  91.        extrn  Func_Tbl                              : word
  92.        extrn  Sem_PID                               : word
  93.        extrn  CallPID                               : word
  94.        extrn  DDDInit                               : word
  95.        extrn  StratEntry                            : word
  96.        extrn  IntEntry                              : word
  97.        extrn  EMaskMax                              : word
  98.        extrn  APMIDCHandle                          : word  ;           
  99.        extrn  SynchFlag                             : word  ;           
  100.  
  101.        extrn  Ctl_Sem                               : dword
  102.        extrn  Sem_Time                              : dword
  103.        extrn  Device_Help                           : dword
  104.        extrn  InfoSegAddr                           : dword
  105.  
  106.        extrn  FlushMonChain                         : far
  107.        extrn  Mouse_Init                            : far
  108.        extrn  RegisterForAPM                        : far   ;           
  109.        extrn  Monitor_Handler                       : near
  110.        extrn  IOMW_MM                               : near
  111.        extrn  AccessCheck                           : near
  112.        extrn  PDDCMD_MSEEntry                       : near
  113.        extrn  SGControl                             : near
  114.        extrn  GetDeviceParms                        : near
  115.        extrn  EnableMouse                           : near
  116.        extrn  DisableMouse                          : near
  117.        extrn  FindCB                                : near
  118.        extrn  InitSDevice                           : near
  119.        extrn  Emi_Config                            : near      ;emi
  120.  
  121.        EXTRNFAR CollisionChk
  122.  
  123.  
  124. CSEG2    SEGMENT   WORD  PUBLIC  USE16 'SWAPCODE'
  125.          ASSUME    CS:CSEG2, SS:nothing, ES:nothing, DS:nothing
  126.  
  127. ;*
  128. ;*  Module Procs made Public for other Mouse Modules
  129. ;*
  130.  
  131.        public  Request_Handler
  132.        public  RH_Exit
  133.        public  REQ_ERR
  134.        public  FLUSH
  135.        public  OPEN
  136.        public  CLOSE
  137.        public  IOCTL
  138.        public  DEINS
  139.        public  INITCOMPLETE                                 ;           
  140.  
  141.  
  142. ;************************************************************************
  143. ;*
  144. ;*  FUNCTION NAME :  Request_Handler
  145. ;*
  146. ;*  DESCRIPTION   :  Mouse Device Driver Request Handler
  147. ;*                   Routine.
  148. ;*
  149. ;*                   Processes requests to the mouse device driver.
  150. ;*                   The following requests are valid: Open, Close,
  151. ;*                   Flush, Init, DeInstall, and Generic IOCtl.
  152. ;*                   All other request are returned with an error code.
  153. ;*                   The Init and DeInstall requests are valid only
  154. ;*                   during install time.  Each request is handled by
  155. ;*                   a separate routine that is called via a call
  156. ;*                   table.   When the request is finished, a DevHlp
  157. ;*                   call is done to indicate that the request is done.
  158. ;*                   Access to the Request_Handler is serialized with
  159. ;*                   a RAM semaphore, with the exception of a close
  160. ;*                   request.semaphore ownership is at the process
  161. ;*                   level.
  162. ;*
  163. ;*  NOTES         :  All requests use the generic device request packet
  164. ;*                   format.  Generic IOCtls use the function specific
  165. ;*                   data area to pass specific parameters to indiviual
  166. ;*                   IOCtl routines.  SI contains the offset to the
  167. ;*                   session control block for the calling session.
  168. ;*
  169. ;*  ENTRY POINT   :  Request_Handler    (PROTECT MODE ONLY)
  170. ;*     LINKAGE    :  CALL FAR
  171. ;*
  172. ;*  INPUT         :  ES:BX points to the request packet.
  173. ;*
  174. ;*  RETURN-NORMAL :  Request Block status field set to indicate
  175. ;*                   function complete, no error.
  176. ;*
  177. ;*  RETURN-ERROR  :  Error codes set in Request Block status field.
  178. ;*
  179. ;*  EFFECTS       :  Stack is clean on return, Registers not preserved.
  180. ;*
  181. ;*  INTERNAL REFERENCES:
  182. ;*     ROUTINES:  Mouse_Init, Open, Close, Flush, Ioctl, Deins,
  183. ;*                Req_Err
  184. ;*
  185. ;*  EXTERNAL REFERENCES:
  186. ;*     ROUTINES: DDDD(Read_Enable, Query_Config, Enable_Device)
  187. ;*     DevHlps:  SemRequest, GetDOSVar, SemClear, DevDone.
  188. ;*
  189. ;*************************************************************************
  190. ;* PSEUDOCODE :
  191. ;*
  192. ;* BeginSub  REQUEST_HANDLER
  193. ;*
  194. ;* IF <IDC initialization is required>
  195. ;*    call GetDeviceParms to do the IDC initialization
  196. ;* ENDIF
  197. ;*
  198. ;* IF <Mouse DD initialized AND NOT deinstalled> THEN
  199. ;*    IF <NOT CLOSE command> THEN
  200. ;*       Call Device_Help(SemRequest) to get mouse semaphore
  201. ;*    ELSE
  202. ;*       set flag to show SemRequest worked
  203. ;*    ENDIF
  204. ;*
  205. ;*    IF <SemRequest worked>
  206. ;*       Call Device_Help(GetDOSVar)
  207. ;*       IF <GetDOSVar worked> THEN
  208. ;*          set calling session to session # in LDT
  209. ;*          IF <procedure type is DETACHED> THEN
  210. ;*             set calling session # to VIO pop up session
  211. ;*             set detached flag on
  212. ;*          ELSE
  213. ;*             set detached flag off
  214. ;*             IF <VIO Windowable OR PresMGR app> THEN
  215. ;*                set calling session # to shell session
  216. ;*             ENDIF
  217. ;*             IF <NOT Fullscreen App AND NOT Detached App> THEN
  218. ;*                set request error in req block
  219. ;*             ELSE
  220. ;*                IF <command is valid> THEN
  221. ;*                   IF <IDC interface is initialized OR
  222. ;*                       command is OPEN               OR
  223. ;*                       command is CLOSE>
  224. ;*                      call requested command service routine
  225. ;*                   ELSE
  226. ;*                      set DeviceNotReady error in Req Block
  227. ;*                   ENDIF
  228. ;*                ELSE
  229. ;*                   Call Req_Err
  230. ;*                ENDIF
  231. ;*             ENDIF
  232. ;*
  233. ;*          ENDIF
  234. ;*       ELSE                                     * GetDOSVar Failed
  235. ;*          GenFail
  236. ;*       ENDIF
  237. ;*
  238. ;*    IF <NOT CLOSE command> THEN
  239. ;*       Call Device_Help(SemClear) to release the semaphore
  240. ;*    ENDIF
  241. ;*
  242. ;* ELSE                                        * mouse not initialized
  243. ;*
  244. ;*    IF <INIT Command> THEN
  245. ;*       Call Mouse_Init to initialize
  246. ;*    ELSE
  247. ;*       Call Req_Err
  248. ;*    ENDIF
  249. ;*    call Device_Help(DevDone) to show done with request packet
  250. ;* ENDIF
  251. ;* return
  252. ;*
  253. ;*EndSub  REQUEST_HANDLER
  254. ;*
  255. ;***********************************************************************
  256.  
  257. Request_Handler  proc  far
  258.  
  259.        ?frame = 0
  260.        LocalVar   TempES, WORD                ; Setup local stack frame
  261.        Localvar   TempBX, WORD
  262.  
  263.        EnterProc
  264.  
  265.        inc  StratEntry                        ; show we have entered strategy rtn
  266.        mov  TempES, ES                        ; Save Request Block Address
  267.        mov  TempBX, BX
  268.        mov  al, es:[bx].PktCmd                ; get current command
  269.        mov  CurCommand, al                    ; save for debugging
  270.  
  271. ;*
  272. ;*     If this is the 1st level 0 call then we must initialize the
  273. ;*     interface with the device dependent DD.  This cannot be done at
  274. ;*     init time because initialization is at level 3 and the entry
  275. ;*     points, returned by AttachDD, to the DDDD are ring 0. For this
  276. ;*     reason the Query_Config and Read_Enable calls are done now.  If
  277. ;*     either fail then we will shut down as if we were deinstalled.
  278. ;*
  279.  
  280.        .if <bit DDDInit nz DI_IDC>            ; if IDC initialization needed
  281.          .if <TypeOverRider eq TRUE>
  282.             call GetDeviceParms               ; go get device data
  283.          .endif
  284.  
  285.          .if <SType eq TRUE>
  286.             call InitSDevice
  287.          .endif
  288.        .endif
  289.  
  290. ;*
  291. ;* Do emi configuration after device dependent so that emi can fix things  ;emi
  292. ;* up if there is no base mouse device so that the mouse driver still works;emi
  293. ;* for the emi devices.                                  ;emi
  294. ;*
  295.  
  296.        .if <bit EmiFlags nz EMI_NEED_CONFIG>  ; emi configuration needed  ;emi
  297.           call Emi_Config                               ;emi
  298.        .endif                                           ;emi
  299. ;*
  300. ;*      If the mouse has be intialized and has not been deinstalled then
  301. ;*      it is OK to continue.
  302. ;*
  303.  
  304.        .if <<word ptr Device_Help+2> ne 0> NEAR AND
  305.        .if <Deinstall eq OFF> near
  306.  
  307. ;*
  308. ;*         If this request is a close request then do not request the
  309. ;*         semaphore. This is because the process could have died owning the
  310. ;*         semaphore.  The close is part of cleaning up old semaphores.
  311. ;*
  312.  
  313.           .if <es:[bx].PktCmd ne CMDClose>  ; If not a Close Request then
  314.  
  315. ;*
  316. ;*            Use DEVHELP (SemRequest) to synchronize request processing
  317. ;*
  318.  
  319.              mov  bx, OFFSET Ctl_Sem         ; High word of Sem addr
  320.  
  321.              mov  ax, ds                     ; Low word of Sem addr
  322.              mov  cx, word ptr Sem_Time      ; Low word of Timeout value
  323.              mov  di, word ptr Sem_Time+2    ; High word of Timeout value
  324.              mov  dl, DevHlp_SemRequest      ; Specify function number
  325.              call Device_help                ; Invoke SemRequest function
  326.           .else                              ; if a close request then
  327.              clc                             ; setup common "good" path result
  328.           .endif                             ; close request test
  329.                                              ; 
  330.           .if nc near                        ; if SemRequest worked then
  331.  
  332.                 les  bx,InfoSegAddr
  333.                 mov  dx, es                  ; Save LDT InfoSeg Selector
  334.                 mov  cx, bx                  ; Put Offset into CX
  335.  
  336.                 mov  ax, es:[bx].LIS_CurScrnGrp     ; Get LDT SG ID
  337.                 mov  CallSessn, al                  ; Save LDT SG ID
  338.                 mov  AX, es:[bx].LIS_CurProcID      ; Get LDT PID
  339.                 mov  CallPID, ax                    ; Save Proc ID
  340.  
  341.                 mov  ah, es:[bx].LIS_ProcType       ; Get LDT Proc Type
  342.  
  343.                 .if <ah eq LIS_PT_DETACHED>         ; If a Detached Process
  344.                    mov  CallSessn, VIO_PopUp_SG     ; Setup PopUp SG ID #
  345.                    mov  Detach_Proc, ON             ; Set Detached Proc Flag
  346.                 .else                               ; If not a Detached Proc
  347.                    mov  Detach_Proc, OFF            ; Reset Detached Proc Flag
  348.                    .if <ah eq LIS_PT_VIOWIN> OR     ; If Vio windowable app
  349.                    .if <ah eq LIS_PT_PRESMGR>       ; or Present. Mgr app.
  350.                       mov  ah, LIS_PT_FULLSCRN      ; Map proc type and SG#
  351.                       mov  CallSessn, Shell_Session ; to Winthorn session
  352.                    .endif                           ; End extended SG test
  353.                 .endif                              ; Detached Process Tests
  354.  
  355.                 mov  es, TempES                     ; Restore Request
  356.                 mov  bx, TempBX                     ; Block Address
  357.  
  358.                 .if <es:[bx].PktCmd ne CMDClose>    ; If not a Close Req then
  359.                    mov  cx, CallPID                 ; Copy LDT PID as
  360.                    mov  Sem_PID, cx                 ; Semaphore owner
  361.                 .endif                              ; Close Request Test
  362.  
  363.                 .if <ah ne LIS_PT_FULLSCRN> AND     ; If not a Full Scrn App
  364.                 .if <ah ne LIS_PT_DETACHED>         ; And Not A Detached App
  365.                    mov  es:[bx].PktStatus, UNKNOWNCMD
  366.                 .else  near                         ; If Protect Mode req
  367.                    mov  al, es:[bx].PktCmd          ; Get Req Blk Cmd Code
  368.                    xor  ah, ah                      ; clear ah
  369.                    .if <al b RBlk_Min> OR           ; If Command Code is
  370.                    .if <al a RBlk_Max>              ; Invalid  then
  371.                       mov  es:[bx].PktStatus, UNKNOWNCMD
  372. ;*
  373. ;*        The request is within the valid range.  Now check to see
  374. ;*        that the IDC to the dependent DD was initialized and/or
  375. ;*        support was not disabled by the dependent DD.  If the
  376. ;*        IDC has been shut down then still allow opens and closes,
  377. ;*        otherwise fail the request with a DEVICENOTREADY error.
  378. ;*
  379.  
  380.                    .else                             ; Else Command Code Valid
  381.                       .if <bit DDDInit nz DI_ERROR> AND    ; IDC Init error ?
  382.                       .if <al ne CMDOpen> AND        ; and not an open or
  383.                       .if <al ne CMDClose>           ; close then
  384.                          mov  es:[bx].PktStatus, DEVICENOTREADY
  385.                       .else                          ; else request is OK
  386.  
  387. ;*
  388. ;*        If the request is a category Bh, function 41h IOCtl
  389. ;*        then the request is a screen group control request.
  390. ;*        In this case do not load DS:SI with the CB address
  391. ;*        because it may not exist.  It will be loaded later
  392. ;*        if needed.  If it is some other request then load
  393. ;*        DS:SI with the CB address for the calling session.
  394. ;*        In either case FS is loaded with the mouse data
  395. ;*        segment.  FS should be used by any routines that
  396. ;*        are below the Request_Handler.
  397. ;*
  398.  
  399.                          push ds                   ; save ds
  400.                          push fs                   ; and fs
  401.                          push ds                   ; put ds in fs
  402.                          pop  fs
  403.  
  404.                          mov  di, ax               ; put function code
  405.                          shl  di, 1                ; in di and shift
  406.  
  407.                          .if <al eq CMDGenIOCTL> and
  408.                          .if <es:[bx].GIOCategory eq 0bh> and
  409.                          .if <es:[bx].GIOFunction eq 41h>
  410.                             call SGControl         ; call screen group control
  411.                          .else
  412.                             push bx
  413.                             xor  bh, bh
  414.                             mov  bl, CallSessn     ; get CB of call sessn
  415.                             call FindCB
  416.                             pop  bx
  417.                             .if <nc>               ; if CB found
  418.                                call fs:RBlk_Tbl[di]; call requested routine
  419.                             .else                  ; else, set a
  420.                                GenFail             ; general failure error
  421.                             .endif
  422.                             mov  bx, TempBX        ; restore BX
  423.                          .endif
  424.                          pop  fs                   ; restore fs
  425.                          pop  ds                   ; restore ds
  426.                       .endif
  427.                    .endif                          ; end valid req test
  428.  
  429.                 .endif                             ; Req Mode tests
  430.  
  431.  
  432.              .if <es:[bx].PktCmd ne CMDClose>  ; If not a Close Request then
  433.  
  434. ;*
  435. ;*        Use DEVHLP (SemClear) to free the process control Semaphore
  436. ;*
  437.  
  438.                 mov  bx, OFFSET Ctl_Sem       ; High word of sem address
  439.  
  440.                 mov  ax, ds                   ; Low word of sem address
  441.                 mov  dl, DevHlp_SemClear      ; Devhelp function number
  442.                 call Device_Help              ; Invoke SemClear function
  443.                 mov  Sem_PID, 0000H           ; Clear Sem ownership PID
  444.              .endif                           ; Close Request Test
  445.  
  446.           .else                               ; If SemRequest failed then
  447.              GenFail                          ; Set General Failure Return Code
  448.           .endif                              ; SemRequest Tests
  449.  
  450.           mov  bx, TempBX                     ; Restore Request Block Address
  451.  
  452. ;*
  453. ;*         use DEVHLP (DevDone) to wrap up request block processing
  454. ;*
  455.  
  456.           mov  dl, DevHlp_DevDone             ; Specify function number
  457.           call Device_help                    ; Invoke DevDone Function
  458.  
  459.        .else                                  ; If DD is not init'd or it's
  460.                                               ; Been DeInstalled then
  461.           mov  al, es:[bx].PktCmd             ; Get Req Blk Cmd Code
  462.  
  463.           .if <al eq CMDInit>                 ; If an INIT Request then
  464.              call Mouse_Init                  ; Invoke Initialization Rtn
  465.           .else                               ; If not an INIT Request then
  466.              .if <DeInstall eq ON>            ; if we have deinstalled
  467.                 mov  es:[bx].PktStatus, UNKNOWNCMD
  468.              .endif
  469.           .endif                              ; INIT Req Tests
  470.  
  471.           or   es:[bx].PktStatus, STDON       ; Set Req Blk Complete Flag
  472.  
  473.        .endif                                 ; DD Initialization tests
  474.  
  475.        LeaveProc                              ; Clear stack frame
  476.        dec  StratEntry                        ; decrement debug aid
  477.  
  478. RH_Exit:
  479.  
  480.        ret                                    ; Return to caller
  481.  
  482. Request_Handler  ENDP
  483.  
  484.  
  485. ;************************************************************************
  486. ;*
  487. ;*  FUNCTION NAME :  Req_Err
  488. ;*
  489. ;*  DESCRIPTION   :  Request block Error handler routine.
  490. ;*
  491. ;*                   This routine sets the request block status field
  492. ;*                   to the error code UNKNOWN COMMAND.  The request
  493. ;*                   block is pointed to by ES:BX.
  494. ;*
  495. ;*  ENTRY POINT   :  Req_Err                    LINKAGE:  CALL NEAR
  496. ;*
  497. ;*  INPUT         :  ES:BX points to the request block.
  498. ;*
  499. ;*  RETURN-NORMAL :  Error return code set within Request Block
  500. ;*                   status field.           (Always)
  501. ;*
  502. ;*  RETURN-ERROR  :  N/A
  503. ;*
  504. ;*  EFFECTS       :  Stack is clean on return, NO registers changed.
  505. ;*
  506. ;*
  507. ;*************************************************************************
  508. ;*
  509. ;* BeginSub  REQ_ERR
  510. ;*
  511. ;*  set packet status in request block to UNKNOWN COMMAND
  512. ;*  return
  513. ;*
  514. ;* EndSub  REQ_ERR
  515. ;*
  516. ;***********************************************************************
  517.  
  518. REQ_ERR  proc  near
  519.  
  520. ;*
  521. ;*      Set Request Block bits 15 and 3 for an Unknown Command Error
  522. ;*
  523.  
  524.        mov  es:[bx].PktStatus, UNKNOWNCMD
  525.        ret
  526. REQ_ERR  endp
  527.  
  528.  
  529. ;************************************************************************
  530. ;*
  531. ;*  FUNCTION NAME :  Flush  (07H, Input Flush Cmd)
  532. ;*
  533. ;*  DESCRIPTION   :  Input Flush Request handler routine.
  534. ;*
  535. ;*                   Flushes the session monitor chain and event que.
  536. ;*                   All events are discarded by the monitor handler
  537. ;*                   until it receives the flush record.   If singleQ
  538. ;*                   mode is active for the session, then an UNKNOWN
  539. ;*                   COMMAND error is returned.
  540. ;*
  541. ;*  ENTRY POINT   :  Flush                          LINKAGE: CALL NEAR
  542. ;*
  543. ;*  INPUT         :  ES:BX Points to the request block.
  544. ;*                   SI has offset to current session's control block
  545. ;*
  546. ;*  RETURN-NORMAL :  Caller's screen group event queue and Monitor
  547. ;*                   Chain are flushed.
  548. ;*
  549. ;*  RETURN-ERROR  :  Error return code value set in Request block
  550. ;*                   Status field.
  551. ;*
  552. ;*  EFFECTS       :  Stack is clean on return, registers not preserved.
  553. ;*
  554. ;*  INTERNAL REFERENCES:
  555. ;*     ROUTINES:  FlushMonChain, Req_Err
  556. ;*
  557. ;*************************************************************************
  558. ;* PSEUDOCODE :
  559. ;*
  560. ;*BeginSub  FLUSH
  561. ;*
  562. ;* IF <NOT a Detached Process> THEN
  563. ;*    IF <SingleQ mode not active> THEN
  564. ;*       disable system ints
  565. ;*       IF <Device NOT busy> THEN
  566. ;*          call FlushMonChain to flush the event queue and mon chain
  567. ;*          IF <DevHlp_MonFlush FAILED> THEN
  568. ;*             set general failure error
  569. ;*          ENDIF
  570. ;*       ELSE
  571. ;*          set general failure error
  572. ;*       ENDIF
  573. ;*       enable system ints
  574. ;*    ELSE
  575. ;*       set request error
  576. ;*    ENDIF
  577. ;* ELSE
  578. ;*    set request error
  579. ;* ENDIF
  580. ;* Return
  581. ;*
  582. ;*EndSub  FLUSH
  583. ;*
  584. ;***********************************************************************
  585.  
  586. FLUSH  proc  near
  587.  
  588.        ?frame = 0                             ; Define local stack frame
  589.        LocalVar TempES, WORD
  590.        LocalVar TempBX, WORD
  591.  
  592.        EnterProc
  593.        mov  TempES, es                        ; Save request block address
  594.        mov  TempBX, bx
  595.  
  596. ;*
  597. ;*      If the process is not a detached process then the flush is done.  If
  598. ;*      the session has singleq mode active then the flush is rejected as an
  599. ;*      unknown command error.  If not then the request is processed.
  600. ;*
  601.  
  602.        .if <fs:Detach_Proc eq OFF> near       ; If Not Detached Process
  603.           test [si].D_Status, SQ_Mode         ; Check SQ Mode Flag Bit
  604.           .if <z> near                        ; If SQ Mode InActive
  605.              cli                              ; Hold ints for queue update
  606.  
  607. ;*
  608. ;*     If the queue is busy with activity then reject the flush with a
  609. ;*     general failure error, otherwise process the flush request.
  610. ;*
  611.  
  612.              test [si].D_Status, Busy_Mask    ; Check Que Busy Flag Bit
  613.              .if <z> near                     ; If Event Que not busy with I/O
  614.                 call FlushMonChain            ; go flush the chain
  615.                 .if c                         ; If MonFlush failed then
  616.                    and  [si].D_Status, NOT Q_Flush  ; Reset Flush Flag Bit
  617.                    GenFail                    ; Set Request Block Error code
  618.                 .endif                        ; MonFlush Completion Flag
  619.  
  620.                 and  [si].D_Status, NOT Busy_Mask  ; Reset Que Busy Flag
  621.  
  622.              .else                            ; If SG Event Queue is busy then
  623.                 GenFail                       ; Set Request Block Error code
  624.              .endif                           ; Event Queue Busy test
  625.              sti                              ; Que reset done, allow interrupts
  626.           .else                               ; If SQ Input Mode is Active
  627.              mov  es:[bx].PktStatus, UNKNOWNCMD
  628.           .endif                              ; SQ Input Mode Tests
  629.  
  630.        .else                                  ; If a Detached Process Then
  631.           mov  es:[bx].PktStatus, UNKNOWNCMD
  632.        .endif                                 ; Detached Process Tests
  633.  
  634.        LeaveProc
  635.  
  636.        ret                                    ; Return to Request_Handler Rtn.
  637. FLUSH  ENDP
  638.  
  639.  
  640.  
  641. ;************************************************************************
  642. ;*
  643. ;*  FUNCTION NAME :  Open
  644. ;*
  645. ;*  DESCRIPTION   :  Device Open Request handler routine.
  646. ;*
  647. ;*                   This routine processes Open requests.  It updates
  648. ;*                   the calling session's active handle counter.  If
  649. ;*                   the counter increments from 0 to 1 then the
  650. ;*                   session's control block is initialized.  The
  651. ;*                   initialized state is the following:
  652. ;*                      Row/Col Scale factors = 16:8
  653. ;*                      All events reportable
  654. ;*                      Monitor chain and event queue flushed
  655. ;*                      If Valid mode data available set:
  656. ;*                         Ptr position to center of screen
  657. ;*                         Define display space as collision area
  658. ;*                      If no mode data available set:
  659. ;*                         Ptr to (0,0)
  660. ;*                         Collision area to (0,0) - (32K, 32K)
  661. ;*                      Device status is set to:
  662. ;*                         Ptr Draw DD is called for ptr operations
  663. ;*                         report display coordinate movement
  664. ;*
  665. ;*  ENTRY POINT   :  Open                        LINKAGE:  CALL NEAR
  666. ;*
  667. ;*  INPUT         :  ES:BX points to the request block.
  668. ;*                   SI has offset to current session's control block
  669. ;*
  670. ;*  RETURN-NORMAL :  Caller's session handle counter is incremented
  671. ;*                   and session initialized if level 1 open.
  672. ;*
  673. ;*  RETURN-ERROR  :  Error return code is set in the Request block
  674. ;*                   Status field.
  675. ;*
  676. ;*  EFFECTS       :  Stack is clean on return, AX, CX, DX, and DI
  677. ;*                   register contents are destroyed.
  678. ;*
  679. ;*  INTERNAL REFERENCES:
  680. ;*     ROUTINES:  Req_Err.
  681. ;*
  682. ;*  EXTERNAL REFERENCES:
  683. ;*     ROUTINES:  Ptr Draw(FreePointerMem), DDDD(Disable_Device,
  684. ;*                Enable_Device)
  685. ;*
  686. ;************************************************************************
  687. ;*
  688. ;*BeginSub  OPEN
  689. ;*
  690. ;*   Call DDDD(Disable_Device) to disable the mouse
  691. ;*
  692. ;*   IF <session hs no open handles>
  693. ;*      RowScale_Fact <- 16
  694. ;*      ColScale_Fact <- 8
  695. ;*      Row_Remain <- 0
  696. ;*      Col_Remain <- 0
  697. ;*      Col_Cell_Remain <- 0
  698. ;*      Row_Cell_Remain <- 0
  699. ;*      Calculate max event mask using number of buttons
  700. ;*      reset settable bits in device status flags
  701. ;*      reset block bit in device status flags
  702. ;*      Event_Q_Size <- 0
  703. ;*      EQ_Head <- start of event queue
  704. ;*      EQ_Tail <- EQ_Head
  705. ;*      Define collision area (area flags <- 1)
  706. ;*      Area_Top <- 0
  707. ;*      Area_Left <- 0
  708. ;*
  709. ;*      IF <mode data not available>
  710. ;*         set unsupported mode in device status
  711. ;*         set pointer position to (0,0)
  712. ;*         Area_Bot <- 7fffh
  713. ;*         Area_Right <- 7fffh
  714. ;*
  715. ;*      ELSE
  716. ;*
  717. ;*         IF <current mode is graphics>
  718. ;*            enable threshold calculations
  719. ;*            use graphics resolutions
  720. ;*         ELSE
  721. ;*            disable threshold calculations
  722. ;*            use text resolutions
  723. ;*         ENDIF
  724. ;*
  725. ;*         Area_Bot <- max vertical resolution
  726. ;*         Area_Right <- max horizontal resolution
  727. ;*         set pointer to center of screen (1/2 resolutions)
  728. ;*
  729. ;*      ENDIF
  730. ;*
  731. ;*      IF <pointer draw DD registered>
  732. ;*         call PointDD(FreePointerMem) to free buffers
  733. ;*      ENDIF
  734. ;*
  735. ;*      IF <Device resolution is above 100 mickeys/inch>
  736. ;*         threshold_1 <- 10
  737. ;*         threshold_2 <- 20
  738. ;*      ELSE
  739. ;*         threshold_1 <- 5
  740. ;*         threshold_2 <- 10
  741. ;*      ENDIF
  742. ;*
  743. ;*   ENDIF   /*  1st level open
  744. ;*
  745. ;*   increment session open handle counter
  746. ;*   call DDDD(Enable_Device) to enable the mouse
  747. ;*
  748. ;*EndSub  OPEN
  749. ;*
  750. ;***********************************************************************
  751.  
  752. OPEN  PROC  NEAR
  753.  
  754.        call DisableMouse               ; Hold Mouse Interrupts
  755.  
  756.        mov  ax, [si].Hdle_Cntr         ; Get SG CB open handle counter
  757.        .if <ax eq 0> NEAR              ; If SG is Opening then
  758.  
  759. ;*
  760. ;*         Initialize the session control block to default values.
  761. ;*
  762.  
  763.           mov  [si].RowScale_Fact, 16   ; Load default
  764.           mov  [si].ColScale_Fact, 8    ; Scaling Factors
  765.           mov  [si].Row_Remain, ax      ; Clear Row remainder
  766.           mov  [si].Col_Remain, ax      ; Clear Col remainder
  767.           mov  [si].Col_Cell_Remain, ax ; Clear Col pixel remainder
  768.           mov  [si].Row_Cell_Remain, ax ; Clear Row pixel remainder
  769.  
  770.           mov  bx, fs:EMaskMax          ; invert to make valid events 1's
  771.           mov  [si].E_Mask, bx          ; All events are queueable
  772.  
  773.           mov  cx, [si].D_Status        ; Get current Status Flags
  774.           xor  ch, ch                   ; Clear Settable Flags
  775.           and  cl, NOT Block_Mask       ; clr blocked bit
  776.           mov  [si].D_Status, cx        ; Restore Dev Status Flags
  777.  
  778. ;*
  779. ;*         Set the event queue to empty and define the session colision area
  780. ;*         as the entire screen.
  781. ;*
  782.  
  783.           mov  [si].Eq_Size, al            ; Set Queue empty count
  784.           mov  cx, [si].E_Queue            ; Get event que base offset
  785.           mov  [si].Eq_Head, cx            ; Queue algorithm ptr
  786.           mov  [si].Eq_Tail, cx            ; Mem offset positions
  787.  
  788.           mov  [si].Area_Flags, 0001H      ; Define Collision Area
  789.           mov  [si].Area_Top, ax           ; Define full screen
  790.           mov  [si].Area_Left, ax          ; Collision Area
  791.  
  792.           mov  [si].Lvl1Mplr, 2            ; 2x at 1st level (Default
  793.           mov  [si].Lvl2Mplr, 4            ; 4x at 2nd level     Multipliers)
  794.  
  795.           mov  cx, [si].MLength            ; Get current mode data len
  796.           .if <cx eq 0>                    ; If No Disp Mode Data then
  797.              mov  [si].D_Status, ax        ; Init Device Status Flags
  798.              or   [si].D_Status, USS_Mode  ; Set     Display Mode Flag Bit
  799.              mov  [si].Ptr_Row_Pos, ax     ; Set Ptr at upper left
  800.              mov  [si].Ptr_Col_Pos, ax     ; Until Mode is set
  801.              mov  [si].Area_Bot, 07fffh    ; Define it to be bigger than
  802.              mov  [si].Area_Right, 07fffh  ; Current default Disp Modes
  803.  
  804.           .else                            ; If Disp Mode data avail
  805.  
  806.              test [si].MType, Graphics     ; Check current Display Mode
  807.              .if  nz                       ; If in Graphics Mode then
  808.                 mov  cx, [si].GRow_Res     ; Get row resolution
  809.                 mov  bx, [si].GCol_Res     ; Get col resolution
  810.              .else                         ; If in Text Mode then
  811.                 mov  cx, [si].TRow_Res     ; Get row resolution
  812.                 mov  bx, [si].TCol_Res     ; Get col resolution
  813.              .endif                        ; Display Mode Tests
  814.  
  815.             .if <cx gt 640> OR             ; if high resolution change
  816.             .if <bx gt 480>                ;   thresholding multipliers
  817.                 mov  [si].Lvl1Mplr, 3      ; 3x at 1st level
  818.                 mov  [si].Lvl2Mplr, 6      ; 6x at 2nd level
  819.             .endif
  820.  
  821.  
  822.              mov  [si].Area_Bot, cx        ; Full Screen Collision Area
  823.              mov  [si].Area_Right, bx      ; = Display Mode Resolution
  824.              shr  cx, 1                    ; Get half row resolution
  825.              mov  [si].Ptr_Row_Pos, cx     ; For center screen ptr pos
  826.              shr  bx, 1                    ; Get half col resolution
  827.              mov  [si].Ptr_Col_Pos, bx     ; For center screen ptr pos
  828.           .endif                           ; Disp Mode Data Test
  829.  
  830. ;*
  831. ;*         Call the session registered pointer draw, if there is one, to
  832. ;*         set the pointer to the default.  Then set the default threshold
  833. ;*         (acceleration) levels according to the mouse device sesitivity.
  834. ;*
  835.  
  836.           .if <<word ptr [si].Screen_Entp+2> ne 0> ; If SG PointDD dfnd
  837.              mov  al, fs:CallSessn                 ; Get FG SG ID #, reset ptr
  838.              FreePointerMem                        ; To PointDD Mode defaults
  839.           .endif                                   ; Defined PointDD Tests
  840.  
  841.           .if <fs:DeviceData.NumMics a 40h> ; If a higher resolution mouse
  842.              mov  [si].Level1, 3                   ; then set the higher res
  843.              mov  [si].Level2, 20                  ; threshold defaults.
  844.           .else                             ; Otherwise if a lower res mouse
  845.              mov  [si].Level1, 5                   ; then set the loser res
  846.              mov  [si].Level2, 10                  ; threshold defaults.
  847.           .endif
  848.  
  849.        .endif                                      ; session itialization test
  850.  
  851.        inc  [si].Hdle_Cntr                         ; Update SG Handle Counter
  852.        call EnableMouse                            ; Allow Mouse Interrupts
  853.        ret                                         ; Return to Request Handler Rtn.
  854.  
  855. OPEN  ENDP
  856.  
  857.  
  858. ;************************************************************************
  859. ;*
  860. ;*  FUNCTION NAME :  Close
  861. ;*
  862. ;*  DESCRIPTION   :  Device Close Request handler routine.
  863. ;*
  864. ;*                   This routine processes two types of close
  865. ;*                   requests.                   They are
  866. ;*
  867. ;*                   1.  Device close - This request decrements the
  868. ;*                       session's active handle counter.  If the
  869. ;*                       counter decrements to 0 then support for that
  870. ;*                       session is closed, the monitor chain is
  871. ;*                       flushed, and the pointer is removed.
  872. ;*
  873. ;*                   2.  Monitor close - This request deregisters all
  874. ;*                       monitors for the process regardless of the
  875. ;*                       session the monitor was registered for.
  876. ;*
  877. ;*  ENTRY POINT   :  Close          LINKAGE:  CALL NEAR
  878. ;*
  879. ;*  INPUT         :  ES:BX points to request block.
  880. ;*                   DS:SI has offset to current session's control block.
  881. ;*
  882. ;*  RETURN-NORMAL :  Caller's screen group handle counter is
  883. ;*                   decremented.
  884. ;*
  885. ;*  RETURN-ERROR  :  Error return code set in Request Block Status
  886. ;*                   field.
  887. ;*
  888. ;*  EFFECTS       :  Stack is clean on return, AX, CX, DX, and SI
  889. ;*                   register contents are destroyed.
  890. ;*
  891. ;*  INTERNAL REFERENCES:
  892. ;*     ROUTINES:  CollisionChk, FlushMonChain.
  893. ;*
  894. ;*  EXTERNAL REFERENCES:
  895. ;*     ROUTINES:  Ptr Draw(RemovePointer), DDDD(Enable_Device,
  896. ;*                Disable_Device)
  897. ;*     DevHlps:   SemClear, DeRegister.
  898. ;*
  899. ;*************************************************************************
  900. ;*
  901. ;*BeginSub  CLOSE
  902. ;*
  903. ;* decrement session open handle
  904. ;* IF <Hdle_Cntr = 0> THEN                        * Session closing
  905. ;*    call DDDD(Disable_Device) to disable the mouse
  906. ;*    IF <Ptr Draw Enabled                          AND
  907. ;*        display mode supported   AND
  908. ;*        pointer draw registered  AND
  909. ;*        there is no collision> THEN
  910. ;*       call Ptr Draw(RemovePointer) for unconditional ptr remove
  911. ;*    ENDIF
  912. ;*
  913. ;*    call FlushMonChain to flush the monitor chain and event queue
  914. ;*    IF <monitor flush failed>
  915. ;*       set general failure error
  916. ;*    ENDIF
  917. ;*
  918. ;*    call DDDD(Enable_Device) to enable the mosue
  919. ;* ENDIF                                         * Session closing
  920. ;*
  921. ;* IF <Monitor Close request> THEN
  922. ;*    WHILE <more sessions>
  923. ;*       IF <Registered monitor> THEN
  924. ;*          call Device_Help(DevHlp_DeRegister(Chain_Hdle,Proc_ID)
  925. ;*          IF <DeRegister FAILED> THEN
  926. ;*             set general failure error code
  927. ;*          ELSE
  928. ;*             set session chain size to what's left
  929. ;*          ENDIF
  930. ;*       ENDIF
  931. ;*    ENDWHILE
  932. ;* ENDIF
  933. ;*
  934. ;* IF <Caller owns Device Semaphore> THEN
  935. ;*    call Device_Help(DevHlp_SemClear) to release it
  936. ;*    IF <Blocked thread AND Blocked thread is closing PID> THEN
  937. ;*       reset blocked thread status
  938. ;*    ENDIF
  939. ;* ENDIF
  940. ;* Return
  941. ;*
  942. ;*EndSub  CLOSE
  943. ;*
  944. ;***********************************************************************
  945.  
  946. CLOSE  PROC  NEAR
  947.  
  948.        ?frame = 0                           ; Define local stack frame
  949.        LocalVar TempES, WORD
  950.        LocalVar TempBX, WORD
  951.        LocalVar TempSI, WORD                ; Alloc Stack Space for SI
  952.        LocalVar TempFS, WORD                ; 
  953.  
  954.        EnterProc
  955.        mov  TempFS, fs                      ; Save Base Mouse Data Sel
  956.        mov  TempES, es                      ; Save Request Block address
  957.        mov  TempBX, bx
  958.        mov  TempSI, si                      ; Save Current SG CB Offset
  959.  
  960.  
  961.        and  [si].Ptr_Flags, NOT SM_WinFlag  ; Reset Set Mode Disable Flag
  962.        dec  [si].Hdle_Cntr                  ; Update SG open handle counter
  963.  
  964. ;*
  965. ;*      If a session is closing, ie. open handle count going to 0, then
  966. ;*      perform session clean up.  This consists of removing the pointer and
  967. ;*      flushing the monitor chain.
  968. ;*
  969.  
  970.        .if <z> near                           ; If SG support is closing then
  971.  
  972.          call DisableMouse                    ; Hold Mouse Interrupts
  973.          mov  bl, fs:FgndSessn                ; Get forground screen group #
  974.  
  975.          test [SI].D_Status, PtrDraw+USS_Mode ; Try PtrDD/Disp Mode Flags
  976.          .if <z> AND                          ; If Ptr DD Used & Mode AOK
  977.          .if <fs:CallSessn eq bl> AND         ; And if process is in FG SG and
  978.          .if <<word ptr [si].Screen_Entp+2> ne 0> ; Ptr draw initialized
  979.            CALLFAR CollisionChk               ; Collision Area Checking
  980.            .if <ax eq 0>                      ; If Not a Ptr Collision
  981.              mov  al, fs:FgndSessn            ; Get forground screen group #
  982.              push cx                          ; Save current reg value
  983.              mov  cx, 0                       ; Flag Remove Ptr Required
  984.              RemovePointer                    ; Hide Mouse Pointer Image
  985.              pop  cx                          ; Restore previous reg value
  986.            .endif                             ; Collision Area Test
  987.          .endif                               ; Valid Hide Ptr Tests
  988.  
  989. ;*
  990. ;*        Now go flush the monitor chain.  This will also clear the event queue.
  991. ;*
  992.  
  993.          call FlushMonChain                   ; flush the mon chain and Event Q
  994.  
  995.          .if <c>                              ; If FlushMonChain failed then
  996.            GenFail                            ; set a general failure return code
  997.          .endif
  998.  
  999.          call EnableMouse                     ; Allow Mouse Interrupts
  1000.  
  1001.        .endif                                 ; SG Closing Test
  1002.  
  1003.        mov  bx, TempBX                        ; Restore RB Offset
  1004.        test es:[bx].PktStatus, OPEN_MONITOR   ; Check Monitor Bit
  1005.        .if <nz> near                          ; If a MonOpen request
  1006.  
  1007.          mov  es:[bx].PktStatus, 0            ; Clear Req Blk Status Flags
  1008.          xor  bx, bx                          ; Setup SG ID Counter
  1009.  
  1010.  
  1011.          .while <bl lt fs:Num_Grps>           ; Loop thru all SG's
  1012.  
  1013.            mov  ds, TempFS                    ; Get base Mouse data seg
  1014.  
  1015.            call FindCB                        ; Returns pointer to CB
  1016.            .if <nc>                           ; If CB found
  1017.  
  1018.               mov  al, [si].Chain_Size        ; Get SG Installed Monitor Count
  1019.               .if <al a 0>                    ; If SG Monitors Installed
  1020.                 push bx                       ; Current SG being processed.
  1021.                 mov  bx, fs:CallPID           ; Set up LDT PID
  1022.                 mov  ax, [si].Chain_Hdle      ; Get SG CB Chain Handle
  1023.                 mov  dl, DevHlp_DeRegister    ; Specify Dev_Help Function number
  1024.                 call fs:Device_Help           ; Invoke DeRegister function
  1025.                 mov  fs, TempFS               ; Get base Mouse data seg
  1026.  
  1027.                 .if c                         ; If DeRegister failed then
  1028.                   GenFail                     ; Set Req Blk Error Return code
  1029.                 .else                         ; If nc, AX = # Monitors
  1030.                   mov  [si].Chain_Size, al    ; Left in SG Mon Chain
  1031.                   .if <zero al>               ; If no more monitors in the chain
  1032.                      mov  ax,[si].Chain_Hdle  ; Specify Create Chain
  1033.                      add  si, MB_Len          ; add in offset to MOB
  1034.                      push ds                  ; SG CB selector
  1035.                      pop  es                  ; SG CB selector
  1036.                      push cs                  ; Setup DS:DI to Mon
  1037.                      pop  ds                  ; Notify Rtn Address
  1038.                      mov  di, offset Monitor_Handler
  1039.                      mov  dl, DevHlp_MonitorCreate
  1040.                      mov  fs, TempFS
  1041.                      call fs:Device_Help     ; Invoke MonitorCreate
  1042.                      mov  fs, TempFS         ; Get base Mouse data seg
  1043.                   .endif
  1044.                 .endif                       ; DeRegister Tests
  1045.                 pop  bx                      ; Get last SG # back.
  1046.               .endif                         ; Installed Monitors Test
  1047.  
  1048.            .endif
  1049.  
  1050.            inc  bl                           ; Update SG Index Counter
  1051.          .endwhile                           ; SG Mon DeReg Loop
  1052.  
  1053.          mov  si, TempSI                     ; Restore Current SGCB Offset
  1054.        .endif                                ; DosMonClose Test
  1055.  
  1056.        mov  bx, fs:CallPID                   ; Get Callers PID
  1057.  
  1058. ;*
  1059. ;*      If process that is doing the close owns the DD semaphore then
  1060. ;*      use DEVHLP (SemClear) to free the semaphore.
  1061. ;*
  1062.  
  1063.        .if <fs:Sem_PID eq bx>                ; If Closing PID owns DD Sem
  1064.           mov  bx, OFFSET Ctl_Sem            ; High word of sem address
  1065.           mov  ax, ds                        ; Low word of sem address
  1066.           mov  dl, DevHlp_SemClear           ; Specify function number
  1067.           call fs:Device_Help                ; Invoke SemClear Function
  1068.  
  1069.           mov  cx, fs:Sem_PID                ; Get LDT PID
  1070.  
  1071.           test [si].d_status, Block_Mask     ; Check Blocked Thread Flag
  1072.           .if <nz> AND                       ; If a thread Blocked and
  1073.           .if <cx eq [si].Eq_PID>            ; the thread is Closing then
  1074.              and  [si].D_Status, NOT Block_Mask ; Reset Blocked Flag Bit
  1075.              mov  [si].Eq_PID, 0000H         ; Clear Eq ownership PID
  1076.          .endif                              ; Blocked Event Que Test
  1077.  
  1078.          mov  fs:Sem_PID, 0000H              ; Clear Main Sem Ownership PID
  1079.  
  1080.        .endif                                ; Dead PID Test
  1081.  
  1082.        mov  bx, TempBX                       ; Restore request block addr
  1083.        mov  es, TempES
  1084.        LeaveProc
  1085.        ret                                   ; Return to Request_Handler Rtn.
  1086.  
  1087. CLOSE  ENDP
  1088.  
  1089.  
  1090.  
  1091. ;************************************************************************
  1092. ;*
  1093. ;*  FUNCTION NAME :  IOCtl
  1094. ;*
  1095. ;*  DESCRIPTION   :  Generic IOCTL Request handler routine.
  1096. ;*
  1097. ;*                   This routine is the router for generic IOCtl
  1098. ;*                   requests.  IOCtl request are routed by using a
  1099. ;*                   function table.  Invalid requests are handled by
  1100. ;*                   calling Req_Err to set the error code.  If the
  1101. ;*                   MODE=R option was specified then only a subset of
  1102. ;*                   IOCtls are allowed.  These are necessary for
  1103. ;*                   operation of the 3xBox.
  1104. ;*
  1105. ;*  ENTRY POINT   :  IOCtl     LINKAGE:  CALL NEAR
  1106. ;*
  1107. ;*  INPUT         :  ES:BX points to the Request block.
  1108. ;*                   SI has offset to current session's control block.
  1109. ;*
  1110. ;*  RETURN-NORMAL :  Requested function completed.
  1111. ;*
  1112. ;*  RETURN-ERROR  :  Request Block status field updated with
  1113. ;*                   appropriate error return code.
  1114. ;*
  1115. ;*  EFFECTS       :  Stack is clean on return.
  1116. ;*
  1117. ;*  INTERNAL REFERENCES:
  1118. ;*     ROUTINES:  Req_Err, IOMW_SM, IOMW_SN, IOMW_SS, IOMW_EM,
  1119. ;*                IOMW_TH, IOMW_PS, IOMW_DP, IOMR_GV, IOMW_SP,
  1120. ;*                IOMR_NB, IOMR_MC, IOMR_GS, IOMR_RD, IOMR_QS,
  1121. ;*                IOMR_GM, IOMR_GF, IOMR_GP, IOMR_PS, IOMR_TH,
  1122. ;*                IOMW_SC, IOMW_MM, IOMW_MD, AccessCheck
  1123. ;*
  1124. ;*  EXTERNAL REFERENCES:
  1125. ;*     ROUTINES:  NONE.
  1126. ;*
  1127. ;************************************************************************
  1128. ;*
  1129. ;*BeginSub  IOCTL
  1130. ;*
  1131. ;* IF <Category is mouse category> THEN
  1132. ;*    IF <Function out of range                     OR
  1133. ;*        Request from detached process> THEN
  1134. ;*       set request error
  1135. ;*    ELSE
  1136. ;*       call AccessCheck to check access to user data areas
  1137. ;*       IF AccessCheck passed
  1138. ;*          call requested support routine
  1139. ;*       ELSE
  1140. ;*          set request error
  1141. ;*       ENDIF
  1142. ;*    ENDIF
  1143. ;* ELSEIF <Category is monitor control> THEN
  1144. ;*    IF <Function is register a monitor>
  1145. ;*       call IOMW_MM to register the monitor
  1146. ;*    ELSE
  1147. ;*       set request error
  1148. ;*    ENDIF
  1149. ;* ELSEIF <Category is general> THEN
  1150. ;*    IF <function is Query Monitor support AND
  1151. ;*        NOT a detached process > THEN
  1152. ;*       set packet status to monitors supported
  1153. ;*    ELSE
  1154. ;*       set request error
  1155. ;*    ENDIF
  1156. ;* ELSE   /* IOCtl not recognized as supported
  1157. ;*    set request error
  1158. ;* ENDIF
  1159. ;*
  1160. ;* Return
  1161. ;*
  1162. ;*EndSub  IOCTL
  1163. ;*
  1164. ;***********************************************************************
  1165.  
  1166. IOCTL  PROC  NEAR
  1167.          ASSUME    CS:CSEG2, SS:nothing, ES:nothing, DS:nothing
  1168.  
  1169.        mov  ah, es:[bx.GIOcategory]        ; Get Request Block Category code
  1170.        mov  al, es:[bx.GioFunction]        ; Get Request Block Function code
  1171.        mov  fs:CurRequest, al              ; save current IOCtl request code
  1172.  
  1173.        .if <ah eq Mou_Cat>                 ; If a Mouse IOCtl then
  1174.  
  1175.           .if <al lt Func_LReq_Start> OR   ; If an invalid Mouse function
  1176.           .if <al gt Func_HReq_End>   OR   ; Is requested or if a Detached
  1177.           .if <fs:Detach_Proc eq ON>       ; Process Request then
  1178.  
  1179.              mov  es:[bx].PktStatus, UNKNOWNCMD
  1180.  
  1181.           .else                            ; If a valid Mouse Function then
  1182.                                            ; Calc call table index as:
  1183.              sub  al, Func_LReq_Start      ; Get relative base table index
  1184.              cbw                           ; Get it as a word value
  1185.              call AccessCheck              ; check access
  1186.              .if <nc>                      ; 
  1187.                 shl  ax, 1                 ; Get byte index as word table index
  1188.                 mov  di, ax                ; Setup DI will call table index
  1189.                 call word ptr fs:Func_Tbl[di] ; Invoke Requested Function Rtn.
  1190.              .else
  1191.                 ParmErr                    ; otherwise a parameter error
  1192.              .endif
  1193.  
  1194.           .endif
  1195.  
  1196.        .elseif <ah eq Mon_Cat>             ; If a Monitor Request then
  1197.  
  1198.           .if <al eq Req_MM>               ; If Monitor Register request then
  1199.              call IOMW_MM                  ; Invoke Monitor Register Rtn.
  1200.  
  1201.           .else                            ; If not Mon Reg request then
  1202.              mov  es:[bx].PktStatus, UNKNOWNCMD
  1203.           .ENDIF                           ; Mon_Cat Function Support Tests
  1204.  
  1205.        .elseif <ah eq Gen_Cat>             ; If a General DD Category Req
  1206.  
  1207.           .if <al eq QMonSup>    AND       ; If Query Mon Support IOCTL
  1208.           .if <fs:Detach_Proc eq OFF>      ; and Not a Detached Proc
  1209.  
  1210.           .else                            ; If not Mon Query or request
  1211.                                            ; From a Detached Process
  1212.              mov  es:[bx].PktStatus, UNKNOWNCMD
  1213.           .endif                           ; Gen_Cat Function Tests
  1214.  
  1215.        .else                               ; If an Unknown Request Category
  1216.           mov  es:[bx].PktStatus, UNKNOWNCMD
  1217.        .endif                              ; Mouse Category Support Tests
  1218.  
  1219.        ret                                 ; Return to Request_Handler Rtn
  1220. IOCTL  ENDP
  1221.  
  1222.  
  1223. ;************************************************************************
  1224. ;*
  1225. ;*  FUNCTION NAME :  DEINS
  1226. ;*
  1227. ;*  DESCRIPTION   :  Deinstallation Request handler routine.
  1228. ;*
  1229. ;*                   Releases all system resources claimed.  Sets a
  1230. ;*                   flag disabling support. Runs with Ints disabled.
  1231. ;*
  1232. ;*  ENTRY POINT   :  DEINS                       LINKAGE:  CALL NEAR
  1233. ;*
  1234. ;*  INPUT         :  ES:BX points to the request block.
  1235. ;*                   SI has offset to current session control block.
  1236. ;*
  1237. ;*  RETURN-NORMAL :  Always, Mouse DD is deinstalled.  Request
  1238. ;*                   Block Status field return code setup.
  1239. ;*
  1240. ;*  RETURN-ERROR  :  N/A
  1241. ;*
  1242. ;*  EFFECTS       :  Stack is clean on return.   AX, CX, DX, SI, and DI
  1243. ;*                   registers are changed.
  1244. ;*
  1245. ;*  INTERNAL REFERENCES:
  1246. ;*     ROUTINES:  NONE.
  1247. ;*
  1248. ;*  EXTERNAL REFERENCES:
  1249. ;*     ROUTINES:  NONE.
  1250. ;*     DevHlps:   MonitorCreate
  1251. ;*
  1252. ;*************************************************************************
  1253. ;*
  1254. ;*BeginSub  DEINS
  1255. ;*
  1256. ;* WHILE <there are more sessions> DO
  1257. ;*    IF <current session is not VDM session control>
  1258. ;*       call Device_Help(MonitorCreate) to destroy the mon chain
  1259. ;*    ENDIF
  1260. ;*    set session open handle count to 0
  1261. ;*    increment current session
  1262. ;* ENDWHILE
  1263. ;* set deinstalled flag to shut down all operations
  1264. ;* return
  1265. ;*
  1266. ;*EndSub  DEINS
  1267. ;*
  1268. ;***********************************************************************
  1269.  
  1270. DEINS  PROC  NEAR
  1271.        ASSUME    CS:CSEG2, SS:nothing, ES:nothing, DS:nothing
  1272.  
  1273.        ?frame = 0                        ; Get Local/Temporary Stack Frame
  1274.        LocalVar TempDS, WORD             ; For DS register
  1275.        LocalVar TempES, WORD             ; For ES register
  1276.        LocalVar TempBX, WORD             ; For BX register
  1277.  
  1278.        EnterProc
  1279.        mov  TempDS, ds                   ; Save Mouse Data Segment
  1280.        mov  TempES, es                   ; Save Request Block
  1281.        mov  TempBX, bx                   ; Address
  1282.  
  1283.        cli                               ; Hold Interrupts for Deinstallation
  1284.  
  1285.        test SynchFlag, APM_IDCACTIVE     ; APM active ?    ;           
  1286.        .if <nz> AND
  1287.        .if <APMIDCHandle ne 0> AND
  1288.        .if <ds:APMDD.ProtEntry ne 0>
  1289.           mov  APMIDCDereg.DEREG_Function, APMIDC_Deregister
  1290.           mov  ax, APMIDCHandle
  1291.           mov  APMIDCDereg.DEREG_hClient, ax
  1292.           lea  bx, APMIDCDereg
  1293.           push ds
  1294.           pop  es                        ; es:bx -> APM registration packet
  1295.           call ds:APMDD.ProtEntry        ; go do the call
  1296.           mov  APMIDCHandle,0            ; clear IDC Handle
  1297.           and  SynchFlag, APM_IDCINACTIVE ; Indicate IDC disabled ;           
  1298.           clc                            ; set good return code
  1299.  
  1300.        .endif
  1301.  
  1302.        xor  cx, cx                       ; Clear loop counter, SG = 0
  1303.  
  1304.        sti                               ; Deinstall complete, Allow interrupts
  1305.  
  1306.        mov  fs:DeInstall, ON             ; Flag Mouse as DeInstalled
  1307.        mov  es, TempES                   ; Restore Request Block Address
  1308.        mov  bx, TempBX
  1309.  
  1310.        LeaveProc                         ; Clear local Stack variables
  1311.  
  1312.        ret                               ; Return to Request Handler Rtn.
  1313. DEINS  ENDP
  1314.  
  1315.  
  1316. ;************************************************************************
  1317. ;*
  1318. ;*  FUNCTION NAME :  INITCOMPLETE                  
  1319. ;*
  1320. ;*  DESCRIPTION   :  Initialization of all device drivers is now guaranteed
  1321. ;*                   to be complete.
  1322. ;*
  1323. ;*                   Do any initialization where it is required to have
  1324. ;*                   knowledge that all other device drivers are now loaded
  1325. ;*                   and their initialization is complete.
  1326. ;*
  1327. ;*  ENTRY POINT   :  INITCOMPLETE                LINKAGE:  CALL NEAR
  1328. ;*
  1329. ;*  INPUT         :  ES:BX points to the request block.
  1330. ;*                   SI has offset to current session control block.
  1331. ;*
  1332. ;*  RETURN-NORMAL :  Always, this call is only for internal post
  1333. ;*                   initialization and any error conditions are internal
  1334. ;*                   to this device driver.
  1335. ;*
  1336. ;*  RETURN-ERROR  :  N/A
  1337. ;*
  1338. ;*  EFFECTS       :  Stack is clean on return.   AX, CX, DX, SI, and DI
  1339. ;*                   registers are changed.
  1340. ;*
  1341. ;*  INTERNAL REFERENCES:
  1342. ;*     ROUTINES:  RegisterForAPM
  1343. ;*
  1344. ;*  EXTERNAL REFERENCES:
  1345. ;*     ROUTINES:  NONE.
  1346. ;*     DevHlps:   NONE
  1347. ;*
  1348. ;*************************************************************************
  1349. ;*
  1350. ;*BeginSub  INITCOMPLETE
  1351. ;*
  1352. ;* call RegisterForAPM
  1353. ;* return
  1354. ;*
  1355. ;*EndSub  INITCOMPLETE
  1356. ;*
  1357. ;***********************************************************************
  1358.  
  1359. INITCOMPLETE  PROC  NEAR
  1360.        ASSUME    CS:CSEG2, SS:nothing, ES:nothing, DS:nothing
  1361.  
  1362.        call RegisterForAPM
  1363.  
  1364.        ret                       ; Return to Request Handler Rtn.
  1365.  
  1366. INITCOMPLETE  ENDP               ;            end
  1367.  
  1368. CSEG2    ENDS
  1369.          END
  1370.