Prev: 45591 Up: Map Next: 45716
45596: 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 85 and 170). The buffer occupies 62848 to 65535: 112 lines of 24 bytes. Only the middle 20 bytes of each line are shown on screen, as the 2 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 45596 LD DE,20470 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 39139 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 45599 LD (38435),SP Save the stack pointer.
45603 LD HL,65533 Point HL at the last visible byte of the buffer, which is the bottom right of the window.
45606 LD BC,28757 Set the line counter to 112 (the height of the play window in pixels) and the background pattern for the bottom line to 85.
45609 EX DE,HL Put the screen address in HL, so that it can be used as the stack pointer.
DrawPlayWindow_Screen 45610 LD SP,HL Point the stack pointer at the screen address, and swap the buffer pointer back into HL.
45611 EX DE,HL
Copy a line of the buffer, two bytes at a time, and replace each byte with the background pattern.
DrawPlayWindow_Line 45612 LD D,(HL) Copy two bytes from the buffer to the screen and replace them with the pattern.
45613 LD (HL),C
45614 DEC L
45615 LD E,(HL)
45616 LD (HL),C
45617 DEC L
45618 PUSH DE
45619 LD D,(HL) Copy the next two bytes.
45620 LD (HL),C
45621 DEC L
45622 LD E,(HL)
45623 LD (HL),C
45624 DEC L
45625 PUSH DE
45626 LD D,(HL) Copy the next two bytes.
45627 LD (HL),C
45628 DEC L
45629 LD E,(HL)
45630 LD (HL),C
45631 DEC HL
45632 PUSH DE
45633 LD D,(HL) Copy the next two bytes.
45634 LD (HL),C
45635 DEC HL
45636 LD E,(HL)
45637 LD (HL),C
45638 DEC L
45639 PUSH DE
45640 LD D,(HL) Copy the next two bytes.
45641 LD (HL),C
45642 DEC L
45643 LD E,(HL)
45644 LD (HL),C
45645 DEC L
45646 PUSH DE
45647 LD D,(HL) Copy the next two bytes.
45648 LD (HL),C
45649 DEC L
45650 LD E,(HL)
45651 LD (HL),C
45652 DEC L
45653 PUSH DE
45654 LD D,(HL) Copy the next two bytes.
45655 LD (HL),C
45656 DEC L
45657 LD E,(HL)
45658 LD (HL),C
45659 DEC HL
45660 PUSH DE
45661 LD D,(HL) Copy the next two bytes.
45662 LD (HL),C
45663 DEC HL
45664 LD E,(HL)
45665 LD (HL),C
45666 DEC L
45667 PUSH DE
45668 LD D,(HL) Copy the next two bytes.
45669 LD (HL),C
45670 DEC L
45671 LD E,(HL)
45672 LD (HL),C
45673 DEC L
45674 PUSH DE
45675 LD D,(HL) Copy the last two bytes of the line (20 bytes have now been copied).
45676 LD (HL),C
45677 DEC L
45678 LD E,(HL)
45679 LD (HL),C
45680 DEC L
45681 PUSH DE
45682 DEC L Skip the margin bytes: the two on the left of this line and the two on the right of the line above.
45683 DEC HL
45684 DEC HL
45685 DEC L
45686 RRC C Swap the background pattern between 85 and 170 for the next line.
45688 EX DE,HL Keep the buffer pointer.
Work out the screen address of the end of the pixel line above.
45689 LD HL,65300 Add 65300 (-236) to the stack pointer, which has moved back 20 bytes along the line, to give the address one pixel line up.
45692 ADD HL,SP
45693 LD A,H Test whether the new address is the bottom pixel line of the character row above.
45694 CPL
45695 AND 7
45697 JR NZ,DrawPlayWindow_NextLine Jump if it is not, as the address is correct.
45699 LD A,L Move up a character row by subtracting 32 from the low byte.
45700 SUB 32
45702 LD L,A
45703 JR C,DrawPlayWindow_NextLine Jump if that crossed a third of the display.
45705 LD A,H Otherwise move to the bottom pixel line of the row.
45706 ADD A,8
45708 LD H,A
DrawPlayWindow_NextLine 45709 DJNZ DrawPlayWindow_Screen Loop back until all 112 lines have been copied.
45711 LD SP,(38435) Restore the stack pointer.
45715 RET Return.
Continue on to DrawPlayWindow_Entry.
Prev: 45591 Up: Map Next: 45716