This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)(Learn how and when to remove this template message)
|Developer||Nine Tiles Networks, Sinclair|
|Platform||ZX80, ZX81, ZX Spectrum|
Sinclair BASIC is a dialect of the BASIC programming language used in the 8-bit home computers from Sinclair Research and Timex Sinclair. The Sinclair BASIC interpreter was made by Nine Tiles Networks Ltd.
- 1 History
- 2 Syntax
- 3 Official versions
- 4 Other versions, extensions, derivatives and successors
- 5 See also
- 6 Notes
- 7 References
- 8 Bibliography
- 9 External links
It was initially an incomplete implementation of the 1978 ANSI minimal BASIC standard with integer arithmetic only, known as the 4K BASIC (for its ROM size) for the ZX80. It evolved through the floating-point 8K BASIC for the ZX81 and TS1000 (which was also available as an upgrade for the ZX80), and became an almost complete version in the 16 KB ROM ZX Spectrum. It is present in all ZX Spectrum compatibles.
Currently, interpreters exist for modern operating systems (as well as for vintage systems) that allow Sinclair Basic to be easily used.
New BASIC programmers might start with a simple program, perhaps using the language's PRINT statement to display a message on the screen; a well-known and often-replicated example is Kernighan and Ritchie's Hello world program:
10 PRINT "Hello, World!" 20 STOP
On the 16K/48K ZX Spectrum, there are 88 keywords in Sinclair BASIC, denoting commands (of which there were 51), functions and logical operators (32), and other keywords (5):
CLOSE #,[note 2]
OPEN #,[note 2]
- Functions and logical operators
VAL$,[note 6][note 8]
- Other keywords
They are entered via Sinclair's unique keyword entry system. The most common commands require just a single keystroke; for example, pressing just P at the start of a line on a Spectrum produces the entire command
BEEP (for example) is keyed by pressing CAPS SHIFT plus SYMBOL SHIFT to access extended mode (later models include an EXTENDED MODE key), keeping SYMBOL SHIFT held down and pressing Z. Keywords are color-coded on the original Spectrum keyboard to indicate which mode is required.
The ZX81 8K BASIC used the shorter forms
RAND, whereas the Spectrum used the longer forms
RANDOMIZE. The ZX80 4K BASIC also used these longer forms but with differed by using the spelling
RANDOMISE. The ZX81 8K BASIC was the only version to use
UNPLOT. The ZX80 4K BASIC had the exclusive function
TL$(); it was equivalent to the string operator
(2 TO ) in later versions.
Unique code points are assigned in the ZX80 character set, ZX81 character set and ZX Spectrum character set for each keyword or multi-character operator, i.e.
"" (tokenized on the ZX81 only),
** (replaced with
↑ on the Spectrum). These are expanded by referencing a token table in ROM. As a result, a keyword uses just one byte of memory, a significant saving over traditional letter-by-letter storage. This also meant that the BASIC interpreter could quickly determine any command or function by evaluating a single byte, and that the keywords didn't need to be reserved words like in other BASIC dialects or other programming languages, e.g. it is allowed to define a variable named
PRINT PRINT. This is also related to the syntax requirement that every line start with a command keyword, and pressing the single keypress for that command at the start of a line changes the editor from command mode to letter mode. As a consequence, variable assignment requires
LET a=1 not just
a=1). This practice is also different from other BASIC dialects. Further, it meant that unlike other BASIC dialects the interpreter didn't require parentheses to identify functions;
SIN x was sufficient, no
SIN(x) required (although the latter would be allowed). The 4K BASIC ROM of the ZX80 had a short list of exceptions to this: the functions
ABS() did not have single-byte tokens but were typed in letter-by-letter and required the parentheses. They were listed as the INTEGRAL FUNCTIONS on a label above and to the right of the keyboard.
The 128K Spectrum models—the ZX Spectrum 128, +2, +3, +2A, and +2B—also stored keywords internally in single byte code points but used a conventional letter-by-letter BASIC input system. They also introduced two new commands:
PLAY, which operated the 128k models' AY-3-8910 music chip
SPECTRUM, which switched the 128k Spectrum into a 48k Spectrum compatibility mode
The original Spanish ZX Spectrum 128 included four additional commands in Spanish, one of which was undocumented. These can be translated as:
EDIT(to edit a line number or invoke the full screen string editor)
RENUM(to renumber the program lines)
DELETE(to delete program lines)
WIDTH(to set the column width of the RS232 device, but undocumented as the code was broken)
RIGHT$() functions used in the ubiquitous Microsoft BASIC dialects for home computers, parts of strings in Sinclair BASIC are accessed by numeric range. For example,
a$(5 TO 10) will give a substring starting with the 5th and ending with the 10th character of the variable
a$. It is therefore possible to replace the
RIGHT$() commands simply by omitting the left or right array position respectively; for instance
a$( TO 5) is equivalent to
a$(5) alone is enough to replace
- 4K BASIC is the original ZX80 BASIC with integer-only arithmetic, by John Grant of Nine Tiles for the ZX80, so named for residing in 4 KiB ROM.
- 8K BASIC is the ZX81 BASIC (also available as an upgrade for the ZX80), updated with floating-point arithmetic by Steve Vickers, so named for residing in 8 KiB ROM.
- 48 BASIC is the BASIC for the original 16/48 kB RAM ZX Spectrum (and clones), with color and more peripherals added by Steve Vickers and John Grant. It resides in 16 KiB ROM and began to be called 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
- 128 BASIC is the BASIC for the ZX Spectrum 128. It offers extra commands and uses letter-by-letter input.
- +3 BASIC is the BASIC with disk support for the ZX Spectrum +3.
- T/S 2000 BASIC was used on the Spectrum-compatible TS2068 and has the following six keywords as well as the ordinary Sinclair BASIC ones:
DELETEdeletes BASIC program line ranges. ⇧ Shift+0 with the
Kcursor produces the command
FREEis a function that gives the amount of free RAM.
PRINT FREEwill show how much RAM is free.
ON ERRis an error-handling function mostly used as
ON ERR GO TOor
ON ERR CONT.
RESETcan be used to reset the behaviour of
ON ERR. It was also intended to reset peripherals.
SOUNDcontrols the AY-3-8192 sound chip.
STICKis a function that gives the position of the internal joystick (Timex Sinclair 2090).
- BASIC64, released by Timex of Portugal, is a software extension to allow better Basic programming with the 512×192 graphic mode available only on Timex 2000 series computers. This extension adds commands and does a complete memory remap to avoid the system overwriting the extended screen memory area. Two versions exist due to different memory maps - a version for TC2048 and a version for TS/TC2068.
Other versions, extensions, derivatives and successors
- Beta BASIC by Dr. Andy Wright, was originally a BASIC extension, but ended up as a full-fledged interpreter.
- YS MegaBasic by Mike Leaman.
- ZebraOS by Zebra Systems in New York, a cartridge version of T/S 2000 BASIC that used the 512×192 screen mode.
- Sea Change ROM by Steve Vickers and Ian Logan, modified by Geoff Wearmouth, a replacement ROM with an enhanced Sinclair BASIC.
- Gosh Wonderful by Geoff Wearmouth, a replacement ROM that fixes bugs and adds a tokenizer, stream lister, delete and renumber commands.
- OpenSE BASIC (formerly SE BASIC) by Andrew Owen, a replacement ROM with bug fixes and many enhancements including ULAplus support, published as open source in 2011
- HiSoft COLT Compiler (a.k.a HiSoft COLT Integer Compiler)
- HiSoft BASIC (a.k.a. HiSoft BASIC Compiler), an integer and floating-point capable compiler
- Laser Compiler
- Softek 'IS' Integer Compiler (successor to Softek Integer Compiler)
- Softek 'FP' Full Compiler
- ZIP Compiler
Derivatives and successors for other machines
- SuperBASIC, a much more advanced BASIC dialect introduced with the Sinclair QL personal computer, with some similarities to the earlier Sinclair BASICs
- SAM Basic, the BASIC on the SAM Coupé, generally considered a ZX Spectrum clone
- ROMU6 by Cesar and Juan Hernandez - MSX
- Spectrum 48 by Whitby Computers - Commodore 64
- Sparky eZX BASIC by Richard Kelsh, an operating system loosely based on ZX Spectrum BASIC - Zilog eZ80
- Sinbas by Pavel Napravnik - MS-DOS
- Basic (and CheckBasic) by Philip Kendall - Unix
- BINSIC by Adrian McMenamin, a reimplementation in Groovy closely modelled on ZX81 BASIC - Java
- BASin by Paul Dunn, a complete Sinclair BASIC IDE based around a ZX Spectrum emulator - Windows
- SpecBAS (a.k.a. SpecOS) by Paul Dunn, an IDE providing an enhanced superset of Sinclair BASIC - Windows, Linux, Pandora and Raspberry Pi
- List of computer system emulators § Sinclair ZX80
- List of computer system emulators § Sinclair ZX81
- List of computer system emulators § Sinclair ZX Spectrum and clones
INVERSEset attributes for outputting text and graphics to the screen. They can be used either as commands, to apply to all subsequent output until set again, or within a
MOVEwere originally designed to be used with peripherals, but at the launch of ZX Spectrum, they had not been completely implemented, such that their use generated an error message (Invalid Stream). Later with the aid of the ZX Interface 1 shadow ROM, they were used for the ZX Microdrive. (The shadow ROM was paged when the BASIC interpreter detected a syntax error, which is why most ZX Microdrive commands use a
- The control variable of a
FORloop must consist of only one alphabetical character.
- Unlike many other BASIC dialects, Sinclair Basic did not include the
ELSEoperator in the
ELSE) clause. A workaround would be to use an
GO TOconstruct instead, bypassing the lines that would have been in an
ELSEclause with the
- The AND, NOT, and OR functions are logical operators.
- String variable names must consist of only one alphabetical character. Thus,
LET Apples=5, and
LET a$="Hello"are all good, while
LET Apples$="Fruit"is not.
- Machine code could be executed using the
USRfunction, the value provided being the start address of the machine code to execute and the return value being the contents of the BC register pair (unlike most other Z80 based computers that returned the value of the HL register pair), thus
LET a=USR 30000would call the machine code subroutine starting at memory address 30000, and after it returns would store the value of the BC register pair into the variable
afor further use.
VALfunction does not just evaluate numbers, but also evaluates full expressions. For example,
PRINT VAL a$will output 14 when given an
VAL$does the same for string expressions.
- Garfield, Simon (2010-02-28). "Sir Clive Sinclair: "I don't use a computer at all"". The Guardian. Guardian Media Group. Retrieved 2011-05-23.
He is keen to credit [...], not least Nine Tiles, the company that made the Basic operating software.
- "ZX80 - 8K BASIC ROM UPGRADE".
- "Picture of ZX80".
- Spectrum 128 ROM Disassembly - Spanish Spectrum 128
- "Sinclair BASIC history".
- Vickers, Steven (1982). Sinclair ZX Spectrum BASIC Programming. Sinclair Research.
- Ardley, Neil (1984). Sinclair ZX Spectrum+ User Guide. Dorling Kindersley in association with Sinclair Research. ISBN 0-86318-080-9.