💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › MiscInfo › Programmin… captured on 2023-01-29 at 10:14:56.

View Raw

More Information

-=-=-=-=-=-=-


William Katz <druid@dorsai.org> wrote:

> Does anyone know if I can redirect output, from ProDOS AppleSoft BASIC for
> example, to a file or serial port?
> What I want to do is send the output of a "catalog" command to either a
> file, or my Apple Super Serial Card serial port.
> I tried the following unsuccessfully:
> At the basic prompt, I typed "pr#2", then typed "catalog".  On my m$-dos
> computer, I only saw garbage characters on the screen.

Two possible causes occur to me:

1. Your SSC's DIP switches must be set to match the settings used on the
PC (preferably 9600, 8N1).

2. Applesoft outputs every character with bit 7 set.  This will appear
to be garbage when it gets to the PC.  A solution is to capture the data
to a file and run it through a utility which will strip the high order
bit (and also convert CR to CR+LF, if necessary).

Some other ways of fixing the output data would be:

- output via a machine code subroutine on the Apple II, which strips bit
7 before sending the characters to the SSC.

- if the SSC has a command which causes it to clear bit 7, turn this
option on by embedded a command in the output stream.

- Use 7-bit data format instead of 8-bit.

> I'm guessing that a simple AppleSoft BASIC program can write output to a
> file?  Something like:
> 
> 10 d$=chr$(4): print d$;"pr#3"
> 20 print d$;"create catalog.txt,ttxt"
> 30 print d$;"open catalog.txt"
> 40 print d$;"catalog,s6,d1"
> 50 print d$;"write catalog.txt"
> 60 print d$;"close catalog.txt"
> 70 end

You would need to put the WRITE command before the CATALOG, but
unfortunately it won't work, because any command to DOS or ProDOS will
cancel an active WRITE.

Under ProDOS, the best way to achieve this is to OPEN and READ the
directory, then OPEN and WRITE a text file, alternating between reading
a line from the catalog and writing a line to the text file (or read
into an array, then write the whole array to the text file).

Under DOS 3.3, the only moderately straightforward way of capturing the
catalog output is to PEEK it off the screen, or capture the text output
via a machine code subroutine (in conjunction with a patch to prevent
the catalog output pausing at the end of each screen).


This is an example of the method under ProDOS.

In effect, reading the catalog gives you a mirror image of the catalog
as it would normally be displayed in 80-column mode, except that one of
the blank lines normally displayed at the top of the catalog is missing.
I forget whether it is the one between the pathname and title line or
the one between the title line and the first file line - the following
code assumes the catalog title follows immediately after the pathname
line.  (If I got it wrong, then swap lines 70 and 80.)

Note that you don't need to use PR#3, because reading the catalog with
this method will always give you an 80-column catalog listing.

10 d$=chr$(4): f$="/pathname/of/folder": t$="catalog.txt"
20 print d$;"open ";f$;",tdir"
30 print d$;"create ";t$;",ttxt"
40 print d$;"open ";t$
50 print d$;"read ";f$
60 input a$: rem pathname
70 input c$: rem catalog title
80 input b$: rem blank line - discarded
90 print d$;"write ";t$
100 print a$: print: print c$: print
110 print d$;"read ";f$
120 dim l$(50)
130 n = 0
140 input l$: rem file line
150 if l$ = "" then goto 200: rem no more file lines
160 l$(n) = l$
170 n = n + 1
180 if n <= 50 then goto 140
190 gosub 500: goto 130
200 if n > 0 then gosub 500
210 input s$: rem summary line
220 print d$;"write ";t$
230 print: print s$
240 print d$;"close"
250 end
500 rem Flush the array
510 print d$;"write ";t$
520 for i = 0 to n: print l$(i): next
530 print d$;"read ";f$
540 return