Prev: 48375 Up: Map Next: 48478
48409: 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 (88 for screen, 248 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 48409 LD A,H A=H.
48410 AND %00000111 Keep only bits 0-2.
48412 OR A Jump to WriteAttributeBlock2Wide_CalcAddress if Y-aligned.
48413 JR Z,WriteAttributeBlock2Wide_CalcAddress
48415 SET 1,D Set bit 1 of D (extra row needed).
Convert the screen buffer address to the attribute address.
WriteAttributeBlock2Wide_CalcAddress 48417 LD A,H A=H.
48418 RRCA Rotate right three positions.
48419 RRCA
48420 RRCA
48421 AND %00000011 Keep only bits 0-1.
48423 OR C Merge with the attribute base in C.
48424 LD H,A H=A.
Branch based on whether an extra column is needed.
48425 BIT 0,D Test bit 0 of D.
48427 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 48429 LD A,(HL) Write the ink bits to *HL.
48430 AND %11111000
48432 OR E
48433 LD (HL),A
48434 INC L Move to the next column.
48435 LD A,(HL) Write the ink bits to *HL.
48436 AND %11111000
48438 OR E
48439 LD (HL),A
Return if Y-aligned, otherwise write a second row.
48440 DEC L Move back one column.
48441 BIT 1,D Test bit 1 of D.
48443 RET Z Return if Y-aligned.
Move down one attribute row.
48444 LD BC,32 BC=0032.
48447 ADD HL,BC HL+=BC.
Write attribute to the second row (2 cells).
48448 LD A,(HL) Write the ink bits to *HL.
48449 AND %11111000
48451 OR E
48452 LD (HL),A
48453 INC L Move to the next column.
48454 LD A,(HL) Write the ink bits to *HL.
48455 AND %11111000
48457 OR E
48458 LD (HL),A
48459 RET Return.
X-aligned: write attributes across 1 column only.
Write attribute to the first row (1 cell).
WriteAttributeBlock2Wide_1Column 48460 LD A,(HL) Write the ink bits to *HL.
48461 AND %11111000
48463 OR E
48464 LD (HL),A
Return if Y-aligned, otherwise write a second row.
48465 BIT 1,D Test bit 1 of D.
48467 RET Z Return if Y-aligned.
Move down one attribute row.
48468 LD BC,32 BC=0032.
48471 ADD HL,BC HL+=BC.
Write attribute to the second row (1 cell).
48472 LD A,(HL) Write the ink bits to *HL.
48473 AND %11111000
48475 OR E
48476 LD (HL),A
48477 RET Return.
Prev: 48375 Up: Map Next: 48478