Prev: B145 Up: Map Next: B19E
B178: Update Screen
Used by the routines at RunGame, DisplayMenu and ShowGameOverScreen.
Copies the whole buffer to the screen. The buffer is held with its bottom line first, so the copy starts with the bottom line of the screen and works its way up.
Set up the addresses of the buffer and of the bottom line of the screen.
UpdateScreen B178 LD HL,$D88F Point HL at the start of the buffer, ScreenBuffer.
B17B LD DE,$57E0 Point DE at the bottom line of the screen, 57E0.
B17E LD C,$C0 Set a counter in C of C0 lines.
UpdateScreen_Loop B180 PUSH BC Stash the line counter on the stack.
B181 PUSH DE Stash the screen address on the stack.
B182 LD BC,$0020 Set a counter in BC of 20 bytes.
B185 LDIR Copy the line to the screen.
B187 POP DE Restore the screen address from the stack.
Move up to the next pixel line of the screen.
B188 DEC D Move up one pixel line.
B189 LD A,D Invert the high byte of the screen address to test its pixel line bits.
B18A CPL
B18B AND %00000111 Keep only the pixel line bits.
B18D JR NZ,UpdateScreen_Next Jump to UpdateScreen_Next if the line is still in the same character row.
B18F LD A,E Move up one character row.
B190 SUB $20
B192 LD E,A
B193 JR C,UpdateScreen_Next Jump to UpdateScreen_Next if that has crossed into the third above.
B195 LD A,D Otherwise cancel the effect of the borrow on the third, by adding 08 to the high byte.
B196 ADD A,$08
B198 LD D,A
UpdateScreen_Next B199 POP BC Restore the line counter from the stack.
B19A DEC C Decrease the line counter.
B19B JR NZ,UpdateScreen_Loop Jump to UpdateScreen_Loop until all the lines have been copied.
B19D RET Return.
View the equivalent code in;
Before After UpdateScreen
update-screen-before update-screen-after
Prev: B145 Up: Map Next: B19E