Prev: C10E Up: Map Next: C184
C152: Scale a scroll step for a parallax layer
Used by the routine at draw_stars.
Divides the step in H by 1, 2 or 4 for the layer in B. A plain arithmetic shift would turn a step of -2 into -1 but +2 into 0 for the far layer, so it would only ever drift one way; instead the far layer takes 0 and -1, or 1 and 0, on alternate passes (bit 0 of the pass counter pass_counter), and moves at a quarter of the speed either way.
Input
B The layer: 1 near, 2 middle, 3 far
H The scroll step (signed pixels)
Output
H The layer's step
parallax_step C152 LD A,B Near layer: the whole step.
C153 CP $01
C155 RET Z
C156 CP $02 Middle layer: just halve it.
C158 JR Z,parallax_step_0
C15A LD A,H Far layer, step -2: no movement on odd passes.
C15B CP $FE
C15D JR NZ,parallax_step_0
C15F LD A,(pass_counter)
C162 AND $01
C164 JR Z,parallax_step_0
C166 LD H,$00
C168 RET
parallax_step_0 C169 LD A,B Far layer, step +2: on odd passes make it 4, so that the quarter is 1.
C16A CP $03
C16C JR NZ,parallax_step_1
C16E LD A,H
C16F CP $02
C171 JR NZ,parallax_step_1
C173 LD A,(pass_counter)
C176 AND $01
C178 JR Z,parallax_step_1
C17A LD H,$04
parallax_step_1 C17C LD A,B Shift right, keeping the sign, B-1 times.
C17D DEC A
parallax_step_2 C17E SRA H
C180 DEC A
C181 JR NZ,parallax_step_2
C183 RET
Prev: C10E Up: Map Next: C184