Prev: D942 Up: Map Next: D978
D94F: The update routine for a villain (graphics 96-111)
A villain walks at speed 4, turning left or right at random when it meets a wall and every so often besides (STEER), and kills the knight at a touch: not a hit off his three but the whole life (WANDERING_MONSTER from offset 59, which also keeps his cell for the next life). Only its own object destroys it (OBJECT_FLIGHT).
While it is on the screen it hums (BLIP_BY_TURN, from offset 3): twelve pulses a turn at a pitch read from a 16-byte table by the turn count. The table was meant to be one of the four that follow the creature's (BLIP_PITCHES), one per villain, but that routine builds the address from BC alone and throws away the table's address loaded into HL here; and the offset in BC is not 0, 16, 32 or 48 but 128, 144, 160 or 176, since the graphic's bit 5 lands in bit 7, which the AND $F0 keeps (AND $30 would have been right). So the pitches come from the ROM's bytes $0080-$00BF, and the four tables are never read. Measured in the simulator: with each villain put beside the knight, the pitch was read from $00BB, $00AD, $009F and $0081 for the villains of graphics 108, 104, 100 and 96.
Input
IX The villain's record (VILLAINS)
VILLAIN_WANDER D94F LD A,(IX+$00) BC: the graphic's bits 2-3 times 16, plus 128 from its bit 5 (meant as an offset into the villains' tables)
D952 RLCA
D953 RLCA
D954 AND $F0
D956 LD C,A
D957 LD B,$00
D959 LD HL,VILLAIN_PITCHES The hum, if it was drawn last turn; the table's address in HL is overwritten there, so BC alone is the address: the ROM
D95C CALL BLIP_FROM_TABLE
D95F LD A,(IX+$05) The step from the speed and the facing; trim it at a wall; move
D962 CALL SET_STEP
D965 CALL MOVE_CLIPPED
D968 CALL APPLY_STEP
D96B CALL STEER Decide whether to turn
D96E CALL FACING_PICTURE Its picture for the facing
D971 CALL TOUCHING_KNIGHT Done unless it touches the knight...
D974 RET NC
D975 JP KNIGHT_KILLED ...who dies, and will start his next life where he stands
Prev: D942 Up: Map Next: D978