Prev: D1A8 Up: Map Next: D24C
D1BF: Generate Random Byte
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 D1BF PUSH HL Stash HL and advance the RNG seed via Advance_RNG_Seed.
D1C0 CALL Advance_RNG_Seed
D1C3 LD A,L XOR-mix the seed high and low bytes to produce the random byte.
D1C4 XOR H
D1C5 POP HL Restore HL and return.
D1C6 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 D1C7 LD D,B Initialise the entity colour byte and advance the entity data pointer.
D1C8 LD (HL),C
D1C9 INC HL
D1CA 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 CEDF) at random valid pixel positions on the playfield.
Spawn_Wave_Enemies_Class2 D1CB LD A,(HL) Read the sprite type byte from the wave definition and store at C425.
D1CC LD ($C425),A
D1CF LD B,A Copy the sprite type to B, accumulate it into Active_Enemy_Count, and advance the definition pointer.
D1D0 LD A,($C41C)
D1D3 ADD A,B
D1D4 LD ($C41C),A
D1D7 INC HL
D1D8 LD A,(HL) Read the direction byte from the definition and store at C426.
D1D9 LD ($C426),A
D1DC INC HL
D1DD LD D,(HL) Read the speed byte, store at C427; set the initial animation frame pair at Animation_Frame_Pair.
D1DE LD A,D
D1DF LD ($C427),A
D1E2 LD E,$FE
D1E4 LD ($C51B),DE
D1E8 INC HL Advance past the definition data and stash the definition pointer; load the entity list write pointer from Entity_List_Write_Pointer.
D1E9 PUSH HL
D1EA LD HL,($C509)
D1ED LD A,B Skip spawning if the enemy count is zero.
D1EE AND A
D1EF JP Z,Spawn_Wave_Enemies_Class2_Done
Spawn_Wave_Enemies_Class2_Loop D1F2 PUSH BC Stash the enemy count and write the secondary entity handler address CEDF to the entity list.
D1F3 LD DE,$CEDF
D1F6 LD (HL),E
D1F7 INC HL
D1F8 LD (HL),D
D1F9 INC HL
Generate_Random_Byte_0 D1FA CALL Generate_Random_Byte Generate a random direction via Generate_Random_Byte.
D1FD AND %00000011 Mask to values 1–3.
D1FF JR Z,Generate_Random_Byte_0 Retry if the direction rolled zero.
D201 LD (HL),A Store the direction and set the initial entity state to 04.
D202 INC HL
D203 LD (HL),$04
D205 INC HL
Generate_Random_Byte_1 D206 CALL Generate_Random_Byte Generate a random Y pixel position via Generate_Random_Byte.
D209 CP $18 Retry if outside the playfield vertical range (18–A3).
D20B JR C,Generate_Random_Byte_1
D20D CP $A4
D20F JR NC,Generate_Random_Byte_1
D211 LD (HL),A Write the Y position and advance the entity pointer.
D212 INC HL
Generate_Random_Byte_2 D213 CALL Generate_Random_Byte Generate a random X pixel position via Generate_Random_Byte.
D216 CP $08 Retry if outside the playfield horizontal range (08–EE).
D218 JR C,Generate_Random_Byte_2
D21A CP $EF
D21C JR NC,Generate_Random_Byte_2
D21E LD (HL),A Write the X position and the entity dimensions (0C × 09).
D21F INC HL
D220 LD (HL),$0C
D222 INC HL
D223 LD (HL),$09
D225 DEC HL Step back to the entity record origin and load the spawn handler Entity_Spawn_Handler into alternate HL.
D226 DEC HL
D227 DEC HL
D228 EXX
D229 LD HL,$D1C7
D22C EXX
D22D CALL HitTestBounds8AtHL Test whether this position overlaps an existing entity via HitTestBounds8AtHL.
D230 JR C,Spawn_Wave_Enemies_Class2_Accept Jump to Spawn_Wave_Enemies_Class2_Accept if the position is clear.
D232 DEC HL Step back and retry with a new X position.
D233 DEC HL
D234 DEC HL
D235 JR Generate_Random_Byte_1
Spawn_Wave_Enemies_Class2_Accept D237 INC HL Advance past the entity record and write the FF end-of-record marker.
D238 LD (HL),$FF
D23A INC HL
D23B POP BC Restore the enemy count and loop for the next secondary enemy.
D23C DJNZ Spawn_Wave_Enemies_Class2_Loop
Spawn_Wave_Enemies_Class2_Done D23E LD DE,$D1A4 Write the entity list return-routine address and the FF sentinel; store the updated entity list write pointer at Entity_List_Write_Pointer.
D241 LD ($C509),HL
D244 LD (HL),E
D245 INC HL
D246 LD (HL),D
D247 INC HL
D248 LD (HL),$FF
D24A POP HL Restore the wave definition pointer and return.
D24B RET
Prev: D1A8 Up: Map Next: D24C