Suppose you have a single byte value you'd like to write to successive locations in PPU memory. Assuming that PPUADDR ($2006) has already been set, bit 2 of PPUCTRL ($2000) = 0 (i.e. VRAM address increment = 1) and zpBuffer is a zero page variable, the code might look something like this:
Now suppose you want to do the same thing, only this time with a repeating word value (2 bytes). Then you might throw the X register into the mix:
And if you really want to get crazy, there's even the Y register for those wacky repeating 3-byte sequences:
My question is this: What's the most optimal way (fewest cycles) to extend the above pattern beyond 3-byte sequences? The best I can think of is to use a single LDX and LDY statement to hold 2 of the values, then use as many LDA statements (zero page) as necessary for the remaining values.
I originally thought it would be cool to set up the buffer at the bottom of the stack (say, $100-$10F), then repeatedly "pull" successive values into PPUDATA. But alas, it doesn't seem like it's possible to pull values directly into memory.
So, are there any tricks out there I might be overlooking?
Code:
LDA zpBuffer
STA PPUDATA
STA PPUDATA
...
STA PPUDATA
STA PPUDATA
STA PPUDATA
STA PPUDATA
...
STA PPUDATA
STA PPUDATA
Now suppose you want to do the same thing, only this time with a repeating word value (2 bytes). Then you might throw the X register into the mix:
Code:
LDA zpBuffer+0
LDX zpBuffer+1
STA PPUDATA
STX PPUDATA
...
STA PPUDATA
STX PPUDATA
LDX zpBuffer+1
STA PPUDATA
STX PPUDATA
...
STA PPUDATA
STX PPUDATA
And if you really want to get crazy, there's even the Y register for those wacky repeating 3-byte sequences:
Code:
LDA zpBuffer+0
LDX zpBuffer+1
LDY zpBuffer+2
STA PPUDATA
STX PPUDATA
STY PPUDATA
...
STA PPUDATA
STX PPUDATA
STY PPUDATA
LDX zpBuffer+1
LDY zpBuffer+2
STA PPUDATA
STX PPUDATA
STY PPUDATA
...
STA PPUDATA
STX PPUDATA
STY PPUDATA
My question is this: What's the most optimal way (fewest cycles) to extend the above pattern beyond 3-byte sequences? The best I can think of is to use a single LDX and LDY statement to hold 2 of the values, then use as many LDA statements (zero page) as necessary for the remaining values.
I originally thought it would be cool to set up the buffer at the bottom of the stack (say, $100-$10F), then repeatedly "pull" successive values into PPUDATA. But alas, it doesn't seem like it's possible to pull values directly into memory.
So, are there any tricks out there I might be overlooking?