Prev: D206 Up: Map Next: D24F
D233: Calculate Buffer Address
Finds the address in PlayfieldBuffer of a pixel. The first row of the buffer is at a vertical position of 48 and the first column is at a horizontal position of 10.
Input
H The vertical position, from 48
L The horizontal position, from 10
Output
HL The address in the buffer
Stash BC.
CalculateBufferAddress D233 PUSH BC Stash BC on the stack.
Work out the column from the horizontal position.
D234 SRL L Divide the horizontal position by eight.
D236 SRL L
D238 SRL L
D23A LD A,L Keep the column, and start with the vertical position.
D23B LD L,H
D23C LD H,$00
Work out 18 times the vertical position.
D23E ADD HL,HL Multiply the vertical position by eight.
D23F ADD HL,HL
D240 ADD HL,HL
D241 LD C,L Keep it.
D242 LD B,H
D243 ADD HL,HL Multiply it by two and add the eight times.
D244 ADD HL,BC
Add the column and the start of the buffer.
D245 LD C,A Move the column into BC.
D246 LD B,$00
D248 ADD HL,BC Add it.
D249 LD BC,$D029 Add the address of PlayfieldBuffer, less the first row and column.
D24C ADD HL,BC
D24D POP BC Restore BC from the stack.
D24E RET Return.
View the equivalent code in;
Prev: D206 Up: Map Next: D24F