BBC Basic – Tips 1

Here are some tips for tricks for BBC Basic, specifically the original Acorn BBC version.

Sleep function (WAIT)

BBC Basic for Windows (and others) have a WAIT function that is really useful to pause execution for a time.

Here is a simple function that provides the same functionality:

   10 MODE 7
   20 VDU 23,1,0;0;0;0;
   30 PRINT "BBC BASIC TIPS"
   40 PRINT "==========================="
   50 PRINT "SLEEP FUNCTION"
   60 FOR I=1 TO 10
   70   PROCSleep(100)
   80   PRINT "TICK"
   90 NEXT
  100 END
  110 DEF PROCSleep(WAITVALUE)
  120 TIME=0
  130 T=TIME
  140 REPEAT
  150   TIMEA=TIME-T
  160 UNTIL TIMEA>WAITVALUE
  170 ENDPROC

Is uses the TIME function and is therefore calibrated to 100/th of a second in the argument.

So if you issue the command:

PROCSleep(100)

That means you wait for 1 seconds, i.e. 100 * (1 second/100)

Keyboard buffer

When reading from the keyboard buffer it can easily get full, if you are using non-blocking GET calls.

Here is an example program that shows a way to avoid that. It works in 2 modes. Firstly it reads values from the buffer using GET and it is easy to fil the buffer up with presses. The FOR NEXT loop is there to ‘do something’ simulating actions that might occur in a game or app.

When you press the space-bar it swaps to the second mode, clearing the buffer before reading.

      10 MODE 7
   20 VDU 23,1,0;0;0;0;
   30 PRINT "BBC BASIC TIPS"
   40 PRINT "==========================="
   50 PRINT "KEYBOARD BUFFER TEST"
  100 PRINT "STANDARD BUFFER MODE"
  110 K=GET
  120 IF K=32 THEN GOTO 170
  130 FOR A=1 TO 500
  140 NEXT
  150 PRINT K
  160 GOTO 110
  170 PRINT "BUFFER CLEAR MODE"
  180 *FX21,0
  190 K=GET
  200 IF K=32 THEN GOTO 40
  210 FOR A=1 TO 500
  220 NEXT
  230 PRINT K
  240 GOTO 180

The key command is:

*FX21,0
K=GET  

The FX command does the clearing, and the behaviour of the second mode is much more predictable. You cant get the program to just continue operation automatically when jamming down keys.

Leave a Reply

Your email address will not be published. Required fields are marked *