Prev: D567 Up: Map Next: D59F
D56F: Update Screen
Used by the routines at RunGame, GameOver and DisplayTextList.
Copies the screen buffer to the screen, and clears the buffer as it goes. The buffer holds the lines of the screen from the bottom up, 20 bytes to a line, so the lines are copied from the bottom of the screen to the top.
Before After UpdateScreen
update-screen-before update-screen-after
Copy each line from the buffer to the display, then clear the buffer.
UpdateScreen D56F LD HL,$D8F3 Point HL at the screen buffer, ScreenBuffer.
D572 LD DE,$57E0 Point DE at the last line of the bitmap of the screen.
D575 LD BC,$20C0 Set the width to 20 bytes and the number of lines to C0.
UpdateScreen_Line D578 PUSH BC Stash the counters on the stack.
D579 PUSH DE Stash the address of the line on the screen on the stack.
D57A PUSH HL Stash the address of the line in the buffer on the stack.
UpdateScreen_Byte D57B LD A,(HL) Fetch a byte from the buffer.
D57C LD (DE),A Copy it to the screen.
D57D LD (HL),$00 Clear the byte in the buffer.
D57F INC HL Move on in the buffer.
D580 INC E Move on in the screen.
D581 DJNZ UpdateScreen_Byte Jump to UpdateScreen_Byte until the line is copied.
D583 POP HL Restore the address of the line in the buffer from the stack.
D584 LD BC,$0020 Set BC to the length of a line.
D587 ADD HL,BC Move on to the next line in the buffer.
D588 POP DE Restore the address of the line on the screen from the stack.
D589 DEC D Go up one line on the screen.
D58A LD A,D Test whether that has gone into the character row above.
D58B CPL
D58C AND %00000111 Keep the bits of the line within the character row.
D58E JR NZ,UpdateScreen_Next Jump to UpdateScreen_Next if it has not.
D590 LD A,E Go up one character row.
D591 SUB $20
D593 LD E,A Store it.
D594 JR C,UpdateScreen_Next Jump to UpdateScreen_Next if that has gone into the third of the screen above.
D596 LD A,D Put the line at the bottom of the character row.
D597 ADD A,$08
D599 LD D,A Store it.
UpdateScreen_Next D59A POP BC Restore the counters from the stack.
D59B DEC C Count down the lines.
D59C JR NZ,UpdateScreen_Line Jump to UpdateScreen_Line until all of the lines are copied.
D59E RET Return.
Prev: D567 Up: Map Next: D59F