;       SCCSID = @(#)prtinit.asm        6.1 91/08/17
        page    ,132
        title   PRTInit - Parallel Port Device Driver Initialization Setup

SCCSID  equ     "@(#)prtinit.asm        6.1 91/08/17"

; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

;/********************** START OF SPECIFICATIONS **********************/
;/*                                                                   */
;/* SOURCE FILE NAME: prtinit                                         */
;/*                                                                   */
;/* DESCRIPTIVE NAME: Initialize parallel port device driver          */
;/*                   structures.                                     */
;/*                                                                   */
;/* FUNCTION: To set a pointer to the Parallel Port Device Driver     */
;/*           configuration data needed when the device driver        */
;/*           initializes.                                            */
;/*                                                                   */
;/* NOTES:                                                            */
;/*   DEPENDENCIES: None                                              */
;/*   RESTRICTIONS: None                                              */
;/*                                                                   */
;/* ENTRY POINTS: PRTInit                                             */
;/*                                                                   */
;/* EXTERNAL REFERENCES: NONE                                         */
;/*                                                                   */
;/*********************** END OF SPECIFICATIONS ***********************/

.xlist
        include dosseg.inc              ; Sysinit segment names
        include basemaca.inc            ; CP/DOS macros
        include fnoinit.inc
        include osmaca.inc              ; CP/DOS macros
        include prtinit.inc             ; prt command line structures
.list

        ModName  , FNO_PRTINIT_ASM

INITDATA segment

extrn   CFG_PrtBufSize:word

INITDATA ends

        FARCODE INIT
INITCODE SEGMENT                        ; This code goes with SYSINIT.

;/********************** START OF SPECIFICATIONS **********************/
;/*                                                                   */
;/* SUBROUTINE NAME: InitPRT                                          */
;/*                                                                   */
;/* DESCRIPTIVE NAME: To setup a pointer to the parallel port         */
;/*                   device driver initialization data structure.    */
;/*                                                                   */
;/* FUNCTION: Arrange command line parameters to printXX.sys          */
;/*           so that CFG_PrintBufSizes get appended with             */
;/*           actual printXX.SYS command line args                    */
;/*                                                                   */
;/* NOTES:                                                            */
;/*                                                                   */
;/* ENTRY POINT: InitPRT                                              */
;/*    LINKAGE:  Call near                                            */
;/*                                                                   */
;/* INPUT: BX:CX = address of command_string (command line args)      */
;/*                                                                   */
;/* EXIT-NORMAL: BX:CX = address of command string with contents      */
;/*                      modified as follows for the Parallel Port    */
;/*                      Device Driver in the initialization packet:  */
;/*                                                                   */
;/*                      1) FIRST THREE WORDS: CFG_PrtBufSize         */
;/*                      2) BYTES THAT FOLLOW CONTAIN printXX.SYS     */
;/*                         COMMAND LINE ARGS                         */
;/*                                                                   */
;/* EXIT-ERROR: None                                                  */
;/*                                                                   */
;/* EFFECTS: All other registers preserved                            */
;/*                                                                   */
;/* INTERNAL REFERENCES:                                              */
;/*    ROUTINES: None                                                 */
;/*                                                                   */
;/* EXTERNAL REFERENCES:                                              */
;/*    ROUTINES: None                                                 */
;/*                                                                   */
;/*********************** END OF SPECIFICATIONS ***********************/
;
; Procedure InitPRT
;
; Get addressability to parameter list
; Append existing command line at end of parameter list
; Return (address of parameter list)
;
; End InitPRT

Procedure InitPRT
        assume cs:INITCODE, ds:INITDATA, es:nothing, ss:nothing

;       Return address of parameter list to caller

        ;/*******************************************************/
        ;/* THIS CODE WILL SHIFT THE PASSED IN COMMAND LINE     */
        ;/* ARGS TO THE RIGHT BY SIX BYTES TO MAKE              */
        ;/* ROOM FOR THE THREE CFG_PrtBufSize WORDS             */
        ;/*                                                     */
        ;/* NOTE: !!! IMPORTANT ASSUMPTIONS !!!                 */
        ;/*                                                     */
        ;/* 1) On entry, INITDATA:CX points to command_string   */
        ;/*    which is an INITBSS 1024 CHAR BUFFER             */
        ;/*                                                     */
        ;/* 2) THE PRINTXX.SYS COMMAND LINE WILL NOT EXCEED     */
        ;/*    CMDLINE_ARGSIZE BYTES                            */
        ;/*                                                     */
        ;/*******************************************************/

        pushf                           ; SAVE FLAGS
        push    es                      ; SAVE ES
        push    ds                      ; SAVE DS
        push    di                      ; SAVE DI
        push    si                      ; SAVE SI

        ;/*******************************************************/
        ;/*  The following represents the command_string buffer */
        ;/*  with beginning offset shown as 0 to simplify the   */
        ;/*  decription of the string shift algorithm.          */
        ;/*                                                     */
        ;/*  In this example, CMDLINE_ARGSIZE = 80H             */
        ;/*                                                     */
        ;/*                                                     */
        ;/*       0 0 0 0 0 0 0 ....... 7 8 8 8 8 8 8           */
        ;/*       0 1 2 3 4 5 6         9 0 1 2 3 4 5           */
        ;/*      +-+-+-+-+-+-+-+       +-+-+-+-+-+-+-+          */
        ;/*      | | | | | | | |       | | | | | | | |          */
        ;/*      +-+-+-+-+-+-+-+       +-+-+-+-+-+-+-+          */
        ;/*                                                     */
        ;/*       ^           ^         ^           ^           */
        ;/*     Start of   Shift To   Cmd Line    Shift         */
        ;/*     Cmd Line   Here         End      to here        */
        ;/*                           (DS:SI)    (ES:DI)        */
        ;/*                                                     */
        ;/* With a string shift from low-to-high we must start  */
        ;/* at the end of the string else we would overwrite    */
        ;/* the string as we shifted it. (use STD with the      */
        ;/* "rep movsb" command to do this)                     */
        ;/*******************************************************/

        mov     es, bx                  ; GET ES & DS POINTING AT
        mov     ds, bx                  ; command_string & CFG_PrtBufSize

        push    cx                      ; SAVE OFFSET OF command_string

        add     cx, CMDLINE_ARGSIZE - 1 ; PTR TO LAST BYTE CMD STRING
        mov     si, cx                  ; DS:SI => LAST BYTE CMD STR
        add     cx, 6                   ; PTR TO LAST BYTE CMD STRING+6
        mov     di, cx                  ; ES:DI => LAST BYTE CMD STRING+6

        mov     cx, CMDLINE_ARGSIZE     ; SHIFT "UP" CMDLINE_ARGSIZE BYTES

        std                             ; SET DIRECTION FLAG (decrement)
        rep     movsb                   ; DECS SI,DI WITH DIRECTION FLAG SET

        pop     cx                      ; RESTORE OFFSET OF command_string

        ;/*******************************************************/
        ;/* NOW MOVE THE THREE WORDS FROM CFG_PrtBufSize TO     */
        ;/* THE FIRST THREE WORDS OF command_string.            */
        ;/*******************************************************/

        lea     si, CFG_PrtBufSize      ; DS:SI PTR TO CFG_PrtBufSize
        mov     di, cx                  ; ES:DI PTR TO command_String

        push    cx                      ; SAVE OFFSET OF command_string
        mov     cx, 3                   ; THREE WORDS (6 BYTES)

        cld                             ; CLEAR DIRECTION FLAG
        rep     movsw                   ; MOVE THE CFG_PrtBufSize WORDS
        pop     cx                      ; RESTORE OFFSET OF command_string

        pop     si                      ; RESTORE SI
        pop     di                      ; RESTORE DI
        pop     ds                      ; RESTORE DS
        pop     es                      ; RESTORE ES
        popf                            ; RESTORE FLAGS (DIRECTION FLAG)

        ret
EndProc InitPRT

INITCODE ENDS
         END
