Prev: C87A Up: Map Next: C948
C89F: Handle Turning
Used by the routine at HandlePlayerLegs.
Turns the player, using the left and right controls or, if a joystick with directional control is in use, the direction that is pressed. The directional controls turn the player a quarter turn at a time towards the direction pressed along the shortest way, and flag the player to walk once it is facing that direction. The facing of the player is stored as the horizontal flip flag and bit 3 of the graphic number.
Input
C The controls
IX Address of the object
Output
C The controls, with the walk control changed if directional control is in use
HandleTurning C89F LD HL,$5BA4 Fetch the control method, ControlMethod.
C8A2 LD A,(HL)
C8A3 AND %00000110 Keep the joystick bits.
C8A5 JR Z,HandleTurning_Rotate Jump to HandleTurning_Rotate if the keyboard is in use.
C8A7 BIT 3,(HL) Jump to HandleTurning_Rotate if directional control is not in use.
C8A9 JR Z,HandleTurning_Rotate
Directional control. The player cannot turn while entering the room, or while it is not standing on something.
C8AB LD A,(IX+$0C) Fetch the flags of the player.
C8AE AND %11110000 Keep the counter of the player entering the room.
C8B0 RET NZ Return if the player is entering the room.
C8B1 BIT 2,(IX+$0C) Test whether the player is standing on something.
C8B5 RET Z Return if it is not.
Find the direction that is pressed. Left takes priority over up.
C8B6 BIT 0,C Jump to HandleTurning_Right if it is pressed.
C8B8 JR NZ,HandleTurning_Right
C8BA BIT 2,C Jump to HandleTurning_North if it is pressed.
C8BC JR NZ,HandleTurning_North
HandleTurning_Right C8BE BIT 1,C Jump to HandleTurning_East if it is pressed.
C8C0 JR NZ,HandleTurning_East
C8C2 BIT 4,C Jump to HandleTurning_South if it is pressed.
C8C4 JR NZ,HandleTurning_South
C8C6 BIT 0,C Jump to HandleTurning_West if it is pressed.
C8C8 JR NZ,HandleTurning_West
C8CA RES 2,C Clear the walk control, as no direction is pressed.
C8CC RET Return.
The facing of the player is 00 for west, 01 for east, 02 for north and 03 for south.
HandleTurning_North C8CD CALL GetFacingDirection Fetch the direction the player is facing.
C8D0 CP $02 Test whether it is north.
HandleTurning_North_Test C8D2 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk if it is.
C8D4 CPL Invert the direction.
HandleTurning_North_Direction C8D5 AND %00000001 Keep bit 0, which decides which way to turn.
C8D7 JR HandleTurning_Turn Jump to HandleTurning_Turn.
HandleTurning_East C8D9 CALL GetFacingDirection Fetch the direction the player is facing.
C8DC CP $01 Test whether it is east.
C8DE JR HandleTurning_North_Test Jump to HandleTurning_North_Test.
HandleTurning_South C8E0 CALL GetFacingDirection Fetch the direction the player is facing.
C8E3 CP $03 Test whether it is south.
HandleTurning_South_Test C8E5 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk if it is.
C8E7 JR HandleTurning_North_Direction Jump to HandleTurning_North_Direction.
HandleTurning_West C8E9 CALL GetFacingDirection Fetch the direction the player is facing.
C8EC AND A Test whether it is west.
C8ED JR HandleTurning_South_Test Jump to HandleTurning_South_Test.
HandleTurning_Walk C8EF SET 2,C Set the walk control, as the player is facing the direction that is pressed.
C8F1 RET Return.
Rotational control. After each turn the player has to wait before it can turn again.
HandleTurning_Rotate C8F2 LD A,(IX+$0D) Fetch the flags.
C8F5 AND %00000111 Keep the turning delay counter, which is in the low three bits.
C8F7 JR Z,HandleTurning_Rotate_ReadControls Jump to HandleTurning_Rotate_ReadControls if it has run out.
C8F9 DEC (IX+$0D) Count it down.
C8FC RET Return.
HandleTurning_Rotate_ReadControls C8FD LD A,C Fetch the controls.
C8FE AND %00000011 Keep left and right.
C900 RET Z Return if neither is pressed.
C901 LD A,(IX+$0C) Fetch the flags of the player.
C904 AND %11110000 Keep the counter of the player entering the room.
C906 RET NZ Return if the player is entering the room.
C907 BIT 3,(IX+$0C) Test whether the player is jumping.
C90B RET NZ Return if it is.
C90C BIT 2,C Jump to HandleTurning_Rotate_Reset if it is pressed.
C90E JR NZ,HandleTurning_Rotate_Reset
C910 PUSH BC Stash the controls on the stack.
C911 CALL PlayFootstepsSound_EveryFrame Play the sound of the footsteps.
C914 POP BC Restore the controls from the stack.
HandleTurning_Rotate_Reset C915 LD A,(IX+$0D) Fetch the flags.
C918 OR %00000010 Set the turning delay counter, which has run out, to 02.
C91A LD (IX+$0D),A Store it.
C91D BIT 1,C Test the right control.
HandleTurning_Turn C91F JR NZ,HandleTurning_ToggleFlip_Test Jump to HandleTurning_ToggleFlip_Test if the player is to turn right.
C921 BIT 6,(IX+$07) Jump to HandleTurning_ToggleFlip if the sprite is flipped horizontally.
C925 JR NZ,HandleTurning_ToggleFlip
HandleTurning_ToggleGraphic C927 LD A,(IX+$00) Fetch the graphic number.
C92A XOR %00001000 Toggle bit 3 of it.
C92C LD (IX+$00),A Store it.
HandleTurning_ToggleFlip C92F LD A,(IX+$07) Fetch the flags.
C932 XOR %01000000 Toggle the horizontal flip flag.
C934 LD (IX+$07),A Store the flags.
C937 LD A,(IX+$00) Fetch the graphic number, and add 10 to get the top half.
C93A ADD A,$10
C93C LD (IX+$20),A Set the graphic number of the top half of the player.
C93F RET Return.
HandleTurning_ToggleFlip_Test C940 BIT 6,(IX+$07) Jump to HandleTurning_ToggleGraphic if the sprite is flipped horizontally.
C944 JR NZ,HandleTurning_ToggleGraphic
C946 JR HandleTurning_ToggleFlip Jump to HandleTurning_ToggleFlip.
View the equivalent code in;
Prev: C87A Up: Map Next: C948