Prev: 53811 Up: Map Next: 53874
53839: Calculate Screen Address
Used by the routines at HandleMenuBullet and DrawMenuSprite.
Finds the address on the screen of a pixel. The vertical position is measured from the bottom of the screen.
Input
H The vertical position, from the bottom
L The horizontal position
Output
HL The address on the screen
Stash DE, and copy the position to it.
CalculateScreenAddress 53839 PUSH DE Stash DE on the stack.
53840 EX DE,HL Copy the position to DE.
Work out the column from the horizontal position.
53841 LD A,E Divide the horizontal position by eight.
53842 RRCA
53843 RRCA
53844 RRCA
53845 AND %00011111 Keep the column.
53847 LD L,A Store it.
Work out the character row within a third of the screen.
53848 LD A,D Invert the vertical position and multiply it by four.
53849 CPL
53850 RLCA
53851 RLCA
53852 AND %11100000 Keep the character row within the third.
53854 OR L Make the low byte of the address.
53855 LD L,A
Work out the third of the screen.
53856 LD A,D Invert the vertical position and divide it by eight.
53857 CPL
53858 RRCA
53859 RRCA
53860 RRCA
53861 AND %00011000 Keep the third.
53863 LD H,A Start the high byte.
Work out the line within the character row, and make the high byte of the address.
53864 LD A,D Invert the vertical position.
53865 CPL
53866 AND %00000111 Keep the line within the character row.
53868 OR H Combine it with the third, add 56 and set the high byte.
53869 ADD A,56
53871 LD H,A
53872 POP DE Restore DE from the stack.
53873 RET Return.
View the equivalent code in;
Prev: 53811 Up: Map Next: 53874