Prev: 48210 Up: Map Next: 48372
48244: Write Attribute Block (3-Wide)
Used by the routine at ApplySpriteAttributes3Wide.
Writes a colour attribute to a 3-wide block of attribute cells at the position derived from the screen buffer address in HL. The height is 2 rows if Y-aligned, or 3 rows if not. The width is 2 or 3 columns depending on bit 0 of D (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; if so, an extra row of attributes is needed.
WriteAttributeBlock3Wide 48244 LD A,H A=H.
48245 AND %00000111 Keep only bits 0-2 (sub-character Y offset).
48247 OR A Jump to WriteAttributeBlock3Wide_CalcAddress if Y-aligned.
48248 JR Z,WriteAttributeBlock3Wide_CalcAddress
48250 SET 1,D Set bit 1 of D (extra row needed).
Convert the screen buffer address to the corresponding attribute address.
WriteAttributeBlock3Wide_CalcAddress 48252 LD A,H A=H.
48253 RRCA Rotate right three positions.
48254 RRCA
48255 RRCA
48256 AND %00000011 Keep only bits 0-1.
48258 OR C Merge with the attribute base in C.
48259 LD H,A H=A.
Branch based on whether an extra column is needed.
48260 BIT 0,D Test bit 0 of D.
48262 JR Z,WriteAttributeBlock3Wide_2Columns Jump to WriteAttributeBlock3Wide_2Columns if X-aligned (2 columns wide).
Not X-aligned: write attributes across 3 columns.
Write attribute to the first row (3 cells).
WriteAttributeBlock3Wide_3Columns 48264 LD A,(HL) Write the ink bits to *HL (preserve paper/brightness).
48265 AND %11111000
48267 OR E
48268 LD (HL),A
48269 INC HL Move to the next column.
48270 LD A,(HL) Write the ink bits to *HL.
48271 AND %11111000 Keep only bits 3-7.
48273 OR E
48274 LD (HL),A
48275 INC HL Move to the next column.
48276 LD A,(HL) Write the ink bits to *HL.
48277 AND %11111000
48279 OR E
48280 LD (HL),A
Move back to the first column and down one attribute row.
48281 DEC HL Move back two columns.
48282 DEC HL
48283 LD BC,32 HL+=0032 (move down one row).
48286 ADD HL,BC
Write attribute to the second row (3 cells).
48287 LD A,(HL) Write the ink bits to *HL.
48288 AND %11111000
48290 OR E
48291 LD (HL),A
48292 INC HL Move to the next column.
48293 LD A,(HL) Write the ink bits to *HL.
48294 AND %11111000
48296 OR E
48297 LD (HL),A
48298 INC HL Move to the next column.
48299 LD A,(HL) Write the ink bits to *HL.
48300 AND %11111000
48302 OR E
48303 LD (HL),A
If Y-aligned, we're done. Otherwise write a third row.
48304 BIT 1,D Test bit 1 of D.
48306 RET Z Return if Y-aligned (no extra row needed).
Move back and down to the third row.
48307 DEC HL Move back two columns.
48308 DEC HL
48309 ADD HL,BC HL+=BC (move down one row).
Write attribute to the third row (3 cells).
48310 LD A,(HL) Write the ink bits to *HL.
48311 AND %11111000
48313 OR E
48314 LD (HL),A
48315 INC HL Move to the next column.
48316 LD A,(HL) Write the ink bits to *HL.
48317 AND %11111000
48319 OR E
48320 LD (HL),A
48321 INC HL Move to the next column.
48322 LD A,(HL) Write the ink bits to *HL.
48323 AND %11111000
48325 OR E
48326 LD (HL),A
48327 RET Return.
X-aligned: write attributes across 2 columns only.
Write attribute to the first row (2 cells).
WriteAttributeBlock3Wide_2Columns 48328 LD A,(HL) Write the ink bits to *HL.
48329 AND %11111000
48331 OR E
48332 LD (HL),A
48333 INC HL Move to the next column.
48334 LD A,(HL) Write the ink bits to *HL.
48335 AND %11111000
48337 OR E
48338 LD (HL),A
Move back and down one attribute row.
48339 DEC HL Move back one column.
48340 LD BC,32 HL+=0032 (move down one row).
48343 ADD HL,BC
Write attribute to the second row (2 cells).
48344 LD A,(HL) Write the ink bits to *HL.
48345 AND %11111000
48347 OR E
48348 LD (HL),A
48349 INC HL Move to the next column.
48350 LD A,(HL) Write the ink bits to *HL.
48351 AND %11111000
48353 OR E
48354 LD (HL),A
If Y-aligned, we're done. Otherwise write a third row.
48355 BIT 1,D Test bit 1 of D.
48357 RET Z Return if Y-aligned.
Move back and down to the third row.
48358 DEC HL Move back one column.
48359 ADD HL,BC HL+=BC (move down one row).
Write attribute to the third row (2 cells).
48360 LD A,(HL) Write the ink bits to *HL.
48361 AND %11111000
48363 OR E
48364 LD (HL),A
48365 INC HL Move to the next column.
48366 LD A,(HL) Write the ink bits to *HL.
48367 AND %11111000
48369 OR E
48370 LD (HL),A
48371 RET Return.
Prev: 48210 Up: Map Next: 48372