short DOS batch utility
Jay Elvove
jay at umd5
Sat Sep 20 01:49:48 AEST 1986
What follows is a short but useful DOS batch utility that compares a
single character typed at the keyboard with a list of expected characters
on the program command line. The program comments should pretty much
speak for themselves. An executable version of this program came with
the Microsoft CODEVIEW demonstration disk. I simply disassembled it and
present interested parties with the source. Since Microsoft has allowed
that all files on that disk are public domain, I think it unlikely that
they will object to my disseminating the program in source form (will you
Microsoft?). If you have the CODEVIEW demo, check out its various batch
files to see some ways the program can be used.
--------------------------------------------
TITLE RESPOND.COM
; The command has the following format:
;
; RESPOND <list>
;
; This program solicits a single keystroke and compares it against
; one or more expected characters. It is primarily designed for use
; in DOS batch files. If a match occurs, the character typed is
; returned in the form of an exit code which can be confirmed via the
; BATCH command IF ERRORLEVEL <num>, where <num> is the numeric value
; of the ASCII character. If an illegal character is typed, the
; program beeps once and waits for another character. A typical
; example follows:
;
; RESPOND YN
;
; The program treats upper and lower case as equivalent. Don't forget
; that ERRORLEVEL responds with a TRUE condition if the exit value
; is equal to OR exceeds the value specified on its command line.
;
; The program also performs one of four other functions if <list> is
; specified as one of the following characters:
;
; char value function
; ---- ----- --------
; (20) return current video mode
; (21) return number of free memory segments
; (22) return current version of DOS
; (<8) set video mode to character specified
; e.g., RESPOND (sets screen to mode two)
;
; Each of the above MUST be entered as an ASCII character.
;
; NOTE: This program originates (in executable form only) from
; Microsoft's CODEVIEW demonstration disk. It was disassembled
; and commented by me (Jay Elvove) on September 19, 1986. My
; only modification has been to remove four unnecessary NOPs.
CSEG SEGMENT
ASSUME DS:CSEG, SS:CSEG, CS:CSEG, ES:CSEG
ORG 100H
RESPOND:
MOV AL,DS:82H ; get first character
CMP AL,7 ; if greater than 7
JG GET_VIDEO_MODE ; ... skip ahead
; set video mode: command line character is 0-7
MOV AH,0 ; else, perform BIOS set
INT 10H ; ... video mode function
JMP SHORT QUIT ; ... and quit
GET_VIDEO_MODE:
CMP AL,20 ; 20 means get current video mode
JNZ COMPUTE_MEMORY ; else, skip ahead
; get video mode: command line character is "" (ASCII value 20)
MOV AH,0FH ; do BIOS get current video
INT 10H ; ... mode function
JMP SHORT QUIT
COMPUTE_MEMORY:
CMP AL,21 ; 21 means compute memory
JNZ GET_DOS_VERSION
; compute memory: command line character is "" (ASCII value 21)
MOV AX,DS:2 ; get top of memory
MOV BX,ES ; get current segment address
SUB AX,BX ; compute # of free segments
MOV AL,AH
JMP SHORT QUIT
GET_DOS_VERSION:
CMP AL,22 ; 22 means get DOS version
JNZ GET_KBD_INPUT
; get DOS version: command line character is "" (ASCII value 22)
MOV AH,30H ; get DOS version
INT 21H
JMP SHORT QUIT
; get a single keystroke: no special characters on command line
GET_KBD_INPUT:
MOV AH,8 ; DOS get single character from
INT 21H ; ... keyboard function (no echo)
XCHG AH,AL
CALL MAKE_UPPER ; convert character to upper case
XCHG AH,AL
MOV SI,80H ; point to cmd. line char count
MOV CX,DS:80H ; put count in CX
XOR CH,CH ; clear high byte
JCXZ NO_INPUT ; no input, clear exit code & quit
INC CX
L014B:
INC SI ; point to cmd line char
DEC CX ; decrement char count
MOV AH,[SI] ; put char in AH
CMP AH,' ' ; space or control char?
JLE L014B ; yes, skip it and get next
CALL MAKE_UPPER ; else, convert char to upper case
CMP AH,AL ; same as we expect?
JZ QUIT ; yes, quit
CMP CX,1 ; more chars on cmd line?
JGE L014B ; yes, try them
; user input didn't match
MOV DL,7 ; signal an error (bell)
MOV AH,2 ; DOS echo character function
INT 21H
JMP RESPOND ; ... and start over
NO_INPUT:
XOR AL,AL ; clear exit code
QUIT:
MOV AH,4CH ; DOS terminate function with exit
INT 21H ; ... code in AL
; --------------------
; program subroutines
; --------------------
MAKE_UPPER:
CMP AH,'a'
JL MAKE_UPPER_RET
CMP AH,'z'
JG MAKE_UPPER_RET
SUB AH,20H
MAKE_UPPER_RET:
RET
CSEG ENDS
END RESPOND
--
---------------------------------
Jay Elvove jay at umd5.umd.edu
c/o Systems, Computer Science Center, U. of MD.
More information about the Comp.sources.unix
mailing list