NES(6502 assembly) Sprites movement

本秂侑毒 提交于 2020-04-07 05:42:07

问题


I am currently working on a NES(6502) assembly game but I dont understand how to make a sprite move.Heres 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 postion of my sprite
INA ;Increment the A register wich would increment the content of A wich 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 Im 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 dont get how to make my sprite move.

Thank you!


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/33222276/nes6502-assembly-sprites-movement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!