Prev: B394 Up: Map Next: B3D3
B3B6: Calculate Attribute Address
Used by the routines at DisplayObjectsCarried and PrintText.
Finds the address in the attribute file of the colour square that holds a pixel. The y co-ordinate counts up from the bottom of the screen. The result is based on 5700 rather than 5800 as the lowest eight character rows are below the screen.
Input
H Pixel y co-ordinate, counting up from the bottom of the screen
L Pixel x co-ordinate
Output
DE Address in the attribute file
Turn the pixel position into a character offset.
CalculateAttributeAddress B3B6 PUSH HL Stash HL on the stack.
B3B7 LD A,H Invert the y co-ordinate.
B3B8 CPL
B3B9 LD H,A
B3BA SRL H Shift the inverted y co-ordinate right four times.
B3BC SRL H
B3BE SRL H
B3C0 SRL H
B3C2 RR L Rotate the last bit shifted out into the top of L, shifting the x co-ordinate right by one.
B3C4 SRL H Shift H again, and rotate the bit shifted out into L.
B3C6 RR L
B3C8 SRL H Shift H once more, and rotate the bit shifted out into L. This leaves HL as the character row times 20 plus the column.
B3CA RR L
Add the attribute file base.
B3CC LD DE,$5700 Set DE to 5700, the base of the attribute file less 0100.
B3CF ADD HL,DE Add the offset to get the address of the attribute.
B3D0 EX DE,HL Keep the attribute address.
B3D1 POP HL Restore HL from the stack.
B3D2 RET Return.
View the equivalent code in;
Prev: B394 Up: Map Next: B3D3