[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String storage
In article <3fksjk$3k1@lastactionhero.rs.itd.umich.edu>,
Sean Michael McAfee <mcafee@umich.edu> wrote:
>
> A problem arose after I had BSAVEd one short program, and found that the
> majority of the binary file was composed of the same characters as on the
> keypad. Only the final part of the file had the correct values. I
> surmised that the file I was trying to create occupied the same space
> that ProDOS uses for string storage--it began at $4080.
>
> Is my conclusion correct?
Probably. Applesoft stores its strings from the top of available
memory (HIMEM) and works back down as more strings are used. Old
strings are not removed until a garbage collection is performed. This
will happen automatically if all the string space has been used up, or
if you use the FRE command. ProDOS BASIC might do an automatic garbage
collection in some cases.
The space above LOMEM (which is set to the end address of the BASIC
program by default) is used to hold integer and floating point
variables, string variable descriptors and arrays. This will grow up
in memory as new variables are created.
In this case, you should use the LOMEM command to protect the area of
memory where the binary data is being POKEd. This will prevent any
variables or strings overwriting the area you're using.
It isn't generally safe to play with HIMEM under ProDOS, because
BASIC.SYSTEM uses it to position new I/O buffers. If you really have
to change HIMEM, make sure it is a multiple of 256, and be aware that
BASIC will move HIMEM down whenever it needs a file buffer.
It is easier to use LOMEM, which is not affected by BASIC.SYSTEM.
The important rule to keep in mind with these commands is to use them
BEFORE you create any variables. I usually put a LOMEM statement on
the first line in the program (after any REMs).
If you need to protect the memory area from $4080 to $41FF, you will
have to set LOMEM to at least 16896 ($4200). For a larger binary
buffer, you will need to set LOMEM higher, as required.
Work out the last address that will be needed, then set LOMEM at least
one byte higher than that.
Here is an example:
10 LOMEM:16896
Another possible solution is to use the FRE command to force garbage
collection earlier. The ProDOS FRE command is much faster than
BASIC's built-in one. It is used as follows. I'm assuming you have a
D$ variable which is set to CHR$(4).
1000 PRINT D$;"FRE"
This will perform a garbage collection, removing any unused old
strings and compacting the used ones back up to high memory.
--
David Empson
dempson@actrix.gen.nz
Snail mail: P.O. Box 27-103, Wellington, New Zealand