Prev: E020 Up: Map Next: E051
E028: 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 40. 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 E028 LD B,H Keep the row in B and the column in C.
E029 LD C,D
E02A PUSH BC Stash the row and column on the stack.
E02B LD C,$00 Clear the lowest byte of the column and of the row, to give the position of the corner of the cell.
E02D LD E,C
Find the horizontal position of the object in the cell.
E02E LD L,(IX+$01) Fetch the X position of the object.
E031 LD H,(IX+$02)
E034 AND A Subtract the X position of the corner of the cell.
E035 SBC HL,DE
E037 SRL H Halve the distance.
E039 RR L
E03B LD A,L Add the offset, to give the position of the object along the X axis in the cell.
E03C ADD A,$40
E03E LD E,A
Find the vertical position of the object in the cell.
E03F LD L,(IX+$03) Fetch the Y position of the object.
E042 LD H,(IX+$04)
E045 AND A Subtract the Y position of the corner of the cell.
E046 SBC HL,BC
E048 SRL H Halve the distance.
E04A RR L
E04C LD A,L Add the offset, to give the position of the object along the Y axis in the cell.
E04D ADD A,$40
E04F LD D,A
E050 POP HL Get the column and the row back.
View the equivalent code in;
Prev: E020 Up: Map Next: E051