Latest release of ProDOS is 2.4.3

ProDOS 2.5 alpha 8 pre-release is available

TechRef - Memory Use

ProDOS 8 Technical Reference Manual Memory Use

This chapter explains the way the Machine Language Interface uses memory. It tells how much memory system programs have available to them, how system programs should manage this free memory, and it discusses the contents of important areas of memory while ProDOS is inn use.

3.1 - Loading Sequence

When you start up your Apple II from a ProDOS startup disk -- one that contains both the MLI (ProDOS) and a system program (XXX.SYSTEM) -- a complex loading sequence is initiated.

A preliminary loading program is stored in the read-only memory (boot ROM) on a disk drive's controller card; the main part of the loader program, as it is called, resides in blocks 0 and 1 of every ProDOS-formatted disk.

When you turn on your computer, or use a PR# or IN# command to reference a disk drive from Applesoft, or otherwise transfer control to the ROM on the disk-drive controller card when a ProDOS startup disk is in the drive, this is what happens:

  1. The program in the ROM reads the loader program from blocks 0 and 1 of the disk, places it into memory starting at location $800, and then executes it.
  2. This loader program looks for the file with the name PRODOS and type $FF (containing the MLI) in the volume directory of the startup disk, loads it into memory starting at location $2000, and executes it.
  3. The MLI ascertains the computer's memory size and moves itself to its final location, as shown in Figure 3-1. Next it determines what devices are in what slots and it sets up the system global page, described in the section "The System Global Page," for this system configuration.
  4. The MLI then searches the volume directory of the boot disk for the first file with the name XXX.SYSTEM and type $FF, loads it into memory starting at $2000, and executes it.

If PRODOS cannot be found, the loader reports to the user that it is unable to load ProDOS. If no XXX.SYSTEM program is found, ProDOS displays the message UNABLE TO FIND A SYSTEM FILE.

The rules for system programs are described in Chapter 5.

The MLI is entirely memory resident. Once it is in memory, it neither moves, nor does it require any additional disk accesses (although the system program might). The memory configuration that results from this loading process is described in the section "Memory Map."

3.2 - Volume Search Order

When a program or user requests access to a volume that ProDOS has not yet accessed, it must search through the volumes that are currently online for the requested volume. The order in which it searches the devices is determined during step 3 above.

The first volume checked is /RAM, if present, then the startup volume (generally slot 6, drive 1). The search then checks slots in descending slot order, starting with slot 7. In any slot, drive 1 is searched before drive 2.

For example, if there are two Disk II drives in slot 6, two Disk II drives in slot 5, and a ProFile in slot 7, the search order is:

/RAM Slot 6, drive 1 Slot 6, drive 2 Slot 7 Slot 5, drive 1 Slot 5, drive 2

The startup volume is the volume in the highest numbered slot that can be identified by the system as a startup volume. This sequence is kept in the device list in the ProDOS global page and can be altered.

Note: If the startup volume is a hard disk, the search order is from slot 7 to slot 1.

3.3 - Memory Map

ProDOS requires at least 64 kilobytes of memory. Figure 3-1 is the ProDOS memory map.

>

Figure 3-1. Memory Map

              Main Memory                                 Auxiliary Memory
                                                       (IIc or 128K IIe only)

 $FFFF+---------+$FFFF+---------+                $FFFF+---------+
      |.Monitor.|     |#########|                     |.........|
 $F800|---------|     |#########|                     |.........|
      |.........|     |#########|                     |.........|
      |.........|     |#########|                     |.........|
      |.........|     |#########|                     |.........|
      |.........|     |#########|                     |.........|
      |.........|     |#########|                     |.........|
      |.........|     |#ProDOS##|                     |.........|
      |Applesoft|     |#########|$DFFF+---------+$E000|---------|$DFFF+---------+
      |.........|     |#########|     |.........|     |         |     |.........|
      |.........|     |#########|     |.........|     |         |     |.........|
      |.........|     |#########|$D400|---------|     |         |     |.........|
      |.........|     |#########|     |#########|     |         |     |.........|
      |.........|     |#########|$D100|---------|     |         |$D100|---------|
      |.........|     |#########|     |         |     |         |     |         |
 $D000|---------|     +---------+     +---------+$D000+---------+     +---------+
      |..Other..|
 $C100+---------+
              ^  $BFFF+---------+                $BFFF+---------+
              |       |#########|                     |.........|
 This ROM area|  $BF00|---------|                $BF00|---------|
 on IIc and IIe       |\\\\\\\\\|                     |         |
 only!                |\\\\\\\\\|                     |         |     +---------+
                      |\\\\\\\\\|                     |         |     |#########|
                      |\\\\\\\\\|                     |         |     +---------+
                      |\\\\\\\\\|                     |         |     Used by ProDOS
                      |\BASIC.\\|                     |         |
                      |\SYSTEM\\|                     |         |
                      |\\\\\\\\\|                     |         |     +---------+
                      |\\\\\\\\\|                     |         |     |\\\\\\\\\|
                      |\\\\\\\\\|                     |         |     +---------+
                      |\\\\\\\\\|                     |         |     Used by
                      |\\\\\\\\\|                     |         |     BASIC.SYSTEM
                 $9600|---------|                     |         |
                      |         |                     |         |
                      |         |                     |         |     +---------+
                      |         |                     |         |     |.........|
                      |         |                     |         |     +---------+
                      |         |                     |         |     Other used or
                      |         |                     |         |     reserved areas
                      |         |                     |         |
                      |         |                     |         |
                      |         |                     |         |     +---------+
                      |         |                     |         |     |         |
                      |         |                     |         |     +---------+
                      |         |                     |         |      Free Space
                      |         |                     |         |
                      /\/\/\/\/\/                     /\/\/\/\/\/

                      /\/\/\/\/\/                     /\/\/\/\/\/
                      |         |                     |         |
                      |         |                     |         |
                      |         |                     |         |
                      |         |                     |         |
                      |         |                     |         |
                  $800|---------|                 $800|---------|
                      |.........|                     |.........|
                      |.........|                     |.........|
                      |.........|                     |.........|
                      |.........|                 $400|---------|
                      |.........|                     |#########|
                  $300|.........|                     |#########|
                      |.........|                     |#########|
                      |.........|                     |#########|
                      |.........|                 $200|---------|
                      |.........|                     |         |
                  $100|---------|                 $100|---------|
                      |         |                     |#########|
                      |         |                  $80|---------|
                   $4F|---------|                     |         |
                      |#Shared/#|                     |         |
                      |####safe#|                     |         |
                   $3A|---------|                     |         |
                      |         |                     |         |
                      +---------+                     +---------+
                   $00

A system program as large as $8F00 (36608) bytes can be loaded into a 64K system. The total amount of space available to a system program running on a 64K system is $B700 (46848) bytes.

3.3.1 - Zero Page

The ProDOS Machine Language Interface uses zero-page locations $40-$4E, but it restores them before it completes a call. The disk-driver routines, called by the MLI, use locations $3A through $3F. These locations are not restored. See Chapter 4 for details.

3.3.2 - The System Global Page

The $BF-page of memory, addresses $BF00 through $BFFF, contains the system's global variables. This section of memory is special because no matter what system ProDOS is booted on, the global page is always in the same location. Because of this it serves as the communication link between system programs and the operating system. The MLI places all information that might be useful to a system program in these locations. These locations are defined and described in Chapter 5.

3.3.3 - The System Bit Map

ProDOS uses a simple form of memory management that allows it to protect itself and the user's data from being overwritten by ProDOS buffer allocation. It represents the lower 48K of the Apple II's random-access memory using twenty-four bytes of the system global page: one bit for each 256-byte page of RAM in the lower 48K of the Apple II. These twenty-four bytes are called the system bit map.

When ProDOS is started up, it protects the zero page, the stack, and the global page, by setting the bits that correspond to the used pages. If at all possible, a system program should not use pages of memory that are already used. If this is not possible, the system program must close all files and clear the bit map, leaving pages 0, 1, 4 through 7, and BF (zero page, stack, text, and ProDOS global page) protected. If an error occurs on the close, the program should ask the user to restart the system. See Chapter 5 for details.

While a system program is using the MLI, there are only three calls that affect the setting of the bit map: OPEN, CLOSE, and SET_BUF. When the system program opens a file, it must specify the starting address of a 1024-byte file buffer. As long as the file is open, this buffer is a part of the system, and is marked off in the bit map. When the file is closed, the buffer is released, and its bits are cleared.

In general, a system program requires the used pages of memory to be contiguous, or touching. This leaves the maximum possible unbroken memory space for the reading and manipulation of data. Suppose a system program opens several files and then closes the one that was opened first. In most cases, this causes a vacant 1K area to appear. The GET_BUF and SET_BUF calls can be used to find this vacant area, and to move another file's buffer into this space.

Refer to Chapter 5 for a specific example of using the system bit map.