In Paged output (VDU14) following Message box can behave incorrectly.

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
circe
Posts: 8
Joined: Wed 07 May 2025, 09:26

In Paged output (VDU14) following Message box can behave incorrectly.

Post by circe »

BBCSDL: If Paged output (VDU14) is selected, if Output is followed by Yes/No Message box, despite *FX21,0 or REPEAT UNTIL INKEY(0)=-1 to clear keyboard buffer.
If SPACE BAR is pressed instead of SHIFT, when SHIFT is eventually pressed, a Message Box after output self-answers with NO (result%=6) and exits. Only affects SPACE BAR. In fact, the keyboard buffer is only cleared up to SPACE perhaps?

Can be demonstrated with:

Code: Select all

      INSTALL @lib$+"msgbox"
      INSTALL @lib$+"dlglib"
      VDU 14
      FOR count%=0 TO 40:PRINT" Line "STR$(count%):NEXT
      *FX21,0
      REPEAT UNTIL INKEY(0)=-1
      result%=FN_messagebox("Test", "Answer Yes or No", 4)
      PRINT "result% is:"STR$(result%)
Richard Russell
Posts: 366
Joined: Tue 18 Jun 2024, 09:32

Re: In Paged output (VDU14) following Message box can behave incorrectly.

Post by Richard Russell »

circe wrote: Mon 19 May 2025, 13:32 If SPACE BAR is pressed instead of SHIFT, when SHIFT is eventually pressed, a Message Box after output self-answers with NO (result%=6) and exits.
After a bit of experimentation it seems that this happens because pausing output (as a result of VDU 14) happens in the UI thread rather than in the interpreter thread. The solution is to force a 'thread synchronisation' before you clear the keyboard buffer:

Code: Select all

      INSTALL @lib$+"msgbox"
      INSTALL @lib$+"dlglib"
      VDU 14
      FOR count%=0 TO 40:PRINT" Line "STR$(count%):NEXT
      IF POS REM SDL thread sync
      *FX21,0
      result%=FN_messagebox("Test", "Answer Yes or No", 4)
      PRINT "result% is:"STR$(result%)
There's no obvious way in which this could be fixed by modifying BBCSDL itself, because you would not want to force a thread synchronisation every time you do *FX 21 (that would hurt performance) but only immediately after a VDU 14 pause had happened - but there's no easy way to detect that.

Possibly it would be acceptable to force a thread sync when a VDU 15 is issued, since that is not likely to be speed critical, but you would then need to remember to do a VDU 15 before calling FN_messagebox(), which you don't in your code (and perhaps might not want to).

The dual-threaded nature of BBCSDL does result in a number of situations when you need to force a thread synchronisation, but I hadn't realised that this was one of them. Good spot!