BASIC high memory limit?

All aspects of programming on the Commander X16.
Post Reply
PaulForgey
Posts: 17
Joined: Tue Mar 12, 2024 3:12 am

BASIC high memory limit?

Post by PaulForgey »

Is it possible to tell the BASIC interpreter to use a maximum high address for variable storage? (like the Applesoft HIMEM:) I'd like to unit test some assembly modules that use this same area of memory for its own storage and not clash
TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Re: BASIC high memory limit?

Post by TomXP411 »

Yes, there's a way to set MEMTOP... I just don't remember how to do it. Let me check with @MooingLemur, who would know the answer to that one.
TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Re: BASIC high memory limit?

Post by TomXP411 »

10 POKE$30F,1:SYS$FF99 20 Y=$8C:X=$00 30 POKE$30D,X:POKE$30E,Y:POKE$30F,0:SYS$FF99 40 CLR

So the way this works: the MEMTOP function in KERNAL serves to both read and set the top of BASIC, as well as to set the number of available RAM banks. (64 or 256, depending on whether you have 512K or 2MB of extended RAM.)

Calling MEMTOP with the Carry flag set reads the values. Calling MEMTOP with the Carry flag clear sets the values.

So the process is to:
  1. Read the values
  2. Alter the top of BASIC (X and Y)
  3. Write them back
To see if this is working, you can add 2 more lines:

0 PRINT FRE(0) 50 PRINT FRE(0)
kelli217
Posts: 532
Joined: Sun Jul 05, 2020 11:27 pm

Re: BASIC high memory limit?

Post by kelli217 »

Also... lay out your memory the way you want to... but you should know, if you don't already, that the area from $0400 to $07FF is unused by the system (and is not needed for the memory map of the text screen like it was on the C64, because that's stored in VERA's own screen RAM), so could be used for up to 1KB of assembly code, binary variables, etc.
PaulForgey
Posts: 17
Joined: Tue Mar 12, 2024 3:12 am

Re: BASIC high memory limit?

Post by PaulForgey »

Thanks, in the time since I posted I found MEMTOP, but found creating a new variable and querying POINTER on it still shows an address above, yet fre(0) does reflect the new memtop setting. Even if I new NEW or CLR first.

Setting memtop=$7fff, if that matters.
PaulForgey
Posts: 17
Joined: Tue Mar 12, 2024 3:12 am

Re: BASIC high memory limit?

Post by PaulForgey »

Found my issue: using load "file",8,1 to an address above memtop leaves things in a very strange state. If I load my binaries and then set memtop, I appear OK
PaulForgey
Posts: 17
Joined: Tue Mar 12, 2024 3:12 am

Re: BASIC high memory limit?

Post by PaulForgey »

..and of course it would! I was stupidly unaware using ,1 still messes with BASICs internal pointers. So the variable space is left above the end of the loading, thus loading above memtop would do strange things.
User avatar
ahenry3068
Posts: 1144
Joined: Tue Apr 04, 2023 9:57 pm

Re: BASIC high memory limit?

Post by ahenry3068 »

PaulForgey wrote: Tue Mar 12, 2024 8:56 pm ..and of course it would! I was stupidly unaware using ,1 still messes with BASICs internal pointers. So the variable space is left above the end of the loading, thus loading above memtop would do strange things.
It's ok to use BLOAD above memtop. I usually use BLOAD if I'm loading binary assets.
TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Re: BASIC high memory limit?

Post by TomXP411 »

Yeah, you want to use BLOAD to load your ML routines. When you assemble them, assemble them as .BIN files without the 2 byte address pointer.
Post Reply