Prev: BF36 Up: Map Next: BF95
BF48: Mark Cell Visited
Used by the routine at SpeedPlayerUp.
Records that the object at IX has entered a cell of the village by setting its bit in the bitmap of visited cells at VisitedCells. The bitmap holds one bit for each of the 20 by 20 cells.
The routine does nothing if the cell is the same as the one visited last time. When the cell holds anything other than open ground and has not been visited before, a four note sound effect is started.
Input
IX Object
MarkCellVisited BF48 LD HL,($BBF6) Fetch the last cell that was visited (the column in L and the row in H).
BF4B LD A,(IX+$02) Jump to MarkCellVisited_NewCell if the object is in a different column.
BF4E CP L
BF4F JR NZ,MarkCellVisited_NewCell
BF51 LD A,(IX+$04) Return if the object is in the same row too.
BF54 CP H
BF55 RET Z
This entry point is used by the routine at StartNewLife.
MarkCellVisited_NewCell BF56 LD L,(IX+$02) Fetch the cell that the object is in.
BF59 LD H,(IX+$04)
BF5C LD ($BBF6),HL Remember it as the last cell visited.
BF5F PUSH HL Keep the cell.
BF60 CALL FindMapTile Fetch the type of tile in this cell.
BF63 POP HL Get the cell back.
BF64 JR NZ,MarkCellVisited_Feature Jump to MarkCellVisited_Feature if the cell is not open ground.
Find the byte and the bit of the bitmap for the cell. The byte is (row * 4 + column / 8) and the bit is (column MOD 8).
MarkCellVisited_SetBit BF66 LD A,L Fetch the column.
BF67 LD L,H Put the row in L.
BF68 RLA Shift the column left by three places.
BF69 RLA
BF6A RLA
BF6B LD H,A Keep the shifted column.
BF6C RLA Shift the top bits of the column into L, so that L holds (row * 4 + column / 8).
BF6D RL L
BF6F RLA
BF70 RL L
BF72 LD A,H Fetch the shifted column.
BF73 LD H,$00 Clear the high byte of the offset.
BF75 LD BC,$BC0E Point at the bitmap of visited cells.
BF78 ADD HL,BC Add the offset to find the byte.
BF79 AND %00111000 Keep the bits that give the bit number (column MOD 8) in bits 3 to 5.
BF7B OR %01000110 Turn this into the opcode of a BIT n,(HL) instruction.
BF7D LD ($BF86),A Change the second byte of the instruction at BF85 to it.
BF80 OR %10000000 Turn it into the opcode of a SET n,(HL) instruction.
BF82 LD ($BF88),A Change the second byte of the instruction at BF87 to it.
BF85 BIT 0,(HL) Test the bit for the cell (the code changes itself). The zero flag is set if the cell has not been visited before.
BF87 SET 0,(HL) Set the bit (self-modifying code).
BF89 RET Return.
The cell holds something other than open ground.
MarkCellVisited_Feature BF8A CALL MarkCellVisited_SetBit Record the cell as visited.
BF8D RET NZ Return if the cell has been visited before.
BF8E LD HL,$0004 Start the first sound effect, which has four notes, by setting the note counter at NoteCounter (and the sound number at SoundNumber).
BF91 LD ($BBF9),HL
BF94 RET Return.
Prev: BF36 Up: Map Next: BF95