Prev: AAE5 Up: Map Next: AB8F
AB0F: Control Player
Used by the routine at RunFrame.
Reads the controls and makes the player entity turn, jump and move forward. The controls are a byte with one bit for each direction, as read by ReadControls: bit 0 and bit 1 turn the player, bit 2 makes the player jump if it is on the ground, and bit 3 makes the player move forward. While the player is held (fields 24 and 25 are not both zero) bits 2-4 are ignored. The rate of turning builds up while a turn control is held, and is kept in TurningRate.
Input
IX The player entity
ControlPlayer AB0F CALL ReadControls Read the controls.
AB12 LD A,(IX+$24) Read field 24 of the entity.
AB15 OR (IX+$25) Combine it with field 25.
AB18 JR Z,ControlPlayer_Store Jump to ControlPlayer_Store if both are zero.
AB1A RES 2,C Ignore bit 2 of the controls.
AB1C RES 3,C Ignore bit 3 of the controls.
AB1E RES 4,C Ignore bit 4 of the controls.
ControlPlayer_Store AB20 LD A,C Fetch the controls.
AB21 LD ($5CDE),A Store them in GameVariable.
AB24 LD HL,($5CF6) Fetch the rate of turning from TurningRate.
AB27 LD DE,$0080 Set the amount by which the rate builds up.
AB2A RR C Move bit 0 into the carry flag.
AB2C JR NC,ControlPlayer_TestLeft Jump to ControlPlayer_TestLeft if it is reset.
AB2E RR C Move bit 1 into the carry flag.
AB30 JR C,ControlPlayer_NoTurn Jump to ControlPlayer_NoTurn if both are set.
AB32 LD B,$FF Set the direction of the turn to FF.
AB34 JR ControlPlayer_Turn Jump to ControlPlayer_Turn.
ControlPlayer_TestLeft AB36 RR C Move bit 1 into the carry flag.
AB38 JR NC,ControlPlayer_NoTurn Jump to ControlPlayer_NoTurn if neither bit is set.
AB3A LD B,$00 Set the direction of the turn to 00.
ControlPlayer_Turn AB3C ADD HL,DE Increase the rate of turning.
AB3D LD A,H Fetch the whole part of the rate.
AB3E CP $03 Jump to ControlPlayer_StoreRate if it is less.
AB40 JR C,ControlPlayer_StoreRate
AB42 DEC H Limit the rate to below 03.
ControlPlayer_StoreRate AB43 LD ($5CF6),HL Store the rate of turning.
AB46 LD A,H Fetch the whole part of the rate.
AB47 BIT 7,B Jump to ControlPlayer_Heading if the turn is in the positive direction.
AB49 JR Z,ControlPlayer_Heading
AB4B NEG Make the turn negative.
ControlPlayer_Heading AB4D LD B,A Keep the turn in B.
AB4E LD A,(IX+$11) Fetch the heading of the player.
AB51 ADD A,B Add the turn.
AB52 AND %00111111 Use bits 0-5.
AB54 LD (IX+$11),A Store the new heading.
AB57 JR ControlPlayer_Jump Jump to ControlPlayer_Jump.
ControlPlayer_NoTurn AB59 RES 7,(IX+$11) Reset bit 7 of the heading of the player, so that it is not moving forward.
AB5D LD E,$40 Set the amount by which the rate of turning falls.
AB5F AND A Clear the carry flag.
AB60 SBC HL,DE Reduce the rate of turning.
AB62 JR NC,ControlPlayer_StoreRate2 Jump to ControlPlayer_StoreRate2 if it is still positive.
AB64 LD HL,$0000 Set the rate of turning to zero.
ControlPlayer_StoreRate2 AB67 LD ($5CF6),HL Store the rate of turning.
ControlPlayer_Jump AB6A RR C Move bit 2 into the carry flag.
AB6C JR NC,ControlPlayer_Forward Jump to ControlPlayer_Forward if it is reset.
AB6E BIT 7,(IX+$1E) Jump to ControlPlayer_Forward if bit 7 of field 1E of the player is reset.
AB72 JR Z,ControlPlayer_Forward
AB74 LD A,($5D00) Fetch the jump flag from JumpCounter.
AB77 AND A Test it.
AB78 JR NZ,ControlPlayer_Forward Jump to ControlPlayer_Forward if the player is already jumping.
AB7A LD (IX+$12),$04 Set the vertical speed of the player (field 12) to 04...
AB7E LD (IX+$13),$00 ...and field 13 to 00.
AB82 LD A,$01 Set the jump flag to 01...
AB84 LD ($5D00),A ...and store it.
ControlPlayer_Forward AB87 RR C Move bit 3 into the carry flag.
AB89 RET NC Return if it is reset.
AB8A SET 7,(IX+$11) Set bit 7 of the heading of the player, so that it moves forward.
AB8E RET Return.
Prev: AAE5 Up: Map Next: AB8F