[comp.sys.apple] Applesoft in a 'B' file

SEWALL@uconnvm (08/06/87)

Oops! Sorry I was cryptic about what happens if you EXEC the
Executioner listing of CATALOG TO LABELS OR FILE that was
posted a couple of days ago.  What occurs is the file that
appears on a DOS 3.3 disk has a file type of 'B'  HOWEVER, if
you try and BRUN it, it'll crash.

An Applesoft file (file type of 'A') is just a special case of a
binary file (one the Applesoft interpreter understands).  Unfortunately,
the Applesoft interpreter will complain if you try and RUN or LOAD
a file that has a type of 'B.'  If you can change the byte in the
DOS 3.3 directory to make CATALOG TO LABELS OR FILE an 'A' (Applesoft)
file, you'll find that it IS exactly that (an Applesoft program file).

The problem, with the way the file was posted is downloading and
EXEC'ing that file isn't sufficient to produce a usable program, and
I suspect lots of readers of the list wouldn't trouble to find a way
to alter it.

The program is but a minor modification of one I posted awhile back
anyway.  What would be more interesting would be a DOS 3.3 version of
Executioner.  Whatever was used to produce the CATALOG TO.... post
ALMOST does the job.  A debugged version of a DOS 3.3 Executioner
(that starts lines with a # or whatever) is what I'm looking for here.

---------------------
ARPA:   sewall%uconnvm.bitnet@wiscvm.wisc.edu       Murphy A. Sewall
BITNET: SEWALL@UCONNVM                          School of Business Admin.
UUCP:   ihnp4!psuvax1!UCONNVM.BITNET!SEWALL     University of Connecticut

tjohnson@sds-intel01.UUCP (08/11/87)

In message <8708061350.aa25994@SMOKE.BRL.ARPA> SEWALL@uconnvm writes:

> An Applesoft file (file type of 'A') is just a special case of a
> binary file (one the Applesoft interpreter understands).  Unfortunately,
> the Applesoft interpreter will complain if you try and RUN or LOAD
> a file that has a type of 'B.'  If you can change the byte in the
> DOS 3.3 directory to make CATALOG TO LABELS OR FILE an 'A' (Applesoft)
> file, you'll find that it IS exactly that (an Applesoft program file).

Just changing the filetype byte in the DOS 3.3 catalog sector will not 
allow you to load a B file as an Applesoft program.  If the B file is a 
BSAVEd memory image of an Applesoft program, then you can recreate the 
Applesoft program but not by the method stated.  

When a B file is saved, four extra bytes are saved with the file (two 
for the load address and two for the length).  When a Applesoft program 
is saved, only two extra bytes are saved with the file (length of program 
only) since DOS 3.3 will always load an Applesoft program at $0801 
(actually, DOS uses the address stored in zero page at $67,$68 but that 
is usually $0801).  That difference will prevent you from just changing 
the catalog byte and loading the file.

It is possible to change the B file into an A file though.  Basically, the 
B file is BLOADed at memory location $801, the Applesoft end of program marks
and end of program pointer are set, and the program is SAVEd back to disk.  
Use the following steps to retrieve a BSAVEd memory image of an Applesoft 
file from a DOS 3.3 disk.

     1.  Find the length of the B file.  Use a program such as Copy II Plus if
you do not know the value.  Add the length to $0801 - this will be the program
end and we will need this value in a later step.

     2.  Boot DOS 3.3 or type "FP" to clear program memory if already booted.

     3.  Get into the monitor ("CALL -151")

     4.  Type "BLOAD <filename>,A$801".

     5.  The end of program marks for an Applesoft program are three 
consecutive $00 bytes.  Use the address calculated in step one and check 
memory to make sure that there are three $00 bytes before this memory 
location.  If not, use the monitor to put the extra $00 bytes into memory.  
Whether you had to add extra bytes or not, the address *after* these three 
$00 bytes is the important one.

     6.  The address found in step 5 is the true end of program.  DOS looks
for the end of program address for an Applesoft program in zero page at 
$AF,$B0.  Put the low byte in $AF and the high byte in $B0.

     7.  The last step is to type "SAVE <new.filename>" and the Applesoft
program will saved back to disk.

     8.  Do not try to run the program at this point or the system will hang
since other necessary pointers have not been initialized.  Just type "FP" and
then either "LOAD" or "RUN" the new program.
---------------------
        Todd Johnson
ARPA:   tjohnson@amc-hq

mat6013@DMZRZU71.BITNET (08/25/87)

Obviously the CATALOG TO LABELS OR FILE program wasn't textualized using a DOS
3.3  version  of the Executioner.  You can find this out if you have a look at
the hex code in the beginning of the text file; it's just the standart one for
ProDOS.   But  it  won't  EXEC  under  ProDOS  because  of the manualy changed
filename in the BSAVE statement at the end which causes a SYNTAX ERROR.  Using
DOS 3.3 the file will be saved (as type "B") but of course the "E00G" crashes.
To correctly EXEC it I suggest:

1)  Edit  the filename in the BSAVE statement from "CATALOG TO LABELS OR FILE"
   to just "CATALOG" (it was actually created using this one as you can see by
   dumping the hex code in the prologue),
2) EXEC it using ProDOS; you will get the BASIC program in a BAS file,
3) Convert this BASIC program to DOS 3.3.

                                        Matthias Kapffer
                                        <MAT6013@DMZRZU71.BITNET>