Prev: BF36 Up: Map Next: BF95
BF48: Mark the knight's cell visited, and sound a new one with a building
Used by the routine at WALK_ON.
Called by WALK_ON as the knight walks. Nothing happens while he stays in LAST_CELL; in a new cell, it becomes LAST_CELL and its bit in VISITED is set. A cell with anything built on it (a type other than 0) that had not been visited before also starts sound effect 0, four notes. NEW_LIFE enters at ENTER_CELL to mark the cell a life starts in.
MARK_VISITED writes the bit number into the BIT and SET instructions that test and set it -- the second byte of each is $46 or $C6 plus eight times the bit -- and returns with Z set if the cell is new: SET leaves the flags as BIT made them.
Input
IX the knight's legs record
VISIT_CELL BF48 LD HL,(LAST_CELL) still in the cell he was in: nothing to do
BF4B LD A,(IX+$02)
BF4E CP L
BF4F JR NZ,ENTER_CELL
BF51 LD A,(IX+$04)
BF54 CP H
BF55 RET Z
This entry point is used by the routine at NEW_LIFE.
ENTER_CELL BF56 LD L,(IX+$02) ENTER_CELL: the new cell, column and row, becomes LAST_CELL
BF59 LD H,(IX+$04)
BF5C LD (LAST_CELL),HL
BF5F PUSH HL open ground (type 0): just mark it
BF60 CALL TOWN_CELL
BF63 POP HL
BF64 JR NZ,VISIT_CELL_0
MARK_VISITED BF66 LD A,L MARK_VISITED: HL = VISITED + 4 * row + column / 8
BF67 LD L,H
BF68 RLA
BF69 RLA
BF6A RLA
BF6B LD H,A
BF6C RLA
BF6D RL L
BF6F RLA
BF70 RL L
BF72 LD A,H
BF73 LD H,$00
BF75 LD BC,VISITED
BF78 ADD HL,BC
BF79 AND $38 write bit (column AND 7) into the next two instructions
BF7B OR $46
BF7D LD ($BF86),A
BF80 OR $80
BF82 LD ($BF88),A
BF85 BIT 0,(HL) BIT n,(HL): Z if the cell is new
BF87 SET 0,(HL) SET n,(HL), the flags as BIT left them
BF89 RET Z for a new cell
VISIT_CELL_0 BF8A CALL MARK_VISITED built on: mark it; visited before, and that is all
BF8D RET NZ
BF8E LD HL,$0004 a new one: sound effect 0, four notes
BF91 LD (EFFECT_TIME),HL
BF94 RET
Prev: BF36 Up: Map Next: BF95