Prev: 62146 Up: Map Next: 62250
62151: Test Entity Overlap At Depth
As Test_EntityOverlap, but match entities whose room is one deeper than IX (room−1). Used when Berk moves forward into the next depth band.
Input
IX Address of complex state data for the subject entity
Test_EntityOverlap_AtDepth 62151 LD BC,1 Load BC with 0001 (reject bit 5, then room−1).
This entry point is used by the routines at Test_EntityOverlap_AllowSpecial and Test_EntityOverlap.
Walk the simple-entity table for a collidable overlap with IX.
Test_EntityOverlap_Scan 62154 PUSH HL Stash HL and DE on the stack.
62155 PUSH DE
62156 LD DE,14 Each entity record is 0014 bytes, then load that into DE.
62159 LD HL,35689 Point HL at the simple entity table (StateData_SimpleEntities).
Next simple-entity slot for the overlap test (or miss on 255).
Test_EntityOverlap_ScanSlot 62162 LD A,(HL) Fetch this entity's type. Is it the table terminator (255)? If not, test the slot at Test_EntityOverlap_CheckSlot.
62163 CP 255
62165 JR NZ,Test_EntityOverlap_CheckSlot
Simple-entity scan miss: restore registers and return carry set.
62167 POP DE Restore DE and HL from the stack.
62168 POP HL
62169 SCF Signal a miss.
62170 RET Return.
Reject empty/inactive/same-type slots; require collidable bit 0 (and optional bit 5).
Test_EntityOverlap_CheckSlot 62171 LD A,(HL) Re-fetch the type. Is the slot empty (type 0)? If so, skip to Test_EntityOverlap_AdvanceSlot.
62172 OR A
62173 JR Z,Test_EntityOverlap_AdvanceSlot
62175 BIT 7,A Is the high bit set (inactive)? If so, skip to Test_EntityOverlap_AdvanceSlot.
62177 JR NZ,Test_EntityOverlap_AdvanceSlot
62179 CP (IX+0) Is it the same type as the subject? If so, skip to Test_EntityOverlap_AdvanceSlot.
62182 JR Z,Test_EntityOverlap_AdvanceSlot
62184 PUSH HL Stash HL on the stack.
62185 INC HL Advance onto flags byte 1.
62186 LD A,(HL) Fetch flags byte 1.
62187 AND %00000001 Keep only the collidable bit (bit 0).
62189 JR Z,Test_EntityOverlap_Reject If it was clear, reject at Test_EntityOverlap_Reject.
62191 BIT 0,B Has the caller allowed bit-5 entities (B bit 0)? If so, skip the bit-5 reject at Test_EntityOverlap_CheckBounds.
62193 JR NZ,Test_EntityOverlap_CheckBounds
62195 BIT 5,(HL) Is bit 5 set on this entity? If so, reject at Test_EntityOverlap_Reject.
62197 JR NZ,Test_EntityOverlap_Reject
Require matching room (minus C) and overlapping y/x extents with IX.
Test_EntityOverlap_CheckBounds 62199 INC HL Advance HL past the unused entity fields onto the room byte.
62200 INC HL
62201 INC HL
62202 LD A,(HL) Fetch the entity's room.
62203 SUB C Subtract the caller's room bias in C.
62204 CP (IX+4) Does it match the subject's room (IX+4)? If not, jump to Test_EntityOverlap_Reject.
62207 JR NZ,Test_EntityOverlap_Reject
62209 INC HL Advance onto the entity's y-coordinate.
62210 LD A,(IX+6) Does the subject's y-extent (IX+6) reach this candidate y? If not, reject at Test_EntityOverlap_Reject.
62213 CP (HL)
62214 JR C,Test_EntityOverlap_Reject
62216 INC HL Advance onto the entity's y-extent.
62217 LD A,(HL) Does this candidate y-extent reach the subject's y (IX+5)? If not, reject at Test_EntityOverlap_Reject.
62218 CP (IX+5)
62221 JR C,Test_EntityOverlap_Reject
62223 INC HL Advance onto the entity's x-coordinate.
62224 LD A,(IX+8) Does the subject's x-extent (IX+8) reach this candidate x? If not, reject at Test_EntityOverlap_Reject.
62227 CP (HL)
62228 JR C,Test_EntityOverlap_Reject
62230 INC HL Advance onto the entity's x-extent.
62231 LD A,(HL) Does this candidate x-extent reach the subject's x (IX+7)? If not, reject at Test_EntityOverlap_Reject.
62232 CP (IX+7)
62235 JR C,Test_EntityOverlap_Reject
Hit: remember the entity and return its type with carry clear.
62237 POP HL Restore HL from the stack.
62238 XOR A Clear A / carry.
62239 LD (29354),HL Store the entity pointer at Pointer_LastCollidedEntity.
62242 LD A,(HL) Fetch the entity's type into A.
62243 POP DE Restore DE and HL from the stack.
62244 POP HL
62245 RET Return.
Reject this overlap candidate and continue the simple-entity walk.
Test_EntityOverlap_Reject 62246 POP HL Restore HL from the stack.
Advance to the next simple-entity record in the overlap scan.
Test_EntityOverlap_AdvanceSlot 62247 ADD HL,DE Advance HL by one entity record.
62248 JR Test_EntityOverlap_ScanSlot Jump to Test_EntityOverlap_ScanSlot to test the next simple entity.
Prev: 62146 Up: Map Next: 62250