]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/DOS/STRIN.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / DOS / STRIN.ASM
1 ; SCCSID = @(#)strin.asm 1.2 85/04/18
2 Break
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 procedure $STD_CON_STRING_INPUT,NEAR ;System call 10
12 ASSUME DS:NOTHING,ES:NOTHING
13
14 MOV AX,SS
15 MOV ES,AX
16 MOV SI,DX
17 XOR CH,CH
18 LODSW
19 ;
20 ; AL is the buffer length
21 ; AH is the template length
22 ;
23 OR AL,AL
24 retz ;Buffer is 0 length!!?
25 MOV BL,AH ;Init template counter
26 MOV BH,CH ;Init template counter
27 ;
28 ; BL is the number of bytes in the template
29 ;
30 CMP AL,BL
31 JBE NOEDIT ;If length of buffer inconsistent with contents
32 CMP BYTE PTR [BX+SI],c_CR
33 JZ EDITON ;If CR correctly placed EDIT is OK
34 ;
35 ; The number of chars in the template is >= the number of chars in buffer or
36 ; there is no CR at the end of the template. This is an inconsistant state
37 ; of affairs. Pretend that the template was empty:
38 ;
39 NOEDIT:
40 MOV BL,CH ;Reset buffer
41 EDITON:
42 MOV DL,AL
43 DEC DX ;DL is # of bytes we can put in the buffer
44 ;
45 ; Top level. We begin to read a line in.
46 ;
47 NEWLIN:
48 MOV AL,[CARPOS]
49 MOV [STARTPOS],AL ;Remember position in raw buffer
50 PUSH SI
51 MOV DI,OFFSET DOSGROUP:INBUF ;Build the new line here
52 MOV [INSMODE],CH ;Insert mode off
53 MOV BH,CH ;No chars from template yet
54 MOV DH,CH ;No chars to new line yet
55 invoke $STD_CON_INPUT_NO_ECHO ;Get first char
56 CMP AL,c_LF ;Linefeed
57 JNZ GOTCH ;Filter out LF so < works
58 ;
59 ; This is the main loop of reading in a character and processing it.
60 ;
61 ; BH is the index of the next byte in the template
62 ; BL is the length of the template
63 ; DH is the number of bytes in the buffer
64 ; DL is the length of the buffer
65 ;
66 entry GETCH
67 invoke $STD_CON_INPUT_NO_ECHO
68 GOTCH:
69 ;
70 ; Brain-damaged TP ignored ^F in case his BIOS did not flush the
71 ; input queue.
72 ;
73 CMP AL,"F"-"@"
74 JZ GETCH
75 ;
76 ; If the leading char is the function-key lead byte
77 ;
78 CMP AL,[ESCCHAR]
79 JZ ESCape ;change reserved keyword DBM 5-7-87
80 ;
81 ; Rubout and ^H are both destructive backspaces.
82 ;
83 CMP AL,c_DEL
84 JZ BACKSPJ
85 CMP AL,c_BS
86 JZ BACKSPJ
87 ;
88 ; ^W deletes backward once and then backs up until a letter is before the
89 ; cursor
90 ;
91 CMP AL,"W" - "@"
92 ; The removal of the comment characters before the jump statement will
93 ; cause ^W to backup a word.
94 ;*** JZ WordDel
95 NOP
96 NOP
97 CMP AL,"U" - "@"
98 ; The removal of the comment characters before the jump statement will
99 ; cause ^U to clear a line.
100 ;*** JZ LineDel
101 NOP
102 NOP
103
104 ;
105 ; CR terminates the line.
106 ;
107 CMP AL,c_CR
108 JZ ENDLIN
109 ;
110 ; LF goes to a new line and keeps on reading.
111 ;
112 CMP AL,c_LF
113 JZ PHYCRLF
114 ;
115 ; ^X (or ESC) deletes the line and starts over
116 ;
117 CMP AL,[CANCHAR]
118 JZ KILNEW
119 ;
120 ; Otherwise, we save the input character.
121 ;
122 SAVCH:
123 CMP DH,DL
124 JAE BUFFUL ; buffer is full.
125 STOSB
126 INC DH ; increment count in buffer.
127 invoke BUFOUT ;Print control chars nicely
128 CMP BYTE PTR [INSMODE],0
129 JNZ GETCH ; insertmode => don't advance template
130 CMP BH,BL
131 JAE GETCH ; no more characters in template
132 INC SI ; Skip to next char in template
133 INC BH ; remember position in template
134 JMP SHORT GETCH
135
136 BACKSPJ: JMP SHORT BACKSP
137
138 BUFFUL:
139 MOV AL,7 ; Bell to signal full buffer
140 invoke OUTT
141 JMP SHORT GETCH
142
143 ESCape: ;change reserved keyword DBM 5-7-87
144 transfer OEMFunctionKey ; let the OEM's handle the key dispatch
145
146 ENDLIN:
147 STOSB ; Put the CR in the buffer
148 invoke OUTT ; Echo it
149 POP DI ; Get start of user buffer
150 MOV [DI-1],DH ; Tell user how many bytes
151 INC DH ; DH is length including CR
152 COPYNEW:
153 SaveReg <DS,ES>
154 RestoreReg <DS,ES> ; XCHG ES,DS
155 MOV SI,OFFSET DOSGROUP:INBUF
156 MOV CL,DH ; set up count
157 REP MOVSB ; Copy final line to user buffer
158 return
159 ;
160 ; Output a CRLF to the user screen and do NOT store it into the buffer
161 ;
162 PHYCRLF:
163 invoke CRLF
164 JMP GETCH
165
166 ;
167 ; Delete the previous line
168 ;
169 LineDel:
170 OR DH,DH
171 JZ GetCh
172 Call BackSpace
173 JMP LineDel
174
175 ;
176 ; delete the previous word.
177 ;
178 WordDel:
179 WordLoop:
180 Call BackSpace ; backspace the one spot
181 OR DH,DH
182 JZ GetChJ
183 MOV AL,ES:[DI-1]
184 cmp al,'0'
185 jb GetChj
186 cmp al,'9'
187 jbe WordLoop
188 OR AL,20h
189 CMP AL,'a'
190 JB GetChJ
191 CMP AL,'z'
192 JBE WordLoop
193 GetChJ:
194 JMP GetCh
195 ;
196 ; The user wants to throw away what he's typed in and wants to start over. We
197 ; print the backslash and then go to the next line and tab to the correct spot
198 ; to begin the buffered input.
199 ;
200 entry KILNEW
201 MOV AL,"\"
202 invoke OUTT ;Print the CANCEL indicator
203 POP SI ;Remember start of edit buffer
204 PUTNEW:
205 invoke CRLF ;Go to next line on screen
206 MOV AL,[STARTPOS]
207 invoke TAB ;Tab over
208 JMP NEWLIN ;Start over again
209
210
211 ;
212 ; Destructively back up one character position
213 ;
214 entry BackSp
215 Call BackSpace
216 JMP GetCh
217
218 BackSpace:
219 OR DH,DH
220 JZ OLDBAK ;No chars in line, do nothing to line
221 CALL BACKUP ;Do the backup
222 MOV AL,ES:[DI] ;Get the deleted char
223 CMP AL," "
224 JAE OLDBAK ;Was a normal char
225 CMP AL,c_HT
226 JZ BAKTAB ;Was a tab, fix up users display
227 ;; 9/27/86 fix for ctrl-U backspace
228 CMP AL,"U"-"@" ; ctrl-U is a section symbol not ^U
229 JZ OLDBAK
230 CMP AL,"T"-"@" ; ctrl-T is a paragraphs symbol not ^T
231 JZ OLDBAK
232 ;; 9/27/86 fix for ctrl-U backspace
233 CALL BACKMES ;Was a control char, zap the '^'
234 OLDBAK:
235 CMP BYTE PTR [INSMODE],0
236 retnz ;In insert mode, done
237 OR BH,BH
238 retz ;Not advanced in template, stay where we are
239 DEC BH ;Go back in template
240 DEC SI
241 return
242
243 BAKTAB:
244 PUSH DI
245 DEC DI ;Back up one char
246 STD ;Go backward
247 MOV CL,DH ;Number of chars currently in line
248 MOV AL," "
249 PUSH BX
250 MOV BL,7 ;Max
251 JCXZ FIGTAB ;At start, do nothing
252 FNDPOS:
253 SCASB ;Look back
254 JNA CHKCNT
255 CMP BYTE PTR ES:[DI+1],9
256 JZ HAVTAB ;Found a tab
257 DEC BL ;Back one char if non tab control char
258 CHKCNT:
259 LOOP FNDPOS
260 FIGTAB:
261 SUB BL,[STARTPOS]
262 HAVTAB:
263 SUB BL,DH
264 ADD CL,BL
265 AND CL,7 ;CX has correct number to erase
266 CLD ;Back to normal
267 POP BX
268 POP DI
269 JZ OLDBAK ;Nothing to erase
270 TABBAK:
271 invoke BACKMES
272 LOOP TABBAK ;Erase correct number of chars
273 JMP SHORT OLDBAK
274
275 BACKUP:
276 DEC DH ;Back up in line
277 DEC DI
278 BACKMES:
279 MOV AL,c_BS ;Backspace
280 invoke OUTT
281 MOV AL," " ;Erase
282 invoke OUTT
283 MOV AL,c_BS ;Backspace
284 JMP OUTT ;Done
285
286 ;User really wants an ESC character in his line
287 entry TwoEsc
288 MOV AL,[ESCCHAR]
289 JMP SAVCH
290
291 ;Copy the rest of the template
292 entry COPYLIN
293 MOV CL,BL ;Total size of template
294 SUB CL,BH ;Minus position in template, is number to move
295 JMP SHORT COPYEACH
296
297 entry CopyStr
298 invoke FINDOLD ;Find the char
299 JMP SHORT COPYEACH ;Copy up to it
300
301 ;Copy one char from template to line
302 entry COPYONE
303 MOV CL,1
304 ;Copy CX chars from template to line
305 COPYEACH:
306 MOV BYTE PTR [INSMODE],0 ;All copies turn off insert mode
307 CMP DH,DL
308 JZ GETCH2 ;At end of line, can't do anything
309 CMP BH,BL
310 JZ GETCH2 ;At end of template, can't do anything
311 LODSB
312 STOSB
313 invoke BUFOUT
314 INC BH ;Ahead in template
315 INC DH ;Ahead in line
316 LOOP COPYEACH
317 GETCH2:
318 JMP GETCH
319
320 ;Skip one char in template
321 entry SKIPONE
322 CMP BH,BL
323 JZ GETCH2 ;At end of template
324 INC BH ;Ahead in template
325 INC SI
326 JMP GETCH
327
328 entry SKIPSTR
329 invoke FINDOLD ;Find out how far to go
330 ADD SI,CX ;Go there
331 ADD BH,CL
332 JMP GETCH
333
334 ;Get the next user char, and look ahead in template for a match
335 ;CX indicates how many chars to skip to get there on output
336 ;NOTE: WARNING: If the operation cannot be done, the return
337 ; address is popped off and a jump to GETCH is taken.
338 ; Make sure nothing extra on stack when this routine
339 ; is called!!! (no PUSHes before calling it).
340 FINDOLD:
341 invoke $STD_CON_INPUT_NO_ECHO
342 CMP AL,[ESCCHAR] ; did he type a function key?
343 JNZ FindSetup ; no, set up for scan
344 invoke $STD_CON_INPUT_NO_ECHO ; eat next char
345 JMP NotFnd ; go try again
346 FindSetup:
347 MOV CL,BL
348 SUB CL,BH ;CX is number of chars to end of template
349 JZ NOTFND ;At end of template
350 DEC CX ;Cannot point past end, limit search
351 JZ NOTFND ;If only one char in template, forget it
352 PUSH ES
353 PUSH DS
354 POP ES
355 PUSH DI
356 MOV DI,SI ;Template to ES:DI
357 INC DI
358 REPNE SCASB ;Look
359 POP DI
360 POP ES
361 JNZ NOTFND ;Didn't find the char
362 NOT CL ;Turn how far to go into how far we went
363 ADD CL,BL ;Add size of template
364 SUB CL,BH ;Subtract current pos, result distance to skip
365 return
366
367 NOTFND:
368 POP BP ;Chuck return address
369 JMP GETCH
370
371 entry REEDIT
372 MOV AL,"@" ;Output re-edit character
373 invoke OUTT
374 POP DI
375 PUSH DI
376 PUSH ES
377 PUSH DS
378 invoke COPYNEW ;Copy current line into template
379 POP DS
380 POP ES
381 POP SI
382 MOV BL,DH ;Size of line is new size template
383 JMP PUTNEW ;Start over again
384
385 entry EXITINS
386 entry ENTERINS
387 NOT BYTE PTR [INSMODE]
388 JMP GETCH
389
390 ;Put a real live ^Z in the buffer (embedded)
391 entry CTRLZ
392 MOV AL,"Z"-"@"
393 JMP SAVCH
394
395 ;Output a CRLF
396 entry CRLF
397 MOV AL,c_CR
398 invoke OUTT
399 MOV AL,c_LF
400 JMP OUTT
401
402 EndProc $STD_CON_STRING_INPUT
403 \1a