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
Top Of Basic and related pointers
-
- Posts: 140
- Joined: Tue Jul 21, 2020 10:08 pm
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: Top Of Basic and related pointers
The MEMTOP ROM routine is what you want. ($FF99)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
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
-
- Posts: 140
- Joined: Tue Jul 21, 2020 10:08 pm
Re: Top Of Basic and related pointers
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.
I was under the impression that BASIC didn’t make use of banked memory for variable storage.
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: Top Of Basic and related pointers
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.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.
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.
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: Top Of Basic and related pointers
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.
Re: Top Of Basic and related pointers
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
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
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: Top Of Basic and related pointers
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.
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.