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.
2024-05-10 20:13
wil

Registered: Jan 2019
Posts: 46
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.
2024-05-10 21:32
Oswald

Registered: Apr 2002
Posts: 5032
instead of "maximizing zeropage usage" it makes more sense to step back and look at which routine runs the most and how you can optimize it best. or step back even more, is your algorithm optimal ?
2024-05-11 07:04
mutetus

Registered: Dec 2020
Posts: 12
My life was miserable. Then I found zero page and now I use it every day!
2024-05-11 09:19
Scrap

Registered: Jan 2021
Posts: 14
I like to use it for small snippets of code like intro-sized loops for an effect to save some cycles…
2024-05-11 15:01
Frostbyte

Registered: Aug 2003
Posts: 174
I don't really maximise its use, but rather use it when appropriate. If, for example, I have a variable which is accessed from many places in the code, zp makes sense. But if I have a variable which is stored rarely but needed often in a single place in code, it's worth storing it directly as the value in e.g. lda #imm.
2024-05-11 15:44
Jetboy

Registered: Jul 2006
Posts: 238
Maximizing zeropage usage is waste of time if it is not required.
2024-05-12 05:12
Martin Piper

Registered: Nov 2007
Posts: 649
Most of the library routines I write have the option of moving some or all of their working memory to defined addresses, which can be in zeropage, or using inline storage which is often (but not always) in other RAM.
2024-05-12 05:23
chancer

Registered: Apr 2003
Posts: 346
i think the term "selective usage" is fair to say, like anything there are pros and cons.

I remember finding a life counter for a game.. and next door to it was the energy counter.. which someone , much to the amazement of a far far better coding person that will remain nameless didn't check :D

still sticks in my memory many moons later
2024-05-13 04:11
TBH

Registered: Mar 2010
Posts: 21
When it makes sense, such as when moving frequently-used variables to ZP reduces the code size, and where globally-accessed variables are used in tight fast loops. Also, small code loops get located in ZP if it shaves off a few more cycles.

I assign ZP labels to successive locations in defined ranges to avoid clashes, like:

zBase = $80
zBase_Current = zBase + 0

; General Storage
zwStore_0 = zBase_Current
zwStore_1 = zwStore_0 + 2
zb_Store_0 = zwStore_1 + 2
zBase_Current = zb_Store_0 + 1
...
; Graphics Lib
zPenColour = zBase_Current
zPaperColour = zPenColour + 1
zBase_Current = zPaperColour + 1
...


If the ROMs will be used, the ZP ranges being clobbered have to be stored-restored in some way.
2024-05-13 08:27
cadaver

Registered: Feb 2002
Posts: 1154
You can use most of the zeropage even with Kernal IO routines without storing / restoring. Assuming Kernal disk load/save will be used, I've gotten used to using (in a game scenario)

$02-$8f
$91-$93
$9c-$a2
$a6-$b6
$bd-$ff
 
... 4 posts hidden. Click here to view all posts....
 
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
csabanw
Alakran_64
Sabbi/Hokuto Force
Smasher/F4CG
WVL/Xenon
t0m3000/HF^BOOM!^IBX
JLD/Finnish Gold
Didi/Laxity
macx
CA$H/TRiAD
Guests online: 83
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.7)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 No Bounds  (9.6)
9 Wonderland XIV  (9.6)
10 Aliens in Wonderland  (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 Original Suppliers
1 Black Beard  (9.7)
2 Derbyshire Ram  (9.5)
3 hedning  (9.2)
4 Baracuda  (9.1)
5 Jazzcat  (8.6)

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