Prev: F38D Up: Map Next: F3EF
F391: Test Entity Below
Find a solid simple entity immediately below IX (for a downward step). On a hit, store it at Pointer_LastCollidedEntity and clear carry; on a miss, set carry.
Input
IX Address of complex state data for the subject entity
Test_EntityBelow F391 LD C,$01 Load C with 01 (room−01 / down bias).
This entry point is used by the routine at Test_EntityAbove.
Walk StateData_SimpleEntities for a solid entity abutting IX vertically.
Test_EntityVertical_Scan F393 PUSH HL Stash HL and DE on the stack.
F394 PUSH DE
F395 LD DE,$000E Each entity record is 000E bytes, then load that into DE.
F398 LD HL,$8B69 Point HL at the simple entity table (StateData_SimpleEntities).
Next simple-entity slot for the vertical abut test (or miss on FF).
Test_EntityVertical_ScanSlot F39B LD A,(HL) Fetch this entity's type. Is it the table terminator (FF)? If not, test the slot at Test_EntityVertical_CheckSlot.
F39C CP $FF
F39E JR NZ,Test_EntityVertical_CheckSlot
F3A0 POP DE Restore DE and HL from the stack.
F3A1 POP HL
F3A2 SCF Signal a miss.
F3A3 RET Return.
Require a solid (bit 02) neighbour; skip room check for type 33.
Test_EntityVertical_CheckSlot F3A4 LD A,(HL) Re-fetch the type. Is the slot empty? If so, skip to Test_EntityVertical_AdvanceSlot.
F3A5 OR A
F3A6 JR Z,Test_EntityVertical_AdvanceSlot
F3A8 BIT 7,A Is the high bit set (inactive)? If so, skip to Test_EntityVertical_AdvanceSlot.
F3AA JR NZ,Test_EntityVertical_AdvanceSlot
F3AC CP (IX+$00) Is it the same type as the subject? If so, skip to Test_EntityVertical_AdvanceSlot.
F3AF JR Z,Test_EntityVertical_AdvanceSlot
F3B1 LD B,A Keep the type in B.
F3B2 PUSH HL Stash HL on the stack.
F3B3 INC HL Advance onto flags byte 1.
F3B4 LD A,(HL) Fetch the flags.
F3B5 AND %00000100 Keep only the solid/platform bit (bit 02).
F3B7 JR Z,Test_EntityVertical_Reject If it was clear, reject at Test_EntityVertical_Reject.
F3B9 BIT 5,(HL) Is bit 05 set? If so, reject at Test_EntityVertical_Reject.
F3BB JR NZ,Test_EntityVertical_Reject
F3BD INC HL Advance past the room/y/y-extent fields onto the room-check byte.
F3BE INC HL
F3BF INC HL
F3C0 LD A,B Keep the candidate type in A. Is it type 33 (skip room check)?.
F3C1 CP $33
F3C3 JR Z,Test_EntityVertical_CheckBounds If so, take the bounds check at Test_EntityVertical_CheckBounds.
F3C5 LD A,(HL) Fetch the entity's room. Subtract the caller's room bias in C. Does it match the subject's room? If not, reject at Test_EntityVertical_Reject.
F3C6 SUB C
F3C7 CP (IX+$04)
F3CA JR NZ,Test_EntityVertical_Reject
Confirm horizontal overlap and Y abutment with the subject.
Test_EntityVertical_CheckBounds F3CC INC HL Advance onto the entity's y-coordinate.
F3CD LD A,(IX+$06) Does the subject's y-extent (IX+06) reach this candidate y? If not, reject at Test_EntityVertical_Reject.
F3D0 CP (HL)
F3D1 JR C,Test_EntityVertical_Reject
F3D3 INC HL Advance onto the entity's y-extent.
F3D4 LD A,(HL) Does this candidate y-extent reach the subject's y (IX+05)? If not, reject at Test_EntityVertical_Reject.
F3D5 CP (IX+$05)
F3D8 JR C,Test_EntityVertical_Reject
F3DA INC HL Advance onto the entity's x-coordinate.
F3DB LD A,(IX+$08) Fetch the subject's x-extent (IX+08). Step it right by one. Does it equal this entity's x (abutting above/below)? If not, reject at Test_EntityVertical_Reject.
F3DE INC A
F3DF CP (HL)
F3E0 JR NZ,Test_EntityVertical_Reject
Vertical neighbour hits: store the entity at Pointer_LastCollidedEntity and return its type.
F3E2 POP HL Restore HL from the stack.
F3E3 LD ($72AA),HL Store it at Pointer_LastCollidedEntity.
F3E6 XOR A Clear carry.
F3E7 LD A,(HL) Fetch the entity's type into A.
F3E8 POP DE Restore DE and HL from the stack.
F3E9 POP HL
F3EA RET Return.
Reject this vertical neighbour and continue the simple-entity walk.
Test_EntityVertical_Reject F3EB POP HL Restore HL from the stack.
Advance to the next simple-entity record in the vertical scan.
Test_EntityVertical_AdvanceSlot F3EC ADD HL,DE Advance HL by one entity record.
F3ED JR Test_EntityVertical_ScanSlot Jump to Test_EntityVertical_ScanSlot to test the next vertical neighbour.
Prev: F38D Up: Map Next: F3EF