![]() |
Routines |
| Prev: 53672 | Up: Map | Next: 53836 |
|
Used by the routines at Handle_Homing_Enemy, Spawn_Primary_Wave_Enemies, Process_Entity_Record_Fast, Spawn_Wave_Enemies, Handle_Horizontal_Enemy_Entity, Spawn_Horizontal_Wave_Enemies, Pick_Random_Spawn_Position_Y, Process_Cluster_Entity, Process_Player_Tracking_Enemy, Spawn_Tracked_Enemy_Entities, Process_Replacement_Enemy_Entity and Process_Final_Phase_Enemy_Entity.
Produces a single pseudo-random byte by advancing the RNG seed via Advance_RNG_Seed and XOR-mixing its two bytes. HL is preserved. Called throughout the enemy spawning routines to pick random positions and directions.
|
||||
| Generate_Random_Byte | 53695 | PUSH HL | Stash HL and advance the RNG seed via Advance_RNG_Seed. | |
| 53696 | CALL Advance_RNG_Seed | |||
| 53699 | LD A,L | XOR-mix the seed high and low bytes to produce the random byte. | ||
| 53700 | XOR H | |||
| 53701 | POP HL | Restore HL and return. | ||
| 53702 | RET | |||
|
Entity spawn handler stub, invoked by HitTestBounds8AtHL during hit-testing. Stores the entity colour from C and advances the entity pointer.
|
||||
| Entity_Spawn_Handler | 53703 | LD D,B | Initialise the entity colour byte and advance the entity data pointer. | |
| 53704 | LD (HL),C | |||
| 53705 | INC HL | |||
| 53706 | RRA | |||
|
This entry point is used by the routine at Stage_Next_Wave.
Secondary wave enemy spawn: reads the entity configuration from the wave definition pointed to by HL, then spawns secondary entities (handler 52959) at random valid pixel positions on the playfield.
|
||||
| Spawn_Wave_Enemies_Class2 | 53707 | LD A,(HL) | Read the sprite type byte from the wave definition and store at 50213. | |
| 53708 | LD (50213),A | |||
| 53711 | LD B,A | Copy the sprite type to B, accumulate it into Active_Enemy_Count, and advance the definition pointer. | ||
| 53712 | LD A,(50204) | |||
| 53715 | ADD A,B | |||
| 53716 | LD (50204),A | |||
| 53719 | INC HL | |||
| 53720 | LD A,(HL) | Read the direction byte from the definition and store at 50214. | ||
| 53721 | LD (50214),A | |||
| 53724 | INC HL | |||
| 53725 | LD D,(HL) | Read the speed byte, store at 50215; set the initial animation frame pair at Animation_Frame_Pair. | ||
| 53726 | LD A,D | |||
| 53727 | LD (50215),A | |||
| 53730 | LD E,254 | |||
| 53732 | LD (50459),DE | |||
| 53736 | INC HL | Advance past the definition data and stash the definition pointer; load the entity list write pointer from Entity_List_Write_Pointer. | ||
| 53737 | PUSH HL | |||
| 53738 | LD HL,(50441) | |||
| 53741 | LD A,B | Skip spawning if the enemy count is zero. | ||
| 53742 | AND A | |||
| 53743 | JP Z,Spawn_Wave_Enemies_Class2_Done | |||
| Spawn_Wave_Enemies_Class2_Loop | 53746 | PUSH BC | Stash the enemy count and write the secondary entity handler address 52959 to the entity list. | |
| 53747 | LD DE,52959 | |||
| 53750 | LD (HL),E | |||
| 53751 | INC HL | |||
| 53752 | LD (HL),D | |||
| 53753 | INC HL | |||
| Generate_Random_Byte_0 | 53754 | CALL Generate_Random_Byte | Generate a random direction via Generate_Random_Byte. | |
| 53757 | AND %00000011 | Mask to values 1–3. | ||
| 53759 | JR Z,Generate_Random_Byte_0 | Retry if the direction rolled zero. | ||
| 53761 | LD (HL),A | Store the direction and set the initial entity state to 4. | ||
| 53762 | INC HL | |||
| 53763 | LD (HL),4 | |||
| 53765 | INC HL | |||
| Generate_Random_Byte_1 | 53766 | CALL Generate_Random_Byte | Generate a random Y pixel position via Generate_Random_Byte. | |
| 53769 | CP 24 | Retry if outside the playfield vertical range (24–163). | ||
| 53771 | JR C,Generate_Random_Byte_1 | |||
| 53773 | CP 164 | |||
| 53775 | JR NC,Generate_Random_Byte_1 | |||
| 53777 | LD (HL),A | Write the Y position and advance the entity pointer. | ||
| 53778 | INC HL | |||
| Generate_Random_Byte_2 | 53779 | CALL Generate_Random_Byte | Generate a random X pixel position via Generate_Random_Byte. | |
| 53782 | CP 8 | Retry if outside the playfield horizontal range (8–238). | ||
| 53784 | JR C,Generate_Random_Byte_2 | |||
| 53786 | CP 239 | |||
| 53788 | JR NC,Generate_Random_Byte_2 | |||
| 53790 | LD (HL),A | Write the X position and the entity dimensions (12 × 9). | ||
| 53791 | INC HL | |||
| 53792 | LD (HL),12 | |||
| 53794 | INC HL | |||
| 53795 | LD (HL),9 | |||
| 53797 | DEC HL | Step back to the entity record origin and load the spawn handler Entity_Spawn_Handler into alternate HL. | ||
| 53798 | DEC HL | |||
| 53799 | DEC HL | |||
| 53800 | EXX | |||
| 53801 | LD HL,53703 | |||
| 53804 | EXX | |||
| 53805 | CALL HitTestBounds8AtHL | Test whether this position overlaps an existing entity via HitTestBounds8AtHL. | ||
| 53808 | JR C,Spawn_Wave_Enemies_Class2_Accept | Jump to Spawn_Wave_Enemies_Class2_Accept if the position is clear. | ||
| 53810 | DEC HL | Step back and retry with a new X position. | ||
| 53811 | DEC HL | |||
| 53812 | DEC HL | |||
| 53813 | JR Generate_Random_Byte_1 | |||
| Spawn_Wave_Enemies_Class2_Accept | 53815 | INC HL | Advance past the entity record and write the 255 end-of-record marker. | |
| 53816 | LD (HL),255 | |||
| 53818 | INC HL | |||
| 53819 | POP BC | Restore the enemy count and loop for the next secondary enemy. | ||
| 53820 | DJNZ Spawn_Wave_Enemies_Class2_Loop | |||
| Spawn_Wave_Enemies_Class2_Done | 53822 | LD DE,53668 | Write the entity list return-routine address and the 255 sentinel; store the updated entity list write pointer at Entity_List_Write_Pointer. | |
| 53825 | LD (50441),HL | |||
| 53828 | LD (HL),E | |||
| 53829 | INC HL | |||
| 53830 | LD (HL),D | |||
| 53831 | INC HL | |||
| 53832 | LD (HL),255 | |||
| 53834 | POP HL | Restore the wave definition pointer and return. | ||
| 53835 | RET | |||
| Prev: 53672 | Up: Map | Next: 53836 |