Retro spotlight: John Grant and Sinclair BASIC

illustrations illustrations illustrations illustrations illustrations illustrations illustrations

Published on 25 April 2024 by Andrew Owen (6 minutes)

Earlier this month, Zilog announced that it would be discontinuing the Z80 microprocessor after 48 years of production. Coincidentally, 48 is the number of kilobytes of RAM in the Z80-based ZX Spectrum microcomputer, which by another coincidence was released 42 years ago this month. This numerological rambling probably only makes sense to you if you’re a fan of “The Hitchhiker’s Guide to the Galaxy” (see last week’s article) and read this paragraph in the voice of Peter Jones. If not, don’t panic. To tell the story of Sinclair BASIC, it’s best to tell the story of some of the minds behind it. A human from the planet Earth was one of them. His name is John Grant.

On May 1 this year, the BASIC language will be 60 years old. I’ve previously written about the early days of BASIC and the development of Sinclair microcomputers. I’ve described the pivotal role Grant played in the development of the Spectrum. So this time I want to give some context and look at what makes Sinclair BASIC a novel version of the language. California’s Silicon Valley is known the world over, but in the 1970s what came to be known as Silicon Fen was developing in Cambridge, England. What started with the founding of Cambridge Science Park in 1970 has now become the greatest concentration of tech and biomedical companies in Europe, home to over 5,000 companies.

One of the early companies that’s still going is Nine Tiles (a reference to Mah-jongg’s maximum scoring Calling Nine Tiles hand), founded by Grant. For most of its history it’s been a networking company, but in the early days it created three successive versions of Sinclair BASIC. Clive Sinclair originally met with Grant in April 1979 to discuss a BASIC interpreter for the ZX80 microcomputer. Grant had no illusions about making any real money off the project, but thought it was something that Nine Tiles would benefit from being associated with.

To achieve the launch price of £79.95 in kit-form, RAM was limited to 1K and the integer BASIC had to be crammed into a 4K ROM. Grant wrote the bulk of tit between June and July. But the resulting program was 5K in length, so he spent that August trimming the code. He laid the path for things to come, introducing many features of Sinclair BASIC that are uncommon in other dialects, including:

  • Token entry: Keywords were mapped directly to keys, removing the need to type them out and the requirement for code to convert them to tokens.
  • On-entry syntax checking: The interpreter refuses to allow most syntax errors to be entered into the program, instead pointing out where the error is in the line before it is entered. This is a feature shared with Atari BASIC (also written in 1979) that makes it much easier to learn and use.
  • Always-on expression evaluation: Any variable can be replaced by an expression.
  • Character-based arrays (as opposed to the more common string-based arrays in other dialects).
  • Boolean logic (as opposed to bitwise logic used in Microsoft variants).

Some common BASIC commands had to be sacrificed for the sake of space. There was no ON, END, DATA, READ or RESTORE. In January 1980, Grant hired mathematician Steve Vickers who would write the ZX81 ROM, reusing much of Grant’s earlier work. For the Spectrum ROM, Sinclair wanted as few changes to the ZX81 code as possible. But Grant wanted the code rewritten, feeling that software designed for a machine with 1K was inappropriate for a machine with 16K and that problems would occur later on. But at every point, Sinclair wanted the maximum new facilities for the minimum money.

Twelve months later, the BASIC was mostly complete. It was greatly enhanced, but depressingly slow. And peripheral support was absent because Sinclair didn’t provide a working prototype until near the end of 1981. In February 1982 it became clear that Sinclair had no intention of paying royalties for the work (in the end, Nine Tiles didn’t get paid until Amstrad bought the rights to the ROM at the same time it acquired Sinclair Research). Then Steve Vickers and Sinclair’s hardware designer Richard Altwasser both quit to start the Jupiter ACE project. As a result, Sinclair shipped the Spectrum with an incomplete ROM with some of its functionality truncated.

The exact extent of this became clear when Grant and his wife Kate donated a prototype ZX Spectrum to the Centre for Computing History, which managed to dump the prototype ROM. Thanks to Daniel Nagy, who disassembled it, we now know that it originally supported the use of streams with the file commands. Grant is a generous individual and I’m personally grateful to him for giving me permission to distribute the ZX80 and ZX81 ROMs, which Nine Tiles still owns the rights to, under an open source license. This is in large part what made it possible to produce an open source firmware for the Spectrum.

But I wasn’t the first to approach Grant about licensing Vickers’ ZX81 ROM. Andy Wright founded BetaSoft in 1983 to sell BetaBASIC for the Spectrum. What started as a toolkit became a full version of BASIC in its own right. Single-key keyword entry was made optional and code was automatically indented, features that would eventually be added in Investronica’s Spectrum 128 (although indentation was dropped in the UK model). It supported a 64-column display (previously only available on the TS2068 with the ZebraOS cartridge). It provided full structured programming, named procedures and functions and local variables. Line numbers were optional. Development continued until 1987.

After that, Wright was contracted by MGT to provide the BASIC for the SAM Coupe (a Welsh Spectrum-compatible machine with various hardware enhancements). To do this, he started with BetaBASIC and gradually replaced the dependencies from the Spectrum ROM. He approached Grant to license the floating point library from the ZX81 ROM, but they couldn’t agree a deal, so he wrote his own.

Due to memory constraints, SAM BASIC lacked some features of BetaBASIC, but Wright later created an enhanced BASIC for the SAM called MasterBASIC. As an aside, MGT also provided a tool for downloading the Spectrum ROM onto the SAM called The Messenger. It came with a reverse engineered version of the Spectrum tape loading code. This was probably also written by Wright. I also owe him a debt of gratitude because he not only published the full source to the SAM ROM, which he still owns the rights to, he also gave me permission to distribute it under an open source license.

Starting with the ZX81 ROM, and the original routines from SE BASIC (my enhanced version of the Spectrum ROM). I was able to reuse the tape routines from The Messenger and a number of routines from SAM BASIC to create an open source version. Using the same reverse engineering technique as The Messenger, I was able to create a fully open source Spectrum firmware. Now that Comcast has closed the door on any future licensing of the original ROM, OpenSE BASIC provides an alternative for legal clones.

OpenSE BASIC also provided the basis for SE BASIC IV, used in the Chloe 280SE project, but that dialect is much closer to Atari BASIC. For those looking for an enhanced Sinclair BASIC interpreter that runs on modern hardware, the best choice is Paul Dunn’s SpecBAS. It does require Windows, although it should work under WINE on Intel versions of Linux. On ARM-based Macs, you can try running it in an emulated X86-64 environment using UTM.