Prev: 6BF6 Up: Map Next: 6C2D
6BFE: Find First Object
Used by the routine at NewGame.
Finds the first map point whose X position is not less than the player's X position minus 60 and writes its address to CurrentObject. If there is not one then the pointer is reset to the start of the map points.
FindFirstObject 6BFE LD BC,$7811 Point BC at the first map point (MapPoints).
6C01 LD HL,($5E05) Fetch the player's X position on the map (PlayerMapPosition).
6C04 LD DE,$0060 Set the furthest distance in view, 0060.
6C07 AND A HL=HL - DE (the left edge of the view).
6C08 SBC HL,DE
6C0A EX DE,HL Exchange DE and HL.
FindFirstObject_Next 6C0B EX DE,HL Exchange them back so HL holds the left edge of the view again.
6C0C LD A,(BC) Fetch the X position of the map point.
6C0D INC BC Move on to the Y position of the map point.
6C0E LD D,A Keep the X position in D.
6C0F CALL ScaleValue_DivideByEight Call ScaleValue_DivideByEight to convert it to map units in DE.
6C12 EX DE,HL Exchange DE and HL.
6C13 AND A HL=HL - DE (the distance from the left edge of the view).
6C14 SBC HL,DE
6C16 JR NC,FindFirstObject_Found Jump to FindFirstObject_Found if the map point is not to the left of the left edge.
6C18 INC BC Move on to the next map point.
6C19 INC BC
6C1A LD HL,$7CD6 Point HL at the end of the map points (Sprite_Car_1, one byte past the end of MapPoints).
6C1D AND A HL=HL - BC.
6C1E SBC HL,BC
6C20 JR NZ,FindFirstObject_Next Jump to FindFirstObject_Next if there are more map points.
6C22 LD BC,$7811 Point BC at the first map point (MapPoints), to go back to the start.
FindFirstObject_Store 6C25 LD ($5E19),BC Write BC to CurrentObject.
6C29 RET Return.
FindFirstObject_Found 6C2A DEC BC Decrease BC by one (back to the X position).
6C2B JR FindFirstObject_Store Jump to FindFirstObject_Store.
Prev: 6BF6 Up: Map Next: 6C2D