The most straightforward way is to use the stack to hold the data, and use an unrolled sequence of PLA STA $2007, so that each byte takes 8 cycles to copy. That way, when processing the buffer, instead of counting down the number of bytes to copy you'd jump somewhere in the middle of this table.Tsutarja wrote:If it's not too complex, I could try to use faster method for reading the buffer.
First there's the unrolled code. 32 bytes seems like a good limit, because it's enough to update an entire row or column of tiles. Pattern updates would have to be broken down into blocks of 2 tiles, since each tile is 16 bytes.
Code: Select all
Update32Bytes:
PLA
STA $2007
Update31Bytes:
PLA
STA $2007
Update30Bytes:
PLA
STA $2007
(...)
Update2Bytes:
PLA
STA $2007
Update1Byte:
PLA
STA $2007
UpdateNothing:
Code: Select all
JumpTableLo:
.db <UpdateNothing, <Update1Byte, (...), <Update32Bytes
JumpTableHi:
.db >UpdateNothing, >Update1Byte, (...), >Update32Bytes
Code: Select all
LDX LastUpdateIndex
ProcessUpdate:
LDA UpdateAddressHi, x
STA $2006
LDA UpdateAddressLo, x
STA $2006
LDY UpdateCount
LDA JumpTableLo, y
STA Pointer+0
LDA JumpTableHi, y
STA Pointer+1
JMP (Pointer)
Update32Bytes:
(...)
UpdateNothing:
DEX
BNE ProcessUpdate
You can probably use 192 bytes of the stack for this, and still have 64 bytes left for normal stack use.