Prev: 53766 Up: Map Next: 53839
53811: Calculate Buffer Address
Finds the address in PlayfieldBuffer of a pixel. The first row of the buffer is at a vertical position of 72 and the first column is at a horizontal position of 16.
Input
H The vertical position, from 72
L The horizontal position, from 16
Output
HL The address in the buffer
Stash BC.
CalculateBufferAddress 53811 PUSH BC Stash BC on the stack.
Work out the column from the horizontal position.
53812 SRL L Divide the horizontal position by eight.
53814 SRL L
53816 SRL L
53818 LD A,L Keep the column, and start with the vertical position.
53819 LD L,H
53820 LD H,0
Work out 24 times the vertical position.
53822 ADD HL,HL Multiply the vertical position by eight.
53823 ADD HL,HL
53824 ADD HL,HL
53825 LD C,L Keep it.
53826 LD B,H
53827 ADD HL,HL Multiply it by two and add the eight times.
53828 ADD HL,BC
Add the column and the start of the buffer.
53829 LD C,A Move the column into BC.
53830 LD B,0
53832 ADD HL,BC Add it.
53833 LD BC,53289 Add the address of PlayfieldBuffer, less the first row and column.
53836 ADD HL,BC
53837 POP BC Restore BC from the stack.
53838 RET Return.
View the equivalent code in;
Prev: 53766 Up: Map Next: 53839