I'm attempting to make a simple Game Boy Advance game that has a sprite with four frames of animation. I'm new to C programming (I'm an assembly hobbyist, ARM assembly makes more sense to me but I gave up because of its limited ability to read and move data into its registers) and I'm running into difficulty understanding how to do things. The code below was supposed to increment the variable i each frame, and cycle through one of four possible graphics for the player sprite. (that's what the 0x20, 0x28, 0x20, and 0x30 represent). But when the game runs it only displays the sprite as if I had just set the sprite attribute to 0x30 and never changes. Basically my if statements have no effect and I don't really understand why.
C code:
ObjectAttributes *spriteAttribs = &oam_object_backbuffer[0];
spriteAttribs->attr0 = 0x2000;
spriteAttribs->attr1 = 0x4000;
spriteAttribs->attr2 = 0x20;
int i;
i = 0;
while(1)
{
i = i++;
vsync();
if (i & 3 == 0) //this doesn't work, no idea why
{
spriteAttribs->attr2 = 0x20;
}
else if (i & 3 == 1)
{
spriteAttribs->attr2 = 0x28;
}
else if (i & 3 == 2)
{
spriteAttribs->attr2 = 0x20;
}
else
{
spriteAttribs->attr2 = 0x30;
}
MEM_OAM[0] = oam_object_backbuffer[0];
// this is what displays the sprite to the screen
key_poll() // not relevant to this question
} //loop forever
This produces the following ARM code:
L21:
sub r1, fp, #20
ldr r3, [r1, #0]
mov r2, r3
str r2, [fp, #-20]
add r3, r3, #1
str r3, [r1, #0]
bl vsync
ldr r2, [fp, #-1068]
mov r3, #48
strh r3, [r2, #4] @ movhi
mov r2, #117440512 @ 0x07000000, address of Game Boy Advance's OAM
mvn r3, #1040 @ By the way is there any way to tell GCC to output these values in
@ hexadecimal?
sub r3, r3, #7
sub r0, fp, #12
add r3, r0, r3
ldmia r3, {r0-r1}
stmia r2, {r0-r1}
bl key_poll
b .L21
Aucun commentaire:
Enregistrer un commentaire