Prev: 57954 Up: Map Next: 58056
58000: Spawn Horizontal Wave Enemies
Used by the routine at Stage_Next_Wave.
Entry point called from Stage_Next_Wave. Reads the horizontal enemy spawn count from *HL and stores it at 50219; if zero, returns immediately. Otherwise loops B times, writing a full entity record into the entity list: the Step_Wide_Entity_Approach handler address, a random entity type in the range 52-55 a valid random screen position via Pick_Random_Spawn_Position_Y, and trailing bytes 14 13 255. Saves the updated entity list pointer to *Entity_List_Write_Pointer and writes the 53668 list terminator.
Spawn_Horizontal_Wave_Enemies 58000 LD A,(HL) Load the horizontal enemy count from *HL and store it at 50219.
58001 LD (50219),A
58004 INC HL Return if the spawn count is zero.
58005 AND A
58006 RET Z
58007 LD B,A Set the spawn loop counter in B and stash the source pointer.
58008 PUSH HL
58009 LD HL,(50441) Load the entity list write pointer from *Entity_List_Write_Pointer.
Spawn_Horizontal_Wave_Enemies_Record 58012 LD DE,53074 Write the Step_Wide_Entity_Approach entity handler as a little-endian word.
58015 LD (HL),E
58016 INC HL
58017 LD (HL),D
58018 INC HL Advance past the handler word.
58019 CALL Generate_Random_Byte Generate a random byte via Generate_Random_Byte.
58022 AND %00000011 Mask to the low 2 bits for the entity type offset.
58024 ADD A,52 Add 52 write the entity type, and advance.
58026 LD (HL),A
58027 INC HL
58028 PUSH BC Stash BC and call Pick_Random_Spawn_Position_Y to place the entity at a valid random screen position.
58029 CALL Pick_Random_Spawn_Position_Y
58032 POP BC
58033 DEC HL Restore BC and step back one byte.
58034 LD (HL),14
58036 INC HL Write trailing record bytes 14 13 and 255.
58037 LD (HL),13
58039 INC HL
58040 LD (HL),255
58042 INC HL Advance HL and loop back to Spawn_Horizontal_Wave_Enemies_Record for the next entity.
58043 DJNZ Spawn_Horizontal_Wave_Enemies_Record
58045 LD (50441),HL Save the updated entity list pointer to *Entity_List_Write_Pointer.
58048 LD DE,53668
58051 LD (HL),E
58052 INC HL
58053 LD (HL),D Write the list terminator 53668 to *HL.
58054 POP HL
58055 RET Return.
Prev: 57954 Up: Map Next: 58056