1 ; SCCSID = @(#)strin.asm 1.2 85/04/18
4 ; A000 version 4.00 Jan. 1988
9 ; DS:DX Point to an input buffer
11 ; Fill buffer from console input until CR
15 procedure $STD_CON_STRING_INPUT
,NEAR ;System call 10
16 ASSUME
DS:NOTHING
,ES:NOTHING
23 mov cs:Temp_Var
,si ;AN000; ; 3/31/KK
25 ; AL is the buffer length
26 ; AH is the template length
29 retz
;Buffer is 0 length!!?
30 MOV BL,AH ;Init template counter
31 MOV BH,CH ;Init template counter
33 ; BL is the number of bytes in the template
36 JBE NOEDIT
;If length of buffer inconsistent with contents
37 CMP BYTE PTR [BX+SI],c_CR
38 JZ EDITON
;If CR correctly placed EDIT is OK
40 ; The number of chars in the template is >= the number of chars in buffer or
41 ; there is no CR at the end of the template. This is an inconsistant state
42 ; of affairs. Pretend that the template was empty:
45 MOV BL,CH ;Reset buffer
48 DEC DX ;DL is # of bytes we can put in the buffer
50 ; Top level. We begin to read a line in.
54 MOV [STARTPOS
],AL ;Remember position in raw buffer
56 MOV DI,OFFSET DOSGROUP
:INBUF
;Build the new line here
57 MOV [INSMODE
],CH ;Insert mode off
58 MOV BH,CH ;No chars from template yet
59 MOV DH,CH ;No chars to new line yet
60 call IntCNE0
;AN000; Get first char 2/17/KK
61 jz SavCh
;AN000; if ZF set then interim character 2/17/KK
63 JNZ GOTCH
;Filter out LF so < works
65 ; This is the main loop of reading in a character and processing it.
67 ; BH is the index of the next byte in the template
68 ; BL is the length of the template
69 ; DH is the number of bytes in the buffer
70 ; DL is the length of the buffer
73 call IntCNE0
;AN000;; 2/17/KK
74 jz SavCh
;AN000;; if ZF set then interim character 2/17/KK
77 ; ^F ignored in case BIOS did not flush the input queue.
82 ; If the leading char is the function-key lead byte
85 JNZ ARM03
;AN000;; 2/17/KK
86 Jmp ESCC
;AN000;; 2/17/KK
87 ARM03: ;AN000;; 2/17/KK
89 ; Rubout and ^H are both destructive backspaces.
92 JZ BACKSPJ0
;AN000; 2/17/KK
94 JNZ ARM04
;AN000;; 2/17/KK
95 BACKSPJ0: ;AN000;; 2/17/KK
96 Jmp BACKSPJ
;AN000;; 2/17/KK
97 ARM04: ;AN000;; 2/17/KK
99 ; ^W deletes backward once and then backs up until a letter is before the
103 ; The removal of the comment characters before the jump statement will
104 ; cause ^W to backup a word.
109 ; The removal of the comment characters before the jump statement will
110 ; cause ^U to clear a line.
116 ; CR terminates the line.
119 JNZ ARM01
;AN000;; 2/17/KK
120 Jmp ENDLIN
;AN000;; 2/17/KK
121 ARM01: ;AN000;; 2/17/KK
123 ; LF goes to a new line and keeps on reading.
126 JNZ ARM00
;AN000;; 2/17/KK
127 Jmp PHYCRLF
;AN000;; 2/17/KK
128 ARM00: ;AN000;; 2/17/KK
130 ; ^X (or ESC) deletes the line and starts over
133 JNZ SAVCH
;AN000;; 2/13/KK
134 JMP KILNEW
;AN000;; 2/13/KK
135 InterLoop: ;AN000;; 2/17/KK
136 call IntCNE0
;AN000;; Get another interim character 2/17/KK
138 ; Otherwise, we save the input character.
141 pushf ;AN000; 2/17/KK
143 JAE BUFFUL
; buffer is full.
144 ;----------------------------- Start of DBCS 2/13/KK
146 invoke TESTKANJ
;AN000;
151 DEC DH ;AN000;; No room for second byte
152 call IntCNE0
;AN000;; Get second byte
153 JMP SHORT BUFFUL
;AN000;
156 STOSB ;AN000;; Store first byte
159 call IntCNE0
;AN000;; Get second byte
161 STOSB ;AN000;; Store second byte
165 jnz ContIn1
;AN000;; interim character?
166 call InterCheck
;AN000;
167 call InterCheck
;AN000;
168 jmp short InterLoop
;AN000;; not interim skip another check
171 ;----------------------------- End of DBCS 2/13/KK
173 INC DH ;AN000;; increment count in buffer.
174 popf ;AN000;; 2/17/KK
175 invoke BUFOUTx
;AN000;; Print control chars nicely 2/17/KK
176 jnz ContIn1
;AN000;; 2/17/KK
177 call InterCheck
;AN000;; 2/17/KK
178 jmp short InterLoop
;AN000;; 2/17/KK
179 CONTIN1: ;AN000;; 2/13/KK
180 ;;;CONTIN: ;AN000;; 2/13/KK
181 CMP BYTE PTR [INSMODE
],0
182 JNZ GETCH0
; insertmode => don't advance template
184 JAE GETCH0
; no more characters in template
185 INC SI ; Skip to next char in template
186 INC BH ; remember position in template
189 MOV AL,BYTE PTR [SI-1] ;AN000;; 2/13/KK
190 invoke TESTKANJ
;AN000;; 2/13/KK
191 POP AX ;AN000;; 2/13/KK
192 JZ GETCH0
;AN000;; Wasn't a dual byte 2/13/KK
193 INC SI ;AN000;; Was a dual byte, 2/13/KK
194 INC BH ;AN000;; skip one more 2/13/KK
195 GETCH0: ;AN000;; 2/17/KK
196 JMP GETCH
;AN000;; 2/17/KK
198 BACKSPJ: JMP SHORT BACKSP
201 popf ;AN000;; 2/17/KK
202 MOV AL,7 ;AN000;; Bell to signal full buffer
206 ; Reduce character count, reduce pointer 2/17/KK
208 InterCheck: ;AN000;; 2/17/KK
209 dec dh ;AN000;; adjust count 2/17/KK
210 dec di ;AN000;; adjust buffer pointer 2/17/KK
214 transfer OEMFunctionKey
; let the OEM's handle the key dispatch
217 STOSB ; Put the CR in the buffer
218 invoke OUTT
; Echo it
219 POP DI ; Get start of user buffer
220 MOV [DI-1],DH ; Tell user how many bytes
221 INC DH ; DH is length including CR
224 RestoreReg
<DS,ES> ; XCHG ES,DS
225 MOV SI,OFFSET DOSGROUP
:INBUF
226 MOV CL,DH ; set up count
227 REP MOVSB ; Copy final line to user buffer
230 ; Output a CRLF to the user screen and do NOT store it into the buffer
237 ; Delete the previous line
241 JNZ bridge00
;AN000;; 2/13/KK
242 JMP GetCh
;AN000;; 2/13/KK
243 bridge00: ;AN000;; 2/13/KK
248 ; delete the previous word.
252 Call BackSpace
; backspace the one spot
268 ; The user wants to throw away what he's typed in and wants to start over. We
269 ; print the backslash and then go to the next line and tab to the correct spot
270 ; to begin the buffered input.
274 invoke OUTT ;Print the CANCEL indicator
275 POP SI ;Remember start of edit buffer
277 invoke CRLF ;Go to next line on screen
280 JMP NEWLIN ;Start over again
284 ; Destructively back up one character position
292 JZ OLDBAK ;No chars in line, do nothing to line
293 CALL BACKUP ;Do the backup
294 MOV AL,ES:[DI] ;Get the deleted char
295 invoke TESTKANJ ;AN000;2/13/KK
296 JNZ OLDBAK ;AN000; Was a dual byte, done 2/13/KK
298 JAE OLDBAK ;Was a normal char
300 JZ BAKTAB ;Was a tab, fix up users display
301 ;; 9/27/86 fix for ctrl-U backspace
302 CMP AL,"U
"-"@
" ; ctrl-U is a section symbol not ^U
304 CMP AL,"T
"-"@
" ; ctrl-T is a paragraphs symbol not ^T
306 ;; 9/27/86 fix for ctrl-U backspace
307 CALL BACKMES ;Was a control char, zap the '^'
309 CMP BYTE PTR [INSMODE],0
310 retnz ;In insert mode, done
312 retz ;Not advanced in template, stay where we are
313 DEC BH ;Go back in template
315 ;-------------------------- Start of DBCS 2/13/KK
317 retz ;AN000;; If we deleted one char and it was the only
318 ;AN000;; one, could not have dual byte
319 ;;;; POP AX ;AN000;; Get start of template
320 ;;;; PUSH AX ;AN000;; Put it back on stack
321 mov ax,cs:Temp_Var ;AN000;; 3/31/KK
327 MOV AL,BYTE PTR [SI];AN000;
328 invoke TESTKANJ ;AN000;
334 JMP SHORT LOOKDUAL ;AN000;
337 retz ;AN000;; Correctly pointing to start of single byte
338 DEC AX ;AN000;; Go back one more to correctly point at start
339 DEC BH ;AN000; ; of dual byte
342 ;-------------------------- End of DBCS 2/13/KK
346 DEC DI ;Back up one char
348 MOV CL,DH ;Number of chars currently in line
352 JCXZ FIGTAB ;At start, do nothing
356 CMP BYTE PTR ES:[DI+1],9
357 JZ HAVTAB ;Found a tab
358 DEC BL ;Back one char if non tab control char
366 AND CL,7 ;CX has correct number to erase
370 JZ OLDBAK ;Nothing to erase
373 LOOP TABBAK ;Erase correct number of chars
377 DEC DH ;Back up in line
379 ;-------------------------Start of DBCS 2/13/KK
381 JZ BACKMES ;AN000;; If deleted one and got only, no dual
383 MOV DI,OFFSET DOSGROUP:INBUF;AN000;
388 MOV AL,BYTE PTR ES:[DI] ;AN000;
389 invoke TESTKANJ ;AN000;
395 JMP SHORT LOOKDUAL2 ;AN000;
398 JE BACKMES ;AN000;; Correctly deleted single byte
399 DEC AX ;AN000; Go back one more to correctly delete dual byte
403 ;---------------------------End of DBCS 2/13/KK
405 MOV AL,c_BS ;Backspace
409 MOV AL,c_BS ;Backspace
412 ;User really wants an ESC character in his line
417 ;Copy the rest of the template
419 MOV CL,BL ;Total size of template
420 SUB CL,BH ;Minus position in template, is number to move
424 invoke FINDOLD ;Find the char
425 JMP SHORT COPYEACH ;Copy up to it
427 ;Copy one char from template to line
429 MOV CX,1 ;AN000;; 2/13/KK
430 MOV AL,[SI] ;AN000;; get char 2/13/KK
431 invoke TestKanj ;AN000;; is it kanji? 2/13/KK
432 JZ CopyEach ;AN000;; no, go do copy2/13/KK
433 INC CX ;AN000;; do 2 byte copy2/13/KK
435 ;Copy CX chars from template to line
437 MOV BYTE PTR [INSMODE],0 ;All copies turn off insert mode
439 JZ GETCH2 ;At end of line, can't do anything
441 JZ GETCH2 ;At end of template, can't do anything
444 ;----------------------------- Start of DBCS 2/13/KK
445 INC BH ;AN000;; Ahead in template
446 INC DH ;AN000;; Ahead in line
447 CALL TestKanj ;AN000;; 2 byte character?
448 JZ CopyLoop ;AN000;; no, go copy next
449 CMP DH,DL ;AN000;; over boundary?
450 JNZ CopyBoth ;AN000;; no, move both
451 DEC BH ;AN000;; yes, backup template
452 DEC DH ;AN000;; back up line
453 DEC SI ;AN000;; patch (from Dohhaku)
454 DEC DI ;AN000;; remember to backup after previous move
455 JMP GetCh ;AN000;; go get next char
458 invoke BUFOUT ;AN000;; output the first byte
459 LODSB ;AN000;; get the second
460 STOSB ;AN000;; move the second
461 INC BH ;AN000;; bump template
462 INC DH ;AN000;; bump line
463 DEC CX ;AN000;; dump byte count
465 invoke BUFOUT ;AN000;
466 LOOP COPYEACH ;AN000;
468 ;;;;; INC BH ;Ahead in template
469 ;;;;; INC DH ;Ahead in line
471 ;----------------------------- End of DBCS 2/13/KK
475 ;Skip one char in template
478 JZ GETCH2 ;At end of template
479 INC BH ;Ahead in template
481 PUSH AX ;AN000;; 2/13/KK
482 MOV AL,BYTE PTR [SI-1] ;AN000;; 2/13/KK
483 invoke TESTKANJ ;AN000;; 2/13/KK
484 POP AX ;AN000;; 2/13/KK
485 JZ GETCH2 ;AN000;; 2/13/KK
486 INC BH ;AN000;; 2/13/KK
487 INC SI ;AN000;; 2/13/KK
491 invoke FINDOLD ;Find out how far to go
496 ;Get the next user char, and look ahead in template for a match
497 ;CX indicates how many chars to skip to get there on output
498 ;NOTE: WARNING: If the operation cannot be done, the return
499 ; address is popped off and a jump to GETCH is taken.
500 ; Make sure nothing extra on stack when this routine
501 ; is called!!! (no PUSHes before calling it).
503 TABLE SEGMENT ;AN000;; 2/17/KK
504 Public KISTR001S,KISTR001E ;AN000;; 2/17/KK
505 KISTR001S label byte ;AN000;; 2/17/KK
506 LOOKSIZ DB 0 ;AN000;; 0 if byte, NZ if word 2/17/KK
507 KISTR001E label byte ;AN000;; 2/17/KK
508 TABLE ENDS ;AN000;; 2/17/KK
511 MOV [LOOKSIZ],0 ;AN000;; Initialize to byte 2/13/KK
512 call IntCNE1 ;AN000;; 2/17/KK
513 CMP AL,[ESCCHAR] ;AN000;; did he type a function key?
514 ;;;;; JNZ FindSetup ;AN000;; no, set up for scan 2/13/KK
515 JNZ TryKanj ;AN000;; no, continue testing 2/13/KK
516 call IntCNE1 ;AN000;; 2/17/KK
517 JMP NotFnd ; go try again
518 ;;;;;;;FindSetup: ;AN000;; 2/13/KK
519 TryKanj: ;AN000;; 2/13/KK
520 invoke TESTKANJ ;AN000;; 2/13/KK
521 JZ GOTLSIZ ;AN000;; 2/13/KK
522 INC [LOOKSIZ] ;AN000;; Gonna look for a word 2/13/KK
523 PUSH AX ;AN000;; Save first byte 2/13/KK
524 call IntCNE1 ;AN000;; 2/17/KK
525 POP CX ;AN000;; 2/13/KK
526 MOV AH,AL ;AN000;; 2/13/KK
527 MOV AL,CL ;AN000;; AX is dual byte sequence to look for
528 XOR CX,CX ;AN000;; Re-zero CH 2/13/KK
531 SUB CL,BH ;CX is number of chars to end of template
532 JZ NOTFND ;At end of template
533 DEC CX ;Cannot point past end, limit search
534 JZ NOTFND ;If only one char in template, forget it
535 PUSH AX ;AN000;; 2/13/KK
536 MOV AL,BYTE PTR [SI] ;AN000;; 2/13/KK
537 invoke TESTKANJ ;AN000;; 2/13/KK
538 POP AX ;AN000;; 2/13/KK
539 JZ NOTDUAL5 ;AN000;; 2/13/KK
540 DEC CX ;AN000;; And one more besides 2/13/KK
541 JZ NOTFND ;AN000;; If only one char in template, forget it
542 NOTDUAL5: ;AN000;; 2/13/KK
547 MOV DI,SI ;Template to ES:DI
549 ;;;; REPNE SCASB ;Look 2/13/KK
550 ;--------------------- Start of DBCS 2/13/KK
552 MOV AL,BYTE PTR ES:[DI] ;AN000;
553 invoke TESTKANJ ;AN000;
556 INC DI ;AN000;; We will skip at least something
559 CMP [LOOKSIZ],0 ;AN000;
563 MOV AL,BYTE PTR ES:[DI] ;AN000;
564 invoke TESTKANJ ;AN000;
570 LOOP LOOKBYTE ;AN000;
571 JMP SHORT ATNOTFND ;AN000;
575 CMP AL,ES:[DI] ;AN000;
578 INC CX ;AN000;; Counter next instruction
579 LOOP LOOKBYTE ;AN000;
582 INC AL ;AN000;; Set NZ
583 ATSPOT: ; 2/13/K;AN000;K
584 ;--------------------- End of DBCS 2/13/KK
587 JNZ NOTFND ;Didn't find the char
588 NOT CL ;Turn how far to go into how far we went
589 ADD CL,BL ;Add size of template
590 SUB CL,BH ;Subtract current pos, result distance to skip
594 POP BP ;Chuck return address
596 ;------------------------- Start of DBCS 2/13/KK
599 MOV AL,BYTE PTR ES:[DI] ;AN000;
600 invoke TESTKANJ ;AN000;
604 LOOP LOOKWORD ;AN000;
605 JMP SHORT ATNOTFND ;AN000;
609 CMP AX,ES:[DI] ;AN000;
613 LOOP LOOKWORD ;AN000; ; Performs second DEC of CX
614 JMP SHORT ATNOTFND ;AN000;
615 ;------------------------- End of DBCS 2/13/KK
618 MOV AL,"@
" ;Output re-edit character
624 invoke COPYNEW ;Copy current line into template
628 MOV BL,DH ;Size of line is new size template
629 JMP PUTNEW ;Start over again
633 NOT BYTE PTR [INSMODE]
636 ;Put a real live ^Z in the buffer (embedded)
648 EndProc $STD_CON_STRING_INPUT
650 ;-------------- Start of DBCS 2/17/KK
651 PUBLIC IntCNE0 ;AN000;
652 procedure IntCNE0,near ;AN000;
653 push word ptr [InterCon] ;AN000;
654 mov [InterCon],01 ;AN000;
656 invoke INTER_CON_INPUT_NO_ECHO ;AN000;; get a byte character
657 pop word ptr [InterCon] ;AN000;
661 procedure IntCNE1,near ;AN000;
662 push word ptr [InterCon] ;AN000;
663 mov [InterCon],00 ;AN000;
664 jmp short get_com ;AN000;
667 procedure outchax,near ;AN000;
669 mov [SaveCurFlg],0 ;AN000;
671 mov [SaveCurFlg],1 ;AN000;
674 mov [SaveCurFlg],0 ;AN000;
679 procedure bufoutx,near ;AN000;
681 mov [SaveCurFlg],0 ;AN000;
683 mov [SaveCurFlg],1 ;AN000;
685 invoke BUFOUT ;AN000;
686 mov [SaveCurFlg],0 ;AN000;
690 ;-------------- End of DBCS 2/17/KK