Prev: 55313 Up: Map Next: 55368
55334: Calculate Screen Address
Finds the address on the screen of the byte that holds a pixel.
Input
B Pixel Y coordinate (from the bottom of the screen)
C Pixel X coordinate
Output
DE Address on the screen
Build the display-file address from the pixel X and Y.
CalculateScreenAddress 55334 LD A,C Fetch the pixel X coordinate and move it right by three bits.
55335 RRCA
55336 RRCA
55337 RRCA
55338 AND %00011111 Keep the byte of the line.
55340 LD E,A Stash it in E.
55341 LD A,B Fetch the pixel Y coordinate, inverted to get the line from the top.
55342 CPL
55343 AND %00000111 Keep the line within the character row.
55345 EX AF,AF' Stash it in the alternate A.
55346 LD A,B Invert the pixel Y coordinate again and move it left by two bits.
55347 CPL
55348 RLCA
55349 RLCA
55350 AND %11100000 Keep the character row within the third, in the high bits.
55352 OR E Add the byte of the line.
55353 LD E,A Store the low byte of the address in E.
55354 LD A,B Invert the pixel Y coordinate again.
55355 CPL
55356 RRCA Move the third of the screen into bits 3 and 4.
55357 RRCA
55358 RRCA
55359 AND %00011000 Keep it.
55361 LD D,A Stash it in D.
55362 EX AF,AF' Fetch the line within the character row.
55363 OR D Add the third of the screen.
55364 ADD A,56 Add 56, to make the high byte of the address.
55366 LD D,A Store the high byte of the address in D.
55367 RET Return.
View the equivalent code in;
Prev: 55313 Up: Map Next: 55368