Prev: 48950 Up: Map Next: 49045
48968: 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 32 by 32 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 48968 LD HL,(48118) Fetch the last cell that was visited (the column in L and the row in H).
48971 LD A,(IX+2) Jump to MarkCellVisited_NewCell if the object is in a different column.
48974 CP L
48975 JR NZ,MarkCellVisited_NewCell
48977 LD A,(IX+4) Return if the object is in the same row too.
48980 CP H
48981 RET Z
This entry point is used by the routine at StartNewLife.
MarkCellVisited_NewCell 48982 LD L,(IX+2) Fetch the cell that the object is in.
48985 LD H,(IX+4)
48988 LD (48118),HL Remember it as the last cell visited.
48991 PUSH HL Keep the cell.
48992 CALL FindMapTile Fetch the type of tile in this cell.
48995 POP HL Get the cell back.
48996 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 48998 LD A,L Fetch the column.
48999 LD L,H Put the row in L.
49000 RLA Shift the column left by three places.
49001 RLA
49002 RLA
49003 LD H,A Keep the shifted column.
49004 RLA Shift the top bits of the column into L, so that L holds (row * 4 + column / 8).
49005 RL L
49007 RLA
49008 RL L
49010 LD A,H Fetch the shifted column.
49011 LD H,0 Clear the high byte of the offset.
49013 LD BC,48142 Point at the bitmap of visited cells.
49016 ADD HL,BC Add the offset to find the byte.
49017 AND %00111000 Keep the bits that give the bit number (column MOD 8) in bits 3 to 5.
49019 OR %01000110 Turn this into the opcode of a BIT n,(HL) instruction.
49021 LD (49030),A Change the second byte of the instruction at 49029 to it.
49024 OR %10000000 Turn it into the opcode of a SET n,(HL) instruction.
49026 LD (49032),A Change the second byte of the instruction at 49031 to it.
49029 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.
49031 SET 0,(HL) Set the bit (self-modifying code).
49033 RET Return.
The cell holds something other than open ground.
MarkCellVisited_Feature 49034 CALL MarkCellVisited_SetBit Record the cell as visited.
49037 RET NZ Return if the cell has been visited before.
49038 LD HL,4 Start the first sound effect, which has four notes, by setting the note counter at NoteCounter (and the sound number at SoundNumber).
49041 LD (48121),HL
49044 RET Return.
Prev: 48950 Up: Map Next: 49045