Prev: 51168 Up: Map Next: 51287
51176: Scroll View Down
Used by the routine at ScrollView.
Scrolls the view down by eight rows when the player has moved towards the top of the view. The rows of the screen buffer are moved down with MoveRowsDown, the new rows at the top are cleared with ClearRows, the view is moved with MoveView and the objects that have come into view are drawn using DrawTopStrip.
Input
IX The player entity
Check whether the player is near enough to the top of the view for the view to scroll down. If it is not, and the view is not part way through a scroll, stop scrolling.
ScrollViewDown 51176 LD A,(23785) Fetch the scroll position, which is 16 when the view is at rest and keep it in C.
51179 LD C,A
51180 LD A,(IX+15) Fetch the row of the player on the screen and keep it in D.
51183 LD D,A
51184 CP 46 Jump to ScrollViewDown_Speed if the player is near the top of the view.
51186 JR C,ScrollViewDown_Speed
51188 LD A,C Fetch the scroll position.
51189 LD L,207 Set the bits of the view flags to keep, to clear the scroll bits.
51191 CP 16 Jump to UpdateViewFlags to clear the scroll bits of the view flags if the view is at rest.
51193 JP Z,UpdateViewFlags
Work out how fast to scroll from the change in the row of the player on the screen. If the player is moving up then the view scrolls down faster.
ScrollViewDown_Speed 51196 LD A,(23782) Fetch the view flags.
51199 AND %11001111 Clear bits 4-5.
51201 LD L,A Keep them in L.
51202 LD A,(23789) Fetch the change in the row of the player.
51205 ADD A,A Double it.
51206 JR NC,ScrollViewDown_Slowest Jump to ScrollViewDown_Slowest if the player is not moving up.
51208 LD E,A Use the doubled change as the amount to scroll.
51209 LD A,L Set bits 4-5 of the flags.
51210 OR 48
51212 LD L,A
51213 JR ScrollViewDown_SetFlags Jump to ScrollViewDown_SetFlags.
ScrollViewDown_Slowest 51215 LD E,254 Scroll by the slowest amount, 254.
51217 LD A,L Set bit 4 of the flags.
51218 OR 16
51220 LD L,A
ScrollViewDown_SetFlags 51221 LD A,L Store the view flags.
51222 LD (23782),A
51225 LD A,E Add the amount to scroll to the scroll position.
51226 ADD A,C
51227 LD (23785),A
51230 JR NZ,ScrollViewDown_CheckWrap Jump to ScrollViewDown_CheckWrap unless the scroll position is zero.
51232 LD A,16 Set the scroll position back to 16.
51234 JR ScrollViewDown_MoveRows Jump to ScrollViewDown_MoveRows.
ScrollViewDown_CheckWrap 51236 BIT 7,A Test bit 7 of the scroll position.
51238 RET Z Return if it has not gone below zero, as the view is not ready to move by a whole row of the buffer.
51239 AND %00001111 Keep the low four bits as the new scroll position.
ScrollViewDown_MoveRows 51241 LD (23785),A Store the scroll position.
Move the view down by eight rows. The player moves down the screen by eight rows, the buffer is moved down, and the eight rows at the top are cleared and drawn again.
51244 LD A,(IX+15) Fetch the row of the player on the screen.
51247 ADD A,8 Add 8.
51249 LD (IX+15),A Store it.
51252 LD (23788),A Store it as the last row of the player.
51255 LD HL,61690 Point HL at the end of the rows to be moved in the buffer.
51258 LD B,120 Set the number of rows to 120.
51260 CALL MoveRowsDown Move the rows of the buffer down.
51263 LD HL,59003 Point HL at ScreenBuffer_Row08.
51266 CALL ClearRows Clear the eight rows.
51269 LD DE,8 Set the distance to move the view origin, 8.
51272 CALL MoveView Move the view origin.
51275 LD HL,58977 Point HL at the first rows of the buffer.
51278 LD (23739),HL Store it as the place to draw to.
51281 LD HL,49416 Point HL at DrawTopStrip.
51284 JP DrawLevelObjects_Second Draw the objects of the level in the strip.
Prev: 51168 Up: Map Next: 51287