I fix ^.`

Clamp X to 160, not 159, so the last pixel is written.
Tile index is * 32, not * 16 (you need another power of 2).
You have to shift from the other way.