Prev: B2EE Up: Map Next: B394
B37F: Calculate Buffer Address
Finds the address in the buffer of the byte that holds a pixel. The buffer is 20 bytes wide with its bottom line first, so the address is ScreenBuffer + y * 20 + x / 08.
Input
B The pixel y position
C The pixel x position
Output
BC The address in the buffer
Work out the byte from the position.
CalculateBufferAddress B37F PUSH HL Stash HL on the stack.
Divide the pixel co-ordinates by eight.
B380 SRL B Divide BC by two.
B382 RR C
B384 SRL B Divide BC by four.
B386 RR C
B388 SRL B Divide BC by eight.
B38A RR C
B38C LD HL,$D88F Start at the first byte of the buffer, ScreenBuffer.
B38F ADD HL,BC Add BC to HL.
B390 LD C,L Keep the address in the buffer.
B391 LD B,H
B392 POP HL Restore HL from the stack and return.
B393 RET
View the equivalent code in;
Prev: B2EE Up: Map Next: B394