The heap limit is the demarcation point between the Main() task stack and the heap. The use of "Option HeapSize &Hffff" is treated as a special case to place the heap limit at the first byte of external RAM and the end of the Main() TCB will be right at the end of internal RAM. This is only useful, of course, for ZX devices that support external RAM.mikep wrote:How? What about an explicit placement of the heap i.e defining the size of RAM that can be used?
Otherwise, "Option HeapSize" is used to specify the size of the heap, in bytes. The end of the task stack for Main() is then located that many bytes from the end of RAM (internal + external, if any).
There are other methods to control the division of RAM between the Main() task stack and the heap. "Option MainTaskStackSize" is used if you want explicitly specify the size of the Main() task stack and dedicate the remaining RAM to the heap. Lastly, "Option HeapLimit" can be used to specify the address of the heap limit. This is likely to be seldom used but may be useful in special situations. There are also command line options that correspond to these directives.
The division of RAM between the Main() task stack and the heap is done in the call to taskStartMain() which is the last instruction in the C main() function that is generated. That system function prepares the Main() task (whose name is zf_main() or some variation thereof) for execution.