Prev: CF5F Up: Map Next: CFA1
CF67: Find Position In Cell
Used by the routines at CheckWallsVerticalFirst and CheckWallsHorizontalFirst.
Finds the code of the cell at column D and row H in TownMap, and where the object is in that cell. The position in the cell is half the distance from the corner, plus 40.
Input
D The column of the cell
H The row of the cell
IX The address of the object
Output
A The code of the cell
D The vertical position of the object in the cell
E The horizontal position of the object in the cell
F The zero flag is set if the cell is empty
Keep the row and column, and find the corner of the cell.
FindPositionInCell CF67 LD B,H Keep the row in B and the column in C.
CF68 LD C,D
CF69 PUSH BC Stash the row and column on the stack.
CF6A LD C,$00 Make DE the corner of the column, and BC the corner of the row.
CF6C LD E,C
Find the horizontal position of the object in the cell.
CF6D LD L,(IX+$01) Fetch the horizontal position of the object.
CF70 LD H,(IX+$02)
CF73 AND A Subtract the corner of the column.
CF74 SBC HL,DE
CF76 SRL H Halve the distance.
CF78 RR L
CF7A LD A,L Add 40 and keep it in E.
CF7B ADD A,$40
CF7D LD E,A
Find the vertical position of the object in the cell.
CF7E LD L,(IX+$03) Fetch the vertical position of the object.
CF81 LD H,(IX+$04)
CF84 AND A Subtract the corner of the row.
CF85 SBC HL,BC
CF87 SRL H Halve the distance.
CF89 RR L
CF8B LD A,L Add 40 and keep it in D.
CF8C ADD A,$40
CF8E LD D,A
Find the code of the cell in TownMap.
CF8F POP HL Restore the row and column from the stack.
CF90 LD A,L Put the column in A and the row in HL.
CF91 LD L,H
CF92 LD H,$00
CF94 ADD HL,HL Multiply the row by sixteen.
CF95 ADD HL,HL
CF96 ADD HL,HL
CF97 ADD HL,HL
CF98 OR L Add the column.
CF99 LD L,A
CF9A LD BC,$5FB1 Add the address of TownMap.
CF9D ADD HL,BC
CF9E LD A,(HL) Fetch the code of the cell and return.
CF9F AND A
CFA0 RET
View the equivalent code in;
Prev: CF5F Up: Map Next: CFA1