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.

ASM > Setting the tile number for a sprite.

#1783 - GbaGuy - Thu Jan 23, 2003 2:12 am

I created this macro, but it doesn't work and I'm not sure why.

Code:

@macro SetNumber Sprite, Number
ldr r2,=(OAM+(Sprite*8))+4
ldr r4,[r2]  ; att2&3
ldr r3,[r2]  ; r3 = att2&3
mov r3,r3,lsl 16  ; r3 = att3
mov r4,r4,lsr 16  ; r4 = att2
and r4,r4,#0xFC000000  ; clear old tile number
orr r4,r4,#Number  ; put in new tile number
mov r3,r3,lsr 16   ; put the atts in the right spot
mov r4,r4,lsl 16   ; ditto
orr r4,r4,r3    ; put them together
str r4,[r2]    ; store back in OAM
@endm


If anyone could figure out why, I'd appreciate it.

Thanks,
- GbaGuy

#1805 - pulstar_3 - Thu Jan 23, 2003 11:42 am

Hi GBAGuy,

The best thing to do is instead loading registers r3 and r4 with the same thing and then shifting just ldrh $7000004 for sprite 1 then put the tile number you want to start the sprite at in r3, then strh it back like this

Code:

@macro SetNumber Sprite,Number
ldr r2,=(OAM+(Sprite*8))+4
ldrh r3,[r2]

;Compare the tile starting no. to get frame of animation.

mov r4,$0                                   ;Start at tile 0
strh r4,[r2]                                  ;Store back at Att 2




This should work but I haven't actually tried it.

Pulstar_3