Prev: E556 Up: Map Next: E596
E579: 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 48 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 E579 PUSH BC Stash BC on the stack.
E57A LD C,L Keep the X position.
E57B LD A,H Work out the Y position at the start of its character row.
E57C AND $F8
E57E LD L,A
E57F LD H,$00
E581 LD A,C Fetch the X position, and copy the Y position into BC.
E582 LD C,L
E583 LD B,H
E584 ADD HL,HL Multiply the Y position by three, to make 24 times the row.
E585 ADD HL,BC
Add the column and the address of the attribute buffer.
E586 SRL A Work out the column from the X position.
E588 SRL A
E58A SRL A
E58C LD C,A Make the column into a 16-bit number.
E58D LD B,$00
E58F ADD HL,BC Add the column.
E590 LD BC,$EF6A Add the address of the attribute buffer.
E593 ADD HL,BC
E594 POP BC Restore BC from the stack and return.
E595 RET
Prev: E556 Up: Map Next: E596