barrym95838 wrote:
Going back a tiny bit to the subject of "safe" zero-page locations. One possible technique is to simply save and restore the locations you wish to use on a per-subroutine basis. Sure, it costs several bytes and several cycles, but if it's done outside any high frequency loops, it can make your code a bit safer and more portable (as long as you don't get tangled up in any interrupt clashes, which is possible but would probably require a big dose of bad luck).
Code:
subroutine:
lda $02
pha
lda $03
pha
; ...
; the meat of your subroutine, which uses $02 and $03 as a temporary pointer
; ...
pla
sta $03
pla
sta $02
rts
Sure thing. That's exactly what I'm doing (minus the stack part).
I'm learning this by developing a simple tac tac toe game. So far I have it drawing the game screen and I can move a selection box around the playing area (to select a square for an X or O). Coming from a C++ background, this C64 assembly slaps me in the face every little bit. haha