Prev: AE0D Up: Map Next: AF21
AEB0: Test Entity Visible
Tests whether the entity is within the view in both directions, allowing for a margin of BC.
Input
IX The entity
BC The margin
Output
A Zero if the entity is out of view, otherwise non-zero
Test the column, which is the x coordinate plus the y coordinate, less the horizontal origin of the view. The entity is out of view if the column is further left than the margin, or further right than C0 plus the margin.
TestEntityVisible AEB0 LD H,(IX+$02) Fetch the x coordinate.
AEB3 LD L,(IX+$03)
AEB6 LD D,(IX+$05) Fetch the y coordinate.
AEB9 LD E,(IX+$06)
AEBC ADD HL,DE Add them to get the column before the origin.
AEBD LD DE,($5CE7) Fetch the horizontal origin of the view.
AEC1 SBC HL,DE Subtract the origin.
AEC3 BIT 7,H Jump to TestEntityVisible_Second if the column is not left of the origin.
AEC5 JR Z,TestEntityVisible_Second
AEC7 ADD HL,BC Add the margin.
AEC8 RL H Test whether the column is still negative.
AECA JR NC,TestEntityVisible_Vertical Go on to the row if the margin brings the column back.
AECC XOR A Report that the entity is out of view.
AECD RET
TestEntityVisible_Second AECE LD DE,$00C0 Set the right edge of the test to C0.
AED1 SBC HL,DE Subtract it from the column.
AED3 SBC HL,BC Subtract the margin as well.
AED5 RL H Test whether the column is now negative.
AED7 JR C,TestEntityVisible_Vertical Go on to the row if the column is inside the right edge.
AED9 XOR A Report that the entity is out of view.
AEDA RET
Test the row, using the same sum as ProjectEntity: half of the x coordinate less half of the y coordinate, less the z coordinate, plus 40 less the vertical origin of the view.
TestEntityVisible_Vertical AEDB LD H,(IX+$02) Fetch the x coordinate.
AEDE LD L,(IX+$03)
AEE1 SRL H Halve the x coordinate.
AEE3 RR L
AEE5 LD D,(IX+$05) Fetch the y coordinate.
AEE8 LD E,(IX+$06)
AEEB SRL D Halve the y coordinate.
AEED RR E
AEEF AND A Subtract half of the y coordinate from half of the x coordinate.
AEF0 SBC HL,DE
AEF2 LD D,(IX+$08) Fetch the high byte of the z coordinate, less one.
AEF5 DEC D
AEF6 LD E,(IX+$09) Fetch the low byte of the z coordinate.
AEF9 AND A Subtract the z coordinate.
AEFA SBC HL,DE
AEFC LD DE,$0040 Set the offset to 40.
AEFF ADD HL,DE Add the offset.
AF00 LD DE,($5CEE) Fetch the vertical origin of the view.
AF04 SBC HL,DE Subtract the origin.
AF06 BIT 7,H Jump to TestEntityVisible_Far if the row is not above the origin.
AF08 JR Z,TestEntityVisible_Far
AF0A ADD HL,BC Add the margin.
AF0B RL H Test whether the row is still negative.
AF0D JR NC,TestEntityVisible_Yes Accept the entity if the margin brings the row back.
AF0F XOR A Report that the entity is out of view.
AF10 RET
TestEntityVisible_Far AF11 LD DE,$0080 Set the bottom of the test to 80.
AF14 SBC HL,DE Subtract it from the row.
AF16 SBC HL,BC Subtract the margin as well.
AF18 RL H Test whether the row is now negative.
AF1A JR C,TestEntityVisible_Yes Accept the entity if the row is inside the bottom edge.
AF1C XOR A Report that the entity is out of view.
AF1D RET
TestEntityVisible_Yes AF1E OR %00010000 Set a non-zero result.
AF20 RET Return.
Prev: AE0D Up: Map Next: AF21