![]() |
Routines |
| Prev: D0E6 | Up: Map | Next: D1A8 |
|
Used by the routine at Stage_Next_Wave.
Reads the enemy count and type for the current wave from the definition pointed to by HL, then spawns that many primary wave entities at random valid screen positions by writing records into the entity list at Entity_List_Write_Pointer. Each entity is placed at a random column (1–30) and row (2–22), scaled to pixel coordinates, and drawn to the screen via CC81. If the count is zero the entity list is left empty and the routine returns immediately.
|
||||||||
| Spawn_Primary_Wave_Enemies | D0F0 | LD B,(HL) | Read the enemy count from the wave definition and store at Wave_Enemy_Count. | |||||
| D0F1 | LD A,B | |||||||
| D0F2 | LD ($C423),A | |||||||
| D0F5 | INC HL | Advance HL to the enemy type byte. | ||||||
| D0F6 | LD A,(HL) | Read the enemy type parameter from the wave definition. | ||||||
| D0F7 | LD ($C424),A | Store the enemy type parameter at Wave_Enemy_Type. | ||||||
| D0FA | INC HL | Advance the wave definition pointer. | ||||||
| D0FB | PUSH HL | Stash the wave definition pointer on the stack. | ||||||
| D0FC | LD HL,($C509) | Load the entity list write pointer from *Entity_List_Write_Pointer. | ||||||
| D0FF | LD A,B | Skip spawning if the wave has no enemies. | ||||||
| D100 | AND A | |||||||
| D101 | JP Z,Spawn_Primary_Wave_Enemies_Done | |||||||
|
For each enemy: write the entity handler, pick a random valid screen position, build the entity record, and draw the sprite.
|
||||||||
| Spawn_Primary_Wave_Enemies_Loop | D104 | PUSH BC | Stash the enemy count on the stack. | |||||
| D105 | LD DE,$CCCE | Load the primary entity handler address Primary_Enemy_Entity_Handler into DE. | ||||||
| D108 | LD (HL),E | Write the primary entity handler address into the entity list. | ||||||
| D109 | INC HL | |||||||
| D10A | LD (HL),D | |||||||
| D10B | INC HL | Advance HL past the handler bytes. | ||||||
| Spawn_Primary_Wave_Enemies_Get_X | D10C | CALL Generate_Random_Byte | Generate a random column via Generate_Random_Byte. | |||||
| D10F | AND %00011111 | Mask to columns 0–31. | ||||||
| D111 | JR Z,Spawn_Primary_Wave_Enemies_Get_X | Retry if the column is at the left or right wall. | ||||||
| D113 | CP $1F | |||||||
| D115 | JR Z,Spawn_Primary_Wave_Enemies_Get_X | |||||||
| D117 | LD B,A | Copy the valid column to B. | ||||||
| Spawn_Primary_Wave_Enemies_Get_Y | D118 | CALL Generate_Random_Byte | Generate a random row via Generate_Random_Byte. | |||||
| D11B | AND %00011111 | Mask to rows 0–31. | ||||||
| D11D | CP $02 | Retry if the row is too close to the top or bottom edge. | ||||||
| D11F | JR C,Spawn_Primary_Wave_Enemies_Get_Y | |||||||
| D121 | CP $17 | |||||||
| D123 | JR NC,Spawn_Primary_Wave_Enemies_Get_Y | |||||||
| D125 | SLA A | Scale the row and column to pixel coordinates (multiply by 8). | ||||||
| D127 | SLA A | |||||||
| D129 | SLA A | |||||||
| D12B | SLA B | |||||||
| D12D | SLA B | |||||||
| D12F | SLA B | |||||||
| D131 | LD (HL),A | Write the Y pixel to the entity record. | ||||||
| D132 | LD ($C4F3),A | Cache the Y pixel at Cached_Spawn_Pixels. | ||||||
| D135 | INC HL | Advance HL to the X slot in the entity record. | ||||||
| D136 | LD (HL),B | Write the X pixel to the entity record. | ||||||
| D137 | LD A,B | Copy the X pixel from B into A and cache it at C4F4. | ||||||
| D138 | LD ($C4F4),A | |||||||
| D13B | INC HL | Advance HL to the colour slot. | ||||||
| D13C | LD (HL),$07 | Write WHITE to the colour and type bytes. | ||||||
| D13E | INC HL | |||||||
| D13F | LD (HL),$07 | |||||||
| D141 | DEC HL | Step back three bytes to point at the start of the entity record. | ||||||
| D142 | DEC HL | |||||||
| D143 | DEC HL | |||||||
| D144 | EXX | Load the entity spawn handler address Entity_Spawn_Handler into alternate HL. | ||||||
| D145 | LD HL,$D1C7 | |||||||
| D148 | EXX | |||||||
| D149 | CALL HitTestBounds8AtHL | Test whether this position overlaps an existing entity via HitTestBounds8AtHL. | ||||||
| D14C | DEC HL | Retry with new coordinates if the position is occupied. | ||||||
| D14D | DEC HL | |||||||
| D14E | DEC HL | |||||||
| D14F | JR NC,Spawn_Primary_Wave_Enemies_Get_X | |||||||
| D151 | INC HL | Advance past the entity record header fields. | ||||||
| D152 | INC HL | |||||||
| D153 | INC HL | |||||||
| D154 | INC HL | |||||||
| D155 | LD A,($C424) | Copy the wave enemy type from Wave_Enemy_Type into the entity record. | ||||||
| D158 | LD (HL),A | |||||||
| D159 | INC HL | |||||||
|
Build the on-screen pixel address and attribute address from the cached pixel coordinates at Cached_Spawn_Pixels.
|
||||||||
| D15A | EX DE,HL | Copy HL to DE (entity record pointer now in DE). | ||||||
| D15B | LD HL,$C4F3 | Point HL at the cached pixel coordinates at Cached_Spawn_Pixels. | ||||||
| D15E | LD A,(HL) | Read the Y pixel (row) from the cache. | ||||||
| D15F | INC HL | Advance HL to the X pixel byte. | ||||||
| D160 | LD C,(HL) | Read the X pixel (column) from the cache. | ||||||
| D161 | LD L,A | Move the Y pixel into L for the row term. | ||||||
| D162 | LD B,$45 | Load the screen address high-byte base 45 into B. | ||||||
| D164 | SLA C | Shift the X pixel left in C. | ||||||
| D166 | RL B | Roll the carry into the screen high byte in B. | ||||||
| D168 | LD H,$46 | Load the second high-byte term 46 into H. | ||||||
| D16A | SLA L | Shift the Y pixel left in L. | ||||||
| D16C | RL H | Finish forming the screen address high byte in H. | ||||||
| D16E | LD A,(HL) | Read the low byte of the pixel data pointer from the table. | ||||||
| D16F | INC HL | Advance HL to the high byte. | ||||||
| D170 | LD H,(HL) | Read the high byte of the pixel data pointer. | ||||||
| D171 | LD L,A | Form the full pixel data pointer in HL (low in L). | ||||||
| D172 | LD A,(BC) | Read a byte from the built screen address in BC. | ||||||
| D173 | OR L | Combine the screen low byte with the pixel table low byte. | ||||||
| D174 | LD L,A | Store the combined screen low byte in L. | ||||||
| D175 | EX DE,HL | Exchange HL with DE (entity record pointer back in HL). | ||||||
| D176 | LD (HL),E | Write the screen address into the entity record. | ||||||
| D177 | INC HL | |||||||
| D178 | LD (HL),D | |||||||
| D179 | INC HL | Advance HL to the attribute slot. | ||||||
| D17A | LD A,D | Load the attribute address high byte from D. | ||||||
| D17B | RRCA | Rotate the attribute page bits toward the low end three times. | ||||||
| D17C | RRCA | |||||||
| D17D | RRCA | |||||||
| D17E | AND %00000011 | Mask to the attribute page bits. | ||||||
| D180 | OR %01011000 | Set the attribute area high byte. | ||||||
| D182 | LD D,A | Store the attribute address high byte in D. | ||||||
| D183 | LD (HL),E | Write the attribute address into the entity record. | ||||||
| D184 | INC HL | |||||||
| D185 | LD (HL),D | |||||||
| D186 | DEC HL | Step HL back four bytes to the entity origin for drawing. | ||||||
| D187 | DEC HL | |||||||
| D188 | DEC HL | |||||||
| D189 | DEC HL | |||||||
| D18A | CALL Draw_Spawned_Entity | Call Draw_Spawned_Entity. | ||||||
| D18D | DEC HL | Step HL to the end-of-record marker position. | ||||||
| D18E | LD (HL),$FF | Write the record terminator FF after this entity. | ||||||
| D190 | INC HL | Advance HL for the next list write. | ||||||
| D191 | POP BC | Restore the enemy count from the stack. | ||||||
| D192 | DEC B | Decrement the remaining enemies to spawn for this wave. | ||||||
| D193 | JP NZ,Spawn_Primary_Wave_Enemies_Loop | Loop back to Spawn_Primary_Wave_Enemies_Loop if more enemies remain. | ||||||
|
All enemies spawned: write the entity list terminator and return.
|
||||||||
| Spawn_Primary_Wave_Enemies_Done | D196 | LD DE,$D1A4 | Load Entity_List_Reset into DE. | |||||
| D199 | LD ($C509),HL | Store the updated write pointer at Entity_List_Write_Pointer. | ||||||
| D19C | LD (HL),E | Store the entity list terminator routine address Entity_List_Reset at *HL (low byte then high byte). | ||||||
| D19D | INC HL | |||||||
| D19E | LD (HL),D | |||||||
| D19F | INC HL | Advance HL past the stored pointer bytes. | ||||||
| D1A0 | LD (HL),$FF | Write the terminator byte (FF) to the entity list. | ||||||
| D1A2 | POP HL | Restore the wave definition pointer from the stack. | ||||||
| D1A3 | RET | Return. | ||||||
|
Inline stub: resets the entity list pointer and returns. Used as the terminal routine address written into the entity list by the spawning routines.
|
||||||||
| Entity_List_Reset | D1A4 | LD HL,$6000 | Reset the entity list pointer to Entity_List. | |||||
| D1A7 | RET | Return. | ||||||
| Prev: D0E6 | Up: Map | Next: D1A8 |