Prev: 991C Up: Map Next: 9962
9924: Spawn Food
Used by the routine at DrawRoom.
Called by the main loop. When the counter at CounterLow is zero and bit 0 of CounterHigh is reset, the next of the food items from FoodItems to EDD8 is looked at (the food pointer in FoodPointer moves on by 08 bytes, and starts again at FoodItems after the last one). If the item is not in the room of the player and is not already in use then it is made one of the foods (sprite IDs 50 to 57), using FRAMES.
SpawnFood 9924 LD A,($5E12) Fetch the counter from CounterLow and keep the low byte of the counter in C.
9927 LD C,A
9928 LD A,($5E13) Fetch the high byte of the counter from CounterHigh.
992B AND %00000001 Keep only bit 0.
992D OR C Return unless the counter is zero and bit 0 of its high byte is reset.
992E RET NZ
992F LD HL,($5E55) HL=*FoodPointer.
9932 LD DE,$0008 DE=0008 (the size of a food item).
9935 ADD HL,DE Move HL on to the next food item.
9936 LD ($5E55),HL Write HL back to FoodPointer.
9939 PUSH HL Copy HL into IX, as the food item.
993A POP IX
993C LD DE,$EDD8 DE=EDD8 (the end of the food items).
993F AND A Subtract DE from HL.
9940 SBC HL,DE
9942 JR NC,SpawnFood_Restart Jump to SpawnFood_Restart if the food pointer is past the last item.
9944 LD A,($EA91) Fetch the room of the player from PlayerRoom.
9947 CP (IX+$01) Return if the player is in the same room.
994A RET Z
994B LD A,(IX+$00) Fetch the sprite ID of the item.
994E AND A Return if the item is in use.
994F RET NZ
9950 LD A,($5C78) Fetch FRAMES.
9953 AND %00000111 Keep only bits 0-2.
9955 ADD A,$50 Add 50 to make the sprite ID of the food.
9957 LD (IX+$00),A Update the sprite ID of the item.
995A RET Return.
SpawnFood_Restart 995B LD HL,$EB58 HL=EB58.
995E LD ($5E55),HL Write HL to FoodPointer.
9961 RET Return.
Prev: 991C Up: Map Next: 9962