Prev: 29934 Up: Map Next: 30026
30004: Calculate Attribute Address
Converts the pixel co-ordinates to the address of the attribute buffer byte for the character cell containing them.
Input
HL Pixel address co-ordinates
Output
HL Attribute buffer address
AttributeAddress 30004 LD A,L Fetch the horizontal co-ordinate.
30005 RRCA Divide by 8 (to get the column).
30006 RRCA
30007 RRCA
30008 AND %00011111 Keep only bits 0-4 (0-31 the range of the columns).
30010 LD L,A Store this back in L.
30011 LD A,H Fetch the vertical co-ordinate.
30012 RLCA Multiply by 4 (the row is the vertical co-ordinate divided by 8 and there are 32 columns in each row).
30013 RLCA
30014 LD C,A Store this in C temporarily.
30015 AND %11100000 Keep only bits 5-7.
30017 OR L Combine with the column in L.
30018 LD L,A Store this back in L.
30019 LD A,C Fetch the stored value from C.
30020 AND %00000011 Keep only bits 0-1.
30022 OR %01011000 Set the MSB of the attribute buffer address (88). This ensures that the address is at least 22528.
30024 LD H,A Store this in H.
30025 RET Return.
Prev: 29934 Up: Map Next: 30026