;------------------------------------------------------------------------------
;- (c) Copyleft Joseph H. Nord 1993.  You may use this code what ever you want.
;- If you find it useful, please give me a plug in the commentary.
;------------------------------------------------------------------------------
;- Name:    lptidc.asm                                  Date Created: 01/26/93
;- Author:  Joseph H. Nord                              Last Update : 05/11/94
;------------------------------------------------------------------------------
;- IDC Communication with base OS/2 parallel port device driver
;-----------------------------------------------------------------------------

                .NOLIST
                INCLUDE DEVSYM6.INC             ; OS/2 toolkit include file
                INCLUDE DEVHLP.INC
                INCLUDE TYPES.INC
                INCLUDE DATA.INC
                INCLUDE LPTIDC.INC
                INCLUDE DEVICE.INC
                .LIST

                                        ;------------------------------- DATA -
DSEG    SEGMENT PUBLIC 'DATA'
DSEG    ENDS

                                        ;------------------------------- CODE -
CSEG            SEGMENT PUBLIC 'CODE'
                ASSUME CS:CSEG,DS:DSEG

                                        ;------------------- LPTIDC_IDCAccess -
; Routine calls the OS/2 printer device driver to negociate
; access to the parallel port.
; Based on the parameter, access is either requested
; or released.  The return code indicates success/failure.
;
; Parameters:
;    [bp+4] - <IDC_REQUEST_ACCESS, IDC_RELEASE_ACCESS>
; Returns(AX)
;    zero - success, or error code from OS/2 printer PDD

LPTIDC_IDCAccess PROC NEAR
                .386p
                push    bp                      ; Establish stack frame
                mov     bp, sp
                push    ebx                     ; Preserve registers
                push    cx
                push    dx
                push    ds
                push    es

                mov     ebx, pLPTIDCEntry       ; Insure IDC is possible
                or      ebx, ebx                ; If not possible, return
                jz      NoIDC                   ; success - access granted

                mov     ax, word ptr [bp+4]     ; Request/release access
                xor     bx, bx                  ; Do not block
                mov     cx, word ptr ulLPTNumber ; Port number 0..2
                push    ds                      ; es := ds
                pop     es                      ; ds := other PDDs DS
                mov     ds, es:LPTIDC_DD_INFO.ProtModeDS
                call    es:pLPTIDCEntry         ; Call other PDD

                ; If carry, then OS/2 printer PDD failed the request,
                ; error code is in ax
                ; OS/2 2.1 GA driver doesn't support IDC.  It always returns
                ; carry set with AX == 0.  To support hot cable swapping
                ; with this level of driver, we ignore this error condition
                ; and do our best to get along without trapping the machine.
                ; With this special case, we can ignore the carry/error flag
                ; and use only the RC - which is directly propagated to caller.

                jmp     Done

NoIDC:          xor     ax, ax                  ; Indicate success

Done:           pop     es                      ; Restore registers
                pop     ds
                pop     dx
                pop     cx
                pop     ebx                     ; Propagate RC in AX
                leave
                ret     2
                .286p
LPTIDC_IDCAccess ENDP

CSEG            ENDS
                END
