Prev: AB73 Up: Map Next: ABE5
AB78: Position Rope End
Used by the routines at Handle_Rope and Update_Rope.
Works out the position of the end of the rope and the position of the point that it hangs from.
The end of the rope is below the point that it hangs from by a depth that is found from the displacement of the rope (Rope_Displacement_Pixels) and its length (Rope_Length). The routine squares the displacement, squares the length, subtracts the first square from the second and takes the square root of the result with Calculate_Square_Root. When the length is 0100 or more, the length and the square of the displacement are halved before they are used.
The x position is the displacement plus 80 and it is stored in Rope_End_Position. The y position is stored in the byte after it. The point that the rope hangs from is stored in Rope_Anchor_Position: it is 24 pixels down at an x position of 80 when the length is less than 80 and 10 pixels down when it is longer.
Input
IX Object record
Square the displacement.
Position_Rope_End AB78 LD D,$00 Clear the high byte of the displacement.
AB7A LD A,($AAA4) Fetch the displacement of the end of the rope.
AB7D BIT 7,A Jump to Position_Rope_End_Square_Displacement if it is positive.
AB7F JR Z,Position_Rope_End_Square_Displacement
AB81 NEG Make it positive.
Position_Rope_End_Square_Displacement AB83 LD E,A Copy the displacement to E.
AB84 CALL MultiplyAByDE Multiply the displacement by itself.
AB87 PUSH HL Stash the square of the displacement on the stack.
Square the length of the rope. If the high byte of the length is not zero, the square of the displacement and the length are halved first.
AB88 LD D,$00 Clear the high byte of the length.
AB8A LD A,($AAA6) Fetch the high byte of the length of the rope.
AB8D AND A Jump to Position_Rope_End_Short_Rope if the length is less than 0100.
AB8E JR Z,Position_Rope_End_Short_Rope
AB90 POP HL Restore the square of the displacement from the stack.
AB91 SRL H Halve it.
AB93 RR L
AB95 PUSH HL Stash it on the stack again.
AB96 LD HL,($AAA5) Fetch the length of the rope.
AB99 SRL H Halve it.
AB9B RR L
AB9D LD A,L Copy the low byte of the halved length to A.
AB9E JR Position_Rope_End_Square_Length Jump to Position_Rope_End_Square_Length.
Position_Rope_End_Short_Rope ABA0 LD A,($AAA5) Fetch the low byte of the length of the rope.
Position_Rope_End_Square_Length ABA3 LD E,A Copy the length to E.
ABA4 CALL MultiplyAByDE Square the length (or half of it).
ABA7 POP DE Restore the square of the displacement from the stack.
ABA8 AND A Subtract the square of the displacement from the square of the length.
ABA9 SBC HL,DE
ABAB CALL Calculate_Square_Root Take the square root, which is the depth of the end of the rope.
ABAE LD A,L Keep the depth of the end of the rope in A.
Work out the y position of the end of the rope and the position that the rope hangs from, which depend on the number of the room along the rope.
ABAF LD HL,($AAA5) Fetch the length of the rope.
ABB2 ADD HL,HL Double it.
ABB3 EX AF,AF' Stash the depth in AF'.
ABB4 LD A,H Copy the high byte (the number of the room along the rope) to A.
ABB5 AND A Test the number of the room.
ABB6 LD DE,$2480 DE=2480 (the position that the rope hangs from in the top room).
ABB9 JR Z,Position_Rope_End_Top_Room Jump to Position_Rope_End_Top_Room if it is the top room.
ABBB LD DE,$1080 DE=1080 (the position that the rope hangs from in the other rooms).
ABBE LD C,$D7 Set the offset to take off the depth to D7.
ABC0 BIT 0,H Jump to Position_Rope_End_Check_Room_Number if bit 0 of the number of the room is clear.
ABC2 JR Z,Position_Rope_End_Check_Room_Number
ABC4 LD C,$58 Set the offset to take off the depth to 58.
Position_Rope_End_Check_Room_Number ABC6 EX AF,AF' Fetch the depth again from AF'.
ABC7 BIT 1,H Jump to Position_Rope_End_Subtract_Offset if bit 1 of the number of the room is clear.
ABC9 JR Z,Position_Rope_End_Subtract_Offset
ABCB SLA A Double the depth.
Position_Rope_End_Subtract_Offset ABCD SUB C Subtract the offset from the depth.
ABCE JR Position_Rope_End_Store_Position Jump to Position_Rope_End_Store_Position.
Position_Rope_End_Top_Room ABD0 EX AF,AF' Fetch the depth again from AF'.
ABD1 ADD A,$18 Add 18 to the depth.
Position_Rope_End_Store_Position ABD3 ADD A,$0C Add 0C to the result.
ABD5 LD ($AA96),A Store it as the y position of the end of the rope.
ABD8 LD ($AAA7),DE Store the position that the rope hangs from.
ABDC LD A,($AAA4) Fetch the displacement of the end of the rope.
ABDF ADD A,$80 Add 80 (the middle of the room) to make the x position of the end of the rope.
ABE1 LD ($AA95),A Store it as the x position of the end of the rope.
ABE4 RET Return.
Prev: AB73 Up: Map Next: ABE5