Just wondering if anyone knows how to get a block of free memory temporarily when an RSX is called. Obviously, I don't want to permanently reserve memory for a temporary buffer, but there's not enough space on the stack for the data I need to store.Basically, what I need is the last byte used by the BASIC runtime and the value of HIMEM. According to http://cpcrulez.fr/firmware.txt (http://cpcrulez.fr/firmware.txt) these seem useful:
&AE5E ³ &AE7B ³ 2 ³ HIMEM (set by MEMORY)
&AE6C ³ &AE89 ³ 2 ³ address of start of free space (wherenext Array entry is placed)
But obviously, this relies on also working out what version of BASIC is running and then looking in the correct places.Also, some initial analysis shows that the strings are stored just below HIMEM (pointed to at &AE5E), so that can't be considered the last free byte. The area pointed to by &AE6C does seem free, but I'm not sure if that's the correct thing to do. Obviously, I'm still not sure how much memory I can allocate either...So, I thought I'd ask you lot if this problem has already been solved, because I'm sure it must have been! Can anyone point to any source, preferably one that auto-detects which version of BASIC is being used.
EDIT: Maybe this is the variable I need to look at?
&B071 ³ &B08D ³ 2 ³ address of end of free space (the byte before the Strings area)
&B073 ³ &B08F ³ 2 ³ address of end of Strings area (=HIMEM)
If anyone's interested, this is what I've come up with. I'd appreciate comments though if people think it won't work:
do_mem_info:
ld c,-1
try_next_rom: ; increment count and test next rom
inc c
ld a,#10
cp c
ret z
call #b915 ; kl probe rom
cp #80 ; foreground and BASIC
jr nz,try_next_rom
ld a,l ; check version number is 1
dec l
jr nz,try_next_rom
ld a,h ; mark (subversion) is 0=464, 1=664, 2=6128
or a
push af ; zero flag set if 464
ld hl,mem_info1_msg
call print
pop af
push af
ld hl,#ae89 ; holds lowmem on 464
jr z, lowmem_464
ld hl,#ae6c ; holds lowmem on 664/6128
lowmem_464:
call outhex_hlhl
ex de,hl
ld hl,mem_info2_msg
call print
pop af
ld hl,#b08d ; holds himem-strings on 464
jr z, himem_464
ld hl,#b071 ; holds himem-strings on 664/6128
himem_464:
call outhex_hlhl
and a
sbc hl,de
inc hl
push hl
ld hl,mem_info3_msg
call print
pop hl
call outhex_hl
ld hl,mem_info4_msg
jp print
mem_info1_msg: defb "Free memory &",0
mem_info2_msg: defb " - &",0
mem_info3_msg: defb " (&",0
mem_info4_msg: defb " bytes)",13,10,0
One thing I'm suspicious of is if an RSX is launched from a non-BASIC foreground ROM...