J.Wilson
J.Wilson

Reputation: 51

NES(6502 assembly) Sprites movement

I am currently working on a NES(6502) assembly game but I don't understand how to make a sprite move. Here's how I think its supposed to works:

(loop)
LDA $200 ;will load into the A register the content of address $200,wich contain the Y position of my sprite
INA ;Increment the A register which would increment the content of A which is the Y position of my sprite..?

However it seems that you cannot increment the A register accumulator because I get an error when trying to assemble with the INA instruction. So I'm a bit lost into that. Should I use STA instead of LDA? But I want to use the content of the address $200 and not place a value that I choose in it. I don't get how to make my sprite move.

Upvotes: 2

Views: 1736

Answers (3)

NMITIMEN
NMITIMEN

Reputation: 91

Keep in mind that usually games don't directly edit sprites. The common way of updating sprite position is first updating the object's position and then use a sprite constructor subroutine to assemble each 8x8 sprite to the correct position relative to the object's position. You can have a table to list all sprites. The list specifies the tile and relative offset for that sprite so you can just add it to the object position to get the position of the sprite you write to the next free OAM slot.

Then at the start of NMI you use OAMDMA to copy the "shadow OAM" (usually on page 2) to the PPU. Games don't generally use OAMADDR and OAMDATA as they are likely to corrupt OAM data.

Upvotes: 2

Cactus
Cactus

Reputation: 27626

If the graphics chip looks for the sprite position in $200, then you will need to write back the modified value after computing it. If all you want to do is increment it, you can do it directly by using the absolute addressing mode of INC:

INC $200

will increment whatever value is stored in $200, without changing any of the register values.

Upvotes: 4

Michael
Michael

Reputation: 58427

There's indeed no INA available on the variant of 6502 used in the NES. You can increment A by 1 using the following pair of instructions:

CLC     ; Clear carry
ADC #1  ; A = A + 1 + carry = A + 1

Or, if either of the index registers are free you can use:

LDX $200  ; or LDY
INX       ; or INY

Keep in mind, though, that the other arithmetic operations like ADC, SBC, LSR, etc, can't be performed on X or Y.

Upvotes: 5

Related Questions