I’m currently reading the 520 page BBC BASIC Reference Manual for RISC OS, which was originally written in 1992, with updates in 2017 and 2021. That’s quite a bit bigger of a BASIC than the Microsoft BASICs that were available to me as a kid in the USA. Even QBasic for MS-DOS wasn’t all that sophisticated.
I thought it would be useful for myself and others to write a blog post summarizing the unique and surprising features of BBC BASIC for RISC OS that aren’t self-explanatory, because there are quite a few. I plan to set up a Patreon page this week for readers who’d like to support my writing about these topics. Stay tuned for more details about that when I’m ready to announce them.
BBC BASIC reminds me of the Perl programming language, where there are a lot of quirks and conventions that you simply have to know about or else you’ll see what appears to be a random punctuation mark and not have any idea what’s going on. If you’re lucky, the surrounding keyword will provide a clue. Those are the quirks I want to cover here, as well as cool features of BBC BASIC.
Chapter 5, variables, lists rules for naming variables. They’re case sensitive, can contain digits, unaccented upper- and lower-case letters, the underscore (_) and the grave character (`). There must be no spaces within the name, they must not start with a digit, and they must not start with most BASIC keywords.
BASIC keywords must be written in uppercase in BBC BASIC, so it’s common to use lowercase or mixed-case variables in order to name variables
cost, which won’t conflict with the
COS keywords, respectively.
Besides the case sensitivity, there are a few other similarities to C that you may find familiar, like some of the operators, covered in chapter 6. You can use
-= to increment and decrement variables by some value. There are
>>> operators to do logical bit shifts left, arithmetic (signed) bit shift right, or logical (unsigned) bit shift right.
Long story short, there are two features missing from original BASIC and also BBC BASIC that make it difficult to write larger programs. First, there’s no “record” or “struct” type to hold data structures with different types of variables. There are only arrays. You can manually set up blocks of memory using an extension to DIM and some additional operators to read/write bytes, 32-bit words, and strings from those arrays. It’s not a very intuitive feature, but it does allow BASIC programs to make RISC OS system calls.
The other missing feature is that there’s no way for native code to call back into BBC BASIC. That’s not a huge gap because the RISC OS GUI’s cooperative multitasking uses an event loop, so system events are received via polling.
From a 2023 perspective, BBC BASIC is quite interesting, and useful for many types of programs, but there’s a reason why Python is so much more popular. There’s a port of Python 3.8, and I’ve been looking into updating it to a newer version. One set of modules ported by the authors is Pygame, designed for teaching programming by making it easy to write simple games.
I’ll have to write a separate blog post all about GCCSDK and Autobuilder, along with GCC 4 vs. GCC 10 and my fork of the repo to attempt to upgrade the compiler toolchain and to use the same base packages as Raspberry Pi OS.
The problem with Python is that it is now quite large and difficult to port, at least if you include all of the popular packages. I was looking for a modern alternative to BASIC that supports data structures and callbacks and then I was reminded that Lua exists and is quite popular as a game scripting engine for its ease of use, reasonable performance, and small size.
Lua is used by the virtual vintage 8-bit game console PICO-8, which I was thinking might be cool to try to port to RISC OS, but then I realized PICO-8 is closed source. So I searched for something similar to Pygame but using Lua, and I found LÖVE, which is exactly what I was looking for. There’s a port of Lua to RISC OS, so I’m going to work on updating that because there seem to be a lot of cool tutorials, and I’d like to get some practice writing my own simple games.
Besides RISC OS, I’m curious to see if I can port a version of LÖVE to the KaiOS feature phones. They’re not very impressive-looking, but I think there’s a market for a $20 phone that can run web apps and has Wi-Fi and 4G LTE data.