I'm porting some C code over from HTC that uses TPA memory for the VIC chip. In HTC it was pretty easy since the heap started at the end of the program and grew towards the bottom of the TPA. I could just malloc what I needed to protect that block of memory.
I'm trying to figure out the z88dk memory model (classic). It appears from my tests that the heap starts near the bottom of the TPA and grows towards the top of the TPA (backwards from HTC). I'd like to know where the stack is and any other sections. Or is it better to just go newlib sections?
CP/M memory organization
Re: CP/M memory organization
Hoping RAM model is what CP/M uses? https://github.com/z88dk/z88dk/wiki/New ... e-compiler
Re: CP/M memory organization
As we found out in an earlier topic, the allocation within the heap starts at the top of the memory allocated for it. Stack by default starts from just below bdos.
The following pragmas should allow you to size and position the heap to avoid the fixed address you're using:
(from https://github.com/z88dk/z88dk/wiki/Classic--Pragmas)
That page also specifies the order of the sections, +cpm uses the RAM model.
The following pragmas should allow you to size and position the heap to avoid the fixed address you're using:
(from https://github.com/z88dk/z88dk/wiki/Classic--Pragmas)
That page also specifies the order of the sections, +cpm uses the RAM model.
You do not have the required permissions to view the files attached to this post.
Re: CP/M memory organization
Let me be more specific, Let's say code+data is 0x0100 - 0x3ff and If set my VIC bank to 0x4000 - 0x7fff, then I could start heap at 0x8000 with a size of 16K, so it would start at 0xbfff and work back to 0x08000? I'm already setting the stack size to 1024.
So on C128 CP/M:
0100-E9FF 58 k transient program area (TPA) DEC and MAY versions (0100-EDFF 59 k TPA on AUG version)
E000-FFFF common with BANK 0 (top of TPA, also BDOS, BIOS, etc.)
So stack would start somewhere below 0xe000?
So on C128 CP/M:
0100-E9FF 58 k transient program area (TPA) DEC and MAY versions (0100-EDFF 59 k TPA on AUG version)
E000-FFFF common with BANK 0 (top of TPA, also BDOS, BIOS, etc.)
So stack would start somewhere below 0xe000?
Re: CP/M memory organization
Okay, so specific, do this to give you a 16k heap at 0x8000:
The stack will be at the top of TPA (actually the address of bdos), so with a 58k TPA it'll end up in the $E000-$FFFF range.
Assuming you limit your program to < ~16k you'll get the memory map you want.
Code: Select all
// zcc +cpm heap.c
long heap = 0;
int main()
{
sbrk(0x8000, 0x4000);
}
Assuming you limit your program to < ~16k you'll get the memory map you want.
Re: CP/M memory organization
So I'm wondering if I can simplify with:
#pragma output CRT_STACK_SIZE = 1024
// Protect VIC memory < 0x8000
#pragma CRT_HEAP_ADDRESS = 0x8000
So I can have max heap. i.e. I don't want to worry about size, just use what's free.
#pragma output CRT_STACK_SIZE = 1024
// Protect VIC memory < 0x8000
#pragma CRT_HEAP_ADDRESS = 0x8000
So I can have max heap. i.e. I don't want to worry about size, just use what's free.
Re: CP/M memory organization
Yes, that would work (note the output parameter on the CRT_HEAP_ADDRESS) line:
Code: Select all
#pragma output CRT_STACK_SIZE = 1024
// Protect VIC memory < 0x8000
#pragma output CRT_HEAP_ADDRESS = 0x8000