| Routines

6A8C: Save the area of the screen that will be overwritten by a message box

Used by the routines at 7414, 74C8 and F4CC. Returns with the carry flag set if the message box would be off-screen. Otherwise copies the area of the screen that will be overwritten by the message box into the buffer at E328, and returns with the attribute file address for the top-left corner of the message box in DE.
Input
DE | Coordinates of the point above the character's head
6A8C | LD A,($7FFF) | B=leftmost column of the play area on screen
6A8F | LD B,A
6A90 | LD A,E | A=x-coordinate of the character's head
6A91 | AND $F8 | A=x-coordinate of the left edge of the message box
6A93 | SUB B | Return with the carry flag set if the message box would be off-screen to the right
6A94 | CP $20
6A96 | CCF
6A97 | RET C
6A98 | LD E,A | E=0, 8, 16 or 24: screen x-coordinate of the left edge of the message box
6A99 | LD A,D | A=y-coordinate of the point above the character's head
6A9A | SUB $03 | A=y-coordinate of the top line of the message box
6A9C | RET C | Return with the carry flag set if this would be off the top of the screen
The message box is going to be printed. Prepare for that by saving the area of the screen that will be overwritten.
6A9D | LD D,$00 | DE=0, 8, 16 or 24
6A9F | PUSH HL | Save HL
6AA0 | ADD A,A | Set HL the to the attribute file address for the top left corner of the message box
6AA1 | ADD A,A
6AA2 | ADD A,A
6AA3 | LD L,A
6AA4 | LD H,$16
6AA6 | ADD HL,HL
6AA7 | ADD HL,HL
6AA8 | ADD HL,DE
6AA9 | PUSH HL | Save this base attribute file address
6AAA | LD DE,$E328 | Point DE at the buffer used to save the screen area overwritten by the message box (at E328)
6AAD | LD A,$03 | Copy three rows of eight attribute bytes each from the screen into the first 24 bytes of the buffer
6AAF | LD BC,$0008
6AB2 | LDIR
6AB4 | LD C,$18
6AB6 | ADD HL,BC
6AB7 | DEC A
6AB8 | JR NZ,$6AAF
6ABA | POP HL | Restore the base attribute file address to HL
6ABB | PUSH HL | And save it again
6ABC | LD A,H | Set HL to the display file address for the top left corner of the message box
6ABD | SUB $50
6ABF | ADD A,A
6AC0 | ADD A,A
6AC1 | ADD A,A
6AC2 | LD H,A
6AC3 | LD C,$03 | There are 3 rows of UDGs to copy
6AC5 | LD A,$08 | 8 pixel rows per UDG
6AC7 | PUSH BC |
6AC8 | PUSH HL |
6AC9 | LD C,$08 | 8 UDGs per row
6ACB | LDIR | Copy one row of pixels into the buffer
6ACD | POP HL |
6ACE | INC H | Move HL to the next row of pixels on screen
6ACF | DEC A |
6AD0 | JR NZ,$6AC8 | Jump back until all 8 pixel rows for this row of UDGs have been copied into the buffer
6AD2 | LD A,L | Move HL to the display file address for the start of the top row of pixels for the next row of UDGs
6AD3 | ADD A,$20
6AD5 | LD L,A
6AD6 | JR C,$6ADC
6AD8 | LD A,H
6AD9 | SUB $08
6ADB | LD H,A
6ADC | POP BC |
6ADD | DEC C | One more row of UDGs copied
6ADE | JR NZ,$6AC5 | Jump back until all 3 rows have been done
6AE0 | POP DE | Drop the base attribute file address into DE
6AE1 | POP HL | Restore the original contents of HL
6AE2 | RET | Return with the carry flag reset