RISC OS sketchpad program

On page 70 of the RISC OS BBC BASIC Reference Manual this program is listed, which "draws lines as
you move the mouse around and hold down its buttons
":
 10 MODE MODE
 20 MOVE 0,0
 30 REPEAT
 40   MOUSE x,y,button
 50   GCOL button + 1
 40   DRAW x,y
 50 UNTIL FALSE
I don't understand how this program is supposed to work. If no mouse buttons are pressed button is (presumably) set to zero, and line 50 will then do a GCOL 1. Surely that will cause a line to be drawn, when it shouldn't be. Or have I misunderstood something?

Comments

  • I guess nobody has commented because there's no RISC OS-specific expertise here, is there somewhere better to ask the question? I'd like to think it's simply an error in the manual, but since it was revised in 2017 and again in 2021 (with "minor corrections") that's not very likely.

    I'd test the code myself in RPCEmu but (although I'm sure I once knew) I've completely forgotten how to enable using the Windows mouse to control the pointer in the emulator, I can't even move the mouse into the window. :(
  • Try *POINTER to wake the mouse up.

    Looking at the code it will always be drawing, and the colour depends on how many buttons you have held down.
  • Soruk wrote: »
    Try *POINTER to wake the mouse up.
    Thank you. Although that works in immediate mode I had to add it to the program as well (as line 15) otherwise running the program disabled the mouse again.
    Looking at the code it will always be drawing
    Interestingly the code as listed in the manual does nothing at all, I am guessing because MODE MODE leaves it in the mode is was in initially, which is MODE 3 with no graphics capability! Changing MODE MODE to MODE 1 has the effect you describe, of drawing all the time.

    So it does look likely to be an error in the documentation that has never been spotted. To fix it one would presumably have to arrange to do GCOL 5,0 (no-op) when none of the buttons are pressed, something like:
     50   IF button GCOL button+1 ELSE GCOL 5,0
    
    That does indeed seem to work. Is there some way of feeding it back to the RISC OS documentation team?
  • Soruk
    edited March 4
    You can drop the ELSE bit entirely, as if it's a no-op, then the code is more efficient just not having it. You can also remove the +1 offset else colour 1 can not be selected. (In MODE 1 left and right buttons will return 5, which maps to 1)

    After *POINTER, you can turn the mouse on with MOUSE ON, and changing mode switches it off again.

    Regarding documentation bugs, I see others have reported documentation bugs in the Bugs section of the RISC OS Open forums. Indeed, you might remember this from a couple of years ago concerning STR$ and @% - https://www.riscosopen.org/forum/forums/4/topics/17046

    (In Matrix Brandy, changing MODE turns the pointer on if windowed, off if full-screen.)
  • Soruk wrote: »
    You can drop the ELSE bit entirely
    How? Just omitting the ELSE clause would result in the DRAW x,y in line 40 (which is still executed) continuing to draw with whatever the last selected colour was. To be able to omit the ELSE you'd have to make the DRAW also conditional on the value of 'button'.

    And even that wouldn't work, because if you don't execute the DRAW statement at all the 'graphics cursor' won't be updated when the mouse is moved. So when you do press the button it will draw a line from where you last pressed the button to the new location, which is not what you want.
    You can also remove the +1 offset else colour 1 can not be selected.
    Funnily enough I tried that - it doesn't work! That's because pressing the (left) mouse button causes button to be set to 4, and (in MODE 1) GCOL 4 is the same as GCOL 0, which draws in black and is therefore invisible (unless drawing over another colour).

    With the +1 pressing the left mouse button does GCOL 5 (equivalent to GCOL 1) and pressing the right mouse button does a GCOL 2, which is ideal.
    After *POINTER, you can turn the mouse on with MOUSE ON, and changing mode switches it off again.
    I didn't find any MOUSE ON (or OFF) to be necessary, *POINTER was sufficient to make the program work (in RPCEmu).
    In Matrix Brandy, changing MODE turns the pointer on if windowed, off if full-screen.
    Interesting. Is it just the visible pointer that is disabled in fullscreen or does MOUSE x,y,b not work at all?
  • Try MODE 9 - it's like MODE 2 but with MODE 1's resolution. Then you have access to colours 0 to 7 depending on which mouse buttons you hold down (or 1 to 8 if you keep the offset).

    Yeah, I misremembered the no-op nature, that GCOL makes all the drawing a no-op, not the GCOL call itself being a no-op. Oops.

    Regarding the mouse pointer, like RISC OS, doing MOUSE x,y,b still returns values even if the pointer is not displayed. Perhaps due to the RPCEmu mouse hook patching, you need to do *POINTER first, after which it will still work even after MOUSE OFF.