shawnleblanc wrote:My specific problem is after currentSpriteDefinition is set to the location of sprite_mario_defintion, I'm not sure how to move the currentSpriteDefinition along the data. I'd be working with it four bytes at a time.
Code: Select all
; defined earlier
SUB_SPRITE_SIZE = 4
...
...
...
; move the currentSpriteDefinition down one sprite. four bytes.
LDA LOW(currentSpriteDefinition)
CLC
ADC SUB_SPRITE_SIZE
STA LOW(currentSpriteDefinition)
LDA HIGH(currentSpriteDefinition)
ADC #0
STA HIGH(currentSpriteDefinition)
I'm pretty sure that "LOW(currentSpriteDefinition)" will return the low byte of the address where "currentSpriteDefinition" is (somewhere in ZP), not the low byte of its contents. Since you want to modify the address it points to, you want to modify its contents. Try this:
Code: Select all
clc
lda currentSpriteDefinition+0
adc #SUB_SPRITE_SIZE ;the "#" is important here!
sta currentSpriteDefinition+0
lda currentSpriteDefinition+1
adc #$00
sta currentSpriteDefinition+1
Again, "+0" is entirely optional and is there only for clarity.
But generally, I'd also like to figure out what exactly the different calls would do.
Let's see...
Code: Select all
; currentSpritesDefinition's location is at $0300. Two bytes reserved.
; currentSpriteDefinition's value is $1234
; sprite_mario_definition's location is at $8000
; sprite_mario_defnition's value is $55
I'm not sure I understand the terminology here. You haven't told me where in RAM currentSpriteDefinition is, but I'll consider it to be at $0000 because of your previous post. Also, I don't get what you mean by "sprite_mario_defnition's value is $55". "sprite_mario_definition" is a label in ROM, and if this label is at address $8000, its "value" should be the contents of address $8000, which from your last post appears to be 0 (the Y offset of the first sprite). I guess we're not on the same page here.
Code: Select all
LDA LOW(currentSpriteDefinition) ; loads $34 into A?
Loads
the contents of memory location $00 (the low byte of $0000) into A. In this case it's be the same as "LDA currentSpriteDefinition", because "currentSpriteDefinition" is in ZP. If "currentSpriteDefinition" is pointing to $1234, the value loaded would be $34. Please note that "LDA HIGH(currentSpriteDefinition)" will also result in $34 being loaded into A, because because the high byte of the address where "currentSpriteDefinition" is is also $00.
Code: Select all
LDA #LOW(currentSpriteDefinition) ; ???
Loads $00 (the low byte of $0000) into A.
Code: Select all
LDA LOW(sprite_mario_defintion) ; loads $00 into A?
Loads
the contents of memory location $00 (the low byte of $8000) into A.
Code: Select all
LDA #LOW(sprite_mario_definition) ; ???
Loads $00 (the low byte of $8000) into A.
Code: Select all
STA LOW(currentSpriteDefinition) ; stores ??? into A?
Stores whatever is in A into memory location $00 (the low byte of $0000).
To sum it up:
There's no reason to ever use LOW() and HIGH() with a store command, it only makes sense to use them with load commands. You only need LOW() and HIGH() if you need the address of a variable/label, never its contents. To access the contents of different bytes of a multi-byte variable you should use "+1", "+2", etc. after their names.