Prev: 39873 Up: Map Next: 39914
39890: Calculate Attribute Address
Converts the pixel position of a point into the address in the attribute buffer of the character cell that holds it.
Input
H The Y position (the pixel line down from the top)
L The X position (the pixel across from the left)
Output
HL The attribute buffer address
AttributeAddress 39890 PUSH BC Stash BC on the stack.
39891 LD A,L Fetch the X position.
39892 RRCA Rotate right three times, which divides the X position by 8.
39893 RRCA
39894 RRCA
39895 AND %00011111 Keep only bits 0-4 (the column).
39897 LD L,A Keep the column in L.
39898 LD A,H Fetch the Y position.
39899 RLCA Rotate left twice.
39900 RLCA
39901 LD C,A Keep the Y position, rotated, in C.
39902 AND %11100000 Keep only bits 5-7 (the character row within the third of the screen).
39904 OR L Combine it with the column.
39905 LD L,A Keep the low byte of the attribute buffer address in L.
39906 LD A,C Fetch the Y position, rotated.
39907 AND %00000011 Keep only bits 0-1 (the third of the screen).
39909 OR %01011000 Set bits 3-4 and 6, so the address is in the attribute buffer (88).
39911 LD H,A Keep the high byte of the attribute buffer address in H.
39912 POP BC Restore BC from the stack.
39913 RET Return.
Prev: 39873 Up: Map Next: 39914