home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / TECLADO / STUFFKB2.ZIP / STUFFKB.V20 < prev   
Encoding:
Text File  |  1990-11-17  |  4.9 KB  |  109 lines

  1.          JMP   START
  2.  
  3.          DB    0Dh,0Ah,'STUFFKB v 2.0 A Utility to Stuff the Keyboard with the Parameter String.',0Dh,0Ah
  4.          DB    'Written by Ed Derzawiec',0Dh,0Ah
  5.          DB    '6 Sweet Fern Rd, Cape Elizabeth, ME  04107',0Dh,0Ah
  6.          DB    'Declared Public Domain, 1989,1990'
  7.          DB    1Ah           ;Clean up a listing of this .COM file
  8.  
  9.  
  10. ParamLen EQU   080           ;PSP offset To Length Of Parameter String
  11. Params   EQU   081           ;PSP offset to Parameters
  12.  
  13. A_BS     EQU   008           ;ASCII Code for BackSpace
  14. A_ESC    EQU   01B           ;Escape
  15. A_CR     EQU   00D           ;Carrage Return
  16. A_BELL   EQU   007           ;Bell
  17.  
  18.                              ;The Following are the control Words
  19.                              ;delimited by "~" characters on the command
  20.                              ;line to be translated into ASCII Code.
  21.                              ;This Table Format is "Word",0,Code,..,0
  22.                              ;  "Word" is the Defined Control Word to Translate
  23.                              ;  0 Delimits the Control Word
  24.                              ;  Code is the Assigned ASCII Code
  25.                              ;  And a Final Null Identifies the End of the Table
  26. Controls:DB    "CR",0,A_CR,"BS",0,A_BS,"ESC",0,A_ESC,0
  27.  
  28. Head     EQU   01A           ;BIOS Pointer Location to Current Head and
  29. Tail     EQU   01C           ;Tail Of Circular Buffer
  30. KeyStart EQU   080           ;BIOS Pointer Location of Actual Start and
  31. KeyEnd   EQU   082           ;End of the Circular Buffer
  32.  
  33. Start:   CMP   b[ParamLen],2
  34.          JL    Exit          ;Exit if No Parameters Passed
  35.          CALL  StuffKBRD
  36. Exit:    SUB   AH,AH
  37.          INT   21h           ;Exit Program
  38.  
  39.          Proc NEAR
  40. ;              This routine will stuff the KeyBoard Buffer with the Parameter passed
  41. ;              It won't work for extended characters (NON ASCII)
  42.  
  43. StuffKBRD:PUSH  ES
  44.          MOV   ES,AX,040     ;BIOS Data Segment resides in Page 40
  45.          MOV   SI,Params+1   ;Move Past FileName Delimiter (Space)
  46.          MOV   AX,ES:w[KeyStart];Get the Beginning Address of the Keyboard Buffer 
  47.          MOV   DI,AX
  48.          MOV   ES:w[Head],AX ;Initialize Keyboard Buffer Pointer
  49.          MOV   AH,0          ;Null Out Scan Code (Not Normally Important)
  50. Stuff1:  LODSb               ;Get ASCII into AL
  51.          CMP   AL,A_CR       ;End Stuff on Carrage Return in Parameter String
  52.          JE    Stuff9        ;Exit on end of string
  53.          CMP   AL,"~"        ;Control Character Delimiter
  54.          JNE   Stuff2
  55.          CALL  ControlDecode
  56. Stuff2:  STOSw               ;Put into Keyboard Buffer (SCAN Code = 0)
  57.          CMP   DI,ES:w[KeyEnd] ;Don't Go Beyond Buffer's End
  58.          JB    Stuff1
  59.          SUB   DI,2          ;Buffer Can only Hold (Size-1) characters when full
  60. Stuff9:  MOV   ES:[Tail],DI  ;Identify the end of the Keyboard Buffer
  61.          POP   ES
  62.          RET
  63.          ENDP
  64.  
  65.          Proc  NEAR          ;Compares the Delimited Control Command at [SI]
  66.                              ;With the Control String ([DI]) to find match
  67.                              ;and return ASCII equivalent in AL (incrementing SI)
  68. ControlDecode:
  69.          PUSH  ES            ;Save The KeyBoard Data Segment
  70.          PUSH  DI            ;And Current Pointer
  71.          PUSH  DS
  72.          POP   ES            ;Move DS to ES
  73.          CALL  UPPER         ;Convert Control Word in Params to UPPER CASE
  74.          MOV   DI,OFFSET(Controls)
  75.          MOV   AL,0
  76.          MOV   BX,SI
  77. Cntl1:   MOV   SI,BX
  78.          MOV   CX,80         ;80 Characters Max/String
  79.          REPE
  80.          CMPSb               ;Increment SI,DI until a Mismatch is found
  81.          CMP   b[DI-1],AL    ;Did the Match end in a proper control delimiter?
  82.          JNE   Cntl2         ;No, Get Try Next Control Word
  83.          CMP   b[SI-1],"~"   ;Did the Match end in a proper control Delimiter?
  84.          JNE   Cntl2         ;No...
  85.          MOV   AL,b[DI]      ;Load the Control Characters ASCII Code in AL
  86.          JMP   Cntl9         
  87. Cntl2:   REPNE 
  88.          SCASb               ;Go to Next Control Word in Control Word List
  89.          INC   DI            ;Skip ASCII Code of previous character
  90.          CMP   b[DI],AL      ;Is this the End of the Control Word String
  91.          JNE   Cntl1         ;No, Continue search with Next Word
  92.          MOV   AL,A_Bell     ;Stuff a beep on No Match Found...
  93. Cntl9:   POP   DI            ;Restore the pointer to the Keyboard Buffer
  94.          POP   ES            ;And Segment
  95.          RET         
  96.          ENDP
  97.  
  98.          PROC  NEAR          ;Converts Control Word at SI to Upper Case
  99. Upper:   PUSH  SI            ;Store the Pointer to the Start of the Word
  100.          MOV   AL,11011111xB 
  101. Upper1:  CMP   b[SI],"~"     ;Done?
  102.          JE    Upper9
  103.          AND   b[SI],AL         ;Convert to upper CASE
  104.          INC   SI
  105.          JMP   Upper1
  106. Upper9:  POP   SI            ;Restore Pointer
  107.          RET
  108.          ENDP
  109.