Prev: BCF7 Up: Map Next: BD5E
BD19: Write Attribute Block (2-Wide)
Used by the routine at ApplySpriteAttributes2Wide.
Writes a colour attribute to a 2-wide block of attribute cells. The height is 1-2 rows if Y-aligned, or 2-3 rows if not. The width is 1 or 2 columns depending on X alignment.
Input
C Attribute base high byte (58 for screen, F8 for room)
D Bit 0: extra column needed, Bit 1: extra row needed
E Attribute value to write (ink bits 0-2)
HL Screen buffer address
Check if the Y position crosses a character boundary.
WriteAttributeBlock2Wide BD19 LD A,H A=H.
BD1A AND %00000111 Keep only bits 0-2.
BD1C OR A Jump to WriteAttributeBlock2Wide_CalcAddress if Y-aligned.
BD1D JR Z,WriteAttributeBlock2Wide_CalcAddress
BD1F SET 1,D Set bit 1 of D (extra row needed).
Convert the screen buffer address to the attribute address.
WriteAttributeBlock2Wide_CalcAddress BD21 LD A,H A=H.
BD22 RRCA Rotate right three positions.
BD23 RRCA
BD24 RRCA
BD25 AND %00000011 Keep only bits 0-1.
BD27 OR C Merge with the attribute base in C.
BD28 LD H,A H=A.
Branch based on whether an extra column is needed.
BD29 BIT 0,D Test bit 0 of D.
BD2B JR Z,WriteAttributeBlock2Wide_1Column Jump to WriteAttributeBlock2Wide_1Column if X-aligned (1 column wide).
Not X-aligned: write attributes across 2 columns.
Write attribute to the first row (2 cells).
WriteAttributeBlock2Wide_2Columns BD2D LD A,(HL) Write the ink bits to *HL.
BD2E AND %11111000
BD30 OR E
BD31 LD (HL),A
BD32 INC L Move to the next column.
BD33 LD A,(HL) Write the ink bits to *HL.
BD34 AND %11111000
BD36 OR E
BD37 LD (HL),A
Return if Y-aligned, otherwise write a second row.
BD38 DEC L Move back one column.
BD39 BIT 1,D Test bit 1 of D.
BD3B RET Z Return if Y-aligned.
Move down one attribute row.
BD3C LD BC,$0020 BC=0020.
BD3F ADD HL,BC HL+=BC.
Write attribute to the second row (2 cells).
BD40 LD A,(HL) Write the ink bits to *HL.
BD41 AND %11111000
BD43 OR E
BD44 LD (HL),A
BD45 INC L Move to the next column.
BD46 LD A,(HL) Write the ink bits to *HL.
BD47 AND %11111000
BD49 OR E
BD4A LD (HL),A
BD4B RET Return.
X-aligned: write attributes across 1 column only.
Write attribute to the first row (1 cell).
WriteAttributeBlock2Wide_1Column BD4C LD A,(HL) Write the ink bits to *HL.
BD4D AND %11111000
BD4F OR E
BD50 LD (HL),A
Return if Y-aligned, otherwise write a second row.
BD51 BIT 1,D Test bit 1 of D.
BD53 RET Z Return if Y-aligned.
Move down one attribute row.
BD54 LD BC,$0020 BC=0020.
BD57 ADD HL,BC HL+=BC.
Write attribute to the second row (1 cell).
BD58 LD A,(HL) Write the ink bits to *HL.
BD59 AND %11111000
BD5B OR E
BD5C LD (HL),A
BD5D RET Return.
Prev: BCF7 Up: Map Next: BD5E