Prev: C0EA Up: Map Next: C152
C10E: Check Star Position
Used by the routine at UpdateStarLayer.
Finds the position of a star on the screen, from its position and the offset of its layer. It is stored in A1D5 and A1D6. In the third zone a star is also left out if it is below the level of the ground.
Output
F The zero flag is set if the star is not on the screen
CheckStarPosition C10E LD HL,($C0E6) Fetch the word at StarVariables into HL.
C111 LD DE,($C0E8) Fetch the word at C0E8 into DE.
C115 LD A,(DE) Read DE.
C116 AND %11111110 Keep the bits of A that are set in FE.
C118 ADD A,(HL) Add the byte at HL to A.
C119 SUB $08 Subtract 08 from A.
C11B CP $E0 Jump to CheckStarPosition_Hidden if A is E0 or more.
C11D JR NC,CheckStarPosition_Hidden
C11F ADD A,$08 Add 08 to A.
C121 LD ($A1D5),A The star's horizontal position.
C124 INC DE Advance DE.
C125 INC HL Advance HL.
C126 LD A,(DE) Read DE.
C127 ADD A,(HL) Add the byte at HL to A.
C128 SUB $18 Subtract 18 from A.
C12A CP $A1 Jump to CheckStarPosition_Hidden if A is A1 or more.
C12C JR NC,CheckStarPosition_Hidden
C12E ADD A,$18 Add 18 to A.
C130 LD ($A1D6),A The star's vertical position.
C133 LD A,($CE58) The map row.
C136 CP $03 Jump to CheckStarPosition_Visible if A is not 03.
C138 JR NZ,CheckStarPosition_Visible
C13A LD A,($CE46) The position down.
C13D CPL Invert A.
C13E SUB $31 Subtract 31 from A.
C140 LD B,A B=A.
C141 LD A,($A1D6) The star's vertical position.
C144 CP B Jump to CheckStarPosition_Hidden if A is B or more.
C145 JR NC,CheckStarPosition_Hidden
CheckStarPosition_Visible C147 LD A,($CCBC) The star flags.
C14A OR %00000001 Set the bits of A that are set in 01.
C14C LD ($CCBC),A Update the star flags.
C14F RET Return.
CheckStarPosition_Hidden C150 XOR A Clear A.
C151 RET Return.
Prev: C0EA Up: Map Next: C152