Prev: 43896 Up: Map Next: 44136
44005: Move Rope
Used by the routine at Update_Rope.
Makes the rope swing. The velocity of the end of the rope (Rope_Velocity) is changed by four towards the middle of the swing (it is increased when the displacement is negative and decreased when it is positive) and then it is multiplied by 32 and added to the displacement (Rope_Displacement).
When the rope is already at rest nothing changes. When the end of the rope is moving towards the middle, the change of velocity is left out on one call in eight (the test is made on the tick counter at GameTimer for a negative displacement and on FRAMES for a positive one).
If the length of the rope is less than 128 the displacement is limited to the length multiplied by 176 and divided by 256. When it would go further, the displacement is set to the limit and the velocity and the fraction are set to zero. For a longer rope the displacement is not limited.
Input
IX Object record
Find out if the rope is at rest (no displacement and no velocity).
Move_Rope 44005 LD A,(43684) Fetch the displacement of the end of the rope.
44008 LD HL,43682 Point at the velocity of the end of the rope.
44011 AND A Jump to Move_Rope_Change_Velocity if the rope is not hanging straight down (the displacement is not zero).
44012 JR NZ,Move_Rope_Change_Velocity
44014 EX AF,AF' Keep the displacement in AF'.
44015 LD A,(HL) Fetch the velocity of the end of the rope.
44016 AND A Return if the rope is at rest (the velocity is zero).
44017 RET Z
44018 EX AF,AF' Fetch the displacement again from AF'.
Change the velocity. A negative displacement adds four to it and a positive one subtracts four.
Move_Rope_Change_Velocity 44019 AND %10000000 Keep only bit 7 (the sign of the displacement).
44021 JR Z,Move_Rope_Positive_Displacement Jump to Move_Rope_Positive_Displacement if the displacement is positive.
44023 BIT 7,(HL) Jump to Move_Rope_Add_Four if the velocity is negative.
44025 JR NZ,Move_Rope_Add_Four
44027 LD A,(36566) Fetch the tick counter from GameTimer.
44030 AND %00000111 Keep only bits 0 to 2.
44032 JR Z,Move_Rope_Move_End Jump to Move_Rope_Move_End without changing the velocity if the result is zero (once in every eight passes).
Move_Rope_Add_Four 44034 INC (HL) Add four to the velocity, to pull the end of the rope back towards the middle.
44035 INC (HL)
44036 INC (HL)
44037 INC (HL)
44038 JR Move_Rope_Move_End Jump to Move_Rope_Move_End.
Move_Rope_Positive_Displacement 44040 BIT 7,(HL) Jump to Move_Rope_Subtract_Four if the velocity is positive.
44042 JR Z,Move_Rope_Subtract_Four
44044 LD A,(23672) Fetch the low byte of FRAMES.
44047 AND %00000111 Keep only bits 0 to 2.
44049 JR Z,Move_Rope_Move_End Jump to Move_Rope_Move_End without changing the velocity if the result is zero (once in every eight passes).
Move_Rope_Subtract_Four 44051 DEC (HL) Subtract four from the velocity, to pull the end of the rope back towards the middle.
44052 DEC (HL)
44053 DEC (HL)
44054 DEC (HL)
Multiply the velocity by 32 and add it to the displacement.
Move_Rope_Move_End 44055 LD A,(HL) Fetch the velocity of the end of the rope.
44056 AND A Test the sign of the velocity.
44057 LD D,0 Clear the high byte of the velocity.
44059 JP P,Move_Rope_Sign_Extended Jump to Move_Rope_Sign_Extended if the velocity is positive.
44062 LD D,255 Set the high byte of the velocity to 255 to extend the sign.
Move_Rope_Sign_Extended 44064 LD E,A Copy the velocity to E.
44065 EX DE,HL Move the velocity (as a word) to HL.
44066 ADD HL,HL Multiply the velocity by 32.
44067 ADD HL,HL
44068 ADD HL,HL
44069 ADD HL,HL
44070 ADD HL,HL
44071 LD DE,(43683) Fetch the displacement (the fraction is in the low byte).
44075 ADD HL,DE Add the velocity to the displacement.
44076 PUSH HL Stash the new displacement on the stack.
44077 LD DE,176 Set the multiplier for the limit of the displacement to 176.
44080 LD HL,(43685) Fetch the length of the rope.
44083 SRL H Halve the length of the rope.
44085 RR L
44087 LD A,L Copy the low byte to A.
44088 AND %11000000 Keep only bits 6 and 7.
44090 JR Z,Move_Rope_Find_Limit Jump to Move_Rope_Find_Limit if the length is less than 128.
44092 POP HL Fetch the new displacement again from the stack.
44093 JR Move_Rope_Store_Displacement Jump to Move_Rope_Store_Displacement to store it without a limit.
Find the limit of the displacement, which is the length of the rope multiplied by 176 and divided by 256.
Move_Rope_Find_Limit 44095 LD A,(43685) Fetch the low byte of the length of the rope.
44098 CALL MultiplyAByDE Multiply it by 176.
44101 LD A,H Copy the high byte of the result (the limit) to A.
44102 POP HL Fetch the new displacement again from the stack.
44103 BIT 7,H Jump to Move_Rope_Negative_Limit if the displacement is negative.
44105 JR NZ,Move_Rope_Negative_Limit
44107 CP H Jump to Move_Rope_Beyond_Limit if the displacement is beyond the limit.
44108 JR C,Move_Rope_Beyond_Limit
44110 LD (43683),HL Store the new displacement.
44113 RET Return.
Move_Rope_Negative_Limit 44114 NEG Make the limit negative.
44116 CP H Jump to Move_Rope_Store_Displacement if the displacement is at the limit.
44117 JR Z,Move_Rope_Store_Displacement
44119 JR NC,Move_Rope_Beyond_Limit Jump to Move_Rope_Beyond_Limit if the displacement is beyond the limit.
Move_Rope_Store_Displacement 44121 LD (43683),HL Store the new displacement.
44124 RET Return.
The displacement is beyond the limit. Set it to the limit and stop the swing.
Move_Rope_Beyond_Limit 44125 LD (43684),A Set the displacement to the limit.
44128 XOR A Clear the fraction of the displacement and the velocity.
44129 LD (43683),A
44132 LD (43682),A
44135 RET Return.
Prev: 43896 Up: Map Next: 44136