!pr2
Put DOS and ProDOS Files on Same Disk......Bob Sander-Cederlof

In the February 1985 issue of AAL I showed how to create a DOS-less DOS 3.3 data disk.  Tracks 1 and 2, normally full of the DOS image, were instead made available for files.  Booting the disk gets you a message that such a disk cannot be booted.

Now that we are publishing more and more programs intended for use under ProDOS, we foresee the need to publish Quarterly Disks that contain both DOS and ProDOS programs.  Believe it or not, this is really possible.

The DOS operating system keeps its Volume Table of Contents (VTOC) and catalog in track $11.  The VTOC is in sector 0 of that track, and the catalog normally fills the rest of the track.  A major part of the VTOC is the bit map, which shows which sectors are as yet unused by any files.  If we want to reserve some sectors for use by a ProDOS directory on the same disk, we merely mark those sectors as already being in use in the DOS bit map.

ProDOS keeps its directory and bit map all in track 0.  This track is not available to DOS for file storage anyway, so we can be comfortable stealing it for a ProDOS setup on the same diskette.

I decided to keep things fairly simple, by splitting the disk into two parts purely on a track basis.  ProDOS gets some number of tracks starting with track 0, and DOS gets all the tracks from just after ProDOS to track 34.  If ProDOS gets more than 17 tracks, it will hop over track $11 (since DOS's catalog is there).  Normally I will split the disk in half, giving tracks 0-16 to ProDOS and tracks 17-34 to DOS.  With this arrangement, ProDOS thus starts with 129 free blocks, and DOS starts with 272 free sectors.

The program I wrote does not interact with the user; instead, you set all the options by changing the source code and re-assembling.  It would be nice to have an interactive front end to get slot, drive, volume number for the DOS half, volume name for the ProDOS half, and how many tracks to put in each half.  Maybe we'll add this stuff later, or maybe you would like to try your hand at it.

The parameters you might want to change are found in lines 1020-1050.  You can see that I started the DOS allocation at track $12, just after the catalog track.  I also chose volume 1, drive 1, slot 6.  You can use any volume number from 1 to 254.  Since these numbers were under my control, I did not bother to check for legal values.  If we add an interactive front end, we will have to validate them.  We might also want to display the number of ProDOS blocks and DOS sectors that result from the DOS.LOW.TRACK selection, maybe in a graphic format.  You might even use a joystick or mouse....

You might also want to change the ProDOS volume name.  I am calling it "DATA".  The name is in line 2850.  It can be up to 15 characters long, and the number of characters must be stored in the right nybble of the byte just before the name.  This is automatically inserted for you, by the assembler.  If you should try to assemble a name larger than 15 characters, line 2870 will cause a RANGE ERROR.  Another way of changing the ProDOS volume name is to do so after initialization using the ProDOS FILER program.

Lines 1090 and 1100 compute the number of free DOS sectors and ProDOS blocks.  The values are not used anywhere in the program, but are nice to know.

Line 1300 sets the program origin at $803.  Why $803, and not $800?  If we load and run an assembly language program at $800, and then later try to load and run an Applesoft program, Applesoft can get confused.  Applesoft requires that $800 contain a $00 value, but it does not make sure it happens when you LOAD an Applesoft program from the disk.  By putting our program at $803 we make sure we don't kill the $00 and $800.  Well, then why not start at $801?  I don't know, we just always did it that way.  (It would make good sense if our program started by putting $00 in $801 and $802, indicating to Applesoft that it had no program in memory.)

DOUBLE.INIT is written to run under DOS 3.3, and makes calls on the RWTS subroutine to format and write information on the disk.  The entire DOUBLE.INIT program is driven by lines 1320-1490.  The flow is very straightforward:

       1.  Format the disk as 35 empty tracks.
       2.  Write DOS VTOC and Catalog in track 17.
       3.  Write ProDOS Directory and bit map in track 0.
       4.  Write "YOU CANNOT BOOT" code in boot sector.

Formatting a blank disk is simple, unless you have a modified DOS with the INIT capability removed.  Lines 1510-1590 set up a format call to RWTS, and fall into my RWTS caller.

Lines 1600-1800 call RWTS and return, unless there was an error condition.  If there was an error, I will print out "RWTS ERROR" and the error code in hex.  The error code values you might see are:

       $08 -- Error during formatting
       $10 -- Trying to write on write protected disk
       $40 -- Drive error

I don't think you can get $20 (volume mismatch) or $80 (read error) from DOUBLE.INIT.  After printing the error message, DOS will be warm started, aborting DOUBLE.INIT.

Building the DOS VTOC and Catalog is handled by lines 1820- 2310.  The beginning section of the VTOC contains information about the number of tracks and sectors, where to find the catalog, etc.  This is all assembled in at lines 2260-2310, and is copied into my buffer by lines 1880-1930.  Since the volume number is a parameter, I specially load it in with lines 1940 and 1950.  The rest of the VTOC is a bit map showing which sectors are not yet used.  Lines 1960-2090 build this bit map.  Lines 1840-1870 and 2100-2120 cause the VTOC image to be written on track 17 ($11) sector 0.

There are some unused bytes in the beginning part of the VTOC, so I decided to put some private information in there.  See line 2270 and line 2290.

The rest of track 17 is a series of empty linked sectors comprising the catalog.  The chain starts with sector $0F, and works backward to sector 1.  Lines 2130-2240 build each sector in turn and write it on the disk.

The ProDOS directory and bit map are installed in track 0 by lines 2330-2900.  This gets a little tricky, because we are trying to write ProDOS blocks with DOS 3.3 RWTS.  Here is a correspondence table, showing the blocks and sectors in track 0:

       ProDOS Block:  0   1   2   3   4   5   6   7
    DOS 3.3 Sectors: 0,E D,C B,A 9,8 7,6 5,4 3,2 F,1

The first sector of each pair contains the first part of each block, and so on.

The ProDOS bit map goes in block 6, which is sectors 3 and 2.  Even if we had an entire diskette allocated to ProDOS the bit map would occupy very little of the first of these two sectors.  Since formatting the disk wrote 256 zeroes into every sector, we can leave sector 2 unchanged.  Lines 2700-2820 build the bit map data for sector 3 and write it out.  Note that block 7 is available, all blocks in track 17 are unavailable.

The ProDOS Directory starts in block 2.  The first two bytes of a directory sector point to the previous block in the directory chain, and the next two bytes point to the following block in the chain.  We follow the standard ProDOS convention of linking blocks 3, 4, and 5 into the directory.  Those three blocks contain no other information, since there are as yet no filenames in the directory.  Here's how the chain links together:

               Previous  Next
                Block   Block
       Block 2:   0       3   (zero means the beginning)
       Block 3:   2       4
       Block 4:   3       5
       Block 5:   4       0   (zero means the end)

Block 2 gets some extra information, the volume header.  Lines 2840-2900 contain the header data, which is copied into my buffer by lines 2590-2630.

The no-booting boot program is shown in lines 3000-3190.  This is coded as a .PHase at $800 (see lines 3010 and 3190), since the disk controller boot ROM will load it at that address.  All the program does is turn off the disk motor and print out a little message.  Lines 1410-1490 write this program on track 0 sector 0.

I think if you really wanted to you could put a copy of the ProDOS boot program in block 0 (sectors 0 and E).  Then if you copied the file named PRODOS into the ProDOS half of the disk, you could boot ProDOS.

There is one thing to look out for if you start cranking out DOUBLE DISKS.  There are some utility programs in existence which are designed to "correct" the DOS bitmap in the VTOC sector.  Since these programs have never heard of ProDOS, let alone of DOUBLE DISKS, they are going to tell DOS that all those tracks we carefully gave to ProDOS belong to DOS.  If you let that happen to a disk on which you have already stored some ProDOS files, zzzaaaapppp!
