Prev: 57376 Up: Map Next: 57425
57384: Find Position In Cell
Used by the routines at CheckWallsVerticalFirst and CheckWallsHorizontalFirst.
Finds where an object is in a cell. The position in the cell is half the distance from the corner, plus 64. FindMapTile finds the tile of that cell.
Input
D Column of the cell
H Row of the cell
IX Object
Output
E The position of the object along the X axis in the cell
D The position of the object along the Y axis in the cell
L The column of the cell
H The row of the cell
Keep the row and column, and find the corner of the cell.
FindPositionInCell 57384 LD B,H Keep the row in B and the column in C.
57385 LD C,D
57386 PUSH BC Stash the row and column on the stack.
57387 LD C,0 Clear the lowest byte of the column and of the row, to give the position of the corner of the cell.
57389 LD E,C
Find the horizontal position of the object in the cell.
57390 LD L,(IX+1) Fetch the X position of the object.
57393 LD H,(IX+2)
57396 AND A Subtract the X position of the corner of the cell.
57397 SBC HL,DE
57399 SRL H Halve the distance.
57401 RR L
57403 LD A,L Add the offset, to give the position of the object along the X axis in the cell.
57404 ADD A,64
57406 LD E,A
Find the vertical position of the object in the cell.
57407 LD L,(IX+3) Fetch the Y position of the object.
57410 LD H,(IX+4)
57413 AND A Subtract the Y position of the corner of the cell.
57414 SBC HL,BC
57416 SRL H Halve the distance.
57418 RR L
57420 LD A,L Add the offset, to give the position of the object along the Y axis in the cell.
57421 ADD A,64
57423 LD D,A
57424 POP HL Get the column and the row back.
View the equivalent code in;
Prev: 57376 Up: Map Next: 57425