![]() |
Routines |
| Prev: E003 | Up: Map | Next: E1B6 |
|
Used by the routine at Stage_Next_Wave.
Reads three spawn-count bytes from HL (slots 10 20 30) and populates the entity list at *Entity_List_Working_Pointer with entities via Spawn_Wave_Enemies_Populate_Slot. Each record has a random screen position and a slot-typed variant; Draw_Wide_Entity_Sprite spawns each entity. Terminates the list with D1A4 and updates *Entity_List_Write_Pointer.
|
||||
| Spawn_Wave_Enemies | E122 | LD DE,($C509) | DE=*Entity_List_Write_Pointer (current entity list write pointer). | |
| E126 | LD ($C50D),DE | Copy DE to *Entity_List_Working_Pointer and *Entity_List_Snapshot. | ||
| E12A | LD ($C50B),DE | |||
| E12E | LD C,$10 | Call Spawn_Wave_Enemies_Populate_Slot with enemy slot 10. | ||
| E130 | CALL Spawn_Wave_Enemies_Populate_Slot | |||
| E133 | LD C,$20 | Call Spawn_Wave_Enemies_Populate_Slot with enemy slot 20. | ||
| E135 | CALL Spawn_Wave_Enemies_Populate_Slot | |||
| E138 | LD C,$30 | Call Spawn_Wave_Enemies_Populate_Slot with enemy slot 30. | ||
| E13A | CALL Spawn_Wave_Enemies_Populate_Slot | |||
| E13D | EX DE,HL | Save the final entity list write pointer to *Entity_List_Write_Pointer. | ||
| E13E | LD ($C509),HL | |||
| E141 | LD BC,$D1A4 | Write the entity list terminator D1A4 to *HL. | ||
| E144 | LD (HL),C | |||
| E145 | INC HL | |||
| E146 | LD (HL),B | |||
| E147 | EX DE,HL | Restore HL and DE. | ||
| E148 | RET | Return. | ||
|
Reads the count byte from *HL. Caches it in the entity count table at C427+index. If zero, jumps to Spawn_Wave_Enemies_Update_Pointer; otherwise loops B times, writing a nine-byte entity record and calling Draw_Wide_Entity_Sprite.
|
||||
| Spawn_Wave_Enemies_Populate_Slot | E149 | PUSH HL | Stash the source pointer on the stack. | |
| E14A | LD D,(HL) | D=*HL (entity count for this slot). | ||
| E14B | LD A,C | Save the slot ID in A. | ||
| E14C | SRL C | Shift C right four times to derive the slot count table index. | ||
| E14E | SRL C | |||
| E150 | SRL C | |||
| E152 | SRL C | |||
| E154 | LD B,$00 | Write entity count (D) to *C427+index. | ||
| E156 | LD HL,$C427 | |||
| E159 | ADD HL,BC | |||
| E15A | LD (HL),D | |||
| E15B | POP HL | Restore the source pointer. | ||
| E15C | LD C,A | C=A (restore the slot ID). | ||
| E15D | LD A,D | A=B=entity count (B drives the entity spawn loop). | ||
| E15E | LD B,A | |||
| E15F | AND A | Test if the entity count is zero. | ||
| E160 | PUSH HL | Stash the source pointer on the stack. | ||
| E161 | LD HL,($C50D) | HL=*Entity_List_Working_Pointer (entity list write pointer). | ||
| E164 | JP Z,Spawn_Wave_Enemies_Update_Pointer | Jump to Spawn_Wave_Enemies_Update_Pointer if the entity count is zero. | ||
|
Build one entity record at *HL: entity handler E007 zero byte, type nibble, random Y (10-AA), random X (08-F0), then 0D 07 FF; call Draw_Wide_Entity_Sprite to spawn. Loop B times.
|
||||
| Spawn_Wave_Enemies_Write_Record | E167 | LD DE,$E007 | DE=E007 (entity update handler address). | |
| E16A | LD (HL),E | Write DE to *HL as a little-endian word. | ||
| E16B | INC HL | |||
| E16C | LD (HL),D | |||
| E16D | INC HL | |||
| E16E | LD (HL),$00 | Write 00 to *HL; advance HL. | ||
| E170 | INC HL | |||
| E171 | CALL Generate_Random_Byte | Call Generate_Random_Byte to generate a random byte. | ||
| E174 | AND %00000011 | Mask to the low two bits. | ||
| E176 | OR C | Write entity type (slot ORed with random bits) to *HL. | ||
| E177 | LD (HL),A | |||
| E178 | INC HL | |||
| Spawn_Wave_Enemies_Get_Y | E179 | CALL Generate_Random_Byte | Call Generate_Random_Byte to generate a random byte. | |
| E17C | CP $10 | Retry if below 10 (outside valid Y range). | ||
| E17E | JP C,Spawn_Wave_Enemies_Get_Y | |||
| E181 | CP $AB | Retry if AB or greater (outside valid Y range). | ||
| E183 | JP NC,Spawn_Wave_Enemies_Get_Y | |||
| E186 | LD (HL),A | Write random Y coordinate to *HL; advance HL. | ||
| E187 | INC HL | |||
| Spawn_Wave_Enemies_Get_X | E188 | CALL Generate_Random_Byte | Call Generate_Random_Byte to generate a random byte. | |
| E18B | CP $08 | Retry if below 08 (outside valid X range). | ||
| E18D | JP C,Spawn_Wave_Enemies_Get_X | |||
| E190 | CP $F1 | Retry if F1 or greater (outside valid X range). | ||
| E192 | JP NC,Spawn_Wave_Enemies_Get_X | |||
| E195 | LD (HL),A | Write random X coordinate to *HL. | ||
| E196 | PUSH HL | Stash HL on the stack; step HL back to the type byte. | ||
| E197 | DEC HL | |||
| E198 | DEC HL | |||
| E199 | EXX | Set B'=INK: WHITE, PAPER: BLACK (BRIGHT) via shadow registers. | ||
| E19A | LD B,$47 | |||
| E19C | EXX | |||
| E19D | PUSH BC | Spawn the entity via Draw_Wide_Entity_Sprite, preserving BC. | ||
| E19E | CALL Draw_Wide_Entity_Sprite | |||
| E1A1 | POP BC | |||
| E1A2 | POP HL | Restore HL (X coordinate position). | ||
| E1A3 | INC HL | Write trailing record bytes 0D 07 and FF. | ||
| E1A4 | LD (HL),$0D | |||
| E1A6 | INC HL | |||
| E1A7 | LD (HL),$07 | |||
| E1A9 | INC HL | |||
| E1AA | LD (HL),$FF | |||
| E1AC | INC HL | Advance HL; loop back to Spawn_Wave_Enemies_Write_Record for the next entity. | ||
| E1AD | DJNZ Spawn_Wave_Enemies_Write_Record | |||
| Spawn_Wave_Enemies_Update_Pointer | E1AF | LD ($C50D),HL | Save the entity list write pointer to *Entity_List_Working_Pointer. | |
| E1B2 | EX DE,HL | Restore DE. | ||
| E1B3 | POP HL | Restore the source pointer; advance past the count byte. | ||
| E1B4 | INC HL | |||
| E1B5 | RET | Return. | ||
| Prev: E003 | Up: Map | Next: E1B6 |