handle wrapping between 0<->511 on X/Y