BBC BASIC on Raspberry Pi

Recently I wrote about setting up RISC OS Pi for Raspberry Pi. One of the good things about RISCO OS is that it has a built in BASIC interpreter which is backwards compatible (mostly) with your BBC micro computer BASIC.

One way of running BBC software on your Raspberry Pi is to use an emulator, however it is also possible to run 'beeb' BASIC programs from your pinboard or command line, as this blog post will attempt to show.

RISC OS pinboard showing native BASIC apps and a stormy day in Scarborough.

Whether you choose to run the emulator, or run BASIC as native programs, your first port of call will be some BBC disc images. You might choose to download your BASIC disc images from the internet, or you may already have them on your vintage beeb machine. This post will cover both situations.

  • First load your disc image into your BBC emulator on your PC. I will be using the excellent BeebEm emulator for Windows.  To do this select: File > Load Disc 0 and find the disc image in your file explorer. The disc image will now be loaded into a virtual drive in your emulator. To see the files, type *cat in the BASIC command line.
Load your disc image into your emulator.
  • Export the BASIC programs that you want from the disc image. BeebEm provides you with the option of exporting a file from your disc image onto you PC. Save this onto a USB flash drive.  To do this select: Edit > Export Files from Disc > Disc 0

Export the BASIC files from the disk image onto a USB device.
  • Rename the file that has been exported. You don't want the DFS directory information showing. For example, change $.file to file only.
  • Plug the USB device into your Raspberry Pi. RISC OS should see the USB device which will allow you to copy the file and save it wherever it makes sense on your machine.
You should see the USB drive appear on your icon bar.
  • At this point you will probably have to change the file type to 'BASIC' rather than 'Text'. To do this, press the middle 'menu' mouse button and choose the appropriate option from the menu.
  • Your BASIC program will be ready to run directly from your pinboard.
To run from the command line, you will need a couple of extra steps.

  • First select the filing system for your USB drive. This is likely to be the command *fat32fs

  • Then mount the disk with *mount 0 or *mount 1 depending on the number of USB devices you have. To get a directory listing try *dir :0 followed by *cat and hopefully you will see your file. This can be executed with CH."filename" or edited with LOAD"filename" and LIST or RUN.

If in doubt, RISC OS provides documentation with the *help command. To return to the main filing system type *SFDS

Data Centre

If you have BASIC programs on floppy disc on a vintage beeb machine, you can also get your code running on RISC OS using the brilliant Data Centre from RetroClinic.

The documentation that comes with your data center explains fully how to transfer disc images from floppies or Compact Flash cards onto your PC.

In my case, I am transferring files stored on compact flash drive under ADFS to virtual RAM drives under DFS. These can then be exported onto the USB stick.  Once you have the disc images you can follow the instructions on getting them running on your Raspberry Pi from above.

Compatibility

Although you will find that most of your BBC micro, Electron or Master BASIC programs will run on your RISC OS Pi or RISC OS pico machine, there may be some minor compatibility problems.

Most notably is that you are going to find that your programs run fast. Very fast! This might not be a problem, in fact it might be very welcome if your program involves a lot of graphics. It could be a problem if you wish to play a game but don't have the reflexes of a Jedi.

With a program that I wrote myself for the BBC Master I notice that the different keyboard layout of the BBC machine and a modern USB keyboard caused an issue. This was because my program uses the key combination SHIFT + '3' to reset a timer. On the BBC machines this combination of keys produces the octothorpe character '#' whereas on my IEEE keyboard, this combination produces the '£' character. This was a minor problem which was overcome by a quick patch of the code.

Another problem was that some BBC BASIC programs do not have well-defined exit strategies. Oftentimes the way out of the program is to reset the machine with the 'BREAK' key. Under RISC OS this may cause programs to hang forever requiring a full reboot of the machine.  In most cases you either need to put up with this, or write an exit strategy.

One way of doing this would be to program the 'ESC' key to act like the 'BREAK' key. Just add the following BASIC line into the start of your program:

  ON ERROR IF ERR = 17 OSCLI("DESKTOP")

If you have enjoyed this post then you might want to read other posts about the Raspberry Pi, or about the BBC micro systems, or just something at random from this blog.



1 comments:

No discussion of BBC BASIC on the Raspberry Pi is complete without mentioning 'BBC BASIC for SDL 2.0' which runs on Raspbian (not RISC OS). This is almost 100% compatible with 'BBC BASIC for Windows' (it supports all the language extensions of that dialect, including structures, huge strings and 64-bit integer variables). It's also entirely free! Details at http://www.bbcbasic.co.uk/bbcsdl/