Prev: C4A3 Up: Map Next: C56C
C4C8: Turn the player
Used by the routine at PLAYER_LEGS.
Two ways of steering. Rotational control -- the keyboard's, and every joystick's as the menu leaves them -- turns a quarter at a time on the two turn controls: bit 0 of C turns left, bit 1 right. Directional control treats the controls as four points of the compass instead: pushing one turns the player towards it and, once he faces it, walks him that way. It needs a joystick method and bit 3 of CONTROL, which no menu choice sets (MENU), so the game as sold never uses it.
Facings, as GET_SPRITE_DIR gives them: 0 is towards lower U (up and left on the screen), 1 higher U (down and right), 2 higher V (up and right), 3 lower V (down and left). A facing is stored as two bits -- bit 2 of the graphic and bit 6 of the flags, the mirror bit -- and a quarter turn always toggles the mirror bit and, half the time, the graphic's bit 2 as well. A left turn goes 0, 3, 1, 2 and round; a right turn the other way. The body's graphic is set to the legs' plus 8 at once, so the two turn in the same turn.
Directional control reads up (bit 2) unless left is also held, then right, down (bit 4), left, and goes the short way round, or two turns for an about-face. Up is the walk bit itself, so pushing up walks even while turning; and down is bit 4, which READ_CONTROLS sets only from the pick-up keys -- every joystick's down is jump, bit 3 -- so a joystick alone can never face 3. This is Knight Lore's code, where the stick's down was bit 4.
Input
IX The player's legs (OBJECTS)
C The controls (INPUT): bits 0 and 1 turn, 2 walk, 3 jump, 4 pick up
Output
C Bit 2 set if the player is to walk
HANDLE_LEFT_RIGHT C4C8 LD HL,CONTROL Bits 1-2 of the control method: 0, the keyboard, always turns rotationally
C4CB LD A,(HL)
C4CC AND $06
C4CE JR Z,HANDLE_LEFT_RIGHT_9
C4D0 BIT 3,(HL) Directional control not switched on
C4D2 JR Z,HANDLE_LEFT_RIGHT_9
C4D4 LD A,(IX+$0C) Directional: nothing during the walk into a room (the count in bits 4-7 of +$0C)
C4D7 AND $F0
C4D9 RET NZ
C4DA BIT 2,(IX+$0C) Nor in the air: bit 2 of +$0C, set when a move down was stopped, means standing
C4DE RET Z
C4DF BIT 0,C Left held: skip up; up held: face 2
C4E1 JR NZ,HANDLE_LEFT_RIGHT_0
C4E3 BIT 2,C
C4E5 JR NZ,HANDLE_LEFT_RIGHT_1
HANDLE_LEFT_RIGHT_0 C4E7 BIT 1,C Right: face 1; down: face 3; left: face 0
C4E9 JR NZ,HANDLE_LEFT_RIGHT_4
C4EB BIT 4,C
C4ED JR NZ,HANDLE_LEFT_RIGHT_5
C4EF BIT 0,C
C4F1 JR NZ,HANDLE_LEFT_RIGHT_7
C4F3 RES 2,C Nothing pushed: no walking (bit 2 is already clear by now)
C4F5 RET
HANDLE_LEFT_RIGHT_1 C4F6 CALL GET_SPRITE_DIR Up: facing 2 already, so walk
C4F9 CP $02
HANDLE_LEFT_RIGHT_2 C4FB JR Z,HANDLE_LEFT_RIGHT_8
C4FD CPL Otherwise invert the facing, so that bit 0 set means a right turn is the short way
HANDLE_LEFT_RIGHT_3 C4FE AND $01
C500 JR HANDLE_LEFT_RIGHT_12
HANDLE_LEFT_RIGHT_4 C502 CALL GET_SPRITE_DIR Right: facing 1 already? The same test as up
C505 CP $01
C507 JR HANDLE_LEFT_RIGHT_2
HANDLE_LEFT_RIGHT_5 C509 CALL GET_SPRITE_DIR Down: facing 3 already? Walk if so
C50C CP $03
HANDLE_LEFT_RIGHT_6 C50E JR Z,HANDLE_LEFT_RIGHT_8
C510 JR HANDLE_LEFT_RIGHT_3 Otherwise the facing's own bit 0 picks the turn
HANDLE_LEFT_RIGHT_7 C512 CALL GET_SPRITE_DIR Left: facing 0 already? The same test as down
C515 AND A
C516 JR HANDLE_LEFT_RIGHT_6
HANDLE_LEFT_RIGHT_8 C518 SET 2,C Facing the way pushed: walk
C51A RET
HANDLE_LEFT_RIGHT_9 C51B LD A,(IX+$0D) Rotational: while the pause between turns (bits 0-2 of +$0D) runs, count it down and do nothing else
C51E AND $07
C520 JR Z,HANDLE_LEFT_RIGHT_10
C522 DEC (IX+$0D)
C525 RET
HANDLE_LEFT_RIGHT_10 C526 LD A,C Neither turn control held
C527 AND $03
C529 RET Z
C52A LD A,(IX+$0C) Not during the walk into a room
C52D AND $F0
C52F RET NZ
C530 BIT 3,(IX+$0C) Not in the middle of a jump
C534 RET NZ
C535 BIT 2,C A jump to the next instruction: Knight Lore plays a turning sound here when the player is not walking, and this is what is left of it
C537 JR NZ,HANDLE_LEFT_RIGHT_11
HANDLE_LEFT_RIGHT_11 C539 LD A,(IX+$0D) A pause of two turns before the next quarter turn
C53C OR $02
C53E LD (IX+$0D),A
C541 BIT 1,C Bit 1: right
HANDLE_LEFT_RIGHT_12 C543 JR NZ,HANDLE_LEFT_RIGHT_15 NZ for a right turn, Z for a left
C545 BIT 6,(IX+$07) Left turn: an unmirrored sprite only mirrors (2 to 0, 3 to 1)
C549 JR Z,HANDLE_LEFT_RIGHT_14
HANDLE_LEFT_RIGHT_13 C54B LD A,(IX+$00) Toggle the graphic's bit 2: the other view
C54E XOR $04
C550 LD (IX+$00),A
HANDLE_LEFT_RIGHT_14 C553 LD A,(IX+$07) Toggle the mirror bit
C556 XOR $40
C558 LD (IX+$07),A
C55B LD A,(IX+$00) The body's graphic is the legs' plus 8
C55E ADD A,$08
C560 LD (IX+$20),A
C563 RET
HANDLE_LEFT_RIGHT_15 C564 BIT 6,(IX+$07) Right turn: a mirrored sprite only mirrors (0 to 2, 1 to 3); otherwise both
C568 JR Z,HANDLE_LEFT_RIGHT_13
C56A JR HANDLE_LEFT_RIGHT_14
Prev: C4A3 Up: Map Next: C56C