gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Moving Sprite in ARM

#28863 - ozahid - Mon Nov 08, 2004 12:04 am

The following is the code i used to try to move the sprite to a different coording (originally 10,10) when the forward button is pressed. During VDraw it checks for a keydown, if its down it sets r6 to 1. Then in VBlank, if r6 is 1 it updates the attributes to have new X and Y values. Then resets r6 to 0. Now, when I run the file on the emulator it works when you hit forward. However, after that the sprite starts refreshing like crazy, I don't see what I did wrong =(

Code:
   ldr r0,=0x04000006   ;VCount
   ldr r1,=0x04000130   ;key register
   ldr r2,=0x07000000   ;OAM Reg
   MOV r5,#10   ;x value
   MOV r6,#0      ;updated?

Inf
VDraw   LDR   r3,[r0]
   CMP    r3,#160
   BGE    VBlank
   LDR   r4,[r1]
   ANDS   r4,r4,#16
   ADDEQ   r5,r5,#10
   MOVEQ   r6,#1   
   B   VDraw
   
VBlank   LDR   r3,[r0]
   CMP    r3,#160
   BLT    Inf
   CMP   r6,#1
   LDREQ    R1,=(SQUARE|COLOR_16|50)|((SIZE_32|50)<<16)
   STREQ    R1,[R2]+4!   ;Move to attribute 2
   LDREQ    R1,=0        ;Tile numbeR 0
   STREQ    R1,[R2]
   MOVEQ   R6,#0
   b      VBlank

_________________
http://people.umass.edu/ozahid

#28864 - poslundc - Mon Nov 08, 2004 12:56 am

Are you releasing the forward button before 1/60th of a second passes and your code executes again?

(HINT: You need more sophisticated code than just checking whether the button is being pushed down or not. You need to compare the current state of the button to its previous state, and take action based on that. This is usually a lot simpler from a high-level language like C.)

Dan.

#28876 - FluBBa - Mon Nov 08, 2004 10:18 am

R2 is screwed up after the first write.
_________________
I probably suck, my not is a programmer.