Prev: EAF7 Up: Map Next: EBB4
EB07: Process Final Phase Enemy Entity
Used by the routine at Process_Replacement_Enemy_Entity.
Per-frame handler for the final phase of a wall-bouncing enemy, reached from Process_Replacement_Enemy_Entity when the replacement entity countdown expires. Spawns the entity with colour WHITE, calls Find_Colliding_Entity to search for a player-contact slot, and jumps to Process_Final_Phase_Enemy_Entity_Kill if none is found. Calls HitTestBounds8AtHL to test player contact and jumps to Strip_Attributes_And_Fade to kill the player if touching. Steps back to the direction field and generates a random value; keeps the current direction if below F0 otherwise picks a new direction, wraps it within 33 and writes it back. Looks up Y and X deltas from Enemy_Movement_Delta_Table (direction & 03 × 2), validates the new position within the play area, and spawns the entity. If no contact slot is found, erases the sprite, removes the entity from the list, awards BCD score, and writes the retire handler.
Input
HL Entity record pointer
Advance past the countdown byte and spawn with white colour.
Process_Final_Phase_Enemy_Entity EB07 INC HL Advance past the countdown field.
EB08 PUSH HL Stash the entity pointer on the stack.
EB09 EXX Load WHITE into B'.
EB0A LD B,$07
EB0C EXX
EB0D CALL Draw_Wide_Entity_Sprite Call Draw_Wide_Entity_Sprite to spawn the entity.
EB10 POP HL Restore the entity pointer from the stack.
EB11 INC HL Advance one byte and switch to alternate registers.
EB12 EXX
Search for a player-contact slot and test overlap.
EB13 CALL Find_Colliding_Entity Call Find_Colliding_Entity to search for a player-contact slot and jump to Process_Final_Phase_Enemy_Entity_Kill if none is found.
EB16 JP NC,Process_Final_Phase_Enemy_Entity_Kill
EB19 LD HL,$C4D4 Load the player position at Player_Y_Position and call HitTestBounds8AtHL to test overlap.
EB1C CALL HitTestBounds8AtHL
EB1F JP NC,Strip_Attributes_And_Fade Jump to Strip_Attributes_And_Fade to kill the player if contact is confirmed.
EB22 EXX Switch to main registers.
Step back to the direction field and pick or keep a direction.
EB23 DEC HL Step back three bytes to the direction field.
EB24 DEC HL
EB25 DEC HL
EB26 CALL Generate_Random_Byte Call Generate_Random_Byte to generate a random value.
EB29 CP $F0 Keep the current direction if the value is below F0.
EB2B JP C,Process_Final_Phase_Enemy_Entity_Keep
Increment and mask the direction byte.
Process_Final_Phase_Enemy_Entity_Retry EB2E DEC HL Step back to the direction field, load it, and increment it.
EB2F LD A,(HL)
EB30 INC A
EB31 AND %00110011 Mask the direction within 33.
EB33 LD (HL),A Write the new direction, advance, and jump to Process_Final_Phase_Enemy_Entity_Apply.
EB34 INC HL
EB35 JP Process_Final_Phase_Enemy_Entity_Apply
Process_Final_Phase_Enemy_Entity_Keep EB38 DEC HL Step back to the direction field, load it, and advance.
EB39 LD A,(HL)
EB3A INC HL
Look up movement deltas and validate the new position.
Process_Final_Phase_Enemy_Entity_Apply EB3B EX DE,HL Exchange DE and HL.
EB3C AND %00000011 Mask the direction to the low 2 bits.
EB3E SLA A Double the index, load the movement table base at Enemy_Movement_Delta_Table, and step to the entry.
EB40 LD C,A
EB41 LD B,$00
EB43 LD HL,$EBB4
EB46 ADD HL,BC
EB47 EX DE,HL Add the Y delta to the entity Y position and jump to Process_Final_Phase_Enemy_Entity_Retry if outside 10–AA.
EB48 LD A,(DE)
EB49 ADD A,(HL)
EB4A CP $AB
EB4C JP NC,Process_Final_Phase_Enemy_Entity_Retry
EB4F CP $10
EB51 JP C,Process_Final_Phase_Enemy_Entity_Retry
EB54 LD C,A Save the validated Y position in C.
EB55 INC HL Advance to the X position, apply the X delta, and jump to Process_Final_Phase_Enemy_Entity_X_Retry if outside the play area.
EB56 INC DE
EB57 LD A,(DE)
EB58 ADD A,(HL)
EB59 CP $F1
EB5B JP NC,Process_Final_Phase_Enemy_Entity_X_Retry
EB5E CP $08
EB60 JP NC,Process_Final_Phase_Enemy_Entity_Write
Process_Final_Phase_Enemy_Entity_X_Retry EB63 DEC HL Step back one byte and jump to Process_Final_Phase_Enemy_Entity_Retry to retry.
EB64 JP Process_Final_Phase_Enemy_Entity_Retry
Write the validated coordinates and spawn with a random colour.
Process_Final_Phase_Enemy_Entity_Write EB67 LD (HL),A Write the validated X and Y coordinates to the entity record.
EB68 DEC HL
EB69 LD (HL),C
EB6A DEC HL
EB6B PUSH HL Stash the entity pointer on the stack.
EB6C EXX Switch to alternate registers.
EB6D CALL Generate_Random_Byte Call Generate_Random_Byte to generate a random colour byte.
EB70 AND %00111000 Mask to bits 3–5 to select the spawn colour.
EB72 LD B,A Load the colour into B and switch to main registers.
EB73 EXX
EB74 CALL Draw_Wide_Entity_Sprite Call Draw_Wide_Entity_Sprite to spawn the entity.
EB77 POP HL Restore the entity pointer from the stack.
EB78 JP Process_Entity_Record_Next6 Jump to Process_Entity_Record_Next6 to advance the entity pointer.
Erase the entity, remove it from the list, and award the score.
Process_Final_Phase_Enemy_Entity_Kill EB7B LD DE,$0006 Step back six bytes to the entity record and save the address in Entity_Record_Pointer.
EB7E SBC HL,DE
EB80 LD ($C4DA),HL
EB83 CALL Erase_Narrow_Entity_Sprite Call Erase_Narrow_Entity_Sprite to erase the entity sprite.
EB86 CALL Remove_Entity_From_List Call Remove_Entity_From_List to remove the entity from the list.
EB89 LD E,$00 Load code 00 and call Initialise_Entity_State to initialise the entity state.
EB8B CALL Initialise_Entity_State
Increment the BCD score and propagate carry to higher digits.
EB8E LD HL,$C405 Load C405, add 01 BCD, write it back, and jump to Process_Final_Phase_Enemy_Entity_Score_Bar if no carry.
EB91 LD A,(HL)
EB92 ADD A,$01
EB94 DAA
EB95 LD (HL),A
EB96 JR NC,Process_Final_Phase_Enemy_Entity_Score_Bar
EB98 DEC HL Carry to the tens digit: load, add 01 BCD, write back, and jump to Process_Final_Phase_Enemy_Entity_Score_Bar if no carry.
EB99 LD A,(HL)
EB9A ADD A,$01
EB9C DAA
EB9D LD (HL),A
EB9E JR NC,Process_Final_Phase_Enemy_Entity_Score_Bar
EBA0 DEC HL Carry to the hundreds digit: load, add 01 BCD, and write back.
EBA1 LD A,(HL)
EBA2 ADD A,$01
EBA4 DAA
EBA5 LD (HL),A
Refresh the colour bar and write the retire handler.
Process_Final_Phase_Enemy_Entity_Score_Bar EBA6 CALL Clear_Colour_Bar_Column Call Clear_Colour_Bar_Column to refresh the colour bar.
EBA9 EXX Switch to main registers.
EBAA DEC HL Step back three bytes to the entity handler field.
EBAB DEC HL
EBAC DEC HL
EBAD LD DE,$E02C Write the retire handler Process_Entity_Record_Next7 into the entity record.
EBB0 LD (HL),D
EBB1 DEC HL
EBB2 LD (HL),E
EBB3 RET Return.
Prev: EAF7 Up: Map Next: EBB4