Prev: 9B5D Up: Map Next: 9BC1
9BA2: Calculate Screen Address
Converts the pixel position of a point into the address in the screen buffer that holds it. The bits that are left over are not used here, so the address is the one for the left-hand pixel of the character cell.
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 screen buffer address
ScreenAddress 9BA2 LD A,L Fetch the X position.
9BA3 RRCA Rotate right three times, which divides the X position by 08.
9BA4 RRCA
9BA5 RRCA
9BA6 AND %00011111 Keep only bits 0-4.
9BA8 LD L,A Keep the column in L.
9BA9 LD A,H Fetch the Y position.
9BAA RLCA Rotate left twice.
9BAB RLCA
9BAC AND %11100000 Keep only bits 5-7 (the character row within the third of the screen).
9BAE OR L Combine it with the column.
9BAF LD L,A Keep the low byte of the screen buffer address in L.
9BB0 LD A,H Fetch the Y position.
9BB1 AND %00000111 Keep only bits 0-2 (the pixel line within the character).
9BB3 EX AF,AF' Switch to the shadow AF register.
9BB4 LD A,H Fetch the Y position.
9BB5 RRCA Rotate right three times.
9BB6 RRCA
9BB7 RRCA
9BB8 AND %00011000 Keep only bits 3-4 (the third of the screen).
9BBA OR %01000000 Set bit 6, so the address is in the screen buffer.
9BBC LD H,A Keep the third of the screen in H.
9BBD EX AF,AF' Switch back to the main AF register.
9BBE OR H Combine the pixel line with the third of the screen.
9BBF LD H,A Keep the high byte of the screen buffer address in H.
9BC0 RET Return.
Prev: 9B5D Up: Map Next: 9BC1