Prev: DB68 Up: Map Next: DC43
DB89: Turn the knight, by the controls
Used by the routine at UPDATE_KNIGHT.
The low three bits of his facing (+6) are a turn delay: while it is not 0 it counts down and he cannot turn. A turn sets it to 1, so a turn key held down turns him a quarter every other turn.
With the keyboard, or a stick with rotational control, left and right turn him a quarter (left subtracts $40 from the facing, right adds it) and walking is left to KNIGHT_WALKS. With a stick and directional control (CONTROL bits 1-2 not 0, bit 3 set), the stick's direction is a facing -- up +V, right +U, down -V, left -U, turned round with the town (SWAP_STICK) -- and he turns a quarter towards it, a random way if it is behind him, walking (bit 2 of E) only once he faces it. The stick is read as up (unless left is held too), then right, down and left, so a diagonal counts as one of its two directions.
Then, from offset 139 (SET_KNIGHT_LOOK, also the entry while he appears), his picture: FACING_LOOKS gives the mirror bit and whether he is seen from the front, by his facing and the view.
Input
IX The legs' record
E The controls: bits 0-1 left and right, 2 walk (up), 3 fire, 4 down, 5 turn the town round
Output
E Bit 2 set if he walks this turn
TURN_KNIGHT DB89 LD A,(IX+$06) Turning delay still running: count it, and only set his picture
DB8C AND $07
DB8E JR Z,TURN_KNIGHT_0
DB90 DEC (IX+$06)
DB93 JR SET_KNIGHT_LOOK
TURN_KNIGHT_0 DB95 LD HL,CONTROL A stick with directional control?
DB98 LD A,(HL)
DB99 AND $06
DB9B JR Z,TURN_KNIGHT_10
DB9D BIT 3,(HL)
DB9F JR Z,TURN_KNIGHT_10
DBA1 LD A,(VIEW) Its directions turned round with the town
DBA4 AND $01
DBA6 CALL NZ,SWAP_STICK
DBA9 BIT 0,E Up, unless left too
DBAB JR NZ,TURN_KNIGHT_1
DBAD BIT 2,E
DBAF JR NZ,TURN_KNIGHT_2
TURN_KNIGHT_1 DBB1 BIT 1,E Right
DBB3 JR NZ,TURN_KNIGHT_6
DBB5 BIT 4,E Down
DBB7 JR NZ,TURN_KNIGHT_7
DBB9 BIT 0,E Left
DBBB JR NZ,TURN_KNIGHT_8
DBBD RES 2,E None: stand
DBBF RET
TURN_KNIGHT_2 DBC0 LD A,(IX+$06) Up: +V, the facing itself
TURN_KNIGHT_3 DBC3 AND $C0 A: the facing less the stick's; no walking unless it is 0
DBC5 RES 2,E
DBC7 JR Z,TURN_KNIGHT_9
DBC9 CP $40 A quarter to the right of it: turn left
DBCB JR Z,TURN_KNIGHT_4
DBCD CP $C0 A quarter to the left: turn right
DBCF JR Z,TURN_KNIGHT_5
DBD1 LD A,(RANDOM) Behind him: either way, at random
DBD4 CP $80
DBD6 JR C,TURN_KNIGHT_5
TURN_KNIGHT_4 DBD8 LD A,(IX+$06) Turn left
DBDB SUB $40
DBDD JR TURN_KNIGHT_12
TURN_KNIGHT_5 DBDF LD A,(IX+$06) Turn right
DBE2 ADD A,$40
DBE4 JR TURN_KNIGHT_12
TURN_KNIGHT_6 DBE6 LD A,(IX+$06) Right: +U
DBE9 SUB $40
DBEB JR TURN_KNIGHT_3
TURN_KNIGHT_7 DBED LD A,(IX+$06) Down: -V
DBF0 SUB $80
DBF2 JR TURN_KNIGHT_3
TURN_KNIGHT_8 DBF4 LD A,(IX+$06) Left: -U
DBF7 SUB $C0
DBF9 JR TURN_KNIGHT_3
TURN_KNIGHT_9 DBFB SET 2,E Facing it already: walk
DBFD RET
TURN_KNIGHT_10 DBFE LD A,(IX+$06) Rotational control: left?
DC01 BIT 0,E
DC03 JR Z,TURN_KNIGHT_11
DC05 SUB $40 Turn left, with a turn's delay
DC07 OR $01
TURN_KNIGHT_11 DC09 BIT 1,E Right? Turn right
DC0B JR Z,TURN_KNIGHT_13
DC0D ADD A,$40
TURN_KNIGHT_12 DC0F OR $01 A turn's delay
TURN_KNIGHT_13 DC11 LD (IX+$06),A The new facing
This entry point is used by the routine at UPDATE_KNIGHT.
SET_KNIGHT_LOOK DC14 LD A,(IX+$06) Index FACING_LOOKS by the facing, flipped with the town
DC17 RLCA
DC18 RLCA
DC19 AND $03
DC1B LD L,A
DC1C LD A,(VIEW)
DC1F ADD A,A
DC20 XOR L
DC21 LD L,A
DC22 LD H,$00
DC24 LD BC,FACING_LOOKS Its bits 6-7 into the flags: the mirror
DC27 ADD HL,BC
DC28 LD A,(HL)
DC29 AND $C0
DC2B LD C,A
DC2C LD A,(IX+$07)
DC2F AND $3F
DC31 OR C
DC32 LD (IX+$07),A
DC35 LD A,(HL) Its bit 3 into the graphic: from behind (16-21) or the front (24-29)
DC36 AND $08
DC38 LD C,A
DC39 LD A,(IX+$00)
DC3C AND $F7
DC3E OR C
DC3F LD (IX+$00),A
DC42 RET
Prev: DB68 Up: Map Next: DC43