Prev: 53087 Up: Map Next: 53153
53095: 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 64.
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 53095 LD B,H Keep the row in B and the column in C.
53096 LD C,D
53097 PUSH BC Stash the row and column on the stack.
53098 LD C,0 Make DE the corner of the column, and BC the corner of the row.
53100 LD E,C
Find the horizontal position of the object in the cell.
53101 LD L,(IX+1) Fetch the horizontal position of the object.
53104 LD H,(IX+2)
53107 AND A Subtract the corner of the column.
53108 SBC HL,DE
53110 SRL H Halve the distance.
53112 RR L
53114 LD A,L Add 64 and keep it in E.
53115 ADD A,64
53117 LD E,A
Find the vertical position of the object in the cell.
53118 LD L,(IX+3) Fetch the vertical position of the object.
53121 LD H,(IX+4)
53124 AND A Subtract the corner of the row.
53125 SBC HL,BC
53127 SRL H Halve the distance.
53129 RR L
53131 LD A,L Add 64 and keep it in D.
53132 ADD A,64
53134 LD D,A
Find the code of the cell in TownMap.
53135 POP HL Restore the row and column from the stack.
53136 LD A,L Put the column in A and the row in HL.
53137 LD L,H
53138 LD H,0
53140 ADD HL,HL Multiply the row by sixteen.
53141 ADD HL,HL
53142 ADD HL,HL
53143 ADD HL,HL
53144 OR L Add the column.
53145 LD L,A
53146 LD BC,24497 Add the address of TownMap.
53149 ADD HL,BC
53150 LD A,(HL) Fetch the code of the cell and return.
53151 AND A
53152 RET
View the equivalent code in;
Prev: 53087 Up: Map Next: 53153