Prev: BF92 Up: Map Next: BFBE
BF97: Find Map Cell
Finds a cell of the map from its column and row, and tests whether it is empty. The address of the cell is also stored. The routine returns with all of the registers kept, apart from A and the flags.
Input
D Column
H Row
Output
A Type of the cell, which is zero if it is empty
F Zero flag set if the cell is empty
FindMapCell BF97 PUSH DE Save DE and HL.
BF98 PUSH HL
BF99 LD E,D Move the column into E and the row into D.
BF9A LD D,H
BF9B JR FindMapCell_Find Jump to find the cell.
This entry point is used by the routines at MainLoop and AddMapCells.
This entry point takes the column in E and the row in D.
FindMapCell_ColumnRow BF9D PUSH DE Save DE and HL.
BF9E PUSH HL
FindMapCell_Find BF9F LD ($962C),DE Store the column and the row.
BFA3 XOR A Clear the high part of the cell offset.
BFA4 SRL D Divide the row by four, keeping the bits that come out in the top of A.
BFA6 RRA
BFA7 SRL D
BFA9 RRA
BFAA OR E Combine them with the column, to give the low byte of the offset of the cell, as there are 40 cells in each row.
BFAB LD E,A
BFAC LD HL,$C515 Add the offset to the address of the map.
BFAF ADD HL,DE
BFB0 LD ($962E),HL Store the address of the cell.
BFB3 LD A,(HL) Fetch the type of the cell, which is in the lower four bits, and jump if it is zero.
BFB4 AND $0F
BFB6 JR Z,FindMapCell_Empty
FindMapCell_Return BFB8 POP HL Restore HL and DE.
BFB9 POP DE
BFBA RET Return.
FindMapCell_Empty BFBB XOR A Mark the cell as empty and jump.
BFBC JR FindMapCell_Return
Prev: BF92 Up: Map Next: BFBE