This program is designated for demonstration and testing of the base functions from 16bit Disk Operating System Application Programming Interface macrolibrary dosapi.htm : DosAPI, GetArgCount, GetArg, StdInput, StdOutput, TerminateProgram.
tdosapi PROGRAM Format=COM,Width=16,Entry=Main:
INCLUDE dosapi.htm, cpuext%^WIDTH.htm
[COM] SEGMENT Purpose=CODE+RODATA+BSS
Main: PROC
GetArgCount ; Count the command-line arguments.
JC .Abort:
MOV [ArgCount],CX
MOV AX,CX
StoD ArgCount$ ; Convert binary number AX to a decimal string.
JC .Abort:
StdOutput =B"%^PROGRAM launched with ", ArgCount$, =B" arguments:", Eol=Yes
JC .Abort:
SUB BX,BX ; BX will be the ordinal number of each argument.
.EchoArg:INC BX
CMP BX,[ArgCount]
JA .EchoEnv: ; Jump when all arguments have been echoed.
MOV AX,BX
StoD ArgNr$ ; Convert binary number AX to a decimal string.
SUB AX,AX
STOSB ; Zero-terminate the string.
GetArg BX ; Retrieve BX-th argument to SI,CX.
JC .Abort:
MOV AX,CX ; Argument size in bytes.
StoD ArgSize$ ; Convert binary number AX to a decimal string.
SUB AX,AX
STOSB ; Zero-terminate the string.
StdOutput ArgNr$, =B".[", ArgSize$, =B"]: "
StdOutput SI, Size=CX, Eol=Yes ; Echo the argument.
JC .Abort:
JMP .EchoArg:
.EchoEnv:StdOutput =B'Environment string OS='
PUSH ES
GetEnv =B'OS', OS$
POP ES
JC .EnvNotSet:
StdOutput OS$,Eol=Yes
StdOutput =B'Environment string UNKNOWN='
GetEnv =B'UNKNOWN', UNKNOWN$
JC .EnvNotSet:
StdOutput UNKNOWN$,Eol=Yes
JMP .EchoInp:
.EnvNotSet:StdOutput =B' was not found.',Eol=Yes
.EchoInp:StdOutput ="Enter some text: "
StdInput Buffer ; Read a string from the keyboard.
JC .Abort:
MOV AX,CX ; String size, including CR+LF.
StoD BufSize$ ; Convert binary number AX to a decimal string.
SUB AX,AX
STOSB ; Zero-terminate the string.
StdOutput =B"Entered[", BufSize$, =B"]: "
StdOutput Buffer, Size=CX ; Echo the input string.
JC .Abort:
StdOutput =B"%^PROGRAM terminated."
TerminateProgram Errorlevel=0
.Abort: StdOutput =B"Aborted, some macro returned CF.", Eol=Yes
TerminateProgram Errorlevel=4
ENDP Main:
ArgCount DW W
ArgCount$ DB 6*B
ArgNr$ DB 6*B
ArgSize$ DB 6*B
BufSize$ DB 6*B
Buffer DB 128*B
OS$ DB 1024*B
UNKNOWN$ DB 1024*B
ENDPROGRAM tdosapi