updateEntitySprites:
ld a, (ix+0) ; ix+0 = type of entity (0 means no entity)
or a
ret z
ld a, (ix+9) ; ix+9 = flag indicating if entity is horizontaly offscreen
or (ix+10) ; ix+10 = flag indicating if entity is verticaly offscreen
jp nz, updateEntitySpriteVerticalyOffscreen
ld a, (ix+14) ; ix+14 = vertical position of entity
cp $C0
ret nc
ld c, a
ld de, (pointerToSpriteTerminator)
push de
ld l, (ix+7) ; ix+7 = low byte of pointer to sprite descriptor
ld h, (ix+8) ; ix+8 = high byte of pointer to sprite descriptor
ld b, (hl) ; Read number of sprites from sprite descriptor
push bc
inc hl
ld a, (hl) ; Read collision data table index from sprite descriptor
ld (ix+19), a ; ix+19 = index into collision data table
inc hl
-:
ld a, c
add a, (hl) ; Read vertical position of sprite from sprite descriptor and add it to entitiy's vertical position
cp $D0
jr nz, +
dec a
+:
ld (de), a ; Write the calculated vertical position into the SAT in RAM
inc e
inc hl
djnz -
ld (pointerToSpriteTerminator), de
pop bc
pop de
sla e
set 7, e
ld c, (ix+12) ; ix+12 = horizontal position of entity
-:
ld a, c
add a, (hl) ; Read horizontal position of sprite from sprite descriptor and add it to entitiy's horizontal position
bit 7, (hl)
jp z, +
ccf
+:
jp nc, +
ld a, $E0
res 7, e
srl e
ld (de), a ; Write the calculated horizontal position into the SAT in RAM
sla e
set 7, e
jp ++
+:
ld (de), a ; Write the calculated horizontal position into the SAT in RAM
++:
inc hl
inc e
ldi ; Copy character code from sprite descriptor into SAT in RAM
inc bc
djnz -
ret