Prev: 704B Up: Map Next: 70AD
7097: Calculate Attribute Address
Used by the routines at MenuWriteText, PrintStringColour, 65B1 and ColouriseSprite.
Input
HL Pixel address co-ordinates
Output
HL Attribute buffer address
Converts a given pixel address to the associated attribute buffer address.
AttributeAddress 7097 LD A,L Horizontal co-ordinate.
7098 RRCA Divide by 08.
7099 RRCA
709A RRCA
709B AND %00011111 Keep only bits 0-4 (00-1F / minimum-maximum horizontal screen values).
709D LD L,A Store this back in L.
709E LD A,H Vertical co-ordinate.
709F RLCA Multiply by 04.
70A0 RLCA
70A1 LD C,A Store this in C temporarily.
70A2 AND %11100000 Keep only bits 5-7.
70A4 OR L Set the bits from L.
70A5 LD L,A L=A.
70A6 LD A,C Fetch the stored value from C.
70A7 AND %00000011 Keep only bits 0-1.
70A9 OR %01011000 Set MSB of the attribute buffer 58. This ensures our value is >= 5800.
70AB LD H,A Store this back in H.
70AC RET Return.
View the equivalent code in;
Prev: 704B Up: Map Next: 70AD