home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / MOUSE / BUS.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  13KB  |  422 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 = BUS.ASM
  16. ;*
  17. ;* DESCRIPTIVE NAME = MS Bus Mouse specific code
  18. ;*
  19. ;*
  20. ;* VERSION      V2.0
  21. ;*
  22. ;* DATE         10/13/91
  23. ;*
  24. ;* DESCRIPTION  This file contains the code specific to the MS
  25. ;*              Bus mouse.
  26. ;*
  27. ;* FUNCTIONS    CheckforBUSDevice()
  28. ;*              FindBusInterrupt ()
  29. ;*              FindBusChangingLevels ()
  30. ;*              FindBusLevel          ()
  31. ;*              BusInit               ()
  32. ;*
  33. ;* NOTES        This file contains the code specific to the MS
  34. ;*              Bus mouse.
  35. ;*
  36. ;*
  37. ;*
  38. ;* STRUCTURES   NONE
  39. ;*
  40. ;* EXTERNAL REFERENCES
  41. ;*
  42. ;*              NONE
  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. ;*
  53. ;*
  54. ;*
  55. ;*
  56. ;*
  57. ;*
  58. ;*
  59. ;**************************************************************************
  60.  
  61.  
  62. .xlist
  63.        include mouse.inc
  64. .list
  65.  
  66. .386p
  67.  
  68. ;*
  69. ;*   External Mouse Module Data References
  70. ;*
  71.  
  72.        extrn DeviceData          : byte
  73.  
  74.        extrn Int_Packet          : word
  75.        extrn ByteCount           : word
  76.        extrn PrevEvent           : word
  77.  
  78.        extrn Device_Help         : dword
  79.  
  80.        extrn GIDC_Entry          : far
  81.  
  82.        extrn _RM_MSE_AllocPorts    :far
  83.        extrn _RM_MSE_DeallocPorts  :far
  84.  
  85.  
  86. CSEG     SEGMENT   WORD  PUBLIC  USE16 'CODE'
  87.          ASSUME    CS:CSEG, SS:nothing, ES:nothing, DS:nothing
  88.  
  89. ;*
  90. ;*    Module Procs made Public for other Mouse Modules
  91. ;*
  92.  
  93.        public  CheckforBUSDevice
  94.        public  FindBusInterrupt
  95.        public  FindBusChangingLevels
  96.        public  FindBusLevel
  97.        public  BusInit
  98.  
  99.  
  100. ;/***************************************************************************
  101. ;*
  102. ;* FUNCTION NAME = CheckforBUSDevice
  103. ;*
  104. ;* DESCRIPTION   = This procedure will attempt to find a bus mouse adaptor
  105. ;*                 In the system and will return the results of this search.
  106. ;*
  107. ;* INPUT         = NONE.
  108. ;*
  109. ;* OUTPUT        = NONE.
  110. ;*
  111. ;*
  112. ;* RETURN-NORMAL = NC NZ           No bus mouse adaptor was found
  113. ;*
  114. ;*                   NC ZR           A bus mouse adaptor was found
  115. ;*                   AL              Interrupt it is jumpered on
  116. ;*                   BL              Bit mask for this interrupt
  117. ;*                   DX              Address of mask register of 8259A
  118. ;*
  119. ;*                   CY NZ           Multiple interrupts were found
  120. ;*
  121. ;*                   CY ZR           No interrupts were found
  122. ;*
  123. ;* RETURN-ERROR  =  NONE.
  124. ;*
  125. ;* EFFECTS       =  AX, BX, CX, DX
  126. ;**************************************************************************/
  127.  
  128.  
  129.  
  130. CheckforBUSDevice  proc  near
  131.  
  132. ;*
  133. ;* We determine if the bus mouse adaptor is present by attempting to
  134. ;*  program the 8255A, and then seeing if we can write a value out to
  135. ;*  Port B on the 8255A and get that value back. If we can, we assume
  136. ;*  that we have a bus mouse adaptor.
  137. ;*
  138.  
  139.         mov  dx, BUS_INIT             ; Get address of 8255A control port.
  140.  
  141.         pusha
  142.         push es
  143.         push dx
  144.         call _RM_MSE_AllocPorts
  145.         or ax, ax
  146.         pop dx
  147.         pop es
  148.         popa
  149.         jnz  PortBusClaimed
  150.  
  151.         mov  al, BUS_INIT_VALUE       ; Get proper value.
  152.         out  dx, al                   ; Set up 8255A.
  153.         MyIODelay                     ; Generate delay between I/O instructions
  154.         address BUS_SIG FROM BUS_INIT ; Get address of Port B.
  155.         mov  ax, 0a5a5h               ; Set Port B with signature.
  156.         out  dx, al
  157.         MyIODelay                     ; Generate delay between I/O instructions
  158.         in      al,dx                 ; Read back Port B.
  159.         MyIODelay                     ; Generate delay between I/O instructions
  160.  
  161.         .if <al ne ah>                ; Does it match signature byte?
  162.            stc
  163.            jmp short tfb_not_found    ; Nope - no bus mouse adaptor.
  164.         .endif
  165.  
  166.         call FindBusInterrupt         ; Determine interrupt level.
  167.         jc   short tfb_not_found      ; Leave right away if returning error.
  168.  
  169.         pushf                         ; Save return flags.
  170.         mov     dx,MASTER_MASK_ADDR   ; Assume we are on master 8259A.
  171.         cmp     al,2                  ; Is it IRQ 2?
  172.         jne     short tfb_irq_mapping_done ; Nope, don't map IRQ.
  173.         mov     al,9                  ; YES! Map IRQ 2 into IRQ 9.
  174.         mov     bl,00000010b          ; ...
  175.         mov     dx,SLAVE_MASK_ADDR    ; ...
  176.  
  177. tfb_irq_mapping_done:
  178.         popf                          ; Restore return flags.
  179.         ret
  180.  
  181. tfb_not_found:
  182.         pusha
  183.         push es
  184.         call _RM_MSE_DeallocPorts
  185.         pop es
  186.         popa
  187.  
  188. PortBusClaimed:
  189.         stc
  190.         ret
  191.  
  192.  
  193. CheckforBUSDevice  endp
  194.  
  195.  
  196. ;/***************************************************************************
  197. ;*
  198. ;* FUNCTION NAME = FindBusInterrupt
  199. ;*
  200. ;* DESCRIPTION   = This procedure determines the interrupt level that the
  201. ;*                 bus mouse adaptor is jumpered at.
  202. ;*
  203. ;* INPUT         = NONE
  204. ;*
  205. ;* ENTRY         = Bus interrupts are enabled at the adaptor.
  206. ;*                 DX              Has address of BUS_SIG
  207. ;*
  208. ;*
  209. ;* EXIT          = carry clear     Only 1 interrupt level was found
  210. ;*                 ZR
  211. ;*                 AL              IRQ # of this interrupt level
  212. ;*                 BL              Bit mask giving bus mouse interrupt level
  213. ;*
  214. ;*                 carry set       Some error occurred
  215. ;*                 NZ              Multiple interrupts were found
  216. ;*                 ZR              No interrupts were found
  217. ;*
  218. ;* OUTPUT        = NONE
  219. ;*
  220. ;*
  221. ;* RETURN-NORMAL = NONE
  222. ;*
  223. ;*
  224. ;* RETURN-ERROR  = NONE
  225. ;*
  226. ;*
  227. ;**************************************************************************/
  228.  
  229.  
  230.  
  231.  
  232. FindBusInterrupt  proc  near
  233.  
  234.         address BUS_CONTROL FROM BUS_SIG; Get address of mouse control port.
  235.         mov     cx,5                  ; Only try to get rid of multiple
  236.  
  237. fbi_loop:
  238.         mov     bh,0FFh               ; All interrupt levels still valid.
  239.                                       ;  interrupts 5 times.
  240.         mov     al,10010000b          ; Value to disable bus interrupts.
  241.         out     dx,al                 ; DISABLE BUS INTERRUPTS
  242.         MyIODelay                  ; Generate delay between I/O instructions
  243.         call    FindBusChangingLevels ; Determine which levels are changing.
  244.         not     ah                    ; Remove from consideration those
  245.         and     bh,ah                 ;  levels which are changing now.
  246.         mov     al,10000000b          ; Value to enable bus interrupts.
  247.         out     dx,al                 ; ENABLE BUS INTERRUPTS
  248.         MyIODelay                     ; Generate delay between I/O instructions
  249.         call    FindBusChangingLevels ; Determine which levels are changing.
  250.         .if <bit ah z bh>             ; If no levels were changing
  251.            stc                        ; No levels were responding!!!!
  252.            jmp  fbi_again
  253.         .endif
  254.  
  255.         call    FindBusLevel          ; Determine interrupt level and mask.
  256.         jnc     short fbi_leave       ; Found it! Leave.
  257.  
  258. fbi_again:
  259.         loop    fbi_loop              ; Found multiple interrupts. Try again.
  260.  
  261.  
  262. fbi_leave:                            ; All return codes set correctly.
  263.         push    ax                    ; Save IRQ level.
  264.         mov     al,10010000b          ; Value to disable bus interrupts.
  265.         out     dx,al                 ; DISABLE BUS INTERRUPTS.
  266.         pop     ax                    ; Restore IRQ level.
  267.         ret
  268.  
  269. FindBusInterrupt  endp
  270.  
  271.  
  272. ;/***************************************************************************
  273. ;*
  274. ;* FUNCTION NAME = FindBusChangingLevels
  275. ;*
  276. ;* DESCRIPTION   = This procedure will return back a bit mask indicating which
  277. ;*                 of the possible bus mouse interrupt levels are changing.
  278. ;*
  279. ;* INPUT         =  NONE
  280. ;*
  281. ;* OUTPUT        =  NONE
  282. ;*
  283. ;* ENTRY         =  DX         Has address of BUS_CONTROL
  284. ;*
  285. ;* EXIT          =  AH         Mask giving levels that were changing
  286. ;*
  287. ;*
  288. ;* OUTPUT        =  NONE
  289. ;*
  290. ;*
  291. ;* RETURN-NORMAL =  NONE
  292. ;*
  293. ;*
  294. ;* RETURN-ERROR  =  NONE
  295. ;*
  296. ;*
  297. ;**************************************************************************/
  298.  
  299.  
  300.  
  301.  
  302. FindBusChangingLevels  proc  near
  303.  
  304.         push cx                   ; Save environment.
  305.         in   al,dx                ; Get current interrupt state.
  306.         MyIODelay                 ; Generate delay between I/O instructions
  307.         mov  bl,al                ; Save as last state.
  308.         xor  ah,ah                ; No levels are currently changing.
  309.         mov  cx, 0ffffh
  310. fbcl_inner:
  311.         in   al,dx                ; Get current state.
  312.         MyIODelay                 ; Generate delay between I/O instructions
  313.         xor  bl,al                ; Determine levels which changed from
  314.         or   ah,bl                ;  last state and save them.
  315.         mov  bl,al                ; Save current state as last state.
  316.         loop fbcl_inner
  317.         and  ah,0fh               ; Keep only valid bits.
  318.         pop  cx                   ; Restore environment.
  319.         ret
  320.  
  321. FindBusChangingLevels  endp
  322.  
  323.  
  324.  
  325. ;/***************************************************************************
  326. ;*
  327. ;* FUNCTION NAME = FindBusLevel
  328. ;*
  329. ;* DESCRIPTION   = This procedure accepts the mask giving possible bus
  330. ;*                 interrupts abd will return back the interrupt mask and
  331. ;*                 the interrupt number for it.
  332. ;*
  333. ;* INPUT         = NONE
  334. ;*
  335. ;* OUTPUT        = NONE
  336. ;*
  337. ;* ENTRY         = AH         Mask of possible levels.
  338. ;*                            Bit 0 == IRQ 5 through Bit 3 == IRQ
  339. ;*
  340. ;* EXIT          = NC              Only 1 possible level.
  341. ;*                 AL              Interrupt number.
  342. ;*                 BL              Interrupt mask
  343. ;*
  344. ;*                 CY              Multiple levels were possible.
  345. ;*
  346. ;* RETURN-NORMAL = NONE
  347. ;*
  348. ;*
  349. ;* RETURN-ERROR  = NONE
  350. ;*
  351. ;*
  352. ;**************************************************************************/
  353.  
  354. FindBusLevel  proc  near
  355.  
  356.         mov     al,5                 ; Start with IRQ 5.
  357.         mov     bl,00100000b         ; Bit mask for IRQ 5.
  358.  
  359. fbl_loop:
  360.         shr     ah,1                 ; Test next possible interrupt level.
  361.         jc      short fbl_got_it     ; Branch if possible level found.
  362.         dec     ax                   ; If not a possible level, move on to
  363.         shr     bl,1                 ;  the next possible level
  364.         jmp     short fbl_loop
  365.  
  366. fbl_got_it:
  367.         jnz     short fbl_leave      ; If more levels still possible, error.
  368.         clc                          ; Show only 1 level was possible.
  369.  
  370. fbl_leave:                           ; Return codes set correctly.
  371.         ret
  372.  
  373. FindBusLevel  endp
  374.  
  375.  
  376.  
  377. ;/***************************************************************************
  378. ;*
  379. ;* FUNCTION NAME =
  380. ;*                  BusInit
  381. ;* DESCRIPTION   =
  382. ;*                  This procedure is called at the end of the initialization
  383. ;*                  process in order to finish the initialization of the
  384. ;*                  bus mouse. It has to perform whatever actions that are
  385. ;*                  necessary in order to put the bus mouse into the state it
  386. ;*                  needs to be in.
  387. ;*
  388. ;* INPUT         =  NONE
  389. ;*
  390. ;* OUTPUT        =  NONE
  391. ;*
  392. ;* ENTRY         =  NONE
  393. ;*
  394. ;* EXIT          =  Carry clear        Init was successful.
  395. ;*
  396. ;*
  397. ;*
  398. ;*
  399. ;*
  400. ;* RETURN-NORMAL =  NONE
  401. ;*
  402. ;*
  403. ;* RETURN-ERROR  =  NONE
  404. ;*
  405. ;*
  406. ;**************************************************************************/
  407.  
  408.  
  409.  
  410. BusInit PROC    NEAR
  411.  
  412.         mov     dx,BUS_CONTROL       ; Get address of the control port.
  413.         xor     al,al                ; Write out the value that enables the
  414.         out     dx,al                ;  counters and interrupts.
  415.         ret                          ; Leave with carry clear.
  416.  
  417. BusInit ENDP
  418.  
  419.  
  420. CSEG     ENDS
  421.          END
  422.