| Routines

F3A0: Update the SRB for a window

Used by the routines at F404 and F485. Updates the screen refresh buffer (SRB) for a window (or window-pair) after a light switch has been flipped or a blind has been raised or lowered.
Input
H | 0xB9-0xBD (corresponding to the 5th, 4th, 3rd, 2nd or 1st floor)
L | 0x00-0x1F or 0x40-0x5F (corresponding to the x-coordinate of the window)
F3A0 | RES 6,L | Now L=X'/8 (where X' is the x-coordinate of the left edge of the window), and HL points at the Z value corresponding to the window
F3A2 | LD BC,($7FFE) | The play area coordinates of the top-left corner of the screen are stored at 7FFE and 7FFF
F3A6 | LD A,C | A=X (the x-coordinate of the leftmost column of the play area on screen)
F3A7 | RRCA | A=X/8
F3A8 | RRCA
F3A9 | RRCA
F3AA | LD E,A | E=X/8 (0-31)
F3AB | LD A,L | A=X'/8 (0-31)
F3AC | SUB E | A=X'/8-X/8
F3AD | CP $04 | Is the window off screen to the right or left?
F3AF | RET NC | Return if so
F3B0 | LD E,A | E=0-3 (index of the 8-tile wide column containing the window)
F3B1 | LD A,H | A=1 (5th floor), 2, 3, 4 or 5 (1st floor)
F3B2 | SUB $B8
F3B4 | LD D,A | D=6 (5th floor), 12, 18, 24 or 30 (1st floor)
F3B5 | ADD A,A
F3B6 | ADD A,D
F3B7 | ADD A,A
F3B8 | LD D,A
F3B9 | SUB B | Subtract Y, the y-coordinate of the topmost row of the play area on screen (2, 8, 14 or 20)
F3BA | ADD A,$04 | Is the window off screen?
F3BC | CP $15
F3BE | RET NC | Return if so
F3BF | ADD A,A | A=4*(D-Y+4)+E
F3C0 | ADD A,A
F3C1 | ADD A,E
F3C2 | LD E,A | Point DE at the SRB byte corresponding to the top row of the window
F3C3 | LD D,$7F
F3C5 | LD C,$80 | C=0x80 (10000000)
F3C7 | LD A,(HL) | Pick up the Z value for the window
F3C8 | LD L,A | Point HL at the Z'' value for the leftmost column of tiles in the 8-tile wide segment that contains the window
F3C9 | SET 7,L
F3CB | LD H,$B8
F3CD | EXX |
F3CE | LD L,A | Point HL' at the Z' value for the 8x6 block of tiles that contains the window
F3CF | LD H,$BF
F3D1 | LD C,$01 | C'=1 (00000001)
F3D3 | EXX |
The following loop examines the 8x6 block of tiles that contains the window and updates the relevant SRB bytes for the affected window tiles.
F3D4 | EXX |
F3D5 | RRC C | Rotate the set bit in C' one place to the right
F3D7 | LD A,(HL) | A=Z' value
F3D8 | AND C | Set the zero flag if we should use the T values in pages 0xA0, 0xA2, 0xA4, 0xA6, 0xA8 and 0xAA
F3D9 | EXX |
F3DA | PUSH HL | Save the pointer to the Z'' value
F3DB | LD L,(HL) | L=Z'' value
F3DC | LD H,$A0 | Point HL at the T value in page 0xA0
F3DE | JR Z,$F3E2 | Jump unless we should use the T values in pages 0xAC, 0xAE, 0xB0, 0xB2, 0xB4 and 0xB6
F3E0 | LD H,$AC | Point HL at the T value in page 0xAC
F3E2 | LD B,$06 | There are 6 rows of tiles to consider
F3E4 | LD A,(HL) | A=T
F3E5 | AND $C0 | Keep only bits 6 and 7
F3E7 | CP $80 | Is there a window tile here?
F3E9 | JR NZ,$F3EE | Jump if not
F3EB | LD A,(DE) | Set the appropriate bit in the SRB byte
F3EC | OR C
F3ED | LD (DE),A
F3EE | INC H | Point HL at the next T value (in page 0xA2, 0xA4, 0xA6, 0xA8, 0xAA, 0xAE, 0xB0, 0xB2, 0xB4 or 0xB6)
F3EF | INC H
F3F0 | LD A,E | Point DE at the SRB byte for the next row down
F3F1 | ADD A,$04
F3F3 | LD E,A
F3F4 | DJNZ $F3E4 | Jump back to consider the tile in the next row down
F3F6 | LD A,E | Point DE back at the SRB byte corresponding to the top row of the window
F3F7 | SUB $18
F3F9 | LD E,A
F3FA | POP HL | Restore the Z'' value pointer to HL
F3FB | INC H | Point HL at the Z'' value for the next column of tiles to the right (in page 0xB9-0xBF)
F3FC | RRC C | Rotate the set bit in C one place to the right
F3FE | JR NC,$F3D4 | Jump back until 8 tile columns have been checked
F400 | RET |