Prev: B217 Up: Map Next: B294
B21C: Draw Play Window
Used by the routine at MainLoop.
Copies the off-screen play window buffer to the display, and at the same time resets the buffer to the dithered grey background of the play window (alternate lines of 55 and AA). The buffer occupies F580 to FFFF: 70 lines of 18 bytes. Only the middle 14 bytes of each line are shown on screen, as the 02 bytes at each end are margins that let sprites overhang the edges of the window. The lines are copied from the bottom of the window to the top, working backwards through the buffer. The stack pointer is pointed at the display and each pair of bytes taken from the buffer is written using a PUSH instruction, which is much faster than storing the bytes one at a time.
Before After
draw-play-window-before draw-play-window-after
DrawPlayWindow B21C LD DE,$4FF6 Point DE at the screen address just after the bottom right byte of the play window.
This entry point is used by the routine at InitialiseGame.
Entered from 98E3 with DE pointing at the ROM, to fill the buffer with the dithered background without drawing anything. DE holds the screen address just after the bottom right byte of the window.
DrawPlayWindow_Entry B21F LD ($9623),SP Save the stack pointer.
B223 LD HL,$FFFD Point HL at the last visible byte of the buffer, which is the bottom right of the window.
B226 LD BC,$7055 Set the line counter to 70 (the height of the play window in pixels) and the background pattern for the bottom line to 55.
B229 EX DE,HL Put the screen address in HL, so that it can be used as the stack pointer.
DrawPlayWindow_Screen B22A LD SP,HL Point the stack pointer at the screen address, and swap the buffer pointer back into HL.
B22B EX DE,HL
Copy a line of the buffer, two bytes at a time, and replace each byte with the background pattern.
DrawPlayWindow_Line B22C LD D,(HL) Copy two bytes from the buffer to the screen and replace them with the pattern.
B22D LD (HL),C
B22E DEC L
B22F LD E,(HL)
B230 LD (HL),C
B231 DEC L
B232 PUSH DE
B233 LD D,(HL) Copy the next two bytes.
B234 LD (HL),C
B235 DEC L
B236 LD E,(HL)
B237 LD (HL),C
B238 DEC L
B239 PUSH DE
B23A LD D,(HL) Copy the next two bytes.
B23B LD (HL),C
B23C DEC L
B23D LD E,(HL)
B23E LD (HL),C
B23F DEC HL
B240 PUSH DE
B241 LD D,(HL) Copy the next two bytes.
B242 LD (HL),C
B243 DEC HL
B244 LD E,(HL)
B245 LD (HL),C
B246 DEC L
B247 PUSH DE
B248 LD D,(HL) Copy the next two bytes.
B249 LD (HL),C
B24A DEC L
B24B LD E,(HL)
B24C LD (HL),C
B24D DEC L
B24E PUSH DE
B24F LD D,(HL) Copy the next two bytes.
B250 LD (HL),C
B251 DEC L
B252 LD E,(HL)
B253 LD (HL),C
B254 DEC L
B255 PUSH DE
B256 LD D,(HL) Copy the next two bytes.
B257 LD (HL),C
B258 DEC L
B259 LD E,(HL)
B25A LD (HL),C
B25B DEC HL
B25C PUSH DE
B25D LD D,(HL) Copy the next two bytes.
B25E LD (HL),C
B25F DEC HL
B260 LD E,(HL)
B261 LD (HL),C
B262 DEC L
B263 PUSH DE
B264 LD D,(HL) Copy the next two bytes.
B265 LD (HL),C
B266 DEC L
B267 LD E,(HL)
B268 LD (HL),C
B269 DEC L
B26A PUSH DE
B26B LD D,(HL) Copy the last two bytes of the line (14 bytes have now been copied).
B26C LD (HL),C
B26D DEC L
B26E LD E,(HL)
B26F LD (HL),C
B270 DEC L
B271 PUSH DE
B272 DEC L Skip the margin bytes: the two on the left of this line and the two on the right of the line above.
B273 DEC HL
B274 DEC HL
B275 DEC L
B276 RRC C Swap the background pattern between 55 and AA for the next line.
B278 EX DE,HL Keep the buffer pointer.
Work out the screen address of the end of the pixel line above.
B279 LD HL,$FF14 Add FF14 (-EC) to the stack pointer, which has moved back 14 bytes along the line, to give the address one pixel line up.
B27C ADD HL,SP
B27D LD A,H Test whether the new address is the bottom pixel line of the character row above.
B27E CPL
B27F AND $07
B281 JR NZ,DrawPlayWindow_NextLine Jump if it is not, as the address is correct.
B283 LD A,L Move up a character row by subtracting 20 from the low byte.
B284 SUB $20
B286 LD L,A
B287 JR C,DrawPlayWindow_NextLine Jump if that crossed a third of the display.
B289 LD A,H Otherwise move to the bottom pixel line of the row.
B28A ADD A,$08
B28C LD H,A
DrawPlayWindow_NextLine B28D DJNZ DrawPlayWindow_Screen Loop back until all 70 lines have been copied.
B28F LD SP,($9623) Restore the stack pointer.
B293 RET Return.
Continue on to DrawPlayWindow_Entry.
Prev: B217 Up: Map Next: B294