; PROGRAM: COMMENT ; AUTHOR: Richard Conn ; VERSION: 2.0 ; DATE: 18 MAY 84 ; PREVIOUS VERSIONS: 1.0 (18 APR 83) vers equ 21 ;vers equ 20 z3env defl 0f400h ;Version 2.1 release, 4/15/91 by Bruce Morgen ;Modified safety header per Wright/Goldstein, found one more JR, ;Type 4 executable included in LBR, relinked with latest/greatest ;Z3LIB/SYSLIB. Added wheel byte check to help messages so user ;won't think we'll print when we won't. ;Version 2.1 mods by Bruce Morgen, March 18, 1989: ;Type 3 format w/safety header, wheel protection for printer toggle, ;improved line-wrap code with reference to CRT width in ENV rather ;that arbitrary "LLEN" value, tightened code. ; ; COMMENT echoes lines, with simple character editing, to the user's ; console. This program is designed to facilitate communication between ; two users who see the same console via redirectable I/O. They can chat ; freely to each other by using this program. ; ;llen equ 65 ; Number of chars allowed before auto newline ; (computed from ENV value as of v2.1) fcb equ 5ch ; FCB ctrlc equ 'C'-'@' ; Abort Character esc equ 1bh ; Escape (Abort Character) cr equ 0dh ; New Line lf equ 0ah ; Line Feed bs equ 8 ; Back Space del equ 7fh ; Delete Char ctrlp equ 'P'-'@' ; ^P ctrlu equ 'U'-'@' ; ^U ctrlx equ 'X'-'@' ; ^X ; ; Externals ; ext z3init,getcrt,getwhl ext cin,cout,eprint,epstr,lout,lcrlf ; ; Environment Definition ; ; External ZCPR3 Environment Descriptor ; ; TYPE 3 HEADER ; Code modified as suggested by Charles Irvine to function correctly with ; interrupts enabled. Program will abort with an error message when not ; loaded to the correct address (attempt to run it under CP/M or Z30). entry: jr start0 ; Must use relative jump db 0 ; Filler db 'Z3ENV',3 ; Type-3 environment z3eadr: dw z3env ; Filled in by Z33 dw entry ; Intended load address start0: ld hl,0 ; Point to warmboot entry ld a,(hl) ; Save the byte there di ; Protect against interrupts ld (hl),0c9h ; Replace warmboot with a return opcode rst 0 ; Call address 0, pushing RETADDR ; Onto stack retaddr: ld (hl),a ; Restore byte at 0 dec sp ; Get stack pointer to point dec sp ; To the value of RETADDR pop hl ; Get it into HL and restore stack ei ; We can allow interrupts again ld de,retaddr ; This is where we should be xor a ; Clear carry flag sbc hl,de ; Subtract -- we should have 0 now jr z,start ; If addresses matched, begin real code add hl,de ; Restore value of RETADDR ld de,notz33msg-retaddr ; Offset to message add hl,de ex de,hl ; Switch pointer to message into DE ld c,9 jp 0005h ; Return via BDOS print string function notz33msg: db 'Not Z33+$' ; Abort message if not Z33-compatible start: ld hl,(z3eadr) ; Pt to ZCPR3 environment ; ; Start of Program -- Initialize ZCPR3 Environment ; call z3init ; Initialize the ZCPR3 Env call eprint db 'COMMENT, Version ' db (vers/10)+'0','.',(vers mod 10)+'0',0 ld a,(fcb+1) ; Check for help request cp '/' ; Help? jp nz,cmt ; ; Help for COMMENT ; call eprint db cr,lf,'Syntax:' db cr,lf,' COMMENT' db cr,lf,'Internal Commands:' db cr,lf,' ^C or ESC - Abort',0 call getwhl jr z,nowh call eprint db cr,lf,' ^P -',0 ld hl,togstr call epstr nowh: call eprint db cr,lf,' BS or DEL - Delete Prev Char' db cr,lf,' ^U or ^X - Delete Line' db 0 ret ; ; Beginning of Comment Routine ; cmt: call eprint db cr,lf,'Strike ^C or ESC to Abort',0 call getwhl jr z,cmt1 call eprint db ',',cr,lf,'^P to' togstr: db ' Toggle Print',0 cmt1: call eprint ; Avoids "CRLF" inclusion db cr,lf,0 xor a ld (prflag),a ; Clear print flag call comment ; Print first prompt and set char count ; ; Main Character Input Loop ; loop: call cin ; Input char and 7fh ; Mask MSB cp ctrlc ret z cp esc ret z cp ctrlp ; Toggle print flag jr z,prtog cp cr ; New line? jr z,newline cp lf ; New line? jr z,newline cp bs ; Back up? jr z,back cp del ; Back up? jr z,back cp ctrlu ; Erase line? jr z,eraln cp ctrlx ; Erase line? jr z,eraln call cout cp ' ' ; Printable char? jr c,loop ld b,a ; Save char in B ld a,(prflag) ; Print? or a ; 0=no ld a,b ; Get char to print call nz,lout ; Print char if PRFLAG is NZ inc c ; Increment char count call getcrt ; Pointer to CRT stats ld a,(hl) ; Width into A sub 12 ; Allow for prompt width cp c ; Compare to current position jr c,newline ; Carry means compusory wrap sub 4 ; Compute "optional" end-of-line cp c ; Check for nearing end-of-line jr nc,loop ; Just loop if not there yet ld a,' ' ; At a space? cp b call nc,comment ; Re-prompt if so jr loop ; Loop around regardless ; ; Toggle print flag ; prtog: call getwhl ; Only wheels can use printer jr z,loop ; Just loop if not wheel ld a,(prflag) ; Flip flag cpl ld (prflag),a or a ; New line to printer if print flag now off call z,lcrlf jr loop ; ; Routine to begin a new line ; newline: call comment ; New line, print prompt, set char count to zero jr loop ; ; Back up one character ; back: ld a,c ; Check for no chars or a jr z,loop call back1 ; Backup routine jr loop ; Continue ; ; General Routine for backing up ; back1: dec c ; Count down call eprint db bs,' ',bs,0 ; Backspace, Space, Backspace ret ; ; Erase Current Line ; eraln: ld a,c ; Done? or a jr z,loop call back1 ; Backup jr eraln ; ; Print User Prompt ; comment: call eprint db cr,lf,'Comment> ',0 ld a,(prflag) ; New line to printer if print flag on or a call nz,lcrlf ld c,0 ; Set char count ret dseg ; ; Buffers ; prflag: ds 1 ; Print flag (0=off, 0FFH=on) end