Prev: D135 Up: Map Next: D174
D157: Calculate Attribute Address
Finds the address in the attribute file of the character square that holds a pixel. The pixel y position is from the bottom of the screen.
Input
H The pixel y position
L The pixel x position
Output
DE The address of the attribute
Work out the square from the position.
CalculateAttributeAddress D157 PUSH HL Stash HL on the stack.
D158 LD A,H Fetch H, invert it and copy it to H.
D159 CPL
D15A LD H,A
D15B SRL H Shift H right four times.
D15D SRL H
D15F SRL H
D161 SRL H
D163 RR L Rotate L right.
D165 SRL H Shift the next bit into L.
D167 RR L
D169 SRL H Shift the next bit into L.
D16B RR L
D16D LD DE,$5700 Point DE at 5700.
D170 ADD HL,DE Add DE to HL.
D171 EX DE,HL Exchange DE and HL.
D172 POP HL Restore HL from the stack.
D173 RET Return.
View the equivalent code in;
Prev: D135 Up: Map Next: D174