Page 1 of 1

BBC BASIC for Raspberry Pi

Posted: Sun Feb 19, 2017 11:16 am
by Richard Russell
Hot on the heels of the Android edition, I’ve now released an edition of BBC BASIC for the Raspberry Pi running Linux (Raspbian Jessie).  This is highly compatible with the SDL 2.0 editions for Windows, Linux, Mac OS-X and Android. Details of how to download and install this edition can be found at the forum. For best results it is necessary to enable the GL Driver in raspi-config.

Image

Re: BBC BASIC for Raspberry Pi

Posted: Sun Feb 19, 2017 8:17 pm
by roland
That looks very nice =D> . On the other forum I read that it should be possible to use the I/O by calling SYS. Can you point us to some examples how to use this SYS? And is it also possible to use the network stack?

Re: BBC BASIC for Raspberry Pi

Posted: Sun Feb 19, 2017 11:18 pm
by Richard Russell
roland wrote:Can you point us to some examples how to use this SYS?

SYS will call SDL, SDL_ttf, FreeType and OpenGL APIs, plus functions in the C Runtime Library. Here for example is how to change the window title:

Code: Select all

      SYS "SDL_SetWindowTitle", @hwnd%, "My new window title"

And is it also possible to use the network stack?

It should be, but you will need to install SDL_net to do so in a cross-platform way. I haven't checked to see if it is available from the RPi repository, but hopefully it is.

Richard.

Re: BBC BASIC for Raspberry Pi

Posted: Mon Feb 20, 2017 1:41 pm
by Richard Russell
roland wrote:I read that it should be possible to use the I/O using SYS

Having investigated what is involved, I can confirm that it is straightforward to access the Raspberry Pi's GPIO from BBC BASIC. I would suggest that the best approach would be to create a library (gpiolib.bbc maybe) containing the main routines for initialising the GPIO, setting pins to input or output etc. This will keep the code in one place and make it easier to update should that be necessary. If there is sufficient interest I will consider writing such a library.

Richard.

Re: BBC BASIC for Raspberry Pi

Posted: Mon Feb 27, 2017 2:55 pm
by Richard Russell
Richard Russell wrote:I will consider writing such a library.

I've today released a new version of BBC BASIC for the Raspberry Pi (RPi 2 or RPi 3) with a GPIO library included. To illustrate its use here is a simple demo/test program:

Code: Select all

      REM Simple GPIO test program for the Raspberry Pi 2, RPi 3 or RPi Zero

      INSTALL @lib$ + "gpiolib"
      INSTALL @lib$ + "stringlib"

      REM Initialise GPIO:
      gpio% = FN_gpio_setup

      REM Set GPIO pins 7 to 11 inclusive to output mode:
      FOR pin% = 7 TO 11
        PROC_gpio_inp(gpio%,pin%) : REM Must use PROC_gpio_inp() before PROC_gpio_out()
        PROC_gpio_out(gpio%,pin%)
      NEXT pin%

      REM Set GPIO pins 24 and 25 to input mode:
      FOR pin% = 24 TO 25
        PROC_gpio_inp(gpio%,pin%)
      NEXT pin%

      REM Enable pull-ups on GPIO pins 24 and 25:
      PROC_gpio_pull(gpio%,2) : REM Select pull-up
      WAIT 0
      PROC_gpio_pullclk0(gpio%,&3000000)
      WAIT 0
      PROC_gpio_pull(gpio%,0)
      PROC_gpio_pullclk0(gpio%,0)

      REM Output a cycling pattern to GPIO pins 7 to 11:
      previous% = %111110000000
      FOR pattern% = %000000000000 TO %111110000000 STEP %10000000
        PROC_gpio_clr(gpio%, (pattern% EOR previous%) AND NOT pattern%)
        PROC_gpio_set(gpio%, (pattern% EOR previous%) AND pattern%)
        previous% = pattern%
        WAIT 20
        PRINT FN_tobase(gpio%!&34 >> 7 AND %11111, 2, 5)
      NEXT pattern%

      END

Richard.

Re: BBC BASIC for Raspberry Pi

Posted: Mon Feb 27, 2017 6:53 pm
by flaxcottage
Thanks for this, Richard. It is looking very good. I shall have to dig my Linux Pi out and have a go.

Re: BBC BASIC for Raspberry Pi

Posted: Thu Mar 02, 2017 1:42 pm
by flaxcottage
This is a great addition to the Raspberry Pi, thanks. A bit quirky then I like quirky.

Now I can run the same program on a real BBC micro, a real Archimedes, a Z88, a DOS PC, a Windows PC, an Android tablet and on a Raspberry Pi running either RISCOS or Linux. =D> =D> =D> =D>