Prev: 43172 Up: Map Next: 43314
43236: Get Robot Speed
Used by the routine at MoveRobotHorizontally.
Works out how far the robot moves in this frame. When the robot is told to speed up it uses some energy and accelerates, up to a limit of 64. When it is not it slows down: the speed is the distance to the next cell, in the direction that it is heading, so the robot always stops at the start of a cell.
Input
IX Robot
Output
B The distance to move
GetRobotSpeed 43236 LD A,(38437) Fetch the controls.
43239 BIT 2,A Jump if the key to speed up is being pressed.
43241 JR NZ,GetRobotSpeed_Accelerate
43243 LD A,(IX+0) Fetch the type of the robot...
43246 RRCA ...and turn it into the direction that it is heading in.
43247 RRCA
43248 AND 3 Jump if the robot is heading in direction zero (X decreasing).
43250 JR Z,GetRobotSpeed_XDecreasing
43252 DEC A Count down the direction.
43253 JR Z,GetRobotSpeed_YIncreasing Jump if the robot is heading in direction one (Y increasing).
43255 DEC A Count down the direction.
43256 JR Z,GetRobotSpeed_XIncreasing Jump if the robot is heading in direction two (X increasing).
43258 LD A,(IX+3) The robot is heading in direction three (Y decreasing), so fetch the fraction of the Y position...
43261 JR GetRobotSpeed_Limit ...and jump to limit the distance.
GetRobotSpeed_XIncreasing 43263 LD A,(IX+1) Fetch the fraction of the X position of the robot...
43266 JR GetRobotSpeed_Negate ...and jump to turn it round.
GetRobotSpeed_YIncreasing 43268 LD A,(IX+3) Fetch the fraction of the Y position of the robot.
GetRobotSpeed_Negate 43271 NEG Subtract it from zero, to get the distance to the next cell.
43273 JR GetRobotSpeed_Limit Jump to limit the distance.
GetRobotSpeed_XDecreasing 43275 LD A,(IX+1) Fetch the fraction of the X position of the robot.
GetRobotSpeed_Limit 43278 CP 64 Jump if the distance is below 64...
43280 JR C,GetRobotSpeed_Store
GetRobotSpeed_UseDefault 43282 LD A,64 ...otherwise use 64.
GetRobotSpeed_Store 43284 LD (IX+6),A Store the speed of the robot...
43287 LD A,(IX+6) ...and fetch it...
43290 LD B,A ...into B.
43291 RET Return.
GetRobotSpeed_Accelerate 43292 RES 2,A Clear the bit for speeding up...
43294 LD (38437),A ...and store the controls.
43297 LD DE,8 Using this costs eight units of energy.
43300 CALL UseEnergy Take them out of the battery using UseEnergy.
43303 LD A,(IX+6) Fetch the speed of the robot...
43306 ADD A,16 ...and add 16.
43308 CP 64 Jump to store it if the new speed is below 64.
43310 JR C,GetRobotSpeed_Store
43312 JR GetRobotSpeed_UseDefault Otherwise jump to use 64.
Prev: 43172 Up: Map Next: 43314