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
Text File  |  2000-06-30  |  5KB  |  260 lines

  1. ;TXTTOWS.MAC - version 1.10
  2. ;
  3. .z80
  4. ;
  5. ; A program to convert a free-format text file to a WordStar-compatible
  6. ; text file. This program makes soft CRs except at the end of a paragraph,
  7. ; sets high bits on words and makes soft spaces.
  8. ;
  9. ; This program may be freely distributed. The object code may be
  10. ; distributed for profit, provided that 1) it is unaltered and
  11. ; 2) it is part of a package or system and its value is insignificant
  12. ; as compared to the package or system.
  13. ; The signon banner must not be altered. The source code is released
  14. ; for non-commercial use and for reference only.
  15. ; Parts of this program are (c) Richard L. Conn (after assembly and linkage)
  16. ;
  17. ; ESKAY Software Service - a non-commercial non-business dedicated to
  18. ; writing better Public Domain Software. Donations welcome.
  19. ; S. Kluger, 7120 Skillman #2104, Dallas TX 75231
  20. ;
  21. ; to assemble:
  22. ; ..>m80 =txttows
  23. ; ..>link txttows,wildex,syslib[s]
  24. ; or
  25. ; ..>l80 txttows,wildex/s,syslib/s,txttows/n/e
  26. ; (wildex.mac/rel is a product of ESKAY, syslib.rel is (c) R L Conn)
  27. ;
  28. cr    equ    0dh
  29. lf    equ    0ah
  30. ;
  31.     extrn    f$open,f$close,f$mopen,f$rename,f$read,f$write
  32.     extrn    f$delete,initfcb,print,codend,pfn1,bdos
  33.     extrn    wildex
  34. ;
  35. begin:    ld    sp,stack
  36.     call    print
  37.     db    cr,lf
  38.     db    ' ----------------------------------------',cr,lf
  39.     db    '| TXT-TO-WS version 1.10 (c) 1984 ESKAY  |',cr,lf
  40.     db    '| Converts text files to WordStar format |',cr,lf
  41.     db    '|       Released to Public Domain        |',cr,lf
  42.     db    ' ----------------------------------------',cr,lf,lf,0
  43.     call    codend        ;get start of dir buffer
  44.     ld    (wildb),hl
  45.     ld    de,5ch        ;default fcb
  46.     call    wildex        ;expand wildcards
  47.     jr    z,nofle
  48.     ld    (count),hl    ;save count
  49.     ld    a,h
  50.     or    l        ;if we have something...
  51.     jr    nz,cont        ;...then continue
  52. nofle:    call    print
  53.     db    'No file found',cr,lf,0
  54.     rst    0
  55. ;
  56. cont:    ex    de,hl
  57.     ld    bc,16
  58.     call    codend
  59. mul:    add    hl,bc
  60.     dec    de
  61.     ld    a,d
  62.     or    e
  63.     jr    nz,mul
  64.     ld    (bufptr),hl    ;save buffer pointer
  65.     ld    (bufbot),hl    ;save buffer bottom
  66.     ld    hl,(6)
  67.     ld    l,0
  68.     ld    (topram),hl
  69. loop:    ld    de,fcb
  70.     ld    hl,(wildb)
  71.     push    de
  72.     ld    bc,16
  73.     ldir
  74.     ld    (wildb),hl
  75.     pop    de
  76.     inc    de
  77.     call    print
  78.     db    cr,lf
  79.     db    'Now processing ',0
  80.     call    pfn1
  81.     dec    de
  82.     call    initfcb
  83.     call    f$open
  84.     jr    z,opnok
  85.     call    print
  86.     db    '-- unable to open, skipping --',0
  87.     jp    nextf
  88. ;
  89. opnok:    ld    de,outfcb
  90.     call    initfcb
  91.     call    f$mopen
  92.     jr    z,makeok
  93.     call    print
  94.     db    '-- fatal error - unable to create file --',0
  95.     rst    0
  96. ;
  97. makeok:    call    fillbf        ;fill buffer with data
  98.     call    soft        ;soften the data
  99.     call    purgbf        ;purge buffer
  100.     ld    a,(eof)
  101.     or    a
  102.     jr    z,makeok
  103.     ld    de,fcb
  104.     call    f$close
  105.     call    f$delete
  106.     ex    de,hl
  107.     ld    de,outfcb
  108.     call    f$close
  109.     call    f$rename
  110. nextf:    ld    hl,(count)
  111.     dec    hl
  112.     ld    (count),hl
  113.     ld    a,h
  114.     or    l
  115.     jp    nz,loop
  116.     call    print
  117.     db    cr,lf,lf
  118.     db    '*** END OF EXECUTION ***',cr,lf,0
  119.     rst    0
  120. ;
  121. ; fill the buffer with data
  122. ;
  123. fillbf:    ld    hl,(bufbot)
  124.     ld    (bufptr),hl
  125.     xor    a
  126.     ld    (secs),a
  127.     ld    (eof),a
  128. fillp:    ld    de,(bufptr)
  129.     ld    hl,128
  130.     add    hl,de
  131.     ld    (bufptr),hl
  132.     ld    c,1ah
  133.     call    bdos
  134.     ld    de,fcb
  135.     call    f$read
  136.     jr    z,rdok
  137.     ld    (eof),a
  138.     ret
  139. ;
  140. rdok:    ld    hl,secs
  141.     inc    (hl)
  142.     ld    de,(topram)
  143.     ld    hl,(bufptr)
  144.     or    a
  145.     sbc    hl,de
  146.     jr    nz,fillp
  147.     ret
  148. ;
  149. ; "soften" the data in the buffer
  150. ;
  151. soft:    ld    hl,(bufbot)    ;bufbot = start of buffer
  152.     ld    de,(bufptr)    ;bufptr = end of buffer + 1
  153.     dec    de        ;de is now end of data
  154.     ld    b,-1        ;set previous crlf flag
  155.     ld    c,0        ;reset previous space flag
  156. softl:    ld    a,(hl)
  157.     cp    lf
  158.     jr    z,nocr        ;totally ignore linefeed
  159.     cp    cr
  160.     jr    z,iscr
  161.     push    af
  162.     ld    a,(chars)
  163.     inc    a
  164.     ld    (chars),a
  165.     pop    af
  166.     ld    b,0        ;reset prev cr flag
  167.     cp    ' '        ;space?
  168.     jr    z,issp
  169.     ld    c,0        ;reset prev sp flag
  170.     ld    (onlysp),a
  171. softl1:    ld    a,(hl)
  172.     and    7fh
  173.     cp    cr
  174.     jr    nz,nocr
  175.     xor    a
  176.     ld    (chars),a
  177. nocr:    inc    hl
  178.     ld    a,h
  179.     cp    d
  180.     jr    nz,softl
  181.     ld    a,l
  182.     cp    e
  183.     jr    nz,softl
  184.     ret
  185. ;
  186. iscr:    xor    a
  187.     ld    c,a
  188.     ld    (onlysp),a
  189.     inc    b
  190.     ld    b,-1
  191.     jr    nz,unflag
  192.     dec    hl
  193.     dec    hl
  194.     res    7,(hl)
  195.     inc    hl
  196.     inc    hl
  197. ;
  198. unflag:    ld    a,(chars)    ;see if <25 char in line (arbitrary, really)
  199.     or    a
  200.     jr    z,softl1    ;if line length 0 then must be hard cr
  201.     cp    26
  202.     jr    c,softl1
  203. doflg:    set    7,(hl)
  204.     jr    softl1
  205. ;
  206. issp:    inc    c
  207.     ld    c,-1
  208.     jr    nz,softl1
  209.     ld    a,(onlysp)
  210.     or    a
  211.     jr    z,softl1
  212.     jr    doflg
  213. ;
  214. ; purge buffer back to disk
  215. ;
  216. purgbf:    ld    hl,(bufbot)
  217.     ld    (bufptr),hl
  218. purglp:    ld    de,(bufptr)
  219.     ld    hl,128
  220.     add    hl,de
  221.     ld    (bufptr),hl
  222.     ld    c,1ah
  223.     call    bdos
  224.     ld    de,outfcb
  225.     call    f$write
  226.     jr    z,wrok
  227.     call    print
  228.     db    '-- fatal error - disk/directory full --',cr,lf,0
  229.     rst    0
  230. ;
  231. wrok:    ld    hl,secs
  232.     dec    (hl)
  233.     jr    nz,purglp
  234.     ret
  235. ;
  236. onlysp:    db    0
  237. chars:    db    0
  238. secs:    db    0
  239. eof:    db    0
  240. bufptr:    dw    0
  241. bufbot:    dw    0
  242. topram:    dw    0
  243. wildb:    dw    0
  244. count:    dw    0
  245. outfcb:    db    0,'TXTTOWS$TMP'
  246.     ds    24
  247. fcb:    ds    36
  248.     ds    80
  249. stack    equ    $
  250.     end
  251. 
  252.     ld    (chars),a
  253. nocr:    inc    hl
  254.     ld    a,h
  255.     cp    d
  256.     jr    nz,softl
  257.     ld    a,l
  258.     cp    e
  259.     jr    nz,softl
  260.     re