First of all, I see you are using MOD. IMHO, the only sensible output for MOD where the second operand is a positive value N is a value between 0 (inclusive) and N (exclusive). Many programming language designers, including SmileBasic, are not sensible in this way, when the first operand is negative. So, test your code under the circumstance that the first operand is negative, or write your code so that it never is.
Second, you seem to be confusing in-game coordinates with on-screen coordinates... or something. Your vertical lines go from Y value 0 to Y value 240, but for your horizontal lines the value of the variable Y only goes as high as CAMERAH. If that's not an outright bug, it's a clear indicator that you've got two concepts mixed up and crossing each other in ways they shouldn't.
So, I'd recommend you take a step back. Be sure you know the semantics of each value - whether in-game coordinates of the game world, coordinates of the camera, coordinates on the screen, any other types of value you use... and make sure the relationships between the values are all clear, the calculations to go from one set of coordinates to another are all correct, and you're not using a number with one type of semantics in a context that requires a different type of number.
Oh yeah and I changed "CAMERA" to "CM" due to laziness, CMX, CMY, CMW, CMH.