Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Do you maximize Zero Page usage?
2024-05-10 19:07
Mr SQL

Registered: Feb 2023
Posts: 122
Do you maximize Zero Page usage?

I like to use as much of the Zero Page as possible.

The zero page is effectively fast RAM, many cycles are saved that add up with frequent access for a faster codebase.

I had good habits maximizing zero page usage on the Atari and also via the 6809 in the Color Computer which had a great feature of a movable zero page window (immediate/direct page) that can slide anywhere in memory. I've been reading about a similar feature on the C128.

There's all kinds of stuff crowding the Zero Page on the C64 including a Tape I/O routine that is there because it needs to be fast.

Aside from locations 0 and 1 nearly all of the zero page can be freed by locking out the BASIC ROM and Kernel.
 
... 10 posts hidden. Click here to view all posts....
 
2024-05-14 02:36
serato

Registered: Feb 2021
Posts: 7
Quoting TBH
I assign ZP labels to successive locations in defined ranges to avoid clashes

Good assemblers have a feature to do this for you. I used to use ACME with a macro to automate, now I use 64tass which has it built in, e.g.
* = $20
atemp	.byte ?
xtemp	.byte ?
ytemp	.byte ?
zarray	.fill 10
2024-05-14 09:58
ChristopherJam

Registered: Aug 2004
Posts: 1391
Yes, that's what ca65's segments are for.

Cool thing is if you use different segment names for different groups of variables you can move entire groups into or out of zero page just with a change to mem.cfg, if you start running low on space in zp and want to see which groups are most important to have fast access to :)

(obviously you have to be careful about zp pointers, but for more general state this is excellent)

    .segment "SONGSTATE"
note:   .byte 0
phrase: .byte 0
    .segment "DECRUNCHPTRS"
zpsp:   .word 0
zpdp:   .word 0

    .segment "CODE"
play:
    ldx#14
voiceloop:
2024-05-14 10:54
Bitbreaker

Registered: Oct 2002
Posts: 501
Zeropage is nice to store variables there, also nice to place code there to suplement indirect indexed addressing. Variables can be written to immidiate values with self modifying code. Overall, if you have code that is heavily modified, it is placed well in the zeropage. Some illegals (SAX $xx,y) are there for zeropage adressing too, what is nice.
Zeropage is often crammed, if code does not fit, it can easily extend into stack or accessed in a loop from $ffxx, as you can also branch into ZP from there upon the wrapping of the PC.
If it is about saving codesize, it is also okay to place data structures in the ZP, as lda/sta (even indexed) is 2 bytes only.
I never struggle about sharing ZP with floppy ROM, Kernal, Basic, as all that is disabled and not used by me.
2024-05-14 20:03
HBH.ZTH

Registered: Jul 2006
Posts: 10
Quote: I’m using zero page memory for time-critical applications like a sorting sprite multiplexer or whenever I need a (zp),y indirect addressing. Other than that, I’m rather trying to avoid it because the zeropage can also be a minefield, especially when you use some Kernal functions in your code or, even worse, the floating point routines (luckily, I sparsely need them).
So if it is not necessary to save that one cycle for handling a variable, I avoid putting it in zeropage. In many cases, using self-modifying code is equally fast.


If it turn into a minefield: Turn off the kernal. Do your own kernal routines if you need them. Get The Whole Memory Map by Melbourne House (large book), it has all the memory locations from $0000-$FFFF. Incl. basic + kernal memory, listed as code with comments, so it's easy to know what each jump vector does or goes to. If it communicate with IO devices, soft-reset, does legwork for basic commands, etc.
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Matt
psenough
The Syndrom/TIA/Pret..
Lord Crucifier/SCS*TRC
Fred/Channel 4
t0m3000/HF^BOOM!^IBX
tlr
WVL/Xenon
Didi/Laxity
REBEL 1
Guests online: 77
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 No Bounds  (9.6)
9 Aliens in Wonderland  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Dawnfall V1.1  (9.5)
8 Birth of a Flower  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Offence  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 Tim  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.036 sec.