Code: Select all
---+-----+----+----------+----------+-------+-------+-----+---+---+------------+
...|INPUT| NL | Temporary|Calculator| SPARE |Machine|GOSUB| ? |3Eh|User-Defined|
...| data| |work space| stack | | stack |stack| ? | | Graphics |
---+-----+----+----------+----------+-------+-------+-----+---+---+------------+
| | | | | | |
WORKSP STKBOT STKEND sp RAMTOP UDG P_RAMT
The area between WORKSP and RAMTOP, is it actually unused unless BASIC code is running? Well, except the CPU stack, but we’ll get to that later. It looks like after NEW, LOAD “”, and even RUN, WORKSP==STKBOT==STKEND, which means entire area between WORKSP and SP is unused, right? And that’s what BC_SPACES call does, allocates a chunk in that area. Also, BC_SPACES crashes hard (exists to BASIC) if you request more than available. And somehow adds 80 bytes to the number your requesting, for whatever reason. Considering all that, how do I estimate the amount of “available” memory there? Basically RAMTOP-STKEND-something would give a rough estimate, but how do I measure/estimate that something? A few bytes, kilobyte, several Kbytes? That something is Z80 stack + GOSUB stack + that mysterious “?”.
There is “FREE MEMORY” routine at 0x1f1a, is that the one I am looking for?
And a few questions to understand the map better:
1. What’s that “?” between “GOSUB stack” and RAMTOP?
2. GOSUB stack, it’s above Z80 stack? Growing it should be expensive… But, anyway, unless BASIC is in the middle of a SUBroutine, GOSUB stack should be 0, right?
3. What would be a safe estimate for the maximum Z80 stack size, used by BASIC? Using FUSE’s built in debugger I can see that SP points to 12 bytes below RAMTOP, when sitting at the prompt, and 18 bytes below when entering code via USR addr.
Similar questions about the area above RAMTOP:
1. What’s the purpose of that “3Eh” between RAMTOP and UDG area?
2. UDG area can only be moved explicitly, right? Unless something modifies UDG sys var, it just stays 8*21 bytes below P_RAMT, right?
Thanks!
P.S. The goal is to allocate a large chunk of memory in your machine code without asking user to explicitly set RAMTOP.