Top Of Basic and related pointers

All aspects of programming on the Commander X16.
Post Reply
Martin Schmalenbach
Posts: 140
Joined: Tue Jul 21, 2020 10:08 pm

Top Of Basic and related pointers

Post by Martin Schmalenbach »

Hi

Where can I find what the Top Of. ASIC and related pointers are?

In the C64 they were locations 51 and 52 in decimal. By manipulating these it is possible to create a static area of string space that can be used to efficiently store temp strings for things like A$ = A$ + I$ where I$ is a single character input and the context for the code snippet is on building up a full line of input from a user and doing a character by character parse at the same time.

This generates a lot of garbage in terms of temporary strings and if using a lot of strings already, the string garbage collector can get VERY VERY slow… unless you trick it by manipulating the top of basic vector.

Cheers

Martin
User avatar
ahenry3068
Posts: 1146
Joined: Tue Apr 04, 2023 9:57 pm

Re: Top Of Basic and related pointers

Post by ahenry3068 »

Martin Schmalenbach wrote: Wed Apr 10, 2024 2:04 am Hi

Where can I find what the Top Of. ASIC and related pointers are?

In the C64 they were locations 51 and 52 in decimal. By manipulating these it is possible to create a static area of string space that can be used to efficiently store temp strings for things like A$ = A$ + I$ where I$ is a single character input and the context for the code snippet is on building up a full line of input from a user and doing a character by character parse at the same time.

This generates a lot of garbage in terms of temporary strings and if using a lot of strings already, the string garbage collector can get VERY VERY slow… unless you trick it by manipulating the top of basic vector.

Cheers

Martin
The MEMTOP ROM routine is what you want. ($FF99)

Carry Set. Returns Banked RAM in A
X,Y hold the pointer to MEMTOP

Carry Clear. Set the values in the A, X & Y



POKE C.REG,1:SYS $FF99:
LAST.BANK = PEEK(A.REG)
IF LAST.BANK=0 THEN LAST.BANK=256
LAST.BANK=LAST.BANK-1
GRAPH.BANK=LAST.BANK-11
Martin Schmalenbach
Posts: 140
Joined: Tue Jul 21, 2020 10:08 pm

Re: Top Of Basic and related pointers

Post by Martin Schmalenbach »

Is MEMTOP also the bottom of the BASIC string heap, which grows downwards in memory?

I was under the impression that BASIC didn’t make use of banked memory for variable storage.
User avatar
ahenry3068
Posts: 1146
Joined: Tue Apr 04, 2023 9:57 pm

Re: Top Of Basic and related pointers

Post by ahenry3068 »

Martin Schmalenbach wrote: Wed Apr 10, 2024 4:23 am Is MEMTOP also the bottom of the BASIC string heap, which grows downwards in memory?

I was under the impression that BASIC didn’t make use of banked memory for variable storage.
Yes MEMTOP is the address 1 byte above the last memory Address that BASIC will use for String storage. BASIC doesn't use Banked Ram for storage by default, But you can POKE & PEEK in Banked RAM. You can also SYS to ML Code in Banked RAM. So the ROM routine lets you know how much Banked RAM you have available. Since there's 256 possible Banks and you'll always have at least 64 banks 0 signifies 256 Banks available. BANKS are numbered 0-255.

MEMTOP with Carry clear sets what is reported, including Banked RAM. So always call it with Carry Set first to read in the current values. If you call it with a Random Value in .A that's whats going to be subsequently reported for BANKED Ram. (including programs after yours exits). Basic provides the BANK command to set what Bank is used for PEEKS, POKES and SYS to Banked addresses.

If your setting MEMTOP to keep string Garbage Collection from happening for some strings you can also Poke that string to Banked Ram and set the VARTAB to point at Banked Ram. In that case you then need to keep track of the VALUE set with BANK when accessing any String Variables you do that with.
User avatar
ahenry3068
Posts: 1146
Joined: Tue Apr 04, 2023 9:57 pm

Re: Top Of Basic and related pointers

Post by ahenry3068 »

BTW: The system ROM reserves RAM Bank 0 for it's own use. Consider it "Off limits" Only exception is the page BF00-BFFF in Bank 0 which is reserved for inter program communication / parameter passing.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Top Of Basic and related pointers

Post by funkheld »

Hi good afternoon.

Can you please provide an example of the basics of this interesting topic?
For me it's a long story that I don't understand.

Thanks.
greeting
User avatar
ahenry3068
Posts: 1146
Joined: Tue Apr 04, 2023 9:57 pm

Re: Top Of Basic and related pointers

Post by ahenry3068 »

I'm at work right now. Don't have access to my code to post.

Look at the program ZSMLOADER that's included in both HANGMAN and my BOOKS programs.

ZSMLOADER Uses MEMTOP to set MEMTOP to keep BASIC from molesting the memory used by ZSMKIT.

I believe in the version included with HANGMAN I'm calling it SETMEM rather than MEMTOP but its the same System Call.
Post Reply