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

Re: Help! (BASIC.SYSTEM)



David Empson (dempson@actrix.gen.nz) wrote:
: Dave Althoff Jr <dalloff@gcfn.org> wrote:

: > I'm about to write a routine to convert some normalized text files to HTML.
: > 
: > Trouble is, I have to do it in ProDOS.  Other trouble is, I can't detect
: > the end of the file in Applesoft.
: > 
: > Now, under DOS 3.3, I can use ONERR GOTO and then PEEK(222) and look for a
: > 5 (END OF DATA) to make sure I'm getting the failure that I think I'm getting.

: This will also work fine in ProDOS.

I thought it would, I just wasn't sure of the codes.  It's simple to watch
for the EOD code and use that to identify the end of the file, but because
I'm not perfect I find that it's a good idea to process an END OF DATA but
crash out on anything else in case something goes wrong.

: Another option is to open and read the catalog, locate the appropriate
: file and parse the length, so you know exactly how many bytes to expect.

Would work, but I don't want to write a directory parser for a one-shot
program...I mean, this is a 'Q&D' one-time conversion; if I get too fancy
with it I'll never manage to get the whole thing written!

: Yet another option is to get BASIC.SYSTEM to do a GET_EOF call for you,
: and PEEK out the resulting length from the parameter block in the
: BASIC.SYSTEM global page.  This parameter block is shared between
: several calls, so you need to time it right.

: It could be done with a small machine code routine which calls the
: kernel (or does it via BASIC.SYSTEM's system call function).

: After OPENing the file, try the following:

: POKE 48839,PEEK(48848): REM Copy the file reference number
: POKE 768,169: POKE 769,209: REM LDA #$D1 = GET_EOF
: POKE 770,32: POKE 771,112: POKE 772,190: JSR $BE70 = GOSYSTEM
: POKE 773,133: POKE 774,0: REM STA $00
: POKE 775,96: REM RTS
: CALL 768

: This will do a GET_EOF call on the file which was just OPENed, and store
: the error code in memory location 0 (0 if no error, else a normal
: BASIC.SYSTEM error code).

: If there was no error, you can now PEEK the 24-bit end of file value
: (file length) from locations 48840 (low byte) through 48842 (high byte).

Interesting.  Again, a little more complexity, though it would work. I
think I'll file this one away in my file of Stuff That David E. Has Showed
Me Over The Years for future reference... 8-)

: > Are the errir (Errir?  I think that's an Error #16* right there) codes the
: > same in BASIC.SYSTEM as under DOS 3.3?  I presume I still POKE 216,0 to
: > clear the error flag...

...And I forgot the footnote that indicates that Error #16 is a ?SYNTAX ERROR

: All the same.

THAT was the answer I was looking for.  My error code list is an old one.  8-)

: You should also use the stack cleanup code in either DOS 3.3 or PRODOS,
: or you could eventually get a stack overflow: this can be done with a
: CALL into Applesoft (-3288), and should be used unless you are going to
: RESUME.

Good point.  I usually don't bother 'cause I'm normally not processing too
terribly much, and Applesoft does its own cleanup when the program ends
(or is it when it starts, I can never remember...) but this time I'm
processing a quite a few files, so that's a good idea...

Thanks for the help!  I'll report back when the project is done!

--Dave Althoff, ][.
-- 
    /^\        _       _         *** Thanks for a great season!!! ***
   /XXX\      /X\     /X\_      _     /X\__      _     _        _____  
  /XXXXX\    /XXX\  _/XXXX\_   /X\   /XXXXX\    /X\   /X\      /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX