Prev: C7FC Up: Map Next: C868
C81F: Update Horizontal Scroll Speed
Used by the routine at CheckTerrainCollision.
Adds the horizontal speed of the ship to the fraction in HorizontalScrollFraction and works out how many whole pixels of horizontal scroll that makes, limited by the value in HorizontalLimit in the same way as UpdateVerticalScrollSpeed for the vertical scroll. The result is stored in HorizontalSpeed.
Input
HL Horizontal speed
UpdateHorizontalScrollSpeed C81F LD DE,($C7FA) Fetch the word at HorizontalScrollFraction into DE.
C823 ADD HL,DE HL gains DE.
C824 LD ($C7FA),HL Update the horizontal scroll fraction.
C827 LD A,H A=H.
C828 SUB D Subtract D from A.
C829 ADD A,A Double A.
C82A LD H,A H=A.
C82B LD A,($5C3E) The horizontal scroll limit.
C82E BIT 7,H Jump to UpdateHorizontalScrollSpeed_Negative if bit 7 of H is set.
C830 JR NZ,UpdateHorizontalScrollSpeed_Negative
C832 ADD A,$02 Add 02 to A.
C834 LD B,A B=A.
C835 JR UpdateHorizontalScrollSpeed_Limit Jump to UpdateHorizontalScrollSpeed_Limit.
UpdateHorizontalScrollSpeed_Negative C837 NEG Negate A.
C839 SUB $02 Subtract 02 from A.
C83B LD B,A B=A.
UpdateHorizontalScrollSpeed_Limit C83C LD A,H A=H.
C83D BIT 7,A Jump to UpdateHorizontalScrollSpeed_Fast if bit 7 of A is set.
C83F JR NZ,UpdateHorizontalScrollSpeed_Fast
C841 CP B Jump to UpdateHorizontalScrollSpeed_Store if A is not B.
C842 JR NZ,UpdateHorizontalScrollSpeed_Store
C844 LD A,($5C3E) The horizontal scroll limit.
UpdateHorizontalScrollSpeed_Fast C847 CP B Jump to UpdateHorizontalScrollSpeed_Store if A is not B.
C848 JR NZ,UpdateHorizontalScrollSpeed_Store
C84A LD A,($5C3E) The horizontal scroll limit.
C84D NEG Negate A.
UpdateHorizontalScrollSpeed_Store C84F LD ($CCBB),A Update the horizontal scroll speed.
C852 CP $04 Jump to UpdateHorizontalScrollSpeed_Halve if A is 04.
C854 JR Z,UpdateHorizontalScrollSpeed_Halve
C856 CP $FC Return if A is not FC.
C858 RET NZ
UpdateHorizontalScrollSpeed_Halve C859 LD A,($CE41) The horizontal offset.
C85C AND %00000010 Keep the bits of A that are set in 02.
C85E RET Z Return if the zero flag is set.
C85F LD A,($CCBB) The horizontal scroll speed.
C862 SRA A Shift A right keeping the sign.
C864 LD ($CCBB),A Update the horizontal scroll speed.
C867 RET Return.
Prev: C7FC Up: Map Next: C868