Prev: 56168 Up: Map Next: 56340
56201: Choose Direction
Used by the routine at UpdatePlayerLegs.
Works out the direction that the player is facing from the controls, which is held in bits 6 and 7 of the direction and timer of the player (0 is up the screen, 1 is right, 2 is down and 3 is left). A turn takes a few frames, which are counted in the lowest bits of the timer.
With the keyboard or when the option for directional control is not set, the controls for left and right turn the player. When it is set, the player turns towards the direction that the controls give, one quarter at a time, and moves when it faces that way.
Input
E Controls
IX Player
Output
E Controls, with bit 2 set only if the player is to move forward
Jump to SetFacingFlags while a turn is still counting.
ChooseDirection 56201 LD A,(IX+6) Fetch the direction and the time left in a turn.
56204 AND %00000111 Keep the time left in a turn.
56206 JR Z,ChooseDirection_Controls Jump to ChooseDirection_Controls if the player is not turning.
Count down the turn counter, and set the sprite of the player.
56208 DEC (IX+6) Count down the time.
56211 JR SetFacingFlags Jump to SetFacingFlags.
Use the keyboard unless a joystick is set to give a direction.
ChooseDirection_Controls 56213 LD HL,48048 Point HL at GameOptions.
56216 LD A,(HL) Fetch GameOptions.
56217 AND %00000110 Keep the bits for the controls.
56219 JR Z,ChooseDirection_Relative Jump to ChooseDirection_Relative if the controls are the keyboard.
56221 BIT 3,(HL) Jump to ChooseDirection_Relative if the option for directional control is not set.
56223 JR Z,ChooseDirection_Relative
Swap the controls for left and right, and up and down, if the view is rotated.
56225 LD A,(48058) Fetch ViewRotatedFlag.
56228 AND %00000001 Keep the lowest bit.
56230 CALL NZ,SwapControls Call SwapControls if the view is rotated.
Turn towards the direction that is pressed.
56233 BIT 0,E Jump to ChooseDirection_Right if the control for left is used.
56235 JR NZ,ChooseDirection_Right
56237 BIT 2,E Jump to ChooseDirection_Up if the control for up is used.
56239 JR NZ,ChooseDirection_Up
The controls are not for up.
ChooseDirection_Right 56241 BIT 1,E Jump to ChooseDirection_WantRight if the control for right is used.
56243 JR NZ,ChooseDirection_WantRight
56245 BIT 4,E Jump to ChooseDirection_WantDown if the control for down is used.
56247 JR NZ,ChooseDirection_WantDown
56249 BIT 0,E Jump to ChooseDirection_WantLeft if the control for left is used.
56251 JR NZ,ChooseDirection_WantLeft
Clear the control for up, and return.
56253 RES 2,E Clear bit 2 of the controls.
56255 RET Return.
The controls are for up.
ChooseDirection_Up 56256 LD A,(IX+6) Fetch the direction of the player.
How far is the heading from the direction that is wanted?
ChooseDirection_Turn 56259 AND %11000000 Keep only the heading.
56261 RES 2,E Clear bit 2 of the controls.
56263 JR Z,ChooseDirection_Forward Jump to ChooseDirection_Forward if the player already faces that way.
56265 CP 64 Jump to ChooseDirection_TurnBack if the player has to turn back by a quarter.
56267 JR Z,ChooseDirection_TurnBack
56269 CP 192 Jump to ChooseDirection_TurnOn if the player has to turn on by a quarter.
56271 JR Z,ChooseDirection_TurnOn
Choose which way to turn from the random seed, as the player has to turn right round.
56273 LD A,(48042) Fetch the random seed.
56276 CP 128 Jump to ChooseDirection_TurnOn if it is less than 128.
56278 JR C,ChooseDirection_TurnOn
Turn back a quarter.
ChooseDirection_TurnBack 56280 LD A,(IX+6) Fetch the direction of the player.
56283 SUB 64 Take a quarter turn off it.
56285 JR ChooseDirection_Counter Jump to ChooseDirection_Counter.
Turn on a quarter.
ChooseDirection_TurnOn 56287 LD A,(IX+6) Fetch the direction of the player.
56290 ADD A,64 Add a quarter turn to it.
56292 JR ChooseDirection_Counter Jump to ChooseDirection_Counter.
The controls are for right.
ChooseDirection_WantRight 56294 LD A,(IX+6) Fetch the direction of the player.
56297 SUB 64 Take a quarter turn off it.
56299 JR ChooseDirection_Turn Jump to ChooseDirection_Turn.
The controls are for down.
ChooseDirection_WantDown 56301 LD A,(IX+6) Fetch the direction of the player.
56304 SUB 128 Take two quarter turns off it.
56306 JR ChooseDirection_Turn Jump to ChooseDirection_Turn.
The controls are for left.
ChooseDirection_WantLeft 56308 LD A,(IX+6) Fetch the direction of the player.
56311 SUB 192 Take three quarter turns off it.
56313 JR ChooseDirection_Turn Jump to ChooseDirection_Turn.
The player faces the way that was asked.
ChooseDirection_Forward 56315 SET 2,E Set the control for moving forward, and return.
56317 RET
Left and right turn the player a quarter.
ChooseDirection_Relative 56318 LD A,(IX+6) Fetch the direction of the player.
Turn the player back by a quarter if the control for left is used.
56321 BIT 0,E Jump to ChooseDirection_RelativeRight if left is not pressed.
56323 JR Z,ChooseDirection_RelativeRight
56325 SUB 64 Take a quarter turn off the heading.
56327 OR %00000001 Start a turn.
Right turns the player the other way.
ChooseDirection_RelativeRight 56329 BIT 1,E Jump to ChooseDirection_Set if right is not pressed.
56331 JR Z,ChooseDirection_Set
56333 ADD A,64 Add a quarter turn to the heading.
Start a turn and store the heading.
ChooseDirection_Counter 56335 OR %00000001 Start a turn.
ChooseDirection_Set 56337 LD (IX+6),A Set the direction of the player.
Continue on to SetFacingFlags.
View the equivalent code in;
Prev: 56168 Up: Map Next: 56340