Prev: 29934 Up: Map Next: 30026
30004: Calculate Attribute Address
Used by the routines at 24545, MenuWriteText, ScoreLabelFlash, PrintString and 29934.
Input
HL Pixel address co-ordinates
Output
HL Attribute buffer address
Converts a given pixel address to the associated attribute buffer address.
AttributeAddress 30004 LD A,L Horizontal co-ordinate.
30005 RRCA Divide by 8.
30006 RRCA
30007 RRCA
30008 AND %00011111 Keep only bits 0-4 (0-31 / minimum-maximum horizontal screen values).
30010 LD L,A Store this back in L.
30011 LD A,H Vertical co-ordinate.
30012 RLCA Multiply by 4.
30013 RLCA
30014 LD C,A Store this in C temporarily.
30015 AND %11100000 Keep only bits 5-7.
30017 OR L Set the bits from L.
30018 LD L,A L=A.
30019 LD A,C Fetch the stored value from C.
30020 AND %00000011 Keep only bits 0-1.
30022 OR %01011000 Set MSB of the attribute buffer 88. This ensures our value is >= 22528.
30024 LD H,A Store this back in H.
30025 RET Return.
View the equivalent code in;
Prev: 29934 Up: Map Next: 30026