ProDOS 8 system programs are always loaded to the start address $2000. For cc65 programs this means that the 6 KB from $800 to $2000 are by default unused. There are however several options to make use of that memory range.
The easiest (and for really large programs in fact the only) way to have a cc65 program use the memory from $800 to $2000 is to link it as binary (as opposed to system) program using the linker configuration apple2enh-loader.cfg with start address $800 and load it with LOADER.SYSTEM - an Apple ][ ProDOS 8 loader for cc65 programs. The program then works like a system program (i.e. quits to the ProDOS dispatcher).
Using LOADER.SYSTEM is as simple as copying it to the ProDOS 8 directory of the
program to load under name <program>.SYSTEM as a system program. For
example the program MYPROG
is loaded by MYPROG.SYSTEM
.
If the cc65 program can be successfully linked as system program using the linker
configuration
apple2enh-system.cfg but
uses the heap either explicitly or implicitly (i.e. by loading a driver) then
the memory from $800 to $2000 can be added to the heap by calling
_heapadd ((void *) 0x0800, 0x1800);
at the beginning of main()
.
ProDOS 8 requires for every open file a page-aligned 1 KB I/O buffer. By default
these buffers are allocated by the cc65 runtime system on the heap using
posix_memalign()
. While this is generally the best solution it means quite
some overhead for (especially rather small) cc65 programs which do open files
but don't make use of the heap otherwise.
The apple2enh package comes with the alternative ProDOS 8 I/O buffer allocation
module apple2enh-iobuf-0800.o
which uses the memory between $800 and
the program start address for the 1 KB I/O buffers. For system programs (with
start address $2000) this results in up to 6 I/O buffers and thus up to 6
concurrently open files.
While using _heapadd()
as described in the section above together with the
default I/O buffer allocation basically yields the same placement of I/O buffers
in memory the primary benefit of apple2enh-iobuf-0800.o
is a reduction in code
size - and thus program file size - of more than 1400 bytes.
Using apple2enh-iobuf-0800.o
is as simple as placing it on the linker command
line like this:
cl65 -t apple2enh -C apple2enh-system.cfg myprog.c apple2enh-iobuf-0800.o