home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / PCMCIA / SOCKET / SSPCIC.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  55KB  |  1,379 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT (C) Award Software International Inc., 1994
  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.                 name    SSPCIC
  13.                 page    60, 132
  14.                 title   'SSPCIC'
  15. ;******************************************************************************
  16. ;*
  17. ;*                            File SSPCIC.ASM
  18. ;*
  19. ;*                        Socket Services PCIC File
  20. ;*
  21. ;*                           PCIC PCMCIA Functions
  22. ;*
  23. ;*
  24. ;*
  25. ;******************************************************************************
  26.  
  27.                 include ssmac.inc           ; Macros
  28.                 include ssdefs.inc          ; Sockets Services definitions
  29.                 include ss_segm.inc         ; Segment definitions
  30.                 include ssPCIC.inc          ; PCIC module defs
  31.                 include ssmsg.inc           ; Messages
  32.  
  33. ;*****************************************************************************
  34. ;*                         --- Segment ResData ---
  35. ;*****************************************************************************
  36. sBegin          ResData
  37.  
  38. ;-------------------------------- Adapter Info --------------------------------
  39.  
  40. ; The ADAPTER structure below must be immediately followed by the Power
  41. ; Management Table for proper operation of InquireAdapter.
  42.  
  43. AdapterInfo     CHARTBL {{0000H}, PCIC_SC_IRQSH, PCIC_SC_IRQSL}
  44. PowerTable      dw      PCIC_MAX_PWR_ENTRIES            ; Number of power levels
  45.                 PWRENTRY { 00H, VCC OR VPP1 OR VPP2 }   ; Vcc, Vpp1 and Vpp2 - No connect
  46.                 PWRENTRY { 32H, VCC OR VPP1 OR VPP2 }   ; Vcc, Vpp1 and Vpp2 -  5.0 VDC
  47.                 PWRENTRY { 78h, VPP1 OR VPP2 }          ; Vpp1 and Vpp2      - 12.0 VDC
  48. _AdapterInfoLen =       $ - OFFSET AdapterInfo
  49. AdapterInfoLen  dw      _AdapterInfoLen
  50.  
  51. ;--------------------------------- Socket Info --------------------------------
  52.  
  53. SocketInfo      CHARTBL {{IF_MEMORY OR IF_IO}, PCIC_SK_IRQSH, PCIC_SK_IRQSL}
  54. _SocketInfoLen  =       SIZEOF SocketInfo
  55. SocketInfoLen   dw      _SocketInfoLen
  56.  
  57. SocketCaps      SKT_CAP {PCIC_SKT_SCI_CAP, PCIC_SKT_SCR_CAP, PCIC_SKT_CI_CAP}               ; AS: Socket capabilities
  58.  
  59. sEnd            ResData
  60.  
  61. ;*****************************************************************************
  62. ;*                         --- Segment ResCode ---
  63. ;*****************************************************************************
  64. sBegin          ResCode
  65.  
  66. ;*****************************************************************************
  67. ;*                              --- GetReg ---
  68. ;*
  69. ;*     Purpose: Return value from register
  70. ;*       Input: AL - Register to read
  71. ;*              BX - Pointer to the adapter data structure
  72. ;*      Output: AL - Readen value
  73. ;* Scratch reg: none
  74. ;*     Written: by Alexis A.Piatetsky 30.07.94
  75. ;*****************************************************************************
  76. GetReg          PROC    NEAR
  77.                 assume  ds:@data, es:Nothing
  78.  
  79.                 push    dx
  80.                 mov     dx, (ADP_DATA PTR [BX]).wBasePort
  81.                 add     al, (ARGS PTR [BP]).bSocketIdx
  82.                 out     dx, al
  83.                 jmp     $+2
  84.  
  85.                 inc     dx
  86.                 in      al, dx
  87.                 jmp     $+2
  88.  
  89.                 pop     dx
  90.                 ret
  91.  
  92. GetReg          ENDP
  93.  
  94. ;*****************************************************************************
  95. ;*                              --- SetReg ---
  96. ;*
  97. ;*     Purpose: Set register value
  98. ;*       Input: AL - register to write
  99. ;*              AH - value to write
  100. ;*              BX - Pointer to the adapter data structure
  101. ;*      Output: none
  102. ;* Scratch reg: none
  103. ;*     Written: by Alexis A.Piatetsky 30.07.94
  104. ;*****************************************************************************
  105. SetReg          PROC    NEAR
  106.                 assume  ds:@data, es:Nothing
  107.  
  108.                 push    dx
  109.                 mov     dx, (ADP_DATA PTR [BX]).wBasePort
  110.                 add     al, (ARGS PTR [BP]).bSocketIdx
  111.                 out     dx, al
  112.                 jmp     $+2
  113.  
  114.                 inc     dx
  115.                 mov     al, ah
  116.                 out     dx, al
  117.                 jmp     $+2
  118.  
  119.                 pop     dx
  120.                 ret
  121.  
  122. SetReg          ENDP
  123.  
  124. ;*****************************************************************************
  125. ;*                            --- asSetSktIRQ ---
  126. ;*
  127. ;*     Purpose: Set New Socket IRQ level
  128. ;*       Input: AH - Interface Type, AL - Socket IRQ
  129. ;*              SI - Socket number
  130. ;*      Output: none
  131. ;* Scratch reg: none
  132. ;*     Written: by Alexis A.Piatetsky 10.06.94
  133. ;*****************************************************************************
  134. asSetSktIRQ     PROC    NEAR
  135.                 assume  ds:@data, es:Nothing
  136.  
  137.                 push    ax                  ; Save used regs
  138.  
  139.                 test    ah, IF_IO           ; I/O Interface requested?
  140.                 mov     ah, PCIC_INTER_CARDIO ; Assume yes
  141.                 jnz     @f                  ; Yes, check IRQ_ENABLED condition
  142.  
  143.                 xor     ax, ax              ; Disable Socket IRQ
  144.                 jmp     short @f            ; Set IRQ disabled
  145.  
  146. @@:             test    al, IRQ_ENABLED     ; Interrupt Enabled?
  147.                 jnz     @f                  ; Yes, set IRQ enabled
  148.  
  149.                 xor     ah, ah              ; Disable socket IRQ
  150.                                             ; (PCIC_INTER_CARDIO)
  151.  
  152. @@:             and     al, P_IRQ15         ; Keep IRQ only
  153.                 or      ah, al              ; Merge with Interface type
  154.  
  155.                 mov     al, PCIC_INTER
  156.                 call    GetReg              ; Read !RESET state
  157.  
  158.                 and     al, PCIC_INTER_RESET ; Clear all other bits
  159.  
  160.                 or      ah, al              ; Leave !RESET as it was!
  161.                 mov     al, PCIC_INTER
  162.                 CALL    SetReg              ; Set Socket IRQ
  163.  
  164.                 pop     ax                  ; Restore used registers
  165.                 ret
  166. asSetSktIRQ     ENDP
  167.  
  168. ;*****************************************************************************
  169. ;*                         --- asSetSktInterface ---
  170. ;*
  171. ;*     Purpose: Set Socket interface type
  172. ;*       Input: [BX] - Pointer to the adapter structure
  173. ;*              [BP] - Pointer to the user args
  174. ;*              SI   - Socket number
  175. ;*              AH   - Socket Interface type
  176. ;*      Output: none
  177. ;* Scratch reg: none
  178. ;*     Written: by Alexis A.Piatetsky 20.07.94
  179. ;*****************************************************************************
  180. asSetSktInterface PROC  NEAR
  181.                 assume  ds:@data, es:Nothing
  182.  
  183.                 push    ax
  184.                 mov     al, PCIC_INTER
  185.                 call    GetReg
  186.  
  187.                 and     al, NOT PCIC_INTER_CARDIO ; Assume memory Interface
  188.                 test    ah, IF_MEMORY       ; Assumption correct?
  189.                 jnz     @f                  ; Yes, continue
  190.  
  191.                 or      al, PCIC_INTER_CARDIO  ; Set I/O mode
  192.  
  193. @@:             mov     ah, al
  194.                 mov     al, PCIC_INTER
  195.                 call    SetReg
  196.  
  197.                 pop     ax
  198.                 ret
  199.  
  200. asSetSktInterface ENDP
  201.  
  202. ;*****************************************************************************
  203. ;*                         --- asSetSktMask ---
  204. ;*
  205. ;*     Purpose: Set Socket Status change interrupt Mask
  206. ;*       Input: [BX] - Pointer to the adapter structure
  207. ;*              [BP] - Pointer to the user args
  208. ;*              SI   - Socket number
  209. ;*              AH   - Socket Mask
  210. ;*      Output: none
  211. ;* Scratch reg: none
  212. ;*     Written: by Alexis A.Piatetsky 20.07.94
  213. ;*****************************************************************************
  214. asSetSktMask    PROC    NEAR
  215.                 assume  ds:@data, es:Nothing
  216.                 pushx   <ax, cx>
  217.  
  218. ; The Intel Status change bits match to the PCMCIA structure, except the
  219. ; fact, that SBM_ bits are located in the upper nibble and PCIC bits in the
  220. ; lower nibble
  221.  
  222.                 mov     cl, 4               ; Move mask to the PCIC location
  223.                 shr     ah, cl
  224.  
  225.                 mov     al, PCIC_SCINT      ; Get current SC level
  226.                 call    GetReg
  227.                 and     al, PCIC_SCINT_IRQ  ; AL = SCI level
  228.  
  229.                 or      ah, al              ; Combine with new mask
  230.  
  231.                 mov     al, PCIC_SCINT      ; Set new mask
  232.                 call    SetReg
  233.  
  234.                 popx    <cx, ax>
  235.                 ret
  236. asSetSktMask    ENDP
  237.  
  238. ;*****************************************************************************
  239. ;*                             --- GetPower   ---
  240. ;*
  241. ;*     Purpose: Return Socket power levels
  242. ;*       Input: [BX] - Pointer to the adapter structure
  243. ;*              [BP] - Pointer to the user args
  244. ;*              SI   - Socket number
  245. ;*      Output: ah   - Lower nibble - Vcc Level
  246. ;*              al   - Upper nibble - Vpp1 Level, Lower nibble - Vpp2 Level
  247. ;* Scratch reg: none
  248. ;*     Written: by Alexis A.Piatetsky 07.06.94
  249. ;*****************************************************************************
  250. GetPower        PROC    NEAR
  251.  
  252.                 push    cx
  253.  
  254.                 xor     cx, cx              ; Vcc = Vpp1 = Vpp2 = 0V
  255.  
  256.                 mov     al, PCIC_POWER
  257.                 call    GetReg              ; Get Vcc Level
  258.  
  259.                 test    al, PCIC_POWER_VCCENABLE
  260.                 jnz     @f
  261.  
  262. ;     fix for Cirrus Logic PD6722. This adapter at card removal clear
  263. ; PCIC_POWER_VCCENABLE bit w/o host command. As result, GetSocket return
  264. ; Vcc zero and Vpp1 and Vpp2 non-zero. In order to avoid this we explicitly
  265. ; put Vpp1 = Vpp2 = 0
  266.  
  267.  
  268.                 mov     ax, cx
  269.                 jmp     short gp_done
  270.  
  271. @@:             mov     ch, 1               ; 5V
  272.                 mov     ah, al              ; Here Vcc = 5V (at least on PCIC)
  273.  
  274.  
  275.                 mov     al, ah              ; Get Vpp1
  276.                 and     al, PCIC_POWER_VPP1MASK
  277.                 mov     cl, 4
  278.                 shl     al, cl
  279.                 xchg    ah, al              ; ah - Vpp1
  280.  
  281.                 and     al, PCIC_POWER_VPP2MASK ; Get Vpp2
  282.                 mov     cl, 2
  283.                 shr     al, cl
  284.  
  285.                 or      al, ah              ; Combine Vpp1 & Vpp2
  286.  
  287.                 mov     ah, ch              ; Combine Vcc and Vpp
  288.  
  289. gp_done:        pop     cx
  290.                 ret
  291. GetPower        ENDP
  292.  
  293. ;*****************************************************************************
  294. ;*                              --- SetVcc   ---
  295. ;*
  296. ;*     Purpose: Set Vcc Value
  297. ;*       Input: [BX] - Pointer to the adapter structure
  298. ;*              [BP] - Pointer to the user args
  299. ;*              ah   - Lower nibble - Vcc Level
  300. ;*      Output: none
  301. ;* Scratch reg: none
  302. ;*     Written: by Alexis A.Piatetsky 20.07.94
  303. ;*****************************************************************************
  304. SetVcc          PROC    NEAR
  305.  
  306.                 pushx   <ax, dx>
  307.  
  308.                 mov     dh, ah              ; dh - required Vcc
  309.                 mov     dl, 0               ; dl - Vcc = 0V
  310.  
  311. ;--------------------------------- Swith off  ---------------------------------
  312.  
  313.                 mov     al, PCIC_POWER
  314.                 call    GetReg
  315.  
  316.                 and     al, NOT PCIC_POWER_VCCENABLE ; preserve all but Vcc enable
  317.  
  318. ;--------------------------- Switch on, if required ---------------------------
  319.  
  320.                 cmp     dh, dl              ; Switch on?
  321.                 je      @f                  ; No, keep off
  322.  
  323.                 or      al, PCIC_POWER_VCCENABLE
  324.  
  325. @@:             mov     ah, al
  326.                 mov     al, PCIC_POWER
  327.                 call    SetReg
  328.                 popx    <dx, ax>
  329.                 ret
  330. SetVcc          ENDP
  331.  
  332. ;*****************************************************************************
  333. ;*                              --- SetVpp   ---
  334. ;*
  335. ;*     Purpose: Set Vpp Value
  336. ;*       Input: [BX] - Pointer to the adapter structure
  337. ;*              [BP] - Pointer to the user args
  338. ;*              al   - Upper nibble - Vpp1 Level, Lower nibble - Vpp2 Level
  339. ;*      Output: none
  340. ;* Scratch reg: none
  341. ;*     Written: by Alexis A.Piatetsky 20.07.94
  342. ;*****************************************************************************
  343. SetVpp          PROC    NEAR
  344.  
  345.                 pushx   <ax, dx>
  346.  
  347.                 mov     dl, al
  348.                 mov     dh, 0               ; dh - Vcc = 0V
  349.  
  350.  
  351. ;--------------------------------- Switch off  --------------------------------
  352.  
  353.                 mov     al, PCIC_POWER
  354.                 call    GetReg                  ; get other bits
  355.  
  356.                 and     al, NOT (PCIC_POWER_VPP1MASK OR PCIC_POWER_VPP2MASK)
  357.                 mov     ah, al
  358.  
  359. ;---------------------------------- Set Vpp1 ----------------------------------
  360.  
  361.                 mov     al, dl
  362.                 shr     al, 1
  363.                 shr     al, 1
  364.                 shr     al, 1
  365.                 shr     al, 1
  366.                 and     al, PCIC_POWER_VPP1MASK
  367.  
  368.                 cmp     al, dh
  369.                 je      @f
  370.  
  371.                 or      ah, al
  372.  
  373. ;---------------------------------- Set Vpp2 ----------------------------------
  374.  
  375. @@:             mov     al, dl
  376.                 and     al, PCIC_POWER_VPP1MASK
  377.                 cmp     al, dh
  378.                 je      @f
  379.  
  380.                 shl     al, 1
  381.                 shl     al, 1
  382.                 or      ah, al
  383.  
  384. @@:             mov     al, PCIC_POWER
  385.                 call    SetReg
  386.  
  387.                 popx    <dx, ax>
  388.                 ret
  389. SetVpp          ENDP
  390.  
  391. ;*****************************************************************************
  392. ;*                            --- SoftReset   ---
  393. ;*
  394. ;*     Purpose: Perform Software reset of the socket
  395. ;*       Input: [BX] - Pointer to the adapter structure
  396. ;*              [BP] - Pointer to the user args
  397. ;*      Output: none
  398. ;* Scratch reg: none
  399. ;*     Written: by Alexis A.Piatetsky 20.07.94
  400. ;*****************************************************************************
  401. SoftReset       PROC    NEAR
  402.                 assume  ds:@data, es:Nothing
  403.  
  404.                 push    ax
  405.                 mov     al, PCIC_INTER
  406.                 call    GetReg              ; Get current value
  407.  
  408.                 mov     ah, al              ; Turn Reset on
  409.                 and     ah, NOT PCIC_INTER_RESET
  410.  
  411.                 mov     al, PCIC_INTER
  412.                 call    SetReg
  413.  
  414.                 push    ax
  415.                 mov     ax, PCIC_RESET_PULSE
  416.                 call    couDelay            ; Wait a decent interval
  417.                 pop     ax
  418.  
  419.                 or      ah, PCIC_INTER_RESET
  420.                 mov     al, PCIC_INTER
  421.                 call    SetReg
  422.  
  423.                 mov     ax, RESET_WAIT      ; Let the card recover
  424.                 call    couDelay
  425.  
  426.                 pop     ax
  427.  
  428.                 ret
  429. SoftReset       ENDP
  430.  
  431. ;*****************************************************************************
  432. ;*                         --- GetSktChanges ---
  433. ;*
  434. ;*     Purpose: Return changes on socket since last SetSocket
  435. ;*       Input: AL   - Instantaneous socket state
  436. ;*              [BX] - Pointer to the adapter structure
  437. ;*              [BP] - Pointer to the user args
  438. ;*              [SI] - Socket number
  439. ;*      Output: AL   - Changes of socket state
  440. ;* Scratch reg: none
  441. ;*     Written: by Alexis A.Piatetsky 21.01.94
  442. ;*****************************************************************************
  443. GetSktChanges   PROC   NEAR
  444.                 assume  ds:@data, es:Nothing
  445.  
  446.                 mov     ah, (ADP_DATA PTR [BX])[SI].bInstState ; Get old state
  447.                 mov     (ADP_DATA PTR [BX])[SI].bInstState, al ; Save new state
  448.  
  449.                 xor     ah, al              ; what's different between
  450.                                             ; instantaneous and saved state?
  451.  
  452.                 or      (ADP_DATA PTR [BX])[SI].bSktChanges, ah
  453.                                             ; Collect changes into bSktChanges
  454.                 mov     ah, (ADP_DATA PTR [BX])[SI].bSktChanges
  455.                                             ; ah - bSktChanges, al - State
  456.                 and     al, ah              ; ah = bSktChanges & State
  457.                 or      al, ah              ; ah = (bSktChanges & State) | bSktChanges
  458.  
  459.                 ret
  460. GetSktChanges   ENDP
  461.  
  462. ;*****************************************************************************
  463. ;*                          --- GetAdapterCnt ---
  464. ;*
  465. ;*     Purpose: Return number of adapters supported
  466. ;*       Input: [BP] = Pointer to entry args on stack
  467. ;*      Output: Args.ALReg - bTotAdapters
  468. ;*              Args.CXReg - Socket Services signature ('SS')
  469. ;* Scratch reg: all
  470. ;*     Written: by Alexis A.Piatetsky 28.07.94
  471. ;*****************************************************************************
  472. GetAdapterCnt   PROC    NEAR
  473.                 assume  ds:@data, es:Nothing
  474.  
  475.                 mov     al, bTotAdapters
  476.                 mov     (ARGS PTR [BP]).ALReg, al
  477.                 mov     (ARGS PTR [BP]).CXReg, SS_SIGNATURE
  478.                 mov     ah, SUCCESS
  479.                 ret
  480.  
  481. GetAdapterCnt   ENDP
  482.  
  483. COMMENT ~*********************************************************************
  484.         Procedure:      GetSSInfo
  485.         Revision:       1
  486.         Date:           05/25/1993
  487.         Purpose:        Returns PCMCIA compliance level and supported adapters
  488.         Entry:          [BP] = Pointer to entry args on stack
  489.         Exit:           Args.ALReg = 0 (Backward compatible with Socket Services 1.01)
  490.                         Args.BXReg = PCMCIA compliance level
  491.                         Args.CLReg = First adapter serviced by this handler
  492.                         Args.CHReg = Number of adapters serviced by this handler
  493. *****************************************************************************~
  494. GetSSInfo       PROC    NEAR
  495.                 assume  ds:@data, es:Nothing
  496.  
  497.                 mov     (ARGS PTR [BP]).ALReg, 0
  498.                 mov     (ARGS PTR [BP]).BXReg, PCMCIA_LEVEL
  499.                 mov     al, bFirstAdapter
  500.                 mov     (ARGS PTR [BP]).CLReg, al
  501.                 mov     al, bNumAdapters
  502.                 mov     (ARGS PTR [BP]).CHReg, al
  503.                 mov     ah, SUCCESS
  504.                 ret
  505. GetSSInfo       ENDP
  506.  
  507. COMMENT ~*********************************************************************
  508.         Procedure:      GetVendorInfo
  509.         Revision:       1
  510.         Date:           05/25/1993
  511.         Purpose:        Return vendor information
  512.         Entry:          [BP] = Pointer to entry args on stack
  513.                         [BX] = Pointer to adapter entry in Adapters array
  514.                         Args.BLReg = Subfunction (Only zero supported)
  515.                         [ES]:[DI] = Client-supplied buffer for Vendor string
  516.         Exit:           Args.AHReg = Return Code
  517.                         If (Args.BLReg NE 0)
  518.                           Args.AHReg = BAD_FUNCTION
  519.                         Else
  520.                           Args.DXReg = Vendor's release number
  521.                           Client-supplied buffer filled with Vendor ASCIIZ string
  522. *****************************************************************************~
  523. GetVendorInfo   PROC    NEAR
  524.                 assume  ds:@data, es:Nothing
  525.  
  526.                 mov     AH, BAD_FUNCTION    ; Default to     function
  527.                 cmp     (ARGS PTR [BP]).BLReg, 0        ; Recognized function ?
  528.                 jne     @f                  ; No, we're done
  529.  
  530.                 mov     si, OFFSET VendorInfo           ; Point to source of
  531.                                                         ; information
  532.  
  533. ;-------------------- Get Length of the Vendor Info string --------------------
  534.  
  535.                 push    es
  536.                 push    di
  537.  
  538.                 push    ds
  539.                 pop     es
  540.         assume  es:@data
  541.  
  542.                 mov     di, si
  543.                 xor     al, al
  544.                 cld
  545.                 mov     cx, -1
  546.         repne   scasb
  547.  
  548.                 mov     cx, di
  549.                 sub     cx, si
  550.  
  551.                 pop     di
  552.                 pop     es
  553.  
  554. ;--------------------- Move the info to the client buffer ---------------------
  555.  
  556.                 call    couCopyInfo
  557.  
  558.                 add     di, es:[di]             ; Add length of buffer
  559.                 add     di, 4 - 1               ; Point past length bytes (less one)
  560.                 mov     byte ptr es:[di], 0     ; Make NULL terminate string
  561.  
  562.                 mov     (ARGS PTR [BP]).DXReg, RELEASE_NUM
  563.                 mov     ah, SUCCESS
  564. @@:             ret
  565.  
  566. GetVendorInfo   ENDP
  567.  
  568. COMMENT ~*********************************************************************
  569.  
  570.         Procedure:      AckInterrupt
  571.  
  572.         Purpose:        Acknowledge change and identify interupting socket(s)
  573.  
  574.         Entry:          [BP] = Pointer to entry args on stack
  575.                         [BX] = Pointer to adapter entry in Adapters array
  576.  
  577.         Exit:           Args.CXReg = Bit-map of sockets reporting status change
  578.  
  579.         Note:           This function is typically called within an interrupt
  580.                         handler and must not enable interrupts.  It is also
  581.                         responsible for resetting the adapter hardware so that
  582.                         it can generate future status change interrupts
  583.  
  584. *****************************************************************************~
  585.  
  586. AckInterrupt    PROC    NEAR
  587.                 assume  ds:@data, es:Nothing
  588.  
  589.                 xor     ch, ch                  ; Prepare loop counter
  590.                 mov     cl, (ADP_DATA PTR [BX]).bNumSockets
  591.  
  592.                 mov     dh, 1                   ; SKTBITS Start with Socket 0
  593.                 xor     dl, dl                  ; SKTBITS Holder
  594.  
  595.                 xor     si, si                  ; Start from Socket 0
  596.  
  597. CheckNextSkt:   mov     ax, si
  598.                 mov     (ARGS PTR [BP]).bSocketNum, al
  599.                 push    cx
  600.                 mov     cl, PCIC_SKTINC
  601.                 mul     cl
  602.                 mov     (ARGS PTR [BP]).bSocketIdx, al
  603.                 pop     cx
  604.  
  605.                 mov     al, PCIC_STATE
  606.                 call    GetReg                  ; Reading will clear all bits
  607.                                                 ; (for acknowledge purposes only
  608.                                                 ; We will get the real status)
  609.                                                 ; change later.
  610.  
  611.                 call    GetInstSktState         ; AL - New Instantineous state
  612.                 xor     al, (ADP_DATA PTR [BX])[SI].bInstState
  613.                                                 ; Compare with saved value
  614.                 and     al, (ADP_DATA PTR [BX])[SI].bSCIRQMask
  615.                                                 ; Report only what user asked
  616.                                                 ; for
  617.                 or      al, al                  ; Any Change Bits Active?
  618.                 je      short @f                ; No Change, Continue.
  619.  
  620.  
  621. ; ----- Yes. Rewrite Status to Local Variable
  622.  
  623.                 or      dl, dh                  ; Mark Socket as changed
  624.  
  625. @@:
  626.                 shl     dh, 1                   ; Advance Socket Mask
  627.                 inc     si                      ; Advance Socket Number
  628.                 loop    CheckNextSkt
  629.  
  630.                 xor     dh, dh
  631.                 mov     (ARGS PTR [BP]).CXReg, dx
  632.                 mov     ah, SUCCESS
  633.                 ret
  634.  
  635. AckInterrupt    ENDP
  636.  
  637. COMMENT ~*********************************************************************
  638.         Procedure:      InquireAdapter
  639.         Revision:       1
  640.         Date:           05/25/1993
  641.         Purpose:        Return adapter capabilities and power management tables
  642.         Entry:          [BP] = Pointer to entry args on stack
  643.                         [BX] = Pointer to adapter entry in Adapters array
  644.                         [ES]:[DI] = Client-supplied buffer for characteristics
  645.         Exit:           Args.BHReg = Number of windows supported by adapter
  646.                         Args.BLReg = Number of sockets supported by adapter
  647.                         Args.CXReg = Number of EDCs supported by adapter
  648.                         Client-supplied buffer filled with adapter characteristics
  649. *****************************************************************************~
  650. InquireAdapter  PROC    NEAR
  651.                 assume  ds:@data, es:Nothing
  652.  
  653.                 mov     cx, AdapterInfoLen      ; Get length of adapter information
  654.                 mov     si, OFFSET AdapterInfo  ; Point to source of information
  655.                 call    couCopyInfo             ; Copy information that fits into buffer
  656.  
  657. ;------------------------ Return adapter specific data  -----------------------
  658.  
  659.                 mov     al, (ADP_DATA PTR [BX]).bNumWindows
  660.                 mov     (ARGS PTR [BP]).BHReg, al
  661.                 mov     al, (ADP_DATA PTR [BX]).bNumSockets
  662.                 mov     (ARGS PTR [BP]).BLReg, al
  663.                 mov     ax, (ADP_DATA PTR [BX]).wNumEDCs
  664.                 mov     (ARGS PTR [BP]).CXReg, ax
  665.                 mov     ah, SUCCESS
  666.                 ret
  667.  
  668. InquireAdapter  ENDP
  669.  
  670. COMMENT ~*********************************************************************
  671.         Procedure:      InquireSocket
  672.         Revision:       1
  673.         Date:           05/25/1993
  674.         Purpose:        Return socket capabilities
  675.         Entry:          [BP] = Pointer to entry args on stack
  676.                         [BX] = Pointer to adapter entry in Adapters array
  677.                         [ES]:[DI] = Client-supplied buffer for characteristics
  678.         Exit:           Args.BHReg = Status change interrupt capabilities (set = true)
  679.                         Args.DHReg = Status change reporting capabilities (set = true)
  680.                         Args.DLReg = Control and indicator capabilities (set = true)
  681.                         Client-supplied buffer filled with socket characteristics
  682. *****************************************************************************~
  683. InquireSocket   PROC    NEAR
  684.                 assume  ds:@data, es:Nothing
  685.  
  686.                 mov     cx, SocketInfoLen       ; Get length of socket information
  687.                 mov     si, OFFSET SocketInfo   ; Point to source of information
  688.                 call    couCopyInfo
  689.                 mov     al, SocketCaps.SCIntCaps
  690.                 mov     (ARGS PTR [BP]).BHReg, al
  691.                 mov     al, SocketCaps.SCRptCaps
  692.                 mov     (ARGS PTR [BP]).DHReg, al
  693.                 mov     al, SocketCaps.SCIndCaps
  694.                 mov     (ARGS PTR [BP]).DLReg, al
  695.                 mov     ah, SUCCESS
  696.                 ret
  697. InquireSocket   ENDP
  698.  
  699.  
  700.  
  701. ;*****************************************************************************
  702. ;*                           --- SetSktPower ---
  703. ;*
  704. ;*     Purpose: Set Power levels
  705. ;*       Input: AH   = Lower nibble - Vcc Level
  706. ;*              AL   = Upper nibble - Vpp1 Level, Lower nibble - Vpp2 Level
  707. ;*              [BP] = Pointer to entry args on stack
  708. ;*              [BX] = Pointer to adapter entry in Adapters array
  709. ;*      Output: none
  710. ;* Scratch reg: none
  711. ;*     Written: by Alexis A.Piatetsky 12.06.94
  712. ;*****************************************************************************
  713. SetSktPower     PROC    NEAR
  714.                 assume  ds:@data, es:Nothing
  715.  
  716.                 pushx   <cx, dx>
  717.                 mov     cx, ax
  718.  
  719.                 mov     dl, 0               ; Index of 0.0V
  720.  
  721.                 call    GetPower            ; Get current power levels
  722.                                             ; Get required power level
  723.                 cmp     ah, ch              ; Any change to Vcc?
  724.                 je      ss_set_vpp          ; No changes required
  725.  
  726.                 cmp     ah, dl              ; Power go from on to off?
  727.                 jne     @f                  ; Yes, skip next
  728.  
  729.                 ; Power is off and being switched on - requires 5V to Vcc,
  730.                 ; Vpp1 and Vpp2
  731.  
  732.                 ; Deassert output to PC Card
  733.  
  734.                 mov     al, PCIC_POWER
  735.                 call    GetReg
  736.  
  737.                 and     al, NOT PCIC_POWER_ENOUTPUT
  738.                 mov     ah, al
  739.  
  740.                 mov     al, PCIC_POWER
  741.                 call    SetReg
  742.  
  743.                 mov     al, PCIC_INTER
  744.                 call    GetReg
  745.  
  746.                 ; No reset at initial Output Enable after power on
  747.  
  748.                 or      al, PCIC_INTER_RESET
  749.                 mov     ah, al              ; Disable RESET condition
  750.  
  751.                 mov     al, PCIC_INTER
  752.                 call    SetReg
  753.  
  754.                 mov     ax, 0111h           ; Set all to 5 volts
  755.  
  756.                 push    ax                  ; Save Power levels
  757.  
  758. ; On IBM Thinkpad 750Cs machine setting of PCIC_POWER to default values causes
  759. ; cross-talk to PIC (programmable Interrupt Controller), that result in issue
  760. ; of random hardware IRQ. We try to prevent this by disabling of INT's during
  761. ; the switch
  762.                 pushf                       ; Save state of Interrupt flag
  763.                 cli                         ; Disable interrupts
  764.                 call    SetVcc
  765.                 call    SetVpp
  766.  
  767.                 mov     ax, POWER_DEAD_TIME
  768.                 call    couDelay
  769.  
  770.                 popf                        ; Restore interrupt state
  771.  
  772.                 mov     ax, POWERON_WAIT
  773.                 call    couDelay
  774.  
  775. ;-------------------------------- Enable Output -------------------------------
  776.  
  777.                 mov     al, PCIC_POWER
  778.                 call    GetReg
  779.  
  780.                 or      al, PCIC_POWER_ENOUTPUT
  781.                 mov     ah, al
  782.  
  783.                 mov     al, PCIC_POWER
  784.                 call    SetReg
  785.  
  786. ;----------------------- Generate soft reset to PC Card -----------------------
  787.  
  788.                 call    SoftReset
  789.  
  790.                 pop     ax                  ; Restore power levels
  791.  
  792. ;------------------------------- Set Correct Vcc ------------------------------
  793.  
  794. @@:             cmp     ah, ch              ; Change to Vcc?
  795.                 je      ss_set_vpp          ; No, skip next
  796.  
  797.                 push    ax
  798.                 mov     ah, ch              ; Take new level
  799.                 pushf                       ; Save state of Interrupt flag
  800.                 cli                         ; Disable interrupts
  801.                 call    SetVcc
  802.  
  803.                 mov     ax, POWER_DEAD_TIME
  804.                 call    couDelay
  805.  
  806.                 popf                        ; Restore interrupt state
  807.                 pop     ax
  808.  
  809. ;------------------------------- Set correct Vpp ------------------------------
  810.  
  811. ss_set_vpp:     cmp     al, cl              ; Any change to Vpp?
  812.                 je      @f                  ; No, skip next
  813.  
  814.                 mov     al, cl              ; Take new level
  815.                 pushf                       ; Save state of Interrupt flag
  816.                 cli                         ; Disable interrupts
  817.                 call    SetVpp
  818.  
  819.                 mov     ax, POWER_DEAD_TIME
  820.                 call    couDelay
  821.  
  822.                 popf                        ; Restore interrupt state
  823.  
  824.                 mov     ax, PROG_POWER_WAIT ; Wait 100 ms
  825.                 call    couDelay
  826.  
  827. ;------------------------ Assert correct initialisation -----------------------
  828.  
  829. @@:             cmp     ch, dl              ; Vcc enabled on card?
  830.                 jne     @f                  ; Yes, skip next
  831.  
  832.                 mov     al, PCIC_POWER      ; Deassert output
  833.                 call    GetReg
  834.  
  835.                 and     al, NOT PCIC_POWER_ENOUTPUT
  836.                 mov     ah, al
  837.  
  838.                 mov     al, PCIC_POWER
  839.                 call    SetReg
  840.  
  841.                 mov     al, PCIC_INTER
  842.                 call    GetReg
  843.  
  844.                 or      al, PCIC_INTER_RESET
  845.                 mov     ah, al              ; Disable RESET condition
  846.  
  847.                 mov     al, PCIC_INTER
  848.                 call    SetReg
  849.  
  850. @@:             mov     ax, cx              ; Restore AX value
  851.                 popx    <dx, cx>            ; Restore CX, DX values
  852.                 ret
  853. SetSktPower     ENDP
  854.  
  855. COMMENT ~*********************************************************************
  856.         Procedure:      GetSocket
  857.         Revision:       7
  858.         Date:           09/30/1993
  859.         Purpose:        Return current socket configuration
  860.         Entry:          [BP] = Pointer to entry args on stack
  861.                         [BX] = Pointer to adapter entry in Adapters array
  862.                         Args.BLReg = Socket Number
  863.         Exit:           Args.BHReg = Status change interrupt mask (set = enabled)
  864.                         Args.CHReg = Lower nibble - Vcc Level
  865.                         Args.CLReg = Upper nibble - Vpp1 Level, Lower nibble - Vpp2 Level
  866.                         Args.DHReg = Socket state (set = true)
  867.                         Args.DLReg = Control and indicator state (set = true)
  868.                           Bit 0..4 = IRQ Level and Interface Type
  869.                           Bit 5    = Level (reset = active low, set = active high)
  870.                           Bit 7    = State (reset = disabled, set = enabled)
  871.                           Bit 8    = Memory-only interface
  872.                           Bit 9    = I/O and memory interface
  873.                           All other bits reserved and are reset to zero (0)
  874. *****************************************************************************~
  875. GetSocket       PROC    NEAR
  876.                 assume  ds:@data, es:Nothing
  877.  
  878. ;---------------------- Get Status Change Interrupt mask ----------------------
  879.  
  880.                 xor     ah, ah
  881.                 mov     al, (ARGS PTR [BP]).bSocketNum
  882.                 mov     si, ax              ; Setup pointer to socket status
  883.  
  884.                 mov     al, (ADP_DATA PTR [BX])[SI].bSCIRQMask
  885.                 mov     (ARGS PTR [BP]).BHReg, al   ; Return SCIRQ Mask
  886.  
  887. ;------------------------------ Get Power levels ------------------------------
  888.  
  889.                 call    GetPower
  890.                 mov     (ARGS PTR [BP]).CXReg, ax
  891.  
  892. ;------------------ Get Socket State and socket changed state -----------------
  893.  
  894.                 call    GetInstSktState         ; al - Inst. socket state
  895.                 call    GetSktChanges           ; al - Socket changes
  896.  
  897.                 mov     (ARGS PTR [BP]).DHReg, al
  898.  
  899. ;----------------------- Get control and indicator state ----------------------
  900.  
  901.                 mov     al, (ADP_DATA PTR [BX]).bCntrlInd
  902.                 mov     (ARGS PTR [BP]).DLReg, al
  903.  
  904. ;----------------- Get current IRQ routing and interface type -----------------
  905.  
  906.                 mov     ah, (ADP_DATA PTR [BX])[SI].bSktIFType
  907.                 mov     al, (ADP_DATA PTR [BX])[SI].bSktIRQLevel
  908.                 mov     (ARGS PTR [BP]).DIReg, ax
  909.  
  910.                 mov     ah, SUCCESS
  911.                 ret
  912.  
  913. GetSocket       ENDP
  914.  
  915. COMMENT ~*********************************************************************
  916.  
  917.         Procedure:      GetStatus
  918.  
  919.         Purpose:        Return current PC Card and socket status
  920.  
  921.         Entry:          [BP] = Pointer to entry args on stack
  922.                         [BX] = Pointer to adapter entry in Adapters array
  923.                         Args.ALReg = Adapter Number
  924.                         Args.BLReg = Socket Number
  925.  
  926.         Exit:           Args.BHReg = Current card state (set = true)
  927.                         Args.DHReg = Socket state (set = true)
  928.                         Args.DLReg = Control and indicator state (set = true)
  929.                         Args.DIReg = IFType (hi byte) IREQRoute (lo byte)
  930. *****************************************************************************~
  931.  
  932. GetStatus       PROC    NEAR
  933.                 assume  ds:@data, es:Nothing
  934.  
  935.                 xor     ah, ah
  936.                 mov     al, (ARGS PTR [BP]).bSocketNum
  937.                 mov     si, ax                  ; si to contain socket number
  938.  
  939. ;-------------------------- Get current PC Card state -------------------------
  940.  
  941.                 call    GetInstSktState         ; al - Inst. state
  942.                 mov     (ARGS PTR [BP]).BHReg, al
  943.  
  944. ;-------------------------- Get latched socket state --------------------------
  945.  
  946.                 call    GetSktChanges           ; al - Socket changes
  947.                 mov     (ARGS PTR [BP]).DHReg, al
  948.  
  949. ;----------------------- Get control and indicator state ----------------------
  950.  
  951.                 mov     al, (ADP_DATA PTR [bx]).bCntrlInd
  952.                 mov     (ARGS PTR [BP]).DLReg, al
  953.  
  954. ;------------------------- Get IREQRouting and IFType -------------------------
  955.  
  956.                 mov     ah, (ADP_DATA PTR [BX])[SI].bSktIFType
  957.                 mov     al, (ADP_DATA PTR [BX])[SI].bSktIRQLevel
  958.                 mov     (ARGS PTR [BP]).DIReg, ax
  959.  
  960.                 mov     ah, SUCCESS
  961.                 ret
  962. GetStatus       ENDP
  963.  
  964. COMMENT ~*********************************************************************
  965.         Procedure:      SetSocket
  966.         Revision:       16
  967.         Date:           09/30/1993
  968.         Purpose:        Configure socket
  969.         Entry:          [BP] = Pointer to entry args on stack
  970.                         [BX] = Pointer to adapter entry in Adapters array
  971.                         Args.BLReg = Socket Number
  972.                         Args.BHReg = Status change interrupt mask (set = enabled)
  973.                         Args.CHReg = Lower nibble - Vcc Level
  974.                         Args.CLReg = Upper nibble - Vpp1 Level, Lower nibble - Vpp2 Level
  975.                         Args.DHReg = Socket state (set = true)
  976.                         Args.DLReg = Control and indicator state (set = true)
  977.                         Args.DIReg = I/O IREQ Routing and IFType
  978.                           Bit 0..4 = IRQ Level
  979.                           Bit 6    = Level (reset = active low, set = active high)
  980.                           Bit 7    = State (reset = disabled, set = enabled)
  981.                           Bit 8    = Memory-only interface
  982.                           Bit 9    = I/O and memory interface
  983.                           All other bits reserved and are reset to zero (0)
  984.         Exit:           Args.AHReg = Return Code
  985. *****************************************************************************~
  986.  
  987. SetSocket       PROC    NEAR
  988.                 assume  ds:@data, es:Nothing
  989.  
  990. ;---------------------------- Validate power levels ---------------------------
  991.  
  992.                 mov     ax, (ARGS PTR [BP]).CXReg
  993.                 call    covValidatePw
  994.                 jc      ss_exit
  995.  
  996. ;------------------------ Validate IFType and IRQ Level -----------------------
  997.  
  998.                 mov     si, offset SocketInfo
  999.                 mov     ax, (ARGS PTR [BP]).DIReg
  1000.                 call    covValidateIFt
  1001.                 jc      ss_exit
  1002.  
  1003. ;------- If set default IRQ, do it, even if IRQ isn't in capability mask ------
  1004.  
  1005.                 mov     cl, PCIC_DEF_IRQ
  1006.                 push    ax
  1007.                 and     al, (P_IRQ15 OR IRQ_HIGH)
  1008.                 and     cl, (P_IRQ15 OR IRQ_HIGH)
  1009.                 cmp     al, cl
  1010.                 pop     ax
  1011.                 je      @f
  1012.  
  1013.                 call    covValidateIRQ
  1014.                 jc      ss_exit
  1015.  
  1016. ;----------------------------- Prepare Set Socket -----------------------------
  1017.  
  1018. @@:             push    ax                  ; Save IFType & IRQ
  1019.                 xor     ah, ah
  1020.                 mov     al, (ARGS PTR [BP]).bSocketNum
  1021.                 mov     si, ax              ; si to contain socket number
  1022.                 pop     ax                  ; Restore IFType & IRQ
  1023.  
  1024. ;---------------------------- Set Socket Interface ----------------------------
  1025.  
  1026.                 mov     (ADP_DATA PTR [BX])[SI].bSktIFType, ah
  1027.                 call    asSetSktInterface
  1028.  
  1029. ;------------------------------- Set Socket IRQ -------------------------------
  1030.  
  1031.                 test    ah, IF_MEMORY       ; Memory Only Interface?
  1032.                 jz      @f                  ; No, I/O
  1033.  
  1034.                 ; Disable set IREQ routing with appropriate interface type
  1035.                 and     al, NOT IRQ_ENABLED
  1036.  
  1037. @@:             cmp     al, (ADP_DATA PTR [BX])[SI].bSktIRQLevel ; New IRQ?
  1038.                 je      short @f                ; No, continue
  1039.  
  1040.                 ; New IRQ level requested, change in local variable.
  1041.  
  1042.                 mov     (ADP_DATA PTR [BX])[SI].bSktIRQLevel, al
  1043.                 call    asSetSktIRQ
  1044.  
  1045. ;------------------------------ Set the SCIRQMask -----------------------------
  1046.  
  1047. @@:             mov     ah, (ARGS PTR [BP]).BHReg
  1048.                 mov     (ADP_DATA PTR [BX])[SI].bSCIRQMask, ah
  1049.                 call    asSetSktMask
  1050.  
  1051. ;------------------------- Set Control and Indicators -------------------------
  1052.  
  1053.                 mov     ah, (ARGS PTR [BP]).DLReg
  1054.                 mov     (ADP_DATA PTR [BX]).bCntrlInd, ah
  1055.  
  1056. ;---------------------------- Reset specified bits ----------------------------
  1057.  
  1058.                 mov     al, (ARGS PTR [BP]).DHReg
  1059.  
  1060.                 not     al                  ; Update socket changes mask
  1061.                 and     (ADP_DATA PTR [BX])[SI].bSktChanges, al
  1062.  
  1063. ;------------------------------ Set Socket Power ------------------------------
  1064.  
  1065.                 mov     ax, (ARGS PTR [BP]).CXReg
  1066.                 call    SetSktPower
  1067.  
  1068.                 mov     ah, SUCCESS
  1069. ss_exit:        ret
  1070.  
  1071. SetSocket       ENDP
  1072.  
  1073. COMMENT ~*********************************************************************
  1074.  
  1075.         Procedure:      ResetSocket
  1076.  
  1077.         Purpose:        Reset PC Card Scoket
  1078.  
  1079.         Entry:          [BP] = Pointer to entry args on stack
  1080.                         [BX] = Pointer to adapter entry in Adapters array
  1081.                         Args.ALReg = Adapter Number
  1082.                         Args.BLReg = Socket Number
  1083.         Exit:           Args.AHReg = Return Code
  1084.  
  1085. *****************************************************************************~
  1086.  
  1087. ResetSocket     PROC    NEAR
  1088.                 assume  ds:@data, es:Nothing
  1089.  
  1090.  
  1091. ;----------------------- Disable status change interrupt ----------------------
  1092.  
  1093.                 xor     ah, ah              ; Set empty mask
  1094.                 call    asSetSktMask
  1095.  
  1096. ;---------------- Disable         currently assigned to socket ----------------
  1097.  
  1098.                 mov     cl, (ADP_DATA PTR [BX]).bNumWindows
  1099.                 xor     ch, ch
  1100.                 mov     dl, (ARGS PTR [BP]).bSocketNum ; Protect important
  1101.                 mov     dh, (ARGS PTR [BP]).bSocketIdx ; values
  1102.  
  1103.                 xor     al, al              ; Start from window 0
  1104.  
  1105. es_diswin:      call    CalcWndIndex        ; Calculate Window Index
  1106.  
  1107.                 cmp     dl, (ARGS PTR [BP]).bSocketNum  ; Our Socket?
  1108.                 jne     es_diswin_next
  1109.  
  1110.                 pushx   <ax, cx>
  1111.                 mov     al, (ARGS PTR [BP]).bSocketNum
  1112.                 mov     cl, PCIC_SKTINC
  1113.                 mul     cl
  1114.                 mov     (ARGS PTR [BP]).bSocketIdx, al
  1115.                 popx    <cx, ax>
  1116.  
  1117.                 call    cowIsWinEnabled     ; Window enabled?
  1118.                 jz      es_diswin_next      ; No, continue
  1119.  
  1120.                 call    cowDisableWindow    ; Disable Window
  1121.  
  1122. es_diswin_next: inc     al
  1123.                 loop    es_diswin
  1124.  
  1125.                 mov     (ARGS PTR [BP]).bSocketNum, dl  ; Restore important
  1126.                 mov     (ARGS PTR [BP]).bSocketIdx, dh  ; values
  1127.  
  1128. ;----------------------- Put default power to the socket ----------------------
  1129.  
  1130.                 push    (ARGS PTR [BP]).AXReg   ; Save Stack frame
  1131.                 push    (ARGS PTR [BP]).BXReg
  1132.                 push    (ARGS PTR [BP]).CXReg
  1133.                 push    (ARGS PTR [BP]).DXReg
  1134.                 push    (ARGS PTR [BP]).DIReg
  1135.  
  1136.                 call    GetSocket
  1137.  
  1138.                 mov     ax, 0111h           ; Initialize socket power up
  1139.                 MOV     (ARGS PTR [BP]).CXReg, ax               ; to 5V
  1140.                 AND     (ARGS PTR [BP]).DIReg, NOT IRQ_ENABLED  ; Disable IRQ
  1141.                 MOV     (ARGS PTR [BP]).DHReg, 0 ; Keep Socket changes mask in
  1142.                                                  ; case SC Interrupt occured
  1143.                                                  ; but not treated yet
  1144.                 call    SetSocket
  1145.  
  1146.                 pop     (ARGS PTR [BP]).DIReg   ; Restore stack frame
  1147.                 pop     (ARGS PTR [BP]).DXReg
  1148.                 pop     (ARGS PTR [BP]).CXReg
  1149.                 pop     (ARGS PTR [BP]).BXReg
  1150.                 pop     (ARGS PTR [BP]).AXReg
  1151.  
  1152. ;-------------------------------- Perform reset -------------------------------
  1153.  
  1154.                 call    SoftReset
  1155.  
  1156. ;--------------------- Set Socket Interface to Memory Only --------------------
  1157.  
  1158.                 xor     ah, ah
  1159.                 mov     al, (ARGS PTR [BP]).bSocketNum
  1160.                 mov     si, ax              ; Setup pointer to socket status
  1161.                 mov     ah, IF_MEMORY
  1162.                 mov     (ADP_DATA PTR [BX])[SI].bSktIFType, ah
  1163.                 call    asSetSktInterface
  1164.  
  1165. ;------------------ Restore Status Change Interrupt IRQ value -----------------
  1166.  
  1167.                 mov     ah, (ADP_DATA PTR [bx]).bSCIRQMask
  1168.                 call    asSetSktMask
  1169.  
  1170.                 mov     ah, SUCCESS         ; Report success
  1171.                 ret
  1172.  
  1173. ResetSocket     ENDP
  1174.  
  1175. ;*****************************************************************************
  1176. ;*                        --- GetInstSktState   ---
  1177. ;*
  1178. ;*     Purpose: Return Instantaneous socket state
  1179. ;*       Input: [BX] - Pointer to the adapter structure
  1180. ;*              [BP] - Pointer to the user args
  1181. ;*      Output: AL   - Instantaneous socket state
  1182. ;* Scratch reg: none
  1183. ;*     Written: by Alexis A.Piatetsky 21.01.94
  1184. ;*****************************************************************************
  1185. GetInstSktState PROC NEAR
  1186.                 assume  ds:@data, es:Nothing
  1187.  
  1188.                 pushx   <cx, dx>
  1189.  
  1190. ;----------------------------- Get Current Status -----------------------------
  1191.  
  1192.                 mov     al, PCIC_IFSTAT
  1193.                 call    GetReg              ; Read Interface Status Register
  1194.  
  1195. ;------------------------------- Battery detect -------------------------------
  1196.  
  1197.                 push    ax                  ; Mask battery bits out
  1198.                 not     al
  1199.                 and     al, PCIC_IFSTAT_BVDMASK
  1200.  
  1201.                 mov     cl, 4               ; Move battery bits to the right
  1202.                 shl     al, cl              ; position
  1203.  
  1204.                 mov     dl, al              ; Store to accumulator. Clear
  1205.                 pop     ax                  ; all other bits
  1206.  
  1207. ;-------------------- Card detect and write protect detect --------------------
  1208.  
  1209.                 push    ax                  ; Mask card detect bits
  1210.                 and     al, PCIC_IFSTAT_CDMASK
  1211.                 cmp     al, PCIC_IFSTAT_CDMASK
  1212.                 jne     @f                  ; No card inserted
  1213.  
  1214.                 or      dl, SBM_CD          ; Card Inserted
  1215.  
  1216. @@:             pop     ax
  1217.  
  1218. ;-------------------------------- Write protect -------------------------------
  1219.  
  1220.                 test    al, PCIC_IFSTAT_WP  ; Write protected?
  1221.                 jz      @f                  ; No, continue
  1222.  
  1223.                 or      dl, SBM_WP          ; Yes, report it
  1224.  
  1225. ;--------------------------------- Ready/Busy ---------------------------------
  1226.  
  1227. @@:             test    al, PCIC_IFSTAT_RDYBSY  ; Card is ready?
  1228.                 jz      @f                  ; No, continue
  1229.  
  1230.                 or      dl, SBM_RDYBSY      ; Yes, indicate ready
  1231.  
  1232. @@:             mov     al, dl              ; Return result in al
  1233.                 popx    <dx, cx>
  1234.                 ret
  1235. GetInstSktState ENDP
  1236.  
  1237. COMMENT ~*********************************************************************
  1238.         Procedure:      GetAdapter
  1239.         Revision:       2
  1240.         Date:           05/25/1993
  1241.         Purpose:        Return current adapter configuration
  1242.         Entry:          [BP] = Pointer to entry args on stack
  1243.                         [BX] = Pointer to adapter entry in Adapters array
  1244.         Exit:           Args.AHReg = Return Code
  1245.                         Args.DHReg = Adapter state
  1246.                           Bit 0    = Reduced Power Consumption (Sleep Mode)
  1247.                           Bit 1    = State Information Preserved
  1248.                           All other bits reserved and are reset to zero (0)
  1249.                         Args.DIReg = Status Change Interrupt (SCI) State
  1250.                           Bit 0..4 = SCI IRQ Level
  1251.                           Bit 5    = SCI Level (reset = active low, set = active high)
  1252.                           Bit 7    = SCI State (reset = disabled, set = enabled)
  1253.                           All other bits reserved and are reset to zero (0)
  1254. *****************************************************************************~
  1255. GetAdapter      PROC    NEAR
  1256.  
  1257.  
  1258. ;-------------------------------- Report status -------------------------------
  1259.  
  1260.                 mov     (ARGS PTR [BP]).DHReg,0 ; Initialise variable
  1261.  
  1262.                 xor     ah, ah          ; Returned saved IRQ state
  1263.                 mov     al, (ADP_DATA PTR [BX]).bSCIRQLevel
  1264.  
  1265.                 mov     (ARGS PTR [BP]).DIReg, AX
  1266.                 ret
  1267.  
  1268. GetAdapter      endp
  1269.  
  1270.  
  1271. COMMENT ~*********************************************************************
  1272.         Procedure:      SetAdapter
  1273.         Revision:       7
  1274.         Date:           09/15/1993
  1275.         Purpose:        Configure adapter
  1276.         Entry:          [BP] = Pointer to entry args on stack
  1277.                         [BX] = Pointer to adapter entry in Adapters array
  1278.                         Args.ALReg = Adapter Number
  1279.                         Args.DHReg = Adapter Control
  1280.                           Bit 0    = Reduce Power Consumption (set = true)
  1281.                           Bit 1    = Preserve state information when power reduced
  1282.                           All other bits are reserved
  1283.                         Args.DIReg = Status Change Interrupt Control
  1284.                           Bit 0..4 = SCI IRQ Level
  1285.                           Bit 5    = SCI Active Level (reset = low, set = high)
  1286.                           Bit 7    = SCI State (reset = disabled, set = enabled)
  1287.                           All other bits reserved and are reset to zero (0)
  1288.         Exit:           Args.AHReg = Return Code
  1289.                         If SCI IRQ Level and Active Level are valid
  1290.                           Args.AHReg = SUCCESS
  1291.                           SCI set as requested for all sockets on adapter
  1292.                         Else
  1293.                           Args.AHReg = BAD_IRQ
  1294.         Notes:          SCI IRQ Level and SCI Active Level fields are validated
  1295.                         whether SCI state is enabled or disabled
  1296.                         If SCI request matches current setting, hardware is
  1297.                         not rewritten
  1298.                         SCI setting is shadowed in RAM.  PCIC requires routing
  1299.                         hardware be set to zero (0) to disable interrupt, losing
  1300.                         IRQ level.
  1301.                         PCIC does not support power management.
  1302. *****************************************************************************~
  1303. SetAdapter      PROC    NEAR
  1304.  
  1305. ;---------------------------- Check SC IRQ request ----------------------------
  1306.  
  1307.                 mov     ax, (ARGS PTR [bp]).DIReg   ; Get IRQ requested
  1308.  
  1309.                 mov     si, offset AdapterInfo
  1310.  
  1311. ;------- If set default IRQ, do it, even if IRQ isn't in capability mask ------
  1312.  
  1313.                 mov     di, PCIC_DEF_SCIRQ
  1314.                 mov     cx, di
  1315.                 push    ax
  1316.                 and     al, (P_IRQ15 OR IRQ_HIGH)
  1317.                 and     cl, (P_IRQ15 OR IRQ_HIGH)
  1318.                 cmp     al, cl
  1319.                 pop     ax
  1320.                 je      @f
  1321.  
  1322.                 call    covValidateIRQ      ; Is IRQ valid?
  1323.                 jc      saExit              ; No, exit now
  1324.  
  1325. ;---------- Request is valid, save it locally and initialize hardware ----------
  1326.  
  1327. @@:             mov     ah, al
  1328.                 mov     (ADP_DATA PTR [BX]).bSCIRQLevel, ah ; Save new setting
  1329.  
  1330. ; Do for all sockets
  1331.  
  1332.                 mov     cl, (ADP_DATA PTR [BX]).bNumSockets
  1333.  
  1334. saLoop:         dec     cl
  1335.  
  1336.                 mov     (ARGS PTR [bp]).bSocketNum, cl
  1337.                 pushx   <ax, cx>
  1338.                 mov     al, cl
  1339.                 mov     cl, PCIC_SKTINC
  1340.                 mul     cl
  1341.                 mov     (ARGS PTR [BP]).bSocketIdx, al
  1342.                 popx    <cx, ax>
  1343.  
  1344.                 push    ax                  ; Save IRQ settings
  1345.                 and     al, P_IRQ15         ; Mask IRQ level
  1346.                 push    cx                  ; Save socket number counter
  1347.                 mov     cl, 4               ; Shift to the right position
  1348.                 shl     al, cl
  1349.                 mov     ah, al
  1350.                 pop     cx                  ; Restore socket number counter
  1351.  
  1352.                 mov     al, PCIC_SCINT      ; Set a new value of IRQ
  1353.                 call    SetReg              ; (Clear Socket Status Change
  1354.                                             ;  interrupt mask)
  1355.  
  1356.                 pop     ax                  ; Restore IRQ settings
  1357.  
  1358.                 test    al, IRQ_ENABLED
  1359.                 jz      @f
  1360.  
  1361.                 push    ax
  1362.                 mov     ah, (ADP_DATA PTR [bx]).bSCIRQMask
  1363.                 call    asSetSktMask
  1364.                 pop     ax
  1365.  
  1366. @@:             inc     cl                  ; Restore Socket counter
  1367.                 loop    saLoop
  1368.  
  1369.  
  1370.                 mov     ah, SUCCESS         ; Indicate success
  1371.  
  1372. saExit:         ret
  1373.  
  1374. SetAdapter      ENDP
  1375.  
  1376. sEnd            ResCode
  1377.  
  1378.                 END
  1379.