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!