![]() |
Routines |
| Prev: 43891 | Up: Map | Next: 44005 |
|
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 256 or more, the length and the square of the displacement are halved before they are used.
The x position is the displacement plus 128 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 36 pixels down at an x position of 128 when the length is less than 128 and 16 pixels down when it is longer.
|
||||||||
|
Square the displacement.
|
||||||||
| Position_Rope_End | 43896 | LD D,0 | Clear the high byte of the displacement. | |||||
| 43898 | LD A,(43684) | Fetch the displacement of the end of the rope. | ||||||
| 43901 | BIT 7,A | Jump to Position_Rope_End_Square_Displacement if it is positive. | ||||||
| 43903 | JR Z,Position_Rope_End_Square_Displacement | |||||||
| 43905 | NEG | Make it positive. | ||||||
| Position_Rope_End_Square_Displacement | 43907 | LD E,A | Copy the displacement to E. | |||||
| 43908 | CALL MultiplyAByDE | Multiply the displacement by itself. | ||||||
| 43911 | 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.
|
||||||||
| 43912 | LD D,0 | Clear the high byte of the length. | ||||||
| 43914 | LD A,(43686) | Fetch the high byte of the length of the rope. | ||||||
| 43917 | AND A | Jump to Position_Rope_End_Short_Rope if the length is less than 256. | ||||||
| 43918 | JR Z,Position_Rope_End_Short_Rope | |||||||
| 43920 | POP HL | Restore the square of the displacement from the stack. | ||||||
| 43921 | SRL H | Halve it. | ||||||
| 43923 | RR L | |||||||
| 43925 | PUSH HL | Stash it on the stack again. | ||||||
| 43926 | LD HL,(43685) | Fetch the length of the rope. | ||||||
| 43929 | SRL H | Halve it. | ||||||
| 43931 | RR L | |||||||
| 43933 | LD A,L | Copy the low byte of the halved length to A. | ||||||
| 43934 | JR Position_Rope_End_Square_Length | Jump to Position_Rope_End_Square_Length. | ||||||
| Position_Rope_End_Short_Rope | 43936 | LD A,(43685) | Fetch the low byte of the length of the rope. | |||||
| Position_Rope_End_Square_Length | 43939 | LD E,A | Copy the length to E. | |||||
| 43940 | CALL MultiplyAByDE | Square the length (or half of it). | ||||||
| 43943 | POP DE | Restore the square of the displacement from the stack. | ||||||
| 43944 | AND A | Subtract the square of the displacement from the square of the length. | ||||||
| 43945 | SBC HL,DE | |||||||
| 43947 | CALL Calculate_Square_Root | Take the square root, which is the depth of the end of the rope. | ||||||
| 43950 | 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.
|
||||||||
| 43951 | LD HL,(43685) | Fetch the length of the rope. | ||||||
| 43954 | ADD HL,HL | Double it. | ||||||
| 43955 | EX AF,AF' | Stash the depth in AF'. | ||||||
| 43956 | LD A,H | Copy the high byte (the number of the room along the rope) to A. | ||||||
| 43957 | AND A | Test the number of the room. | ||||||
| 43958 | LD DE,9344 | DE=9344 (the position that the rope hangs from in the top room). | ||||||
| 43961 | JR Z,Position_Rope_End_Top_Room | Jump to Position_Rope_End_Top_Room if it is the top room. | ||||||
| 43963 | LD DE,4224 | DE=4224 (the position that the rope hangs from in the other rooms). | ||||||
| 43966 | LD C,215 | Set the offset to take off the depth to 215. | ||||||
| 43968 | BIT 0,H | Jump to Position_Rope_End_Check_Room_Number if bit 0 of the number of the room is clear. | ||||||
| 43970 | JR Z,Position_Rope_End_Check_Room_Number | |||||||
| 43972 | LD C,88 | Set the offset to take off the depth to 88. | ||||||
| Position_Rope_End_Check_Room_Number | 43974 | EX AF,AF' | Fetch the depth again from AF'. | |||||
| 43975 | BIT 1,H | Jump to Position_Rope_End_Subtract_Offset if bit 1 of the number of the room is clear. | ||||||
| 43977 | JR Z,Position_Rope_End_Subtract_Offset | |||||||
| 43979 | SLA A | Double the depth. | ||||||
| Position_Rope_End_Subtract_Offset | 43981 | SUB C | Subtract the offset from the depth. | |||||
| 43982 | JR Position_Rope_End_Store_Position | Jump to Position_Rope_End_Store_Position. | ||||||
| Position_Rope_End_Top_Room | 43984 | EX AF,AF' | Fetch the depth again from AF'. | |||||
| 43985 | ADD A,24 | Add 24 to the depth. | ||||||
| Position_Rope_End_Store_Position | 43987 | ADD A,12 | Add 12 to the result. | |||||
| 43989 | LD (43670),A | Store it as the y position of the end of the rope. | ||||||
| 43992 | LD (43687),DE | Store the position that the rope hangs from. | ||||||
| 43996 | LD A,(43684) | Fetch the displacement of the end of the rope. | ||||||
| 43999 | ADD A,128 | Add 128 (the middle of the room) to make the x position of the end of the rope. | ||||||
| 44001 | LD (43669),A | Store it as the x position of the end of the rope. | ||||||
| 44004 | RET | Return. | ||||||
| Prev: 43891 | Up: Map | Next: 44005 |