home *** CD-ROM | disk | FTP | other *** search
- cseg segment
- assume cs:cseg,ds:cseg
- org 100h
- go: JMP START
-
- DB 0Dh,0Ah,'STUFFKB v 1.01 A Utility to Stuff the Keyboard with the Parameter String.',0Dh,0Ah
- DB 'Written by Ed Derzawiec',0Dh,0Ah
- DB '6 Sweet Fern Rd, Cape Elizabeth, ME 04107',0Dh,0Ah
- DB 'Declared Public Domain, 1989'
- DB 1Ah ;Clean up a listing of this .COM file
-
-
- ParamLen EQU 080h ;PSP offset To Length Of Parameter String
- Params EQU 081h ;PSP offset to Parameters
-
- A_BS EQU 008h ;ASCII Code for BackSpace
- A_ESC EQU 01Bh ;Escape
- A_CR EQU 00Dh ;Carrage Return
- A_BELL EQU 007h ;Bell
-
- ;The Following are the control Words
- ;delimited by "~" characters on the command
- ;line to be translated into ASCII Code.
- ;This Table Format is "Word",-1,Code,...,0
- ; "Word" is the Defined Control Word to Translate
- ; -1 Delimits the Control Word
- ; Code is the Assigned ASCII Code
- ; And a Null Identifies the End of the Table
- Controls:DB "CR",-1,A_CR,"BS",-1,A_BS,"ESC",-1,A_ESC,0
- ControlLen DW ? ;The Length of the above string
-
- Start: mov al,2
- CMP al, byte ptr [ParamLen]
- JL Exit ;Exit if No Parameters Passed
- CALL GetControlLength
- CALL StuffKBRD
- Exit: SUB AH,AH
- INT 21h ;Exit Program
-
- GetControlLength Proc NEAR
- ;This Procedure Assigns the Length of the
- ;Control Character String Defined above.
- MOV DI,OFFSET(Controls)
- MOV AX,0
- MOV CX,-1
- REPNE SCASB ;Find the End of the Control String
- NEG CX
- DEC CX
- DEC CX ;Normalize CX to the Length of the Control String
- MOV ControlLen,CX ;and store the value
- RET
- GetControlLength ENDP
-
- StuffKBRD Proc NEAR
- ; This routine will stuff the KeyBoard Buffer with the Parameter passed
- ; It won't work for extended characters (NON ASCII)
- Head EQU 01Ah
- Tail EQU 01Ch
- Kbuffer EQU 01Eh
-
- PUSH ES
- MOV AX,040h ;BIOS Keyboard Buffer resides in Page 40
- MOV ES,AX
- MOV SI,Params+1 ;Move Past FileName Delimiter (Space)
- MOV DI,KBuffer
- MOV word ptr ES:[Head],Kbuffer ;Initialize Keyboard Buffer Pointers
- MOV word ptr ES:[Tail],Kbuffer
- MOV AH,0 ;Null Out Scan Code (Not Normally Important)
- Stuff1: LODSb ;Get ASCII into AL
- CMP AL,A_CR ;End Stuff on Carrage Return in Parameter String
- JE Stuff9 ;Exit on end of string
- CMP AL,"~" ;Control Character Delimiter
- JNE Stuff2
- CALL ControlDecode
- Stuff2: STOSw ;Put into Keyboard Buffer (SCAN Code = 0)
- CMP DI,Kbuffer+30 ;Stuff a Max of 15 Characters
- JB Stuff1
- Stuff9: MOV ES:[Tail],DI ;Identify the end of the Keyboard Buffer
- POP ES
- RET
- StuffKBRD ENDP
-
- ControlDecode Proc NEAR ;Compares the Delimited Control Command at [SI]
- ;With the Control String ([DI]) to find match
- ;and return ASCII equivalent in AL (incrementing SI)
- PUSH ES ;Save The KeyBoard Data Segment
- PUSH DI ;And Current Pointer
- PUSH DS
- POP ES ;Move DS to ES
- CALL UPPER ;Convert Control Word in Params to UPPER CASE
- MOV DI,OFFSET(Controls)
- MOV CX,ControlLen ;Compare to End of Control String
- Cntl1: PUSH SI ;Store in case you need to loop by a mismatch
- PUSH DI ; "
- PUSH CX ; "
- CMPSb ;Does The First Character Match
- JNE Cntl2 ;No, Try Next Word in Control List
- REPE CMPSb ;Increment SI,DI until a Mismatch is found
- CMP byte ptr [DI-1],-1 ;Did the Match end in a proper control delimiter?
- JE Cntl5 ;Possibly, Yes
- Cntl2: POP CX ;No.. Restore to value at start of Word Match
- POP DI ; "
- POP SI ; "
- MOV AL,-1
- REPNE SCASb ;Go to Next Control Word in Control Word List
- INC DI ;Skip ASCII Code of previous character
- DEC CX ; "
- CMP CX,0 ;Has the end of the Control List been reached?
- JNE Cntl1 ;No.. Look for another initial Match
- ;Yes.. Push a Bell Character for this Control
- PUSH SI
- POP DI ;Move SI to DI
- MOV AL,"~"
- MOV CX,80 ;Allow for a Maximum 80 Character Parameter
- REPNE SCASb ;Go to Next Control Word in the Parameter String
- PUSH DI
- POP SI ;Move DI to SI
- MOV AL,A_Bell ;Stuff a beep on No Match Found...
- JMP Cntl9 ;Exit Subroutine
- Cntl5: CMP byte ptr [SI-1],"~" ;Did the Match end in a proper control Delimiter?
- JNE Cntl2 ;No...
- POP CX ;Yes... Discard Variables On Successful Match
- POP DX ; "
- POP CX ; "
- MOV AL,byte ptr [DI] ;Load the Control Characters ASCII Code in AL
- Cntl9: POP DI ;Restore the pointer to the Keyboard Buffer
- POP ES ;And Segment
- RET
- ControlDecode ENDP
-
- Upper PROC NEAR ;Converts Control Word at SI to Upper Case
- PUSH SI ;Store the Pointer to the Start of the Word
- Upper1: CMP byte ptr [SI],"~" ;Done?
- JE Upper9
- LODSb ;Get the Character in the control string
- AND AL,11011111B ;Convert to upper CASE
- MOV byte ptr [SI-1],AL ;Store Converted Character
- JMP Upper1
- Upper9: POP SI ;Restore Pointer
- RET
- Upper ENDP
- cseg ends
- end go