Prev: 9D23 Up: Map Next: 9D91
9D41: Test Amulet Proximity
Used by the routine at HandlerTribesman.
Tests whether an actor is close to any of the four amulet pieces which have not been collected yet (those with a non-zero sprite ID in the records at AmuletData). A piece counts as close if either of these is true:
  • the column of the room (bits 0-3 of the room number) matches the column of the room of the piece and the X positions are less than 10 apart
  • the row of the room (bits 4-7 of the room number) matches the row of the room of the piece and the Y positions are less than 10 apart
The room is only compared in part so the test does not require the actor and the piece to be in exactly the same room.
Input
IX Actor record
Output
A The distance to the piece which is close
F Carry flag set if an amulet piece is close
Check each of the four amulet piece records in turn.
TestAmuletProximity 9D41 LD DE,$000B Set the offset to the next amulet piece in DE to 0B.
9D44 LD HL,$97FE Point HL at the first amulet piece record at AmuletData.
9D47 LD B,$04 Set the amulet piece counter in B to 04.
TestAmuletProximity_Loop 9D49 LD A,(HL) Fetch the sprite ID of the amulet piece.
9D4A INC HL Move onto the room of the amulet piece.
9D4B AND A Jump to TestAmuletProximity_Next if the amulet piece is not present.
9D4C JR Z,TestAmuletProximity_Next
Compare the columns of the rooms.
9D4E LD A,(HL) Fetch the room of the amulet piece.
9D4F AND %00001111 Keep only the column of the room (bits 0-3).
9D51 LD C,A Stash the column of the amulet piece in C.
9D52 LD A,(IX+$01) Fetch the room of the actor.
9D55 AND %00001111 Keep only the column of the room (bits 0-3).
9D57 CP C Jump to TestAmuletProximity_Columns if the actor is in the same column as the amulet piece.
9D58 JR Z,TestAmuletProximity_Columns
Compare the rows of the rooms.
TestAmuletProximity_Rows 9D5A LD A,(HL) Fetch the room of the amulet piece.
9D5B AND %11110000 Keep only the row of the room (bits 4-7).
9D5D LD C,A Stash the row of the amulet piece in C.
9D5E LD A,(IX+$01) Fetch the room of the actor.
9D61 AND %11110000 Keep only the row of the room (bits 4-7).
9D63 CP C Jump to TestAmuletProximity_Rows_Same if the actor is in the same row as the amulet piece.
9D64 JR Z,TestAmuletProximity_Rows_Same
Move on to the next piece.
TestAmuletProximity_Next 9D66 ADD HL,DE Move onto the next amulet piece.
9D67 DJNZ TestAmuletProximity_Loop Decrease the amulet piece counter by one and loop back to TestAmuletProximity_Loop until all four pieces have been checked.
9D69 AND A Clear the carry flag (no amulet piece is close).
9D6A RET Return.
The columns are the same so compare the X positions.
TestAmuletProximity_Columns 9D6B INC HL Move onto the X position of the amulet piece.
9D6C INC HL
9D6D LD A,(HL) Fetch the X position of the amulet piece.
9D6E DEC HL Move back onto the room of the amulet piece.
9D6F DEC HL
9D70 SUB (IX+$03) Subtract the X position of the actor to get the horizontal distance.
9D73 JP P,TestAmuletProximity_Columns_Positive Jump to TestAmuletProximity_Columns_Positive if the distance is positive.
9D76 NEG Make the distance positive.
TestAmuletProximity_Columns_Positive 9D78 CP $10 Jump to TestAmuletProximity_Rows if the horizontal distance is 10 or more.
9D7A JR NC,TestAmuletProximity_Rows
9D7C RET Return with the carry flag set (the amulet piece is close).
The rows are the same so compare the Y positions.
TestAmuletProximity_Rows_Same 9D7D INC HL Move onto the Y position of the amulet piece.
9D7E INC HL
9D7F INC HL
9D80 LD A,(HL) Fetch the Y position of the amulet piece.
9D81 DEC HL Move back onto the room of the amulet piece.
9D82 DEC HL
9D83 DEC HL
9D84 SUB (IX+$04) Subtract the Y position of the actor to get the vertical distance.
9D87 JP P,TestAmuletProximity_Rows_Same_Positive Jump to TestAmuletProximity_Rows_Same_Positive if the distance is positive.
9D8A NEG Make the distance positive.
TestAmuletProximity_Rows_Same_Positive 9D8C CP $10 Jump to TestAmuletProximity_Next if the vertical distance is 10 or more.
9D8E JR NC,TestAmuletProximity_Next
9D90 RET Return with the carry flag set (the amulet piece is close).
Prev: 9D23 Up: Map Next: 9D91