; TLINE.MAC ; ; TLine -- Tiny in-line editor. Only backspace and delete are available ; for editing input line. Rejects other control characters, except ; carriage return and control-C. Carriage return ends edit, buffer ; contains null-terminated string. ^C aborts editor, buffer contents ; not terminated. ; ; Version 1.2 -- November 11, 1990 -- Howard Goldstein ; Saved a few bytes. ; ; Version 1.1 -- October 19, 1990 -- Gene Pizzetta ; Eliminated several PUSH's and POP's, at the suggestion of ; Howard Goldstein. Now correctly determines beginning of ; buffer in IsBS routine. ; ; Version 1.0 -- October 13, 1990 -- Gene Pizzetta ; Written for WHEEL 3.3 to replace SYSLIB INLINE editor. It adds ; more safety (accepts only number of characters requested), ; echoes dots in non-echo mode, uses buffer internal to program, ; and saves considerable code size. ; ; Entry: HL = address of buffer (length=number of characters + 1) ; B = number of characters allowed (255 maximum, but must ; be 1 less that length of buffer). ; A = echo user input flag (0=don't echo, non-zero=echo). ; Exit: A = 0 and zero flag set (Z) if buffer contains null- ; terminated string. ; A = 3 and zero flag reset (NZ) if user aborted with ^C. ; Uses: AF ; public tline ; ext cin,cout ; SYSLIB ; MACLIB Z80 ; extended Intel mnemonics ; CtrlC equ 03h BEL equ 07h BS equ 08h CR equ 0Dh DEL equ 7Fh ; ; Entry here . . . ; TLine: push h ; save registers push d mov e,a ; save echo flag in E mov d,b ; save buffer length in D TLoop: call cin cpi CR ; carriage return? jrz TLEnd cpi BS ; backspace? jrz IsBS cpi DEL ; delete? jrz IsBS cpi ' ' ; control character? jrc IsCtrl inr d ; check number of characters dcr d jrz BufEnd ; past end of buffer mov m,a ; store character inr e ; check echo flag dcr e ; do we echo it? jrz ChrOut ; (echo it) mvi a,'.' ; no, echo dot ChrOut: call cout inx h ; increment buffer pointer dcr d ; decrement character counter jr TLoop ; ; BufEnd -- we're at the beginning or end of the buffer and somebody's ; trying to push through the boundary. Ring the console and do nothing. ; BufEnd: mvi a,BEL ; sound bell call cout jr TLoop ; ; IsBS -- we have a backspace or delete. If we're not at the beginning ; of the buffer, we backspace 1 character, print a space, and backspace ; again, erasing the last character on the screen. At the beginning of ; the buffer we ring the console and do nothing. ; IsBS: mov a,d ; put character counter in A cmp b ; compare to buffer length in B jrz BufEnd ; at beginning of buffer mvi a,BS call cout ; print backspace mvi a,' ' call cout ; print space mvi a,BS call cout ; print backspace inr d ; increment character counter dcx h ; decrement buffer pointer jr TLoop ; ; IsCtrl -- we have a control character. If it's ^C, we abort the edit, ; return A=03h and the zero flag reset (NZ). Otherwise, be ring the ; console and do nothing. ; IsCtrl: cpi CtrlC ; ^C ? jrnz BufEnd ; (no, continue) ora a ; abort, return NZ jr TLEnd1 ; ; TLEnd -- we have a carriage return which ends the edit. Push null ; at end of string and return A=0 and zero flag set (Z). ; TLEnd: xra a ; add null mov m,a TLEnd1: pop d ; restore registers pop h ; get back buffer address ret ; return Z, okay ; end ; TLine