[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applesoft Basic Question



Rich Hare (rhare@mich.com) wrote:
: I've got my old Applesoft Basic book out and my Dos manual and I'm still
: stumped.

: I've got a small routine that reads a DOS 3.3 file off of a disk and
: converts it to a text file and writes it back.  Input statements are
: provided for the name of the incoming file and for your choice of names
: for the outgoing file.

: Problem is that it directs all disk operations to S6,D1.

: I have a large number of files to process, and the disk swapping is
: slowing me down.  I'd like to have the program read the file from S6,D1
: and write it to S6,D2; but darn it I can't seem to parse the statements
: to make it work.  It seems that it should be something like:

: 100 D$=CHR$(4)
: 110 PRINT D$;"BLOAD"A$;S6,D1

There is your first problem.  That should read, 

110 PRINT D$;"BLOAD ";A$;",S6,D1"
Note that if all of your access is coming from S6, there is no need to
specify.  Also, I am guessing you are converting a Bank Street Writer or
AppleWriter ][ file here?  You might want to specify the load address...say...

110 PRINT D$;"BLOAD ";A$;",A8192,S6,D1"

: and later
: 120 PRINT D$;"OPEN"T$;S6,D2
: 130 PRINT D$;"WRITE"T$;S6,D2

Here, again the syntax is wrong...it needs to be OPEN FILENAME,S6,D2. 
Also, again, you just accessed S6,D1, so the S6 is redundant...though not
a bad idea.  Re-write as follows:

120 PRINT D$;"OPEN ";T$;",S6,D2"
130 PRINT D$;"WRITE ";T$

Note that specifying slot and drive is not necessary for a WRITE, READ, or
POSITION instruction relating to a file that is already open.  Uncle DOS
remembers where the file is from the OPEN instruction and will use that
file.  In fact, I am not certain that S and D are valid parameterd for
READ and WRITE if the file is already open.  Note that DOS 3.3 will
automatically OPEN an existing file for you if you forget, but if the file
does not already exist, it will not be created.  Also, unlike ProDOS, DOS
3.3 will automatically close open files if the program crashes most of the
time, but not always, and not necessarily predictably.

: Got to be a simple answer but I just can't see it.

It's just the syntax.  Here's a useful tip when you are writing code--

As you are creating your program, disable the ONERR GOTO instructions
whenever possible.  That way, you can see *which* error you are getting,
and *where* it is coming from (for instance, "^G?SYNTAX ERROR" is an
Applesoft error, while "^GSYNTAX ERROR" comes from DOS...notice the
difference?).  Of course, this is not always possible; I know I sometimes
use ONERR GOTO to trap the FILE NOT FOUND and END OF DATA messages in
order to check for file existence and to find the end of a text file.  In
those cases, write yourself an error handler which will report back the
line number and error code before crashing.  Also, at the end of the area
where you expect to find errors (as when hunting all disks for a
particular file), issue a POKE 216,0 to disable the ONERR GOTO.  Also
useful for using multiple error traps for different sections of the program.

For reference, the error codes--
DOS 3.3:
1:  LANGUAGE NOT AVAILABLE
2:  RANGE ERROR
3:  RANGE ERROR
4:  WRITE PROTECTED
5:  END OF DATA
6:  FILE NOT FOUND
7:  VOLUME MISMATCH
8:  I/O ERROR
9:  DISK FULL
10:  FILE LOCKED
11:  SYNTAX ERROR
12:  NO BUFFERS AVAILABLE
13:  FILE TYPE MISMATCH
14:  PROGRAM TOO LARGE
15:  NOT DIRECT COMMAND

Applesoft:
0:  ?NEXT WITHOUT FOR ERROR
16:  ?SYNTAX ERROR
22:  ?RETURN WITHOUT GOSUB ERROR
42:  ?OUT OF DATA ERROR
53:  ?ILLEGAL QUANTITY ERROR
69:  ?OVERFLOW ERROR
77:  ?OUT OF MEMORY ERROR
90:  ?UNDEF'D STATEMENT ERROR
107:  ?BAD SUBSCRIPT ERROR
120:  ?REDIM'ED ARRAY ERROR
133:  ?DIVISION BY ZERO ERROR
163:  ?TYPE MISMATCH ERROR
176:  ?STRING TOO LONG ERROR
191:  ?FORMULA TOO COMPLEX ERROR
224:  ?UNDEF'D FUNCTION ERROR
254:  ?REENTER (bad response to INPUT; non-fatal error)
255:  BREAK  (^C has been struck)

After an ONERR GOTO you can find the code with a PEEK (222).  Somewhere
around here I have the formula for the error-causing line number, but I'm
not sure where...

--Dave Althoff, ][
-- 
    /^\        _       _            *** Closed for the season 8-( ***
   /XXX\      /X\     /X\_      _     /X\__      _     _        _____  
  /XXXXX\    /XXX\  _/XXXX\_   /X\   /XXXXX\    /X\   /X\      /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX