Prev: ADD6 Up: Map Next: ADF8
ADE0: Calculate Attribute Address
Converts a pixel position into the address of the matching cell of the attribute buffer.
Input
HL Position (L is the x position, H is the y position)
Output
HL Attribute buffer address
AttributeAddress ADE0 PUSH BC Stash BC on the stack.
ADE1 LD A,L Fetch the x position.
ADE2 RRCA Divide it by 08.
ADE3 RRCA
ADE4 RRCA
ADE5 AND $1F Keep only five bits.
ADE7 LD L,A Store the column in L.
ADE8 LD A,H Fetch the y position.
ADE9 RLCA Multiply it by 04.
ADEA RLCA
ADEB LD C,A Store the result in C.
ADEC AND $E0 Keep only the bits that give the low part of the row.
ADEE OR L Combine them with the column.
ADEF LD L,A Store the low byte of the address in L.
ADF0 LD A,C Fetch the multiplied y position.
ADF1 AND $03 Keep only the bits that give the high part of the row.
ADF3 OR $58 Add the start of the attribute buffer.
ADF5 LD H,A Store the high byte of the address in H.
ADF6 POP BC Restore BC from the stack.
ADF7 RET Return.
Prev: ADD6 Up: Map Next: ADF8