Prev: 38639 Up: Map Next: 38811
38728: Update Spawn Points
Used by the routine at RunFrame.
Called every frame. Once in every 64 frames, on average, it creates a pickup (see CreatePickup). It then goes through the spawn points of the level, which have seven bytes each, counting down the delay of each one and, when the delay has run out, trying to create the entity the spawn point makes.
UpdateSpawnPoints 38728 LD A,(24474) Fetch the low byte of the random seed from RandomNumber_Seed.
38731 AND %00111111 Keep only bits 0-5.
38733 CALL Z,CreatePickup Call CreatePickup to create a pickup if they are all zero.
38736 LD A,(48499) Fetch the number of spawn points from ObjectCount.
38739 AND A Test it.
38740 RET Z Return if there are none.
38741 LD B,A Set the spawn point counter in B.
38742 LD IY,48500 Point IY at the first spawn point at 48500.
UpdateSpawnPoints_Loop 38746 PUSH BC Stash the spawn point counter on the stack.
38747 PUSH IY Stash the address of the spawn point on the stack.
38749 LD A,(IY+5) Fetch the delay of the spawn point.
38752 AND A Test it.
38753 JR Z,UpdateSpawnPoints_Create Jump to UpdateSpawnPoints_Create if it has run out.
38755 DEC A Decrease the delay by one.
38756 LD (IY+5),A Store it.
38759 JR UpdateSpawnPoints_Next Jump to UpdateSpawnPoints_Next to go on to the next spawn point.
UpdateSpawnPoints_Create 38761 LD E,(IY+6) Fetch the kind of the spawn point.
38764 LD A,E Copy it into A.
38765 CP 3 Jump to UpdateSpawnPoints_Next if it is 3, which makes nothing.
38767 JR Z,UpdateSpawnPoints_Next
38769 ADD A,A Multiply it by seven...
38770 ADD A,A
38771 ADD A,A
38772 SUB E ...by multiplying by eight and subtracting the kind.
38773 LD E,A Move it into E.
38774 LD D,0 Clear D.
38776 LD IY,39051 Point IY at SpawnKinds.
38780 ADD IY,DE Add the offset of the kind to find its entry.
38782 LD L,(IY+0) Fetch the low byte of the address of the first entity slot of the kind.
38785 LD H,(IY+1) Fetch the high byte of the address of the first entity slot of the kind.
38788 PUSH HL Copy it into IX (using the stack).
38789 POP IX
38791 LD B,(IY+2) Fetch the number of entity slots of the kind into B.
38794 CALL FindFreeEntity Call FindFreeEntity to find a free slot.
38797 JP Z,CreateSpawnedEntity Jump to CreateSpawnedEntity if there is one, to create the entity.
This entry point is used by the routine at CreateSpawnedEntity.
UpdateSpawnPoints_Next 38800 POP IY Restore the address of the spawn point from the stack.
UpdateSpawnPoints_Advance 38802 LD BC,7 BC is 7 the size of a spawn point.
38805 ADD IY,BC Move onto the next spawn point.
38807 POP BC Restore the spawn point counter from the stack.
38808 DJNZ UpdateSpawnPoints_Loop Decrease the spawn point counter by one and jump back to UpdateSpawnPoints_Loop until all of the spawn points have been done.
38810 RET Return.
Prev: 38639 Up: Map Next: 38811