Prev: C7E0 Up: Map Next: C857
C7E8: 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 C7E8 LD A,($5CE9) Fetch the scroll position, which is 10 when the view is at rest and keep it in C.
C7EB LD C,A
C7EC LD A,(IX+$0F) Fetch the row of the player on the screen and keep it in D.
C7EF LD D,A
C7F0 CP $2E Jump to ScrollViewDown_Speed if the player is near the top of the view.
C7F2 JR C,ScrollViewDown_Speed
C7F4 LD A,C Fetch the scroll position.
C7F5 LD L,$CF Set the bits of the view flags to keep, to clear the scroll bits.
C7F7 CP $10 Jump to UpdateViewFlags to clear the scroll bits of the view flags if the view is at rest.
C7F9 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 C7FC LD A,($5CE6) Fetch the view flags.
C7FF AND %11001111 Clear bits 4-5.
C801 LD L,A Keep them in L.
C802 LD A,($5CED) Fetch the change in the row of the player.
C805 ADD A,A Double it.
C806 JR NC,ScrollViewDown_Slowest Jump to ScrollViewDown_Slowest if the player is not moving up.
C808 LD E,A Use the doubled change as the amount to scroll.
C809 LD A,L Set bits 4-5 of the flags.
C80A OR $30
C80C LD L,A
C80D JR ScrollViewDown_SetFlags Jump to ScrollViewDown_SetFlags.
ScrollViewDown_Slowest C80F LD E,$FE Scroll by the slowest amount, FE.
C811 LD A,L Set bit 4 of the flags.
C812 OR $10
C814 LD L,A
ScrollViewDown_SetFlags C815 LD A,L Store the view flags.
C816 LD ($5CE6),A
C819 LD A,E Add the amount to scroll to the scroll position.
C81A ADD A,C
C81B LD ($5CE9),A
C81E JR NZ,ScrollViewDown_CheckWrap Jump to ScrollViewDown_CheckWrap unless the scroll position is zero.
C820 LD A,$10 Set the scroll position back to 10.
C822 JR ScrollViewDown_MoveRows Jump to ScrollViewDown_MoveRows.
ScrollViewDown_CheckWrap C824 BIT 7,A Test bit 7 of the scroll position.
C826 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.
C827 AND %00001111 Keep the low four bits as the new scroll position.
ScrollViewDown_MoveRows C829 LD ($5CE9),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.
C82C LD A,(IX+$0F) Fetch the row of the player on the screen.
C82F ADD A,$08 Add 08.
C831 LD (IX+$0F),A Store it.
C834 LD ($5CEC),A Store it as the last row of the player.
C837 LD HL,$F0FA Point HL at the end of the rows to be moved in the buffer.
C83A LD B,$78 Set the number of rows to 78.
C83C CALL MoveRowsDown Move the rows of the buffer down.
C83F LD HL,$E67B Point HL at ScreenBuffer_Row08.
C842 CALL ClearRows Clear the eight rows.
C845 LD DE,$0008 Set the distance to move the view origin, 08.
C848 CALL MoveView Move the view origin.
C84B LD HL,$E661 Point HL at the first rows of the buffer.
C84E LD ($5CBB),HL Store it as the place to draw to.
C851 LD HL,$C108 Point HL at DrawTopStrip.
C854 JP DrawLevelObjects_Second Draw the objects of the level in the strip.
Prev: C7E0 Up: Map Next: C857