Prev: 28747 Up: Map Next: 28845
28823: Calculate Attribute Address
Used by the routines at MenuWriteText, PrintStringColour, 26033 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 28823 LD A,L Horizontal co-ordinate.
28824 RRCA Divide by 8.
28825 RRCA
28826 RRCA
28827 AND %00011111 Keep only bits 0-4 (0-31 / minimum-maximum horizontal screen values).
28829 LD L,A Store this back in L.
28830 LD A,H Vertical co-ordinate.
28831 RLCA Multiply by 4.
28832 RLCA
28833 LD C,A Store this in C temporarily.
28834 AND %11100000 Keep only bits 5-7.
28836 OR L Set the bits from L.
28837 LD L,A L=A.
28838 LD A,C Fetch the stored value from C.
28839 AND %00000011 Keep only bits 0-1.
28841 OR %01011000 Set MSB of the attribute buffer 88. This ensures our value is >= 22528.
28843 LD H,A Store this back in H.
28844 RET Return.
View the equivalent code in;
Prev: 28747 Up: Map Next: 28845