Prev: 58710 Up: Map Next: 58774
58745: Calculate Attribute Address
Used by the routines at StartGame, UpdateLogoPiece and ColourWallColumn.
Works out the address in the attribute buffer of a position in the window. The buffer is 24 bytes wide, and has a row for each eight rows of the screen buffer.
Input
H Y position (from 72 at the first row of the buffer)
L X position
Output
HL Address in the attribute buffer
Work out 24 times the character row.
CalculateAttributeAddress 58745 PUSH BC Stash BC on the stack.
58746 LD C,L Keep the X position.
58747 LD A,H Work out the Y position at the start of its character row.
58748 AND 248
58750 LD L,A
58751 LD H,0
58753 LD A,C Fetch the X position, and copy the Y position into BC.
58754 LD C,L
58755 LD B,H
58756 ADD HL,HL Multiply the Y position by three, to make 24 times the row.
58757 ADD HL,BC
Add the column and the address of the attribute buffer.
58758 SRL A Work out the column from the X position.
58760 SRL A
58762 SRL A
58764 LD C,A Make the column into a 16-bit number.
58765 LD B,0
58767 ADD HL,BC Add the column.
58768 LD BC,61290 Add the address of the attribute buffer.
58771 ADD HL,BC
58772 POP BC Restore BC from the stack and return.
58773 RET
Prev: 58710 Up: Map Next: 58774