Prev: 58664 Up: Map Next: 58710
58682: Calculate Buffer Address
Used by the routines at DrawStripGraphic, DrawWallStrip and DrawSprite.
Works out the address in the screen buffer of a position in the window. The buffer is 24 bytes wide.
Input
H Y position (from 72 at the first row of the buffer)
L X position
Output
HL Address in the screen buffer
Work out the column and 24 times the row.
CalculateBufferAddress 58682 PUSH BC Stash BC on the stack.
58683 SRL L Divide the X position by eight.
58685 SRL L
58687 SRL L
58689 LD A,L Keep the column, and start with the Y position.
58690 LD L,H
58691 LD H,0
58693 ADD HL,HL Multiply the Y position by eight.
58694 ADD HL,HL
58695 ADD HL,HL
58696 LD C,L Keep the result.
58697 LD B,H
58698 ADD HL,HL Multiply by two more, and add it to get 24 times the Y position.
58699 ADD HL,BC
Add the column and the address of the buffer.
58700 LD C,A Add the X position divided by eight.
58701 LD B,0
58703 ADD HL,BC Add the column.
58704 LD BC,57090 Add the address of the buffer.
58707 ADD HL,BC
58708 POP BC Restore BC from the stack and return.
58709 RET
View the equivalent code in;
Prev: 58664 Up: Map Next: 58710