;ZTXTTOWS.Z80, derived from ;TXTTOWS.MAC - version 1.10 ; ; Adapted for ZCPR3 by Bruce Morgen, 5/19/86 ; ; A program to convert a free-format text file to a WordStar-compatible ; text file. This program makes soft CRs except at the end of a paragraph, ; sets high bits on words and makes soft spaces. ; ; This program may be freely distributed. The object code may be ; distributed for profit, provided that 1) it is unaltered and ; 2) it is part of a package or system and its value is insignificant ; as compared to the package or system. ; The signon banner must not be altered. The source code is released ; for non-commercial use and for reference only. ; Parts of this program are (c) Richard L. Conn (after assembly and linkage) ; ; ESKAY Software Service - a non-commercial non-business dedicated to ; writing better Public Domain Software. Donations welcome. ; S. Kluger, 7120 Skillman #2104, Dallas TX 75231 ; ; to assemble: ; ..>m80 =txttows ; ..>link txttows,wildex,syslib[s] ; or ; ..>l80 txttows,wildex/s,syslib/s,txttows/n/e ; (wildex.mac/rel is a product of ESKAY, syslib.rel is (c) R L Conn) ; CR EQU 0DH LF EQU 0AH ; EXTRN Z3INIT,Z3LOG,DUTDIR,RETUD EXTRN F$OPEN,F$CLOSE,F$MOPEN,F$RENAME,F$READ,F$WRITE EXTRN F$DELETE,INITFCB,EPRINT,CODEND,PFN2,BDOS,COUT EXTRN WILDEX,PRNDU,FENV ; START: LD (STACK),SP LD SP,STACK CALL FENV JP Z,NOTZ3 CALL Z3INIT CALL EPRINT DB CR,LF DB 'TXT-TO-WS, ZCPR3 version 1.0, (c) 1984 ESKAY',CR,LF DB 'Converts text files to WordStar format',CR,LF,LF,0 LD DE,5DH ;default fcb+1 LD A,(DE) CP '/' JR NZ,BEGIN CALL EPRINT DB 'Syntax:',CR,LF,9 DB 'TXTTOWS [du: or dir:]afn',CR,LF,0 JP EXITIT BEGIN: DEC DE CALL Z3LOG CALL RETUD CALL DUTDIR JR Z,EXWILD PUSH HL CALL EPRINT DB 'Searching the ',0 POP HL LD B,8 NDRLOP: LD A,(HL) CP ' ' JR Z,NDRMSG CALL COUT INC HL DJNZ NDRLOP NDRMSG: CALL EPRINT DB ' directory.',CR,LF,0 EXWILD: CALL CODEND ;get start of dir buffer LD (WILDB),HL CALL WILDEX ;expand wildcards JR Z,NOFLE LD (COUNT),HL ;save count LD A,H OR L ;if we have something... JR NZ,CONT ;...then continue NOFLE: CALL EPRINT DB 'No file found',CR,LF,0 JP EXITIT ; CONT: EX DE,HL LD BC,16 CALL CODEND MUL: ADD HL,BC DEC DE LD A,D OR E JR NZ,MUL LD (BUFPTR),HL ;save buffer pointer LD (BUFBOT),HL ;save buffer bottom LD HL,(6) LD L,0 LD (TOPRAM),HL LOOP: LD DE,FCB LD HL,(WILDB) PUSH DE LD BC,16 LDIR LD (WILDB),HL POP DE INC DE CALL EPRINT DB CR,LF DB 'Now processing ',0 CALL RETUD CALL PRNDU CALL PFN2 DEC DE CALL INITFCB CALL F$OPEN JR Z,OPNOK CALL EPRINT DB '-- unable to open, skipping --',0 JR NEXTF ; OPNOK: LD DE,OUTFCB CALL INITFCB CALL F$MOPEN JR Z,MAKEOK CALL EPRINT DB '-- fatal error - unable to create file --',0 JP EXITIT ; MAKEOK: CALL FILLBF ;fill buffer with data CALL SOFT ;soften the data CALL PURGBF ;purge buffer LD A,(EOF) OR A JR Z,MAKEOK LD DE,FCB CALL F$CLOSE CALL F$DELETE EX DE,HL LD DE,OUTFCB CALL F$CLOSE CALL F$RENAME NEXTF: LD HL,(COUNT) DEC HL LD (COUNT),HL LD A,H OR L JP NZ,LOOP CALL EPRINT DB CR,LF,LF DB '*** END OF EXECUTION ***',CR,LF,0 JP EXITIT ; ; fill the buffer with data ; FILLBF: LD HL,(BUFBOT) LD (BUFPTR),HL XOR A LD (SECS),A LD (EOF),A FILLP: LD DE,(BUFPTR) LD HL,128 ADD HL,DE LD (BUFPTR),HL LD C,1AH CALL BDOS LD DE,FCB CALL F$READ JR Z,RDOK LD (EOF),A RET ; RDOK: LD HL,SECS INC (HL) LD DE,(TOPRAM) LD HL,(BUFPTR) OR A SBC HL,DE JR NZ,FILLP RET ; ; "soften" the data in the buffer ; SOFT: LD HL,(BUFBOT) ;bufbot = start of buffer LD DE,(BUFPTR) ;bufptr = end of buffer + 1 DEC DE ;de is now end of data LD B,-1 ;set previous crlf flag LD C,0 ;reset previous space flag SOFTL: LD A,(HL) CP LF JR Z,NOCR ;totally ignore linefeed CP CR JR Z,ISCR PUSH AF LD A,(CHARS) INC A LD (CHARS),A POP AF LD B,0 ;reset prev cr flag CP ' ' ;space? JR Z,ISSP LD C,0 ;reset prev sp flag LD (ONLYSP),A SOFTL1: LD A,(HL) AND 7FH CP CR JR NZ,NOCR XOR A LD (CHARS),A NOCR: INC HL LD A,H CP D JR NZ,SOFTL LD A,L CP E JR NZ,SOFTL RET ; ISCR: XOR A LD C,A LD (ONLYSP),A INC B LD B,-1 JR NZ,UNFLAG DEC HL DEC HL RES 7,(HL) INC HL INC HL ; UNFLAG: LD A,(CHARS) ;see if <25 char in line (arbitrary, really) OR A JR Z,SOFTL1 ;if line length 0 then must be hard cr CP 26 JR C,SOFTL1 DOFLG SET 7,(HL) JR SOFTL1 ; ISSP: INC C LD C,-1 JR NZ,SOFTL1 LD A,(ONLYSP) OR A JR Z,SOFTL1 JR DOFLG ; ; purge buffer back to disk ; PURGBF: LD HL,(BUFBOT) LD (BUFPTR),HL PURGLP: LD DE,(BUFPTR) LD HL,128 ADD HL,DE LD (BUFPTR),HL LD C,1AH CALL BDOS LD DE,OUTFCB CALL F$WRITE JR Z,WROK CALL EPRINT DB '-- fatal error - disk/directory full --',CR,LF,0 JR EXITIT ; WROK: LD HL,SECS DEC (HL) JR NZ,PURGLP RET ; NOTZ3: CALL EPRINT DB 'This is apparently not a ZCPR3 system: Aborting!',0 EXITIT: LD SP,(STACK) RET ; ONLYSP: DB 0 CHARS: DB 0 SECS: DB 0 EOF: DB 0 BUFPTR: DW 0 BUFBOT: DW 0 TOPRAM: DW 0 WILDB: DW 0 COUNT: DW 0 OUTFCB: DB 0,'TXTTOWS$TMP' DS 24 FCB: DS 36 DS 80 STACK: DS 2 END