home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
PROGRAMS
/
WSTAR
/
TXTTOWS.LBR
/
TXTTOWS.MQC
/
TXTTOWS.MAC
Wrap
Text File
|
2000-06-30
|
5KB
|
260 lines
;TXTTOWS.MAC - version 1.10
;
.z80
;
; 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 f$open,f$close,f$mopen,f$rename,f$read,f$write
extrn f$delete,initfcb,print,codend,pfn1,bdos
extrn wildex
;
begin: ld sp,stack
call print
db cr,lf
db ' ----------------------------------------',cr,lf
db '| TXT-TO-WS version 1.10 (c) 1984 ESKAY |',cr,lf
db '| Converts text files to WordStar format |',cr,lf
db '| Released to Public Domain |',cr,lf
db ' ----------------------------------------',cr,lf,lf,0
call codend ;get start of dir buffer
ld (wildb),hl
ld de,5ch ;default fcb
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 print
db 'No file found',cr,lf,0
rst 0
;
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 print
db cr,lf
db 'Now processing ',0
call pfn1
dec de
call initfcb
call f$open
jr z,opnok
call print
db '-- unable to open, skipping --',0
jp nextf
;
opnok: ld de,outfcb
call initfcb
call f$mopen
jr z,makeok
call print
db '-- fatal error - unable to create file --',0
rst 0
;
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 print
db cr,lf,lf
db '*** END OF EXECUTION ***',cr,lf,0
rst 0
;
; 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 print
db '-- fatal error - disk/directory full --',cr,lf,0
rst 0
;
wrok: ld hl,secs
dec (hl)
jr nz,purglp
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 equ $
end
ld (chars),a
nocr: inc hl
ld a,h
cp d
jr nz,softl
ld a,l
cp e
jr nz,softl
re