This was a good read, thank you to those who gave such well explained advice.
Allow me to ask a question: Like the OP, I dabble a bit with a simple project where I need to dynamically change memory addresses.
I want to print a series of characters on the screen starting with $0400 and ending with $07e7. To do that I have written four loops Right, down, left, up.
something like this
Code:
*=$1000
right:
lda #$d7 // petscii circle
sta $0400,x
inx
cpx #40 // max length of row.
bne right
That is not too hard, the X index stops at 40, but I struggle with the "down" bit
Code:
ldy #0
stx $1100
down:
lda #$d7 // petscii circle
sta $0400,x // X must increase 40 per cycle to print downwards in a line
lda $1100 //get the stored X value (should be 40 first pass)
adc #40
sta $1101 //
ldx $1100
iny
cpy #25 // with 25 rows this is the max
bne down
It works until x ($1100) reaches 255, then the x index flips because it has 8 bits only, and my whole little thing comes crashung down.
Could I change the routine so that I don't address $0400,x but increment the address itself that the petscii circle is stored to?