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

Re: Memory Use in a ][+? (or how much is left?)



In article <carndtCwAnyv.C0D@netcom.com> carndt@netcom.com (Chris Arndt) writes:
>I recently revived one of my ][+s for a project. My program moves DOS to
>the language card (David-DOS), loads several (6) binary files and a small
>text file, and waits for input from a card. I would like to add some more
>functions to the program. How can I tell how much memory I have left, as
>I don't want the binaries to overwrite the Applesoft?

In your Applesoft code, just say X =  FRE (0).  This will garbage-collect
the string space, and return with the number of free bytes in X.

In machine language, you need to look at the Applesoft zero-page pointers.
Here are the important ones:

     Location  Name      Purpose
     --------  ----      -------
     $67,$68   TXTTAB    Start of program
     $AF,$B0   PRGEND    End of program
     $69,$6A   VARTAB    LOMEM, beginning of simple variable space
     $6B,$6C   ARYTAB    End of simple vars and beginning of arrays
     $6D,$6E   STREND    End of arrays
     $6F,$70   FRETOP    Bottom of string space
     $73,$74   MEMSIZ    HIMEM, top of string space

All the memory from the location pointed to by STREND to the location
pointed to by FRETOP are free.  You probably don't want to put stuff near
FRETOP, though, because FRETOP moves down whenever you do string
operations.  Right above STREND is a little better, but only after ALL the
variables your Applesoft code needs have already been allocated (otherwise
references to new variables will move STREND upward, possibly colliding
with your machine code if you're not careful).

Much safer than hiding stuff in Applesoft's free space is hiding it above
HIMEM, or below (or even inside) the Applesoft program.

The HIMEM technique:  In DOS 3.3, move HIMEM down far enough to make room
for your code, and load the code directly above HIMEM, and don't change
MAXFILES after loading your machine code.  In ProDOS, move HIMEM down by an
exact multiple of 256 bytes, and load your code four pages (1024 bytes)
above your new HIMEM (don't OPEN any files until after HIMEM is changed, or
ProDOS could get really confused).

The below-the-Applesoft-program technique:  Raise the start-of-program
pointer far enough to make room for your machine code, by poking the new
value into TXTTAB.  Poke a zero byte into the memory location just prior to
the new start-of-program location, and LOAD your Applesoft code.  Then load
your machine code at $800.

               - Neil Parker
--
Neil Parker                 No cute ASCII art...no cute quote...no cute
nparker@cie-2.uoregon.edu   disclaimer...no deposit, no return...
nparker@cie.uoregon.edu     (This space intentionally left blank:           )