Back to BASIC

27 Mar

“The less fortunate BASICs picked up bad habits and vulgar language. We would no sooner think of using street BASIC than we would think of using FORTRAN.” —Kemeny & Kurtz

Detail from the cover of Zilog's ZDS-1 manual

Sinclair BASIC is a popular version of the BASIC (Beginner’s All purpose Symbolic Instruction Code) programming language. Originally written for the ZX80 which celebrated its 30th anniversary last year, it is now available for a wide range of computers in native versions or via emulation. This is the history of its evolution.

In July 1975 Micro-Soft, as it was then called, shipped BASIC (Beginner’s All purpose Symbolic Instruction Code) version 2.0 for the MITS Altair 8800 hobbyist computer. This was the first commercial version of the Beginner’s All-purpose Symbolic Instruction Code programming language, originally developed by Hungaraian-American John George Kemeny, and Thomas Eugene Kurtz in 1964 at Dartmouth College in the United States.

By then Kemeny and Kurtz had addressed the main criticisms of BASIC; that it lacked structure and encourage bad programming habits, but the 4K and 8K versions for the Altair, written by Paul Allen and Bill Gates, were based on the original Dartmouth BASIC.

Microsoft BASIC became so popular that it made Gates and Allen their first fortune and was subsequently supplied with the majority of 8-bit computers. So not surprisingly, when the ANSI Standard for Minimal BASIC (X3.60-1978) was launched, it was based mainly on the Microsoft version.

In May 1979, a team of Clive Sinclair’s engineers in Cambridge, England, headed by Jim Westwood, began work on the machine that would become the ZX80. Sinclair was inspired to create the machine after seeing how much his son enjoyed using a TRS-80 but guessing that many people would be put off buying one because of the high price — just under £500.

Unlike Sinclair’s previous foray in to the computer hobbyist market, the MK14, this machine would ship with BASIC, based on the ANSI standard. At Commodore, Jack Tramiel managed to negotiate a permanent licence from Gates for a fixed one-time fee which did not require Microsoft to be given an on-screen credit. To this day many people are not aware that Commodore BASIC is Microsoft BASIC.

But at Sinclair the aim was to keep costs to a minimum, and that precluded paying even a one off fee to Microsoft. To this end, Sinclair had already met with John Grant of Nine Tiles in April to discuss the software requirements of the ZX80.

Given the tiny research and development budget, Nine Tiles stood to make hardly any money out of the deal, but the feeling was that the project was exciting and worthwhile, and one the company 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 the ROM between June and July. But the resulting program was 5K in length so Grant spent that August trimming the code.

It was written using Zilog’s own assembler on the ZDS1 development system.

“Most of the source was written in pencil and then typed in,” says John.

“24 lines of 80 characters didn’t let you see enough to write code directly on the screen.”

This was not long after code was typed on to cards or paper tape and programmers had one or two runs a day.

“If you left out a semicolon, say, you couldn’t just put it in and recompile,” says John.

“It meant we were quite careful to make sure everything was right.”

The ROM program was debugged on the Zilog system using the VDU to emulate the screen and keyboard. The only hardware development aid was an oscilloscope.

“It was only the hardware related parts that had to be debugged on the prototype,” says John.

“The first few EPROMs we put into the prototype stuck in a tight enough loop that we could just read and note down each of the address and data signals to find out what was going on.

“Once we got a picture on the television we could see what was happening and the rest was easy. If you didn’t get a picture you knew it was because of a change you’d just made.”

According to Cambridge mathematician Steve Vickers, who wrote the subsequent versions of Sinclair BASIC: “The ZX80 integer BASIC, written by John Grant, was in Z80 assembly code pure and simple, though it did use the usual stack based techniques for interpreting expressions.”

The lack of support for floating-point numbers, overshadows Grant’s achievement. He laid the path for things to come, introducing many unique features of Sinclair BASIC, such as the way it 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, making it much easier to learn and use than any other version of BASIC.

The kit was launched at a computer fair in the first week of February 1980, and while it was not a massive success by comparison with the ZX Spectrum, it turned Sinclair’s fortunes around, eventually earning him a knighthood, and it sold well enough to persuade him to make a new computer – the ZX81.

Work on the hardware had begun in September 1979, even before the launch of the ZX80, but it was the development of the uncommitted logic array, or ULA, which allowed the machine to go into production. The ULA, produced by Ferranti for Sinclair, reduced the total chip count to just four (ROM, RAM, ULA, Z80) and brought the retail cost of the machine, in kit-form, down to £49.95. Clive Sinclair recently remarked that of the ZX machines he was most proud of the ZX81. It was elegant inside and out, and while the Spectrum was a bigger success it should be seen as a development of the amazing work that went into the ZX81.

Again, Nine Tiles was called on to provide the New BASIC, but this time there was 8K to play with. Vickers, who had joined Nine Tiles in January 1980, wrote a new set of floating point arithmetic routines, and modified Grant’s work extensively, while retaining much of the ZX80 code.

“As far as Clive was concerned, it wasn’t a question of what the machine ought to be able to do, but more what could be crammed into the machine given the component budget he’d set his mind on,” said Vickers in an interview on July 23, 1985. “The only firm brief for the ZX81 was that the ZX80’s math package must be improved.”

The ROM was almost complete by the end of autumn 1980, but support still had to be added for the ZX Printer. Somewhere between this time and the launch, a bug crept in which caused the square root of 0.25 to be 1.3591409. Vickers quickly fixed the bug, but Sinclair was somewhat tardy in making this version available to people who had already bought the machine.

Despite this problem, the ZX81 was well received and became a massive success. Buoyed by the public’s reaction, and partly in an attempt to win the contract to design a computer for the British Broadcasting Corporation, which eventually went to Acorn,  Sinclair decided to develop a colour computer.

The ZX80 and ZX81 hardware had been the primarily the work of Jim Westwood, but he had been moved to the flat-screen television department, so the hardware design job on the machine which became the ZX Spectrum, was given to Richard Altwasser. Rick Dickinson again provided the industrial design, while at Nine Tiles, Vickers provided the BASIC.

The ZX Spectrum ROM retains almost the entire ZX81 program but further improves the arithmetic and adds support for the, sound, colour and hi-res graphics.

Sinclair wanted as few changes to the ZX81 code as possible but at Nine Tiles the feeling was that software designed for a machine with 1K was inappropriate for a machine with 16K and that problems would occur later on. They were right.

“Certainly with the Spectrum we wanted to rewrite the code, but there wasn’t the time and there definitely weren’t the resources,” says Grant. “At every point Clive wanted the maximum new facilities for the minimum money.”

After the best part of a year’s work the BASIC was almost finished. While it was greatly enhanced, it was also depressingly slow, but more problems were to follow. The main problem was providing support for the planned peripherals because no working prototypes were available to Vickers until near the end of 1981. But then, in February 1982 Nine Tiles began to have financial disagreements with Sinclair over royalties which it became apparent would not be forthcoming. To make matters worse, Vickers and Altwasser both handed in their resignations in order to form their own company, Cantab, which went on to produce the Jupiter Ace, essentially a ZX80 with the Forth language built-in in place of BASIC. The result of the delays these problems caused was that when Sinclair launched the machine, it did so with an incomplete ROM. Nine Tiles continued working on the ROM for three months after the launch in April 1982, but by then too many units had been sold and the program was never finished.

The original plan was to issue only a limited number of Spectrums with the incomplete ROM and provide an upgrade, much in the way the bug in the ZX81 ROM had been handled,but by the time Sinclair got its act together, around 75,000 units had been sold and the plan became unworkable.

This is the reason why the microdrive commands don’t work in the standard ROM, and hence led to the development by Ian Logan of the shadow ROM in the Interface 1 in order to handle peripherals which should have been supported directly by BASIC.

Various ‘enhancements’ were made to the BASIC over the years, including the extra syntax of the shadow ROM introduced with the Sinclair Interface I, and in America in 1983 when an attempt was made to overhaul the BASIC by Timex when it launched the TS2068. But again, the version of the ROM launched with the machine was incomplete, and the TS2068 was unable to run the majority of Spectrum software because of hard-coded calls to locations in the ROM which were different in the Spectrum.

In 1985, in a joint venture with its Spanish distributor Investronica, Sinclair launched the Spectrum 128, codenamed Derby, with a new editor bolted on to the original BASIC. This was slightly more compatible than the Timex effort but the editor was bug ridden, and some software refused to work, even in 48 mode, because the empty space at the end of the original ROM, used as a table by some programs, was now overwritten with extra code.

It did introduce some useful new commands and a built-in text editor, although inexplicably these were replaced with a menu system with less functionality in the English version of the machine launched the following year. However, criticism of the 128 Editor must be put in context. The programmers were relying on the Logan & O’Hara disassembly of the original ROM publised by Melbourne House, since if Sinclair ever had a copy of the original source by now it had been lost, and were working on a network of VAX machines running CP/M.

Fortunately, tracing the development of the 128 Editor is made easier by the fact that the initials of programmers are stored at the beginning of the Spanish ROM and (MB, KM, and AT) at the end of the English ROM (Martin Brennan, Steve Berry, Andrew Cummins, Rupert Goodwins and Kevin Males).

According to Rupert Goodwins, editor of the +2 manual and the person responsible for the Spectrum logo on the menu system, the Sinclair programmers didn’t realise that the unused bytes in the original ROM were being used as a table by games programmers.

“The television test screen and other ancillary code was in there for production testing,” he says.

“As Spectrums came off the production line, they got checked and set up for keyboard, tape, ports, colour, and sound.”

Goodwins recalls there being an Interface 2-style cartridge system at one point but that most of the test code ended up in the ROM.

“We had the space and it’s obviously cheaper and more efficient that way.”

There were also some strange features planned for the 128 which were removed before production as they couldn’t be made to work properly.

“There were certainly plans to do more with the keypad. What a bizarre idea that was,” he says.

“It was originally supposed to have been a mouse as well. Can you imagine?”

Kevin Males worked on both versions of the 128 Editor ROM.

“I wrote the music string interpreter for the 128, plus various other bits and pieces that never made it into the ROM,” he says.

“I also did a lot of work on microdrives, but its a long time since I wrote any Z80 code though!”

He may also be the author of the text editor in the original Spanish Editor.

“I recall working on various text editors for the 128 that didn’t make it into the ROM,” he says.

In addition, he worked on automated test and diagnostic software for both Spectrum & QL microdrives. He was also involved in the notorious Loki project.

“Towards the end I started looking at software to control a proposed digital synth for the new games machine but the company was sold before that could be realised,” he says

Martin Brennan, who worked on no-end of projects at Sinclair, wrote the editor with contributions from Steve Berry, and Andrew Cummins probably wrote the tricky number handling code.

Amazingly, Sinclair never owned the rights to the ROM. Amstrad had to acquire them seperately from Nine Tiles in 1986 when it bought out Sinclair.

When Spectrum clones began appearing back in late 1984, Sinclair Research boss Nigel Searle found he was powerless to do anything about it because the only really unique part of the Spectrum was the ROM and in the disagreements following the Spectrum’s launch, Sinclair had failed to acquire the rights, for which it had originally offered Grant £5,000. By now the Spectrum had sold more than 2.5 million units.

Amstrad only obtained the rights to the Spectrum and the QL, which they sold on. It permits the distribution of the Spectrum ROM in software only.

Nine Tiles Networks retains the rights to the ZX80 and ZX81 ROMs and has permitted their use under the GPL open source license.

Sinclair Research retains the rights to the Interface 1 ROM. In fact, the developers of the SAM Coupe, a powerful Z80 based machine with a Sinclair compatible BASIC, approached Nine Tiles with a view to licensing the floating-point routines from the ZX81 ROM. But, at the time the asking price was too high.

Towards the end of 1986, when Amstrad wanted to create a Spectrum with a built in disk drive, it simply took the DOS from its PCW machine and patched the 128 editor to provide simple disk access. The operating system, written by Cliff Lawson, was a very good one, although its full power remained untapped by +3 BASIC. It is also at the heart of ResiDOS.

Unfortunately none of the bugs were fixed in the first version of the +3 and new ones were introduced, but perhaps this is understandable as there was little documentation at the Sinclair Computers division and development had moved from a VAX network running CP/M to a room full of PCWs running CP/M which was less than ideal.

Amstrad stopped selling the last Spectrum model, the +2B, in the early 1990s. For a time it looked as if the SAM Coupe might offer an upgrade path to Sinclair BASIC users, but after two false starts the machine disappeared into obscurity.

However, thanks mainly to Paul Dunn’s BASin (an integrated development environment for Sinclair BASIC) the language has been undergoing something of a renaissance. Although it is designed for Windows it also runs on Linux under Wine.

As for the future, Dunn is now working on a project called SpecOS which will enable you to use the full power of the host machine from Sinclair BASIC.

Leave a comment

Posted by on March 27, 2011 in Technology


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: