Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: Jerros on July 12, 2011, 03:44:53 am
-
The thing is, there are 16 sprites defined as followed:
SpriteNumber .equ AppBackUpScreen
yspr1 .equ SpriteNumber+2
xspr1 .equ yspr1+1
yspr2 .equ xspr1+1
xspr2 .equ yspr2+1
yspr3 .equ xspr2+1
xspr3 .equ yspr3+1
yspr4 .equ xspr3+1
xspr4 .equ yspr4+1
yspr5 .equ xspr4+1
xspr5 .equ yspr5+1
;etc.
Now, there is the following piece of code, with input C = Xcoordinate of a sprite.
The idea is that it's loading C (thus an x-coordinate) to Sprite1, then Sprite2, then 3 etc. and after Sprite16 has been assigned, it starts over with Spr1 again. There's something glitchy, since it sometimes suddenly removes sprites from the screen (thus assigns x,y values to a sprite on the screen already). I can'tr figure out what's wrong though. Could it perhaps be because of direct input with the buttonpresses that it sometimes fails to finish this loop or something?
Script:
NextSprite:
LD hl, SpriteNumber
LD A, (SpriteNumber)
LD B, A
NextSpriteLoop:
INC HL ; 2x INC HL will go to the next sprite, since each HL holds X
INC HL ; and Y respectively of the current spritenumber
djnz NextSpriteLoop ; Keeps track of the current sprite
LD A, -9 ; Set the Y position of the current sprite
LD (hl), A ; And save it to Sprite*number*
INC HL
LD (hl), C ; Save an X-coordinate to Sprite*number*
LD A, (SpriteNumber)
CP 16 ; After giving an X and Y to Sprite16, start with Sprite 1 again
JR Z, ResetSpriteNumber
INC A
LD (SpriteNumber), A
ret
ResetSpriteNumber:
LD A, 1
LD (SpriteNumber), A
ret
So... is there something wrong? Or are the errors caused by other factors?
Thanks!
-
So, is it supposed to set the coordinates of the current sprite to (C,-9) and then make the next sprite the current one, and making the first one currrent if it just set the coordinates of the 16th sprite?
-
So, is it supposed to set the coordinates of the current sprite to (C,-9) and then make the next sprite the current one, and making the first one currrent if it just set the coordinates of the 16th sprite?
Yup.
So you "LD C, [x-coordinate] ", then call this and it should put spr.1 to those coordinates. Then spr.2 at the next call etc. untill it goes back to 1 after having set 16. But something's wrong, and it might be this script...
If not, the problem lies elsewhere and everyone's free to use this, lol.