Prev: 8506 Up: Map Next: 853D
851E: Calculate Screen Address
Converts a pixel address into the matching screen buffer address.
Input
HL Pixel address co-ordinates
Output
HL Screen buffer address
Convert the pixel X/Y in HL into a screen address.
ScreenAddress 851E LD A,L Fetch the horizontal co-ordinate.
851F RRCA A=A / 08.
8520 RRCA
8521 RRCA
8522 AND %00011111 Keep only bits 0-4.
8524 LD L,A L=A.
8525 LD A,H A=H.
8526 RLCA A=A * 04.
8527 RLCA
8528 AND %11100000 Keep only bits 5-7.
852A OR L Merge in the column bits.
852B LD L,A Store this back in L.
Work out the high byte from the vertical co-ordinate.
852C LD A,H Fetch the vertical co-ordinate.
852D AND %00000111 Keep only bits 0-2.
852F EX AF,AF' Switch to the shadow AF register.
8530 LD A,H Fetch the vertical co-ordinate.
8531 RRCA Divide by 08.
8532 RRCA
8533 RRCA
8534 AND %00011000 Keep only bits 3-4.
8536 OR %01000000 Set the screen-buffer MSB bit.
8538 LD H,A Store this back in H.
8539 EX AF,AF' Switch to the shadow AF register.
853A OR H Merge in the line bits.
853B LD H,A Store this back in H.
853C RET Return.
Prev: 8506 Up: Map Next: 853D