; * * * * * FT: builds Files by Typing ; MACLIB CPMEQU ; include standard names MACLIB PROG ; prolog, service macros MACLIB COSUB ; console output routines MACLIB CISUB ; cisub for cocrlf only ; PROLOG2 FT ; ; * * * ERROR MESSAGES ; CCMSG DB 'Can''t close the file',cr,lf,'$' CWMSG DB 'Error on write',cr,lf,'$' CMMSG DB 'Can''t make the file',cr,lf,'$' FEMSG DB 'File exists -- you erase it',cr,lf,'$' ; INPUT CIBUFF 128 ; define line input buffer ; FT EQU $ ; start of program LDA CPMFCB+1 CPI BLANK ; any operand given? RZ ; done if not ; SERVICE 15,CPMFCB ; open file as for input INR A ; does file exist? JZ FT2 ; no, continue LXI D,FEMSG ; yes, quit with a message JMP ERROREXIT ; FT2 SERVICE 22,CPMFCB ; new file, make it INR A ; did that work? JNZ FT3 ; yes, continue LXI D,CMMSG ; no, quit with a message JMP ERROREXIT ; FT3 LXI D,CPMBUFF ; DE indexes disk buffer MVI B,00 ; [B] counts bytes in it ; FTOP EQU $ ; here for each console line CALL COCRLF ; cursor to next screen line LXI H,INPUT CALL CILINE ; service 10 gets input line JZ FTCLOSE ; all done if null line ; FTLOOP CALL CIGETC ; next inbyte JZ FTEOL ; (end of line) CALL FTPUT ; got a byte, put it in file JMP FTLOOP ; ..and get next ; FTEOL MVI A,CR ; end of input line, put CALL FTPUT ; ..CR, LF into MVI A,LF ; ..the file CALL FTPUT JMP FTOP ; then get next line ; ; WHEN a null line is received, fill the rest of the ; buffer with EOF marks, write it, and close the file ; FTCLOSE MVI A,EOF ; fill disk record with SUBs STAX D INX D INR B JP FTCLOSE SERVICE 21,CPMFCB ; then write last record ORA A ; did it work? JNZ CANT$WRITE SERVICE 16,CPMFCB ; close the file INR A ; check success RNZ ; return to EPILOG if ok LXI D,CCMSG JMP ERROREXIT ; ; Subroutine to stow the byte in [A] in the disk buffer. ; DE --> BUFFER, BC counts bytes in it. write the buffer ; when it fills up. ; FTPUT STAX D ; put byte in buffer, INX D ; step buffer index, INR B ; count bytes in this record RP ; return if not up to 128 LXI D,CPMBUFF ; reset buffer ptr, MVI B,00 ; ..and byte count SERVICE 21,CPMFCB ; then write record ORA A ; ..and if it worked RZ ; ..continue in program CANT$WRITE EQU $ LXI D,CWMSG ; if it did not, JMP ERROREXIT ; ..quit with a message ; ; COMMON SUBROUTINES ; CISUBM COSUBM END