You know you could make your loops simpler by using
for (i=499; i>=0; i--)
It would be easier to see what's happening.

Easiest way to debug something without using the debugger is to print...