Shop OBEX P1 Docs P2 Docs Learn Events
Help spot the possible bug(?) — Parallax Forums

Help spot the possible bug(?)

Lord SteveLord Steve Posts: 206
edited 2007-03-16 01:00 in Propeller 1
I just got my first prop plug two days ago so be gentle if this is a head slapper.

For learning purposes I was coding a little text editor.· The project uses the VGA_HiRes_Text object and the Keyboard object and the Propeller Proto board with the VGA/Keyboard/Mouse accessory.

In the attached spin file, I have a case statement that switches on a character read from a keyboard.· When the uses presses the UP ARROW (hex $C2), my little baby text editor's cursor should pop up a line, if it's not on the first line.· But, the cursor jumps way up to before the screen...to negative land.· The debug print-out at the bottom of the screen shows what happens to the variable cursorPos.· I have stared at the spin code and can't see anything wrong with it...it just subtracts 128 from cursorPos.

Check out the $C2 case statement (line 55) in the PutChar method.

If anyone wants to take a stab at humilitating me with how dumb it is that I can't see the problem...please do.

Comments

  • Michael PopoloskiMichael Popoloski Posts: 42
    edited 2007-03-16 00:03
    You are a C++ programmer, aren't you? Actually, I wouldn't have found the problem myself if I hadn't remembered reading about a similar problem before. Apparently, in Spin, the >= operator is actually =>. If you use the >= operator like you are now, it is actually using the > operator and then using the assignment operator (=). So basically, you are performing the comparison which evaluates to true, which is then getting stored in the position, then you subtract 128 from it, so it will always be negative. Read page 157 in the Propeller Manual for a complete listing of operators, and other important information on the language.

    BTW, you aren't stupid or dumb, I would have made the same mistake. Its kind of weird that they deviated from other standard languages so much with the Spin language constructs, but what are ya gonna do?
  • BergamotBergamot Posts: 185
    edited 2007-03-16 00:29
    Michael Popoloski said...
    You are a C++ programmer, aren't you? Actually, I wouldn't have found the problem myself if I hadn't remembered reading about a similar problem before. Apparently, in Spin, the >= operator is actually =>. If you use the >= operator like you are now, it is actually using the > operator and then using the assignment operator (=). So basically, you are performing the comparison which evaluates to true, which is then getting stored in the position, then you subtract 128 from it, so it will always be negative. Read page 157 in the Propeller Manual for a complete listing of operators, and other important information on the language.

    BTW, you aren't stupid or dumb, I would have made the same mistake. Its kind of weird that they deviated from other standard languages so much with the Spin language constructs, but what are ya gonna do?
    IMHO it would have been just as weird to switch partway from +=, -=, etc to =< and =>
  • Lord SteveLord Steve Posts: 206
    edited 2007-03-16 01:00
    Wow.· Thank you.· I never would have thought to look at ">=".· That's a gotcha, ain't it.
Sign In or Register to comment.