Prev: 8DC4 Up: Map Next: 8EA0
8E26: Per-frame update for the knight
One of three near-identical routines, one per playable character: this is the knight, UPDATE_WIZARD and UPDATE_SERF are the other two. Which one runs is decided by the sprite byte alone -- see ACTOR_HANDLERS.
Treats +$06 and +$07 as a signed dx/dy, compares their magnitudes to decide whether the movement is mostly horizontal or mostly vertical, and picks a sprite accordingly -- base + 4 or base + 8, with the low two bits cycling to give the walk cycle.
This looked at first like it contradicted MOVE_ACTOR, which treats +$06 as a pair of direction bits rather than a signed value. It does not: the two routines work on different records. Breaking on each and reading IX shows UPDATE_KNIGHT is only ever called with IX = $EA90, the player, while MOVE_ACTOR is called with the 16-byte monster records at $EE90. Both readings stand; the field simply means different things in the two layouts.
Input
IX The actor to animate
UPDATE_KNIGHT 8E26 LD BC,$2020
8E29 LD DE,$0303
8E2C LD HL,$0707
8E2F CALL MOVE_PLAYER
8E32 LD E,(IX+$06) dx and dy. If both are zero the thing is standing still and keeps its sprite.
8E35 LD D,(IX+$07)
8E38 LD A,D
8E39 OR E
8E3A JR Z,UPDATE_KNIGHT_4
8E3C LD A,($5C78) FRAMES, so the walk cycle advances every fourth frame rather than every call. Interrupts are enabled during play (checked live: IFF1 set, IM 1), so the ROM's interrupt handler is what keeps this ticking.
8E3F AND $03
8E41 JR NZ,UPDATE_KNIGHT_4
8E43 LD A,(IX+$00) Cycle the low two bits: the four frames of the walk.
8E46 AND $03
8E48 INC A
8E49 LD (IX+$00),A
8E4C LD A,D
8E4D AND A
8E4E JP P,UPDATE_KNIGHT_0
8E51 NEG
UPDATE_KNIGHT_0 8E53 LD C,A
8E54 LD A,E
8E55 AND A
8E56 JP P,UPDATE_KNIGHT_1
8E59 NEG
UPDATE_KNIGHT_1 8E5B CP C
8E5C JR NC,UPDATE_KNIGHT_5
8E5E LD A,D Mostly-vertical movement takes one sprite group, mostly-horizontal another.
8E5F AND A
8E60 LD A,(IX+$00)
8E63 JP M,UPDATE_KNIGHT_2
8E66 ADD A,$04
UPDATE_KNIGHT_2 8E68 ADD A,$08
UPDATE_KNIGHT_3 8E6A LD (IX+$00),A
8E6D CALL SOUND_FOOTSTEP A footstep.
UPDATE_KNIGHT_4 8E70 CALL READ_CONTROLS
8E73 AND $10
8E75 CALL Z,KNIGHT_FIRE
This entry point is used by the routines at UPDATE_WIZARD and UPDATE_SERF.
PLAYER_TICK 8E78 CALL SPAWN_MONSTER_INTO_ROOM
8E7B LD A,($5E12) Only while TICKS -- main-loop passes, not frames -- is a multiple of sixteen; the gate stays open for every frame of that pass, so it takes one or two units per sixteen passes.
8E7E AND $0F
8E80 JR NZ,REDRAW_ACTOR
8E82 LD A,($5E28) The life force runs down on its own, a unit at a time. Reaching zero is death -- there is no way to stand still and survive.
8E85 DEC A
8E86 JR Z,LOSE_LIFE
8E88 LD ($5E28),A Store it and redraw the roast, which only actually redraws once an eighth has gone.
8E8B CALL DRAW_FOOD
This entry point is used by the routines at SPIN_SPELL, MOVE_ARCS, MOVE_ACTOR, SPAWN_MONSTER and COUNTDOWN_ACTOR.
REDRAW_ACTOR 8E8E CALL REDRAW_MOVED
8E91 JP DRAW_FROM_RECORD
UPDATE_KNIGHT_5 8E94 LD A,E
8E95 AND A
8E96 LD A,(IX+$00)
8E99 JP M,UPDATE_KNIGHT_3
8E9C ADD A,$04
8E9E JR UPDATE_KNIGHT_3
Prev: 8DC4 Up: Map Next: 8EA0