Skip to content
Techniques & Technology

Sinclair BASIC

The keyword-tokenised dialect built into every Spectrum

Sinclair BASIC is the dialect of BASIC built into the ZX Spectrum's 16 KB ROM, derived from Steve Vickers and John Grant's work on the ZX81. Distinctive for its single-key keyword entry, single-letter string and FOR-loop variable rules, integrated graphics/sound/I/O commands, and direct hardware access via PEEK, POKE, IN, and OUT. The first language millions of British eight-year-olds typed at.

sinclair-zx-spectrumsinclair-zx81 programmingbasicsinclairlanguages 1980–present

Overview

Sinclair BASIC is the dialect of BASIC built into the ZX Spectrum's 16 KB ROM, available the instant the machine is switched on. It was written by Steve Vickers and John Grant at Nine Tiles Networks under contract to Sinclair Research — originally for the ZX80 and ZX81, then significantly extended for the 1982 Spectrum to support colour graphics, sound, the additional keys, and the larger memory.

For the Spectrum's first generation of users — millions of them — Sinclair BASIC was simply programming. It was the prompt that appeared when the machine booted. It was the language the manual taught. It was what the type-in listings in Sinclair Programs, Your Computer, Your Sinclair, and Crash's programming pages were written in. The progression from "type LET A = 5" to "load this game from cassette" to "write a game of your own" happened entirely inside Sinclair BASIC for an entire cohort of children before any of them went near machine code.

Fast facts

  • Authors: Steve Vickers and John Grant (Nine Tiles Networks), under contract to Sinclair Research.
  • ROM size: 16 KB on the 48K Spectrum; expanded on the 128K models.
  • Tokenisation: Each keyword is a single byte; entry is via single-key chording rather than letter-by-letter typing.
  • Editor mode indicators: The cursor changes to show editing mode — K (keyword), L (letter), C (caps), E (extended), G (graphics).
  • Speed: Interpreted, dynamically parsed at runtime — slow enough that real-time action games in pure BASIC are impractical, fast enough for a generation of menu-driven adventures and turn-based puzzles.

The single-key keyword entry

The Spectrum's signature input quirk: each rubber key has up to five functions printed on it, and the keyword entry system means typing PRINT is a single keystroke (the P key in K mode), not five letters. After entering LET A =, the editor shifts to L mode for the right-hand side; the cursor visibly changes to show you what mode the machine is in.

This was simultaneously a help (no keyword could be misspelled — they were single bytes) and a hindrance (new users had to learn an unusual keyboard layout before they could type anything). The 128K +2 added a more conventional letter-by-letter editor as an option but retained the original mode for compatibility.

Distinctive language features

Graphics commands directly in the language — unusual for the era:

CommandWhat it does
PLOT x, yPlot a single pixel at (x, 175-y) — co-ordinates inverted from screen address
DRAW dx, dyDraw a line from current PLOT position by relative offset
DRAW dx, dy, angleDraw an arc — the angle is in radians
CIRCLE x, y, rDraw a circle
INK c / PAPER c / FLASH 0|1 / BRIGHT 0|1 / INVERSE 0|1 / OVER 0|1Set attribute parameters; persist for subsequent PRINT and PLOT
BORDER cSet the border colour via OUT ($FE), c

Sound directly in the language:

CommandWhat it does
BEEP duration, pitchGenerate a tone on the 1-bit speaker; pitch is semitones above middle C; duration in seconds

Hardware access from BASIC:

CommandWhat it does
PEEK addrRead a byte from memory
POKE addr, valueWrite a byte to memory
IN portRead an I/O port
OUT port, valueWrite an I/O port
RANDOMIZE USR addrCall a machine-code routine; returns the value of BC

RANDOMIZE USR addr is the seam between BASIC and assembly — the way every hybrid Spectrum program shifts execution to machine code.

Variable name rules

Sinclair BASIC's variable rules are stricter than most contemporary BASICs and worth knowing because they bite when you don't expect them to:

  • Numeric variables may have any length, every character significant: score and scoreboard are different variables. Spaces inside names are silently stripped — my score is the same variable as myscore. Names can include digits, but not as the first character.
  • String variables must be single-letter + $: a$ through z$, no more. name$ is not accepted.
  • FOR loop variables must be single-letter: FOR i = 1 TO 10. FOR counter = 1 TO 10 fails.
  • Array names must be single-letter: DIM a(10), DIM b$(20, 5).
  • No underscores anywhere.

This is stricter than C64 BASIC v2 (any name accepted; only first 2 characters significant) and visibly stricter than the BBC BASIC contemporary. For curriculum work in BASIC — including this Project's BASIC track — these rules constrain what idiomatic Spectrum BASIC code can even look like.

Common commands

CommandPurpose
LET x = 5Assignment — LET is mandatory, unlike most other BASICs
PRINT "x = "; xOutput; ; separates fields without a space
INPUT aNumeric input (full line editor opens for entry)
INPUT a$String input
IF condition THEN statementConditional — no ELSE
FOR i = 1 TO 10 ... NEXT iLoop
GOSUB 1000 ... RETURNSubroutine
GO TO 100Jump — note the space; GOTO is not accepted as a keyword
RNDPseudo-random number 0-1
CLSClear screen
RESTORE / READ / DATAInline data tables for use in loops

The missing ELSE is the single most-cited friction point — Spectrum BASIC programmers learnt to write IF condition THEN GO TO 200 followed by the else branch on the next line.

Learning progression

The canonical Spectrum coder's path, observed across thousands of contemporary letters-to-the-editor and later interviews:

  1. Type in listings from magazines. First contact with the language. See type-in programs.
  2. Modify the listings. Change a colour, an enemy speed, a score. The first taste of authorship.
  3. Write a first original program in BASIC. Usually a menu-driven adventure, a simple arcade game, or a calculator.
  4. Hit the speed wall. Real-time action games are visibly too slow in BASIC.
  5. Move to machine code. Initially with hand-assembly via POKEs; then with an assembler; then natively. See machine code for beginners.
  6. Build hybrid programs. BASIC wrapper handling menus and high scores; machine code routines invoked via RANDOMIZE USR for the action.

Why Sinclair BASIC matters for Code Like It's 198x

The Project's BASIC track — 16 games at the Usborne bar, floor 128 units, target 240 — is written in Sinclair BASIC, on a real or emulated Spectrum, observing all of the language's distinctive constraints. The track is, in part, a continuation of the Spectrum's original learning ladder: the language built into the machine's ROM, used the way British eight-year-olds used it in 1983, with the same variable-name rules, the same single-key keyword entry, and the same BEEP and INK commands that defined what BASIC sound and BASIC graphics meant on the platform.

See also