It might be possible to produce gcode that avoids the need to deal with this. For example I wrote a wizard that produces code to engrave a knurl that only requires the A axis to rotate in one direction throughout. I posted it somewhere on here, I'll try to find it.