Prev: 27592 Up: Map Next: 27705
27660: Validate Position
Validates a proposed position (B=Y, C=X) against the boundary table pointed to by *Pointer_RedBirdFlightpathData. Used by the red bird (UpdateRedBirdMovement), helicopter (Handler_Helicopter) and UFO (Handler_UFO); each caller ensures Pointer_RedBirdFlightpathData points to the appropriate boundary data. Scans through the table for a region containing the position.
Each entry is 4 bytes: Y-min, Y-max, X-min, X-max. If a valid region is found, the position is stored to *IX and carry is clear. If no valid region is found (entry is 0), carry is set.
Input
B Proposed Y position
C Proposed X position
IX Pointer to sprite data (red bird, helicopter or UFO)
Output
F Carry clear = valid, carry set = out of bounds
Validate_Position 27660 LD HL,(27835) HL=*Pointer_RedBirdFlightpathData (boundary table pointer).
Validate_Position_Loop 27663 PUSH HL Stash the boundary pointer on the stack.
27664 LD A,(HL) A=*HL (Y-min for this region).
27665 OR A Jump to Validate_Position_OutOfBounds if A is 0 (end of boundary data).
27666 JR Z,Validate_Position_OutOfBounds
Check Y-min <= B.
27668 CP B Jump to Validate_Position_Next if B is less than Y-min.
27669 JR NC,Validate_Position_Next
Check B <= Y-max.
27671 INC HL Advance to Y-max.
27672 LD A,(HL) A=*HL.
27673 CP B Jump to Validate_Position_Next if B is greater than Y-max.
27674 JR C,Validate_Position_Next
Check X-min <= C.
27676 INC HL Advance to X-min.
27677 LD A,(HL) A=*HL.
27678 CP C Jump to Validate_Position_Next if C is less than X-min.
27679 JR NC,Validate_Position_Next
Check C <= X-max.
27681 INC HL Advance to X-max.
27682 LD A,(HL) A=*HL.
27683 CP C Jump to Validate_Position_Next if C is greater than X-max.
27684 JR C,Validate_Position_Next
Position is within this region so store it and return success.
27686 LD (IX+0),C Write C to *IX+0 (X position).
27689 LD (IX+1),B Write B to *IX+1 (Y position).
27692 POP HL Restore the boundary pointer from the stack.
27693 AND A Clear carry (valid position).
27694 RET Return.
Position is outside this region so try the next one.
Validate_Position_Next 27695 POP HL Restore the boundary pointer from the stack.
27696 INC HL Advance HL by 4 (next boundary entry).
27697 INC HL
27698 INC HL
27699 INC HL
27700 JR Validate_Position_Loop Jump to Validate_Position_Loop.
End of boundary data. No valid region found.
Validate_Position_OutOfBounds 27702 POP HL Restore the boundary pointer from the stack.
27703 SCF Set carry (out of bounds).
27704 RET Return.
Prev: 27592 Up: Map Next: 27705