Prev: BE8F Up: Map Next: BF66
BEE7: Find Tiles Overlapped
Used by the routine at SelectNextTile.
Finds the tile record for the position of the object using FindTileRecord, works out where the object is within the tile and stores it in ScratchValues to CE3D and counts the tiles that it overlaps (up to four) in TileNumber.
FindTilesOverlapped BEE7 LD BC,($BF81) Fetch the word at BF81 into BC.
BEEB LD DE,($BF7F) Fetch the word at TilePosition into DE.
BEEF CALL FindTileRecord Call FindTileRecord.
BEF2 LD A,($BF7F) The tile position.
BEF5 LD C,A C=A.
BEF6 LD A,($5C2C) The segment screen column.
BEF9 LD B,A B=A.
BEFA LD A,C A=C.
BEFB ADD A,$18 Add 18 to A.
BEFD ADD A,B A gains B.
BEFE LD E,B E=B.
BEFF JR NC,FindTilesOverlapped_Horizontal Jump to FindTilesOverlapped_Horizontal if the carry flag is clear.
BF01 LD B,A B=A.
BF02 LD A,($5C1D) The tiles still to test.
BF05 AND A Jump to FindTilesOverlapped_Right if A is not zero.
BF06 JR NZ,FindTilesOverlapped_Right
BF08 LD A,B A=B.
BF09 LD ($5C2A),A The object reaches into the next column.
BF0C LD A,$01 A=01.
BF0E LD ($E41B),A Update the slope direction.
FindTilesOverlapped_Right BF11 LD A,$E8 A=E8.
BF13 SUB C Subtract C from A.
BF14 LD E,A E=A.
FindTilesOverlapped_Horizontal BF15 LD A,E A=E.
BF16 LD ($CE3D),A The horizontal edge in the tile.
BF19 LD A,C A=C.
BF1A LD ($CE3A),A The horizontal position in the tile.
BF1D LD A,($BF81) The vertical position.
BF20 LD C,A C=A.
BF21 LD A,($5C2D) The segment screen row.
BF24 LD B,A B=A.
BF25 LD A,C A=C.
BF26 SUB $17 Subtract 17 from A.
BF28 SUB B Subtract B from A.
BF29 LD E,B E=B.
BF2A JR NC,FindTilesOverlapped_Vertical Jump to FindTilesOverlapped_Vertical if the carry flag is clear.
BF2C LD B,A B=A.
BF2D LD A,($5C1D) The tiles still to test.
BF30 AND A Jump to FindTilesOverlapped_Up if A is not zero.
BF31 JR NZ,FindTilesOverlapped_Up
BF33 LD A,B A=B.
BF34 NEG Negate A.
BF36 LD ($5C2B),A The object reaches into the zone above.
FindTilesOverlapped_Up BF39 LD A,C A=C.
BF3A SUB $17 Subtract 17 from A.
BF3C LD E,A E=A.
FindTilesOverlapped_Vertical BF3D LD A,E A=E.
BF3E LD ($CE3C),A The vertical edge in the tile.
BF41 LD A,C A=C.
BF42 LD ($CE3B),A The vertical position in the tile.
BF45 LD A,($5C1D) The tiles still to test.
BF48 AND A Return if A is not zero.
BF49 RET NZ
BF4A LD B,$01 B=01.
BF4C LD A,($5C2A) The object reaches into the next column.
BF4F AND A Jump to FindTilesOverlapped_Count if A is zero.
BF50 JR Z,FindTilesOverlapped_Count
BF52 INC B Advance B.
BF53 LD A,($5C2B) The object reaches into the zone above.
BF56 AND A Jump to FindTilesOverlapped_Count if A is zero.
BF57 JR Z,FindTilesOverlapped_Count
BF59 INC B Advance B.
FindTilesOverlapped_Count BF5A LD A,($5C2B) The object reaches into the zone above.
BF5D AND A Jump to FindTilesOverlapped_Return if A is zero.
BF5E JR Z,FindTilesOverlapped_Return
BF60 INC B Advance B.
FindTilesOverlapped_Return BF61 LD A,B A=B.
BF62 LD ($5C1D),A Update the tiles still to test.
BF65 RET Return.
Prev: BE8F Up: Map Next: BF66