Prev: 53536 Up: Map Next: 53591
53557: Calculate Screen Address
Finds the address on the screen of the byte that holds a pixel. The pixel y position is from the bottom of the screen.
Input
B The pixel y position
C The pixel x position
Output
DE The address on the screen
Work out the byte from the position.
CalculateScreenAddress 53557 LD A,C Divide C by eight.
53558 RRCA
53559 RRCA
53560 RRCA
53561 AND %00011111 Keep bits 0 to 4.
53563 LD E,A Copy it to E.
53564 LD A,B Fetch B and invert it.
53565 CPL
53566 AND %00000111 Keep bits 0 to 2.
53568 EX AF,AF' Copy it to A'.
53569 LD A,B Fetch B and invert it.
53570 CPL
53571 RLCA Move the character row into bits 5 to 7.
53572 RLCA
53573 AND %11100000 Keep bits 5 to 7.
53575 OR E Merge E.
53576 LD E,A Copy it to E.
53577 LD A,B Fetch B and invert it.
53578 CPL
53579 RRCA Move the third into bits 3 and 4.
53580 RRCA
53581 RRCA
53582 AND %00011000 Keep bits 3 and 4.
53584 LD D,A Copy it to D.
53585 EX AF,AF' Fetch A'.
53586 OR D Merge D.
53587 ADD A,56 Add 56.
53589 LD D,A Copy it to D.
53590 RET Return.
View the equivalent code in;
Prev: 53536 Up: Map Next: 53591