unit Params;

{$F+,S-}

interface

function ParCount: Integer;
function ParStr(Index: Integer): string;

implementation

procedure ParStrCnt; near; assembler;
asm
        MOV     ES,PrefixSeg
        MOV     DI,80H
        MOV     CL,ES:[DI]
        XOR     CH,CH
        INC     DI
        XOR     BX,BX
@@1:    JCXZ    @@3
@@2:    CMP     ES:[DI].Byte,' '
        JA      @@3
        INC     DI
        LOOP    @@2
@@3:    MOV     SI,DI
        JCXZ    @@6
        JMP     @@5
@@4:    CMP     ES:[DI].Byte,' '
        JBE     @@6
        CMP     ES:[DI].Byte,'/'
        JE      @@6
@@5:    INC     DI
        LOOP    @@4
@@6:    MOV     AX,DI
        SUB     AX,SI
        JZ      @@7
        INC     BX
        DEC     DX
        JNZ     @@1
@@7:
end;

function ParCount: Integer; assembler;
asm
        XOR     DX,DX
        CALL    ParStrCnt
        XCHG    AX,BX
end;

function ParStr(Index: Integer): string; assembler;
asm
        MOV     DX,Index
        OR      DX,DX
        JZ      @@1
        CALL    ParStrCnt
        JMP     @@4
@@1:    MOV     AH,30H
        INT     21H
        CMP     AL,3
        MOV     AX,0
        JB      @@4
        MOV     ES,PrefixSeg
        MOV     ES,ES:2CH
        XOR     DI,DI
        CLD
@@2:    CMP     AL,ES:[DI]
        JE      @@3
        MOV     CX,-1
        REPNE   SCASB
        JMP     @@2
@@3:    ADD     DI,3
        MOV     SI,DI
        MOV     CX,256
        REPNE   SCASB
        XCHG    AX,CX
        NOT     AL
@@4:    PUSH    DS
        PUSH    ES
        POP     DS
        LES     di,@Result
        CLD
        STOSB
        XCHG    AX,CX
        REP     MOVSB
        POP     DS
end;

end.
