Prev: E2C8 Up: Map Next: E31C
E2FD: Clamp Entity Velocity
Adds a 16-bit signed delta (DE) to a velocity byte in H, sign-extending H to a full 16-bit value first, then clamps the result to the range FC00-03FF. Returns the clamped result in HL. Called from Process_Tracked_Enemy_Entity and Process_Player_Tracking_Enemy when updating tracked enemy velocities.
Clamp_Entity_Velocity E2FD LD A,H Sign-extend H into a 16-bit value and add the delta in DE.
E2FE AND $80
E300 LD H,$00
E302 JP Z,Clamp_Entity_Velocity_0
E305 LD H,$FF Positive result: check bit 7 and jump if the result is negative.
Clamp_Entity_Velocity_0 E307 ADD HL,DE
E308 LD A,H
E309 BIT 7,H Positive ceiling: return if within range; clamp to 03FF otherwise.
E30B JP NZ,Clamp_Entity_Velocity_Negative
E30E CP $04
E310 RET C
E311 LD HL,$03FF
E314 RET
Clamp_Entity_Velocity_Negative E315 CP $FC Negative result: return if within range; clamp to FC00 otherwise.
E317 RET NC
E318 LD HL,$FC00
E31B RET
Prev: E2C8 Up: Map Next: E31C