tokumaru wrote:Celius wrote:Each object accesses its own bytes with indirect addressing through a single pointer variable that gets updated after each object is done being processed.
That's the reason why I don't use linear blocks of memory for my objects. Having to modify Y in order to access any byte would be a pain in the ass. I figured that having the object memory interleaved would be more efficient. Loads and stores are 1 cycle faster than in indirect addressing, and there's no need to modify an index register to access different object properties, you just use labels. Also, modifying only the index register to access different object slots is quicker than modifying a 16-bit pointer. I took all that into consideration before deciding to go with the interleaved way. It just happens that, on the 6502, 99% of the time it's easier/faster to handle interleaved data than linear data.
That's a really great idea! So if I'm understanding correctly, you'll have something like this in RAM:
Code: Select all
ObjectXL: .ds 8
ObjectXH: .ds 8
ObjectYL: .ds 8
ObjectYH: .ds 8
ObjectHealth: .ds 8
...
Then in your AI code, you'll have something like X loaded with the object number, so in your code you can do:
Code: Select all
ldx ObjectNumber
lda ObjectXL,x
sta Var
lda ObjectXH,x
sta Var2
instead of the slower:
Code: Select all
ldy #CoordXL
lda (pointer),y
sta Var
iny
lda (pointer),y
sta Var2
If I'm understanding that correctly, that is way more efficient than the way I'm doing it now. From what I see, going interleaved is almost always faster! I interleave a lot of my data, like tile definitions, but for some reason I never thought to interleave variables.
If only I'd thought about doing this earlier! I could save hundreds of bytes and cycles...