Prev: A115 Up: Map Next: A170
A149: Turn pixel coordinates into a screen address
The standard Spectrum screen-address calculation from a pixel position: L is x (0-255, its low three bits dropped) and H is y (0-191 from the top). Everything in the game that draws on the screen uses this.
Input
L x in pixels
H y in pixels
Output
HL The screen byte containing the pixel
pixel_to_screen A149 LD A,L The column, x divided by 8
A14A RRC A
A14C RRC A
A14E RRC A
A150 AND $1F
A152 LD L,A
A153 LD A,H Bits 3-5 of y become bits 5-7 of the low byte
A154 RLC A
A156 RLC A
A158 AND $E0
A15A OR L
A15B LD L,A
A15C LD A,H Bits 0-2 of y are the pixel line within the cell
A15D AND $07
A15F EX AF,AF'
A160 LD A,H Bits 6-7 of y pick the third of the screen; combine with the pixel line
A161 RRC A
A163 RRC A
A165 RRC A
A167 AND $18
A169 OR $40
A16B LD H,A
A16C EX AF,AF'
A16D OR H
A16E LD H,A
A16F RET
Prev: A115 Up: Map Next: A170