Katana VentraIP

Sinclair BASIC

Sinclair BASIC is a dialect of the programming language BASIC used in the 8-bit home computers from Sinclair Research, Timex Sinclair and Amstrad. The Sinclair BASIC interpreter was written by Nine Tiles Networks Ltd.[1]

For the implementation of BASIC used on the Sinclair QL, see SuperBASIC.

Designed to run in only 1 kB of RAM, the system makes a number of decisions to lower memory usage. This led to one of Sinclair BASIC's most notable features, that the keywords were entered using single keystrokes; each of the possible keywords was mapped to a key on the keyboard, when pressed, the token would be placed into memory while the entire keyword was printed out on-screen. This made code entry easier whilst simplifying the parser.


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. When the system was ported to the ZX81 in 1981, a full floating point implementation was added. 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.


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. This led to an entirely new BASIC for the following Sinclair QL, as well as a number of 3rd-party BASICs for the Spectrum and its various clones. The original version continued to be modified and ported in the post-Sinclair era.

History[edit]

Clive Sinclair initially met with John Grant, the owner of Nine Tiles, in April 1979 to discuss a BASIC for Sinclair's new computer concept.[2] Sinclair was inspired to make a new machine after watching his son enjoy their TRS-80, but that machine's £500 price tag appeared to be a serious limit on its popularity. He wanted a new kit that would expand on their previous MK14 and feature a built-in BASIC at the target price of £79.95. To meet this price point, the machine would ship with only 1 kB of RAM and 4 kB of ROM. Grant suggested using the Forth language instead, but the budget precluded this. 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. It was initially an incomplete implementation of the 1978 American National Standards Institute (ANSI) Minimal BASIC standard with integer arithmetic only, termed 4K BASIC.[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. This work was assigned to Steve Vickers, who joined Nine Tiles in January 1980. Whilst Grant worked on the code interfacing with hardware, Vickers used the larger space to introduce floating-point arithmetic and a suite of trig functions, which were expected of any BASIC from that era, producing 8K BASIC.[4] The initial version did not support the ZX Printer and had a bug in its square root function. Nine Tiles provided a new version to address these, but Sinclair was slow to include the new version in the ROMs. The new ROMs were eventually offered to owners of the earlier ZX80 as well.[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. ROM space would once again be increased, this time to 16 kB. 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. Due to the RAM also being increased, to 48 kB, this version was known as 48K BASIC and eventually 48 BASIC with the introduction of the ZX Spectrum 128 at which time the 16 KB Spectrum was no longer sold and most existing ones in use had been upgraded to 48 KB.[6][7] The new version was available near the end of 1981, but it was "depressingly slow" and "snail like". Additionally, as no prototypes were available until the end of the year, it lacked support for the new line of peripherals Sinclair was planning.[8]


In February 1982, Nine Tiles began to have disagreements with Sinclair over owed royalties for the various manuals that Nine Tiles had produced. Around the same time, Vickers and his Sinclair counterpart, Richard Altwasser, left their respective companies to start the Jupiter Ace project.[9] When the Spectrum was launched the ROM was still not complete, and although Nine Tiles continued working on it until April 1982, by that point 75,000 Spectrums had already been sold and the project was cancelled. The missing functionality was later added by additional code in the ZX Interface 1. After Nine Tiles and Sinclair went their own ways, several new versions of 48 BASIC were created.


In 1983, as part of introducing the Spectrum to the US market as the TS2068, Timex modified it as T/S 2000 BASIC. The new version was incapable of running many Spectrum programs due to the memory location of machine's functions moving. A similar, but somewhat more compatible version, was introduced as part of the Spanish Spectrum 128 of 1985, 128 BASIC.[7]


Amstrad purchased Sinclair Research in 1986. As Sinclair had never owned the copyright to the language, Amstrad had to arrange a new license with Nine Tiles. Several other versions also appeared in this period as various extensions and clones of the Spectrum were introduced. These included +3 BASIC, BASIC64 and Timex Extended Basic.[7][6]


As of 2015, interpreters exist for modern operating systems,[10] and older systems,[11] that allow Sinclair Basic to be used easily.

Description[edit]

Program editing[edit]

Like most home-computer BASICs, Sinclair BASIC is anchored around its line editor. 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. When a line is entered and the NEW LINE key is pressed, it either runs immediately if it does not have a line number prefix, or clears the screen and performs the equivalent of a LIST command, placing a ">" cursor after the line number in the most recently entered line.


In contrast to most machines of the era, the editor does not allow freeform editing at any point on the screen. Instead, when the user presses EDIT, the current line of code is copied back to the bottom of the screen. The user can move horizontally through this line using the cursor keys and commits their changes by pressing NEW LINE again. 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 most notable feature of the editor is that keywords are entered using single keystrokes. For instance, on the ZX81, the P key on the keyboard would cause the entire keyword PRINT to be entered into the currently editing line. Once a keyword has been entered, the cursor changes to an "L" to indicate what follows will be interpreted as normal text. For instance, pressing P again at this point would enter a single letter "P".


Keys generally had two separate keywords assigned to them – one above it and one below. Pressing the key in "K" mode would enter the keyword above the key, like PRINT for P. If the system was in "L" mode, one could return to "K" by pressing the shift key – the systems did not initially support lowercase text, so the shift was not otherwise needed. 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". Entering common code often resulted in a significant number of keystrokes.


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. This single-character representation included multi-character items like <>. This has the added advantages of simplifying the runtime, as it can immediately determine whether a character in the source code is a keyword or text, and also means that keywords are never entered directly, meaning that one can, for instance, have a variable named "PRINT", as the system can determine that it is not the same as the keyword.


As the systems evolved and added new keywords, the entry system became increasingly difficult to use. 48 BASIC in the Spectrum required every key to host up to four keywords. Entering keywords was a time-consuming process of looking over the relatively small type on the keyboard for the appropriate key, and then correctly entering the multiple keystrokes needed to enter it properly. For instance, entering BEEP required one to type CAPS SHIFT+SYMBOL SHIFT to access extended mode (later models include a separate EXTENDED MODE key), keeping SYMBOL SHIFT held down, and then and pressing Z. To improve the complex entry on the Spectrum, the keywords were colour-coded to indicate the required mode:[12]

Syntax[edit]

Keywords[edit]

On the 16K/48K ZX Spectrum (48 BASIC), there are 88 keywords in Sinclair BASIC, denoting commands (of which there are 50), functions and logical operators (31), and other keywords (16, including 9 which are also commands or functions):

4K BASIC

[76]

Other versions, extensions, derivatives and successors[edit]

Interpreters for the ZX Spectrum family[edit]

Several ZX Spectrum interpreters exist.[80]

List of computer system emulators § Sinclair ZX80

List of computer system emulators § Sinclair ZX81

List of computer system emulators § Sinclair ZX Spectrum and clones

Adamson, Ian; Kennedy, Richard (1986). . Penguin.

Sinclair and the 'sunrise' Technology

Ardley, Neil (1984). Sinclair ZX Spectrum+ User Guide. in association with Sinclair Research. ISBN 0-86318-080-9.

Dorling Kindersley

Vickers, Steven (1982). Sinclair ZX Spectrum BASIC Programming. Sinclair Research.

Vickers, Steven (1983). Sinclair ZX Spectrum BASIC Programming (2 ed.). Sinclair Research.

Cambridge Communication (1983). Sinclair ZX Spectrum Microdrive and Interface 1 manual. Sinclair Research.

: The original 1982 manual by Steven Vickers (referenced above)

Sinclair ZX Spectrum BASIC Programming

Archived 2007-04-22 at the Wayback Machine: also by Vickers

Sinclair ZX81 Basic Programming

: By Andrew Owen

The History of Sinclair BASIC

: Basic 64 user manual for Timex Computer 2048

Timex Computer World

: A LL(1) grammar specification for parsing Sinclair BASIC 16/48K

Sinclair BASIC grammar