Prev: 41237 Up: Map Next: 41328
41289: Get Screen Address
Finds the address in the display file of a pixel position. The vertical position is the number of the row of pixels, counted from the top of the screen, so 191 is the bottom row.
Input
H Vertical position
L Horizontal position
Output
HL Screen address
GetScreenAddress 41289 LD A,L Fetch the horizontal position.
41290 RRC A Divide it by eight.
41292 RRC A
41294 RRC A
41296 AND %00011111 Keep the five bits of the column.
41298 LD L,A Store it in L.
41299 LD A,H Fetch the vertical position.
41300 RLC A Multiply it by four.
41302 RLC A
41304 AND %11100000 Keep the bits that give the row of the cell.
41306 OR L Combine them with the column.
41307 LD L,A Store the low byte of the address.
41308 LD A,H Fetch the vertical position.
41309 AND %00000111 Keep the bits that give the pixel row within the cell.
41311 EX AF,AF' Save them.
41312 LD A,H Fetch the vertical position.
41313 RRC A Divide it by eight.
41315 RRC A
41317 RRC A
41319 AND %00011000 Keep the bits that give the third of the screen.
41321 OR %01000000 Add the address of the display file.
41323 LD H,A Store the high byte of the address.
41324 EX AF,AF' Restore the pixel row.
41325 OR H Combine it with the high byte.
41326 LD H,A Store the high byte of the address.
41327 RET Return.
View the equivalent code in;
Prev: 41237 Up: Map Next: 41328