diff options
Diffstat (limited to 'v2.0/source/STRIN.ASM')
| -rw-r--r-- | v2.0/source/STRIN.ASM | 292 |
1 files changed, 292 insertions, 0 deletions
diff --git a/v2.0/source/STRIN.ASM b/v2.0/source/STRIN.ASM new file mode 100644 index 0000000..2bc58fb --- /dev/null +++ b/v2.0/source/STRIN.ASM | |||
| @@ -0,0 +1,292 @@ | |||
| 1 | procedure $STD_CON_STRING_INPUT,NEAR ;System call 10 | ||
| 2 | ASSUME DS:NOTHING,ES:NOTHING | ||
| 3 | |||
| 4 | ; Inputs: | ||
| 5 | ; DS:DX Point to an input buffer | ||
| 6 | ; Function: | ||
| 7 | ; Fill buffer from console input until CR | ||
| 8 | ; Returns: | ||
| 9 | ; None | ||
| 10 | |||
| 11 | MOV AX,SS | ||
| 12 | MOV ES,AX | ||
| 13 | MOV SI,DX | ||
| 14 | XOR CH,CH | ||
| 15 | LODSW | ||
| 16 | OR AL,AL | ||
| 17 | retz ;Buffer is 0 length!!? | ||
| 18 | MOV BL,AH ;Init template counter | ||
| 19 | MOV BH,CH ;Init template counter | ||
| 20 | CMP AL,BL | ||
| 21 | JBE NOEDIT ;If length of buffer inconsistent with contents | ||
| 22 | CMP BYTE PTR [BX+SI],c_CR | ||
| 23 | JZ EDITON ;If CR correctly placed EDIT is OK | ||
| 24 | NOEDIT: | ||
| 25 | MOV BL,CH ;Reset buffer | ||
| 26 | EDITON: | ||
| 27 | MOV DL,AL | ||
| 28 | DEC DX ;DL is # of bytes we can put in the buffer | ||
| 29 | NEWLIN: | ||
| 30 | MOV AL,[CARPOS] | ||
| 31 | MOV [STARTPOS],AL ;Remember position in raw buffer | ||
| 32 | PUSH SI | ||
| 33 | MOV DI,OFFSET DOSGROUP:INBUF ;Build the new line here | ||
| 34 | MOV [INSMODE],CH ;Insert mode off | ||
| 35 | MOV BH,CH ;No chars from template yet | ||
| 36 | MOV DH,CH ;No chars to new line yet | ||
| 37 | invoke $STD_CON_INPUT_NO_ECHO ;Get first char | ||
| 38 | CMP AL,c_LF ;Linefeed | ||
| 39 | JNZ GOTCH ;Filter out LF so < works | ||
| 40 | entry GETCH | ||
| 41 | invoke $STD_CON_INPUT_NO_ECHO | ||
| 42 | GOTCH: | ||
| 43 | CMP AL,"F"-"@" ;Ignore ^F | ||
| 44 | JZ GETCH | ||
| 45 | CMP AL,[ESCCHAR] | ||
| 46 | JZ ESC | ||
| 47 | CMP AL,c_DEL | ||
| 48 | JZ BACKSPJ | ||
| 49 | CMP AL,c_BS | ||
| 50 | JZ BACKSPJ | ||
| 51 | CMP AL,c_CR | ||
| 52 | JZ ENDLIN | ||
| 53 | CMP AL,c_LF | ||
| 54 | JZ PHYCRLF | ||
| 55 | CMP AL,CANCEL | ||
| 56 | JZ KILNEW | ||
| 57 | SAVCH: | ||
| 58 | CMP DH,DL | ||
| 59 | JAE BUFFUL ;No room | ||
| 60 | STOSB | ||
| 61 | INC DH ;Got a char | ||
| 62 | invoke BUFOUT ;Print control chars nicely | ||
| 63 | CMP BYTE PTR [INSMODE],0 | ||
| 64 | JNZ GETCH ;In insert mode, get more chars | ||
| 65 | CMP BH,BL | ||
| 66 | JAE GETCH ;We are out of chars in template | ||
| 67 | INC SI ;Skip to next char in template | ||
| 68 | INC BH | ||
| 69 | JMP SHORT GETCH | ||
| 70 | |||
| 71 | BACKSPJ: JMP SHORT BACKSP | ||
| 72 | |||
| 73 | BUFFUL: | ||
| 74 | MOV AL,7 ;Bell | ||
| 75 | invoke OUT | ||
| 76 | JMP SHORT GETCH | ||
| 77 | |||
| 78 | ESC: | ||
| 79 | transfer OEMFunctionKey | ||
| 80 | |||
| 81 | ENDLIN: | ||
| 82 | STOSB ;Put the CR in the buffer | ||
| 83 | invoke OUT ;Echo it | ||
| 84 | POP DI ;Get start of buffer | ||
| 85 | MOV [DI-1],DH ;Tell user how many bytes | ||
| 86 | INC DH ;DH is length including CR | ||
| 87 | COPYNEW: | ||
| 88 | MOV BP,ES ;XCHG ES,DS | ||
| 89 | MOV BX,DS | ||
| 90 | MOV ES,BX | ||
| 91 | MOV DS,BP | ||
| 92 | MOV SI,OFFSET DOSGROUP:INBUF | ||
| 93 | MOV CL,DH | ||
| 94 | REP MOVSB ;Copy final line to user buffer | ||
| 95 | return ;All done | ||
| 96 | |||
| 97 | ;Output a CRLF | ||
| 98 | entry CRLF | ||
| 99 | MOV AL,c_CR | ||
| 100 | invoke OUT | ||
| 101 | MOV AL,c_LF | ||
| 102 | JMP OUT | ||
| 103 | |||
| 104 | ;Output a CRLF which is not terminate buffer | ||
| 105 | PHYCRLF: | ||
| 106 | invoke CRLF | ||
| 107 | JMP GETCH | ||
| 108 | |||
| 109 | ;Zap the line without zapping the template | ||
| 110 | entry KILNEW | ||
| 111 | MOV AL,"\" | ||
| 112 | invoke OUT ;Print the CANCEL indicator | ||
| 113 | POP SI ;Remember start of edit buffer | ||
| 114 | PUTNEW: | ||
| 115 | invoke CRLF ;Go to next line on screen | ||
| 116 | MOV AL,[STARTPOS] | ||
| 117 | invoke TAB ;Tab over | ||
| 118 | JMP NEWLIN ;Start over again | ||
| 119 | |||
| 120 | ;Back up one char | ||
| 121 | entry BACKSP | ||
| 122 | OR DH,DH | ||
| 123 | JZ OLDBAK ;No chars in line, do nothing to line | ||
| 124 | CALL BACKUP ;Do the backup | ||
| 125 | MOV AL,ES:[DI] ;Get the deleted char | ||
| 126 | CMP AL," " | ||
| 127 | JAE OLDBAK ;Was a normal char | ||
| 128 | CMP AL,c_HT | ||
| 129 | JZ BAKTAB ;Was a tab, fix up users display | ||
| 130 | CALL BACKMES ;Was a control char, zap the '^' | ||
| 131 | OLDBAK: | ||
| 132 | CMP BYTE PTR [INSMODE],0 | ||
| 133 | JNZ GETCH1 ;In insert mode, get more chars | ||
| 134 | OR BH,BH | ||
| 135 | JZ GETCH1 ;Not advanced in template, stay where we are | ||
| 136 | DEC BH ;Go back in template | ||
| 137 | DEC SI | ||
| 138 | GETCH1: | ||
| 139 | JMP GETCH | ||
| 140 | |||
| 141 | BAKTAB: | ||
| 142 | PUSH DI | ||
| 143 | DEC DI ;Back up one char | ||
| 144 | STD ;Go backward | ||
| 145 | MOV CL,DH ;Number of chars currently in line | ||
| 146 | MOV AL," " | ||
| 147 | PUSH BX | ||
| 148 | MOV BL,7 ;Max | ||
| 149 | JCXZ FIGTAB ;At start, do nothing | ||
| 150 | FNDPOS: | ||
| 151 | SCASB ;Look back | ||
| 152 | JNA CHKCNT | ||
| 153 | CMP BYTE PTR ES:[DI+1],9 | ||
| 154 | JZ HAVTAB ;Found a tab | ||
| 155 | DEC BL ;Back one char if non tab control char | ||
| 156 | CHKCNT: | ||
| 157 | LOOP FNDPOS | ||
| 158 | FIGTAB: | ||
| 159 | SUB BL,[STARTPOS] | ||
| 160 | HAVTAB: | ||
| 161 | SUB BL,DH | ||
| 162 | ADD CL,BL | ||
| 163 | AND CL,7 ;CX has correct number to erase | ||
| 164 | CLD ;Back to normal | ||
| 165 | POP BX | ||
| 166 | POP DI | ||
| 167 | JZ OLDBAK ;Nothing to erase | ||
| 168 | TABBAK: | ||
| 169 | invoke BACKMES | ||
| 170 | LOOP TABBAK ;Erase correct number of chars | ||
| 171 | JMP SHORT OLDBAK | ||
| 172 | |||
| 173 | BACKUP: | ||
| 174 | DEC DH ;Back up in line | ||
| 175 | DEC DI | ||
| 176 | BACKMES: | ||
| 177 | MOV AL,c_BS ;Backspace | ||
| 178 | invoke OUT | ||
| 179 | MOV AL," " ;Erase | ||
| 180 | invoke OUT | ||
| 181 | MOV AL,c_BS ;Backspace | ||
| 182 | JMP OUT ;Done | ||
| 183 | |||
| 184 | ;User really wants an ESC character in his line | ||
| 185 | entry TwoEsc | ||
| 186 | MOV AL,[ESCCHAR] | ||
| 187 | JMP SAVCH | ||
| 188 | |||
| 189 | ;Copy the rest of the template | ||
| 190 | entry COPYLIN | ||
| 191 | MOV CL,BL ;Total size of template | ||
| 192 | SUB CL,BH ;Minus position in template, is number to move | ||
| 193 | JMP SHORT COPYEACH | ||
| 194 | |||
| 195 | entry CopyStr | ||
| 196 | invoke FINDOLD ;Find the char | ||
| 197 | JMP SHORT COPYEACH ;Copy up to it | ||
| 198 | |||
| 199 | ;Copy one char from template to line | ||
| 200 | entry COPYONE | ||
| 201 | MOV CL,1 | ||
| 202 | ;Copy CX chars from template to line | ||
| 203 | COPYEACH: | ||
| 204 | MOV BYTE PTR [INSMODE],0 ;All copies turn off insert mode | ||
| 205 | CMP DH,DL | ||
| 206 | JZ GETCH2 ;At end of line, can't do anything | ||
| 207 | CMP BH,BL | ||
| 208 | JZ GETCH2 ;At end of template, can't do anything | ||
| 209 | LODSB | ||
| 210 | STOSB | ||
| 211 | invoke BUFOUT | ||
| 212 | INC BH ;Ahead in template | ||
| 213 | INC DH ;Ahead in line | ||
| 214 | LOOP COPYEACH | ||
| 215 | GETCH2: | ||
| 216 | JMP GETCH | ||
| 217 | |||
| 218 | ;Skip one char in template | ||
| 219 | entry SKIPONE | ||
| 220 | CMP BH,BL | ||
| 221 | JZ GETCH2 ;At end of template | ||
| 222 | INC BH ;Ahead in template | ||
| 223 | INC SI | ||
| 224 | JMP GETCH | ||
| 225 | |||
| 226 | entry SKIPSTR | ||
| 227 | invoke FINDOLD ;Find out how far to go | ||
| 228 | ADD SI,CX ;Go there | ||
| 229 | ADD BH,CL | ||
| 230 | JMP GETCH | ||
| 231 | |||
| 232 | ;Get the next user char, and look ahead in template for a match | ||
| 233 | ;CX indicates how many chars to skip to get there on output | ||
| 234 | ;NOTE: WARNING: If the operation cannot be done, the return | ||
| 235 | ; address is popped off and a jump to GETCH is taken. | ||
| 236 | ; Make sure nothing extra on stack when this routine | ||
| 237 | ; is called!!! (no PUSHes before calling it). | ||
| 238 | FINDOLD: | ||
| 239 | invoke $STD_CON_INPUT_NO_ECHO | ||
| 240 | CMP AL,[ESCCHAR] ; did he type a function key? | ||
| 241 | JNZ FindSetup ; no, set up for scan | ||
| 242 | invoke $STD_CON_INPUT_NO_ECHO ; eat next char | ||
| 243 | JMP NotFnd ; go try again | ||
| 244 | FindSetup: | ||
| 245 | MOV CL,BL | ||
| 246 | SUB CL,BH ;CX is number of chars to end of template | ||
| 247 | JZ NOTFND ;At end of template | ||
| 248 | DEC CX ;Cannot point past end, limit search | ||
| 249 | JZ NOTFND ;If only one char in template, forget it | ||
| 250 | PUSH ES | ||
| 251 | PUSH DS | ||
| 252 | POP ES | ||
| 253 | PUSH DI | ||
| 254 | MOV DI,SI ;Template to ES:DI | ||
| 255 | INC DI | ||
| 256 | REPNE SCASB ;Look | ||
| 257 | POP DI | ||
| 258 | POP ES | ||
| 259 | JNZ NOTFND ;Didn't find the char | ||
| 260 | NOT CL ;Turn how far to go into how far we went | ||
| 261 | ADD CL,BL ;Add size of template | ||
| 262 | SUB CL,BH ;Subtract current pos, result distance to skip | ||
| 263 | return | ||
| 264 | |||
| 265 | NOTFND: | ||
| 266 | POP BP ;Chuck return address | ||
| 267 | JMP GETCH | ||
| 268 | |||
| 269 | entry REEDIT | ||
| 270 | MOV AL,"@" ;Output re-edit character | ||
| 271 | invoke OUT | ||
| 272 | POP DI | ||
| 273 | PUSH DI | ||
| 274 | PUSH ES | ||
| 275 | PUSH DS | ||
| 276 | invoke COPYNEW ;Copy current line into template | ||
| 277 | POP DS | ||
| 278 | POP ES | ||
| 279 | POP SI | ||
| 280 | MOV BL,DH ;Size of line is new size template | ||
| 281 | JMP PUTNEW ;Start over again | ||
| 282 | |||
| 283 | entry EXITINS | ||
| 284 | entry ENTERINS | ||
| 285 | NOT BYTE PTR [INSMODE] | ||
| 286 | JMP GETCH | ||
| 287 | |||
| 288 | ;Put a real live ^Z in the buffer (embedded) | ||
| 289 | entry CTRLZ | ||
| 290 | MOV AL,"Z"-"@" | ||
| 291 | JMP SAVCH | ||
| 292 | $STD_CON_STRING_INPUT ENDP | ||