Prev: B873 Up: Map Next: B8CC
B8AD: Calculate Screen Address
Converts pixel coordinates into the address of the byte in the display file that holds the pixel.
Input
H Y coordinate
L X coordinate
Output
HL Screen address
The low byte is made up of the column (bits 0-4) and the character row within the third of the screen (bits 5-7).
ScreenAddress B8AD LD A,L A=L.
B8AE RRCA Divide the X coordinate by 08 to get the column.
B8AF RRCA
B8B0 RRCA
B8B1 AND %00011111 Keep only bits 0-4.
B8B3 LD L,A L=A.
B8B4 LD A,H A=H.
B8B5 RLCA Multiply the Y coordinate by 04 which moves bits 3-5 into bits 5-7.
B8B6 RLCA
B8B7 AND %11100000 Keep only bits 5-7.
B8B9 OR L Merge in the column.
B8BA LD L,A L=A.
The high byte is made up of the third of the screen (bits 3-4) and the pixel line within the character (bits 0-2).
B8BB LD A,H A=H.
B8BC AND %00000111 Keep only bits 0-2 (the pixel line).
B8BE EX AF,AF' Store the pixel line in AF'.
B8BF LD A,H A=H.
B8C0 RRCA Divide the Y coordinate by 08.
B8C1 RRCA
B8C2 RRCA
B8C3 AND %00011000 Keep only bits 3-4 (the third of the screen).
B8C5 OR %01000000 Set bit 6 to point to the display file.
B8C7 LD H,A H=A.
B8C8 EX AF,AF' Fetch the pixel line from AF'.
B8C9 OR H Merge in the third of the screen.
B8CA LD H,A H=A.
B8CB RET Return.
Prev: B873 Up: Map Next: B8CC