I have been told your compiler can produce bad results if you do not clearly separate your logic.
All four If statements have the issue pointed out below....
This might not be the root of your problem but it is ideal to do this moving forward.
if ( (p1&JOY_LEFT) && ( (x<=32) && (x>0) ) )