Prev: C7FC Up: Map Next: C868
C81F: Turn the speed across into this pass's horizontal step
Used by the routine at hit_block.
The second half of accelerate_across, also used by hit_block. The speed is added to the running position word ship_position_across, and twice the change in its high byte is the step in pixels (the landscape moves in 2-pixel steps). A step of the top speed (top_speed) plus 2 is cut to the top speed. The step goes to scroll_across. One last rule: a step of 4 taken when the fine scroll (origin_x) is at 2 or 6 is halved, so 4-pixel steps start only from 0 or 4.
Input
HL The speed across (8.8)
speed_to_scroll C81F LD DE,(ship_position_across) The position word moves by the speed; the step is twice the change in its whole part.
C823 ADD HL,DE
C824 LD (ship_position_across),HL
C827 LD A,H
C828 SUB D
C829 ADD A,A
C82A LD H,A
C82B LD A,(top_speed) The limit: the top speed (top_speed) plus 2, with the step's sign.
C82E BIT 7,H
C830 JR NZ,speed_to_scroll_0
C832 ADD A,$02
C834 LD B,A
C835 JR speed_to_scroll_1
speed_to_scroll_0 C837 NEG
C839 SUB $02
C83B LD B,A
speed_to_scroll_1 C83C LD A,H A step at the limit becomes the top speed.
C83D BIT 7,A
C83F JR NZ,speed_to_scroll_2
C841 CP B
C842 JR NZ,speed_to_scroll_3
C844 LD A,(top_speed)
speed_to_scroll_2 C847 CP B
C848 JR NZ,speed_to_scroll_3
C84A LD A,(top_speed)
C84D NEG
speed_to_scroll_3 C84F LD (scroll_across),A This pass's horizontal scroll; anything but a 4-pixel step is done.
C852 CP $04
C854 JR Z,speed_to_scroll_4
C856 CP $FC
C858 RET NZ
speed_to_scroll_4 C859 LD A,(origin_x) A 4-pixel step from 2 or 6 becomes 2.
C85C AND $02
C85E RET Z
C85F LD A,(scroll_across)
C862 SRA A
C864 LD (scroll_across),A
C867 RET
Prev: C7FC Up: Map Next: C868