Prev: 51196 Up: Map Next: 51304
51231: 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 51231 LD DE,(51194) Fetch the word at HorizontalScrollFraction into DE.
51235 ADD HL,DE HL gains DE.
51236 LD (51194),HL Update the horizontal scroll fraction.
51239 LD A,H A=H.
51240 SUB D Subtract D from A.
51241 ADD A,A Double A.
51242 LD H,A H=A.
51243 LD A,(23614) The horizontal scroll limit.
51246 BIT 7,H Jump to UpdateHorizontalScrollSpeed_Negative if bit 7 of H is set.
51248 JR NZ,UpdateHorizontalScrollSpeed_Negative
51250 ADD A,2 Add 2 to A.
51252 LD B,A B=A.
51253 JR UpdateHorizontalScrollSpeed_Limit Jump to UpdateHorizontalScrollSpeed_Limit.
UpdateHorizontalScrollSpeed_Negative 51255 NEG Negate A.
51257 SUB 2 Subtract 2 from A.
51259 LD B,A B=A.
UpdateHorizontalScrollSpeed_Limit 51260 LD A,H A=H.
51261 BIT 7,A Jump to UpdateHorizontalScrollSpeed_Fast if bit 7 of A is set.
51263 JR NZ,UpdateHorizontalScrollSpeed_Fast
51265 CP B Jump to UpdateHorizontalScrollSpeed_Store if A is not B.
51266 JR NZ,UpdateHorizontalScrollSpeed_Store
51268 LD A,(23614) The horizontal scroll limit.
UpdateHorizontalScrollSpeed_Fast 51271 CP B Jump to UpdateHorizontalScrollSpeed_Store if A is not B.
51272 JR NZ,UpdateHorizontalScrollSpeed_Store
51274 LD A,(23614) The horizontal scroll limit.
51277 NEG Negate A.
UpdateHorizontalScrollSpeed_Store 51279 LD (52411),A Update the horizontal scroll speed.
51282 CP 4 Jump to UpdateHorizontalScrollSpeed_Halve if A is 4.
51284 JR Z,UpdateHorizontalScrollSpeed_Halve
51286 CP 252 Return if A is not 252.
51288 RET NZ
UpdateHorizontalScrollSpeed_Halve 51289 LD A,(52801) The horizontal offset.
51292 AND %00000010 Keep the bits of A that are set in 2.
51294 RET Z Return if the zero flag is set.
51295 LD A,(52411) The horizontal scroll speed.
51298 SRA A Shift A right keeping the sign.
51300 LD (52411),A Update the horizontal scroll speed.
51303 RET Return.
Prev: 51196 Up: Map Next: 51304