Prev: A303 Up: Map Next: A59F
A57E: Find Buffer Address
Used by the routine at DrawSprites.
Finds the address in the buffer at F800 of the top left of a sprite in the rectangle that is being drawn by DrawSprites.
Input
H Vertical position
L Horizontal position
Output
HL Address in the buffer
FindBufferAddress A57E LD A,($5C2C) Fetch the left of the rectangle.
A581 LD C,A Store it in C.
A582 LD A,L Fetch the horizontal position.
A583 SUB C Subtract the left of the rectangle.
A584 SRL A Divide it by eight to get the number of bytes across.
A586 SRL A
A588 SRL A
A58A LD L,A Store it in L.
A58B LD A,($5C2D) Fetch the bottom of the rectangle.
A58E SUB H Subtract the vertical position to get the number of rows up.
A58F JR Z,FindBufferAddress_Page Jump to FindBufferAddress_Page if the sprite is at the bottom.
A591 LD C,A Store the number of rows in C.
A592 LD A,($CE35) Fetch the number of bytes in a row.
A595 LD H,A Store it in H.
FindBufferAddress_Row A596 LD A,L Fetch the offset.
A597 ADD A,H Add the number of bytes in a row.
A598 LD L,A Store the offset.
A599 DEC C Count the rows.
A59A JR NZ,FindBufferAddress_Row Loop back to FindBufferAddress_Row for each row.
FindBufferAddress_Page A59C LD H,$F8 Use the buffer.
A59E RET Return.
Prev: A303 Up: Map Next: A59F