The Sinclair BASIC interpreter was written by Nine Tiles Networks Ltd.[1] Designed to run in only 1 KB of RAM, the system makes a number of decisions to lower memory usage.
The original ZX80 version supported only integer mathematics, which partially made up for some of the memory-saving design notes which had negative impact on performance.
This version was very slow, among the slowest BASICs on the market at the time, but given the limited capabilities of the machine, this was not a serious concern.
The low speed was not mainly due to an inefficient interpreter though, it was an effect of the fact that 70-80% of the machine cycles were consumed by the video hardware.
Performance became a more serious issue with the release of the ZX Spectrum in 1983, which ran too slowly to make full use of the machine's new features.
Grant wrote the BASIC interpreter between June and July 1979, but the code initially came in at 5 KB and he spent the next month trimming it down.
[3] Even before the ZX80 was introduced in February 1980, the constant downward price-pressure in the industry was allowing the already inexpensive design to be further reduced in complexity and cost.
In particular, many of the separate circuits in the ZX80 were re-implemented in a single uncommitted logic array from Ferranti, which allowed the price to be reduced to only £49.95 while increasing the size of the ROM to 8 KB.
[5] When Sinclair lost the contest to build the BBC Computer, he moved ahead with plans to produce a low-cost colour-capable machine that emerged as the ZX Spectrum of April 1982.
In keeping with his philosophy of making systems for the lowest possible expenditure, Sinclair wanted the absolute minimum changes to the existing 8K BASIC.
Although Nine Tiles felt that something much better would be needed for the new machine, the schedule would not allow it, and yet another expansion of the original code was produced.
Additionally, as no prototypes were available until the end of the year, it lacked support for the new line of peripherals Sinclair was planning.
Around the same time, Vickers and his Sinclair counterpart, Richard Altwasser, left their respective companies to start the Jupiter Ace project.
The new version was incapable of running many Spectrum programs due to the memory location of machine's functions moving.
When the machine is booted, it runs BASIC and displays an inverse video "K" at the bottom of the screen to indicate the entry point.
Instead, when the user presses EDIT, the current line of code is copied back to the bottom of the screen.
In contrast, on machines like the Commodore 64 or Atari 8-bit computers, the up and down keys can be used to move among the lines in the program and edit them in-place.
The keywords below the keys required a second keystroke, ⇧ Shift+NEW LINE, which put the editor into "function mode", changing the cursor to an "F".
The system has the advantage of representing all multi-character keywords as a single character in memory, which was a significant savings in the early machines that shipped with only 1 KB of RAM.
To improve the complex entry on the Spectrum, the keywords were colour-coded to indicate the required mode:[12] This concept had run its course, and later machines running 128 BASIC (ZX Spectrum 128, +2, +3, +2A, and +2B) featured a more traditional editor where the user typed-in the keyword as individual characters, similar to other home computers of the era.
The resulting in-memory storage of the program was otherwise similar to Microsoft BASIC, in that only the keywords are presented as tokens, while non-keywords – like string and numeric constants and variable names – are left in their original typed-in format.
Typically, interpreters use a fixed-size entry to hold data, making it easy to scan the variable table.
Due to the extremely limited memory of the ZX series, any wasted space had to be avoided, and this led to the use of a variable-length format.
To make this somewhat easier, arrays also stored a two-byte length, so the entire structure could be skipped over more easily.
The 4K BASIC ROM of the ZX80 had a short list of exceptions to this: the functions CHR$(), STR$(), TL$(), PEEK(), CODE(), RND(), USR() and ABS() did not have one-byte tokens but were typed in letter-by-letter and required the parentheses.
[80] In all colour-related commands, the number 8 may be used to indicate “transparent” while in INK and PAPER may also be set to 9 for “contrast” — that is, to put a dark colour on a light background or vice versa automatically.