Prev: A8A4 Up: Map Next: A932
A8E4: 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 40. 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 A8E4 LD A,($9625) Fetch the controls.
A8E7 BIT 2,A Jump if the key to speed up is being pressed.
A8E9 JR NZ,GetRobotSpeed_Accelerate
A8EB LD A,(IX+$00) Fetch the type of the robot...
A8EE RRCA ...and turn it into the direction that it is heading in.
A8EF RRCA
A8F0 AND $03 Jump if the robot is heading in direction zero (X decreasing).
A8F2 JR Z,GetRobotSpeed_XDecreasing
A8F4 DEC A Count down the direction.
A8F5 JR Z,GetRobotSpeed_YIncreasing Jump if the robot is heading in direction one (Y increasing).
A8F7 DEC A Count down the direction.
A8F8 JR Z,GetRobotSpeed_XIncreasing Jump if the robot is heading in direction two (X increasing).
A8FA LD A,(IX+$03) The robot is heading in direction three (Y decreasing), so fetch the fraction of the Y position...
A8FD JR GetRobotSpeed_Limit ...and jump to limit the distance.
GetRobotSpeed_XIncreasing A8FF LD A,(IX+$01) Fetch the fraction of the X position of the robot...
A902 JR GetRobotSpeed_Negate ...and jump to turn it round.
GetRobotSpeed_YIncreasing A904 LD A,(IX+$03) Fetch the fraction of the Y position of the robot.
GetRobotSpeed_Negate A907 NEG Subtract it from zero, to get the distance to the next cell.
A909 JR GetRobotSpeed_Limit Jump to limit the distance.
GetRobotSpeed_XDecreasing A90B LD A,(IX+$01) Fetch the fraction of the X position of the robot.
GetRobotSpeed_Limit A90E CP $40 Jump if the distance is below 40...
A910 JR C,GetRobotSpeed_Store
GetRobotSpeed_UseDefault A912 LD A,$40 ...otherwise use 40.
GetRobotSpeed_Store A914 LD (IX+$06),A Store the speed of the robot...
A917 LD A,(IX+$06) ...and fetch it...
A91A LD B,A ...into B.
A91B RET Return.
GetRobotSpeed_Accelerate A91C RES 2,A Clear the bit for speeding up...
A91E LD ($9625),A ...and store the controls.
A921 LD DE,$0008 Using this costs eight units of energy.
A924 CALL UseEnergy Take them out of the battery using UseEnergy.
A927 LD A,(IX+$06) Fetch the speed of the robot...
A92A ADD A,$10 ...and add 10.
A92C CP $40 Jump to store it if the new speed is below 40.
A92E JR C,GetRobotSpeed_Store
A930 JR GetRobotSpeed_UseDefault Otherwise jump to use 40.
Prev: A8A4 Up: Map Next: A932