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.
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:
| Command | What it does |
|---|---|
PLOT x, y | Plot a single pixel at (x, 175-y) — co-ordinates inverted from screen address |
DRAW dx, dy | Draw a line from current PLOT position by relative offset |
DRAW dx, dy, angle | Draw an arc — the angle is in radians |
CIRCLE x, y, r | Draw a circle |
INK c / PAPER c / FLASH 0|1 / BRIGHT 0|1 / INVERSE 0|1 / OVER 0|1 | Set attribute parameters; persist for subsequent PRINT and PLOT |
BORDER c | Set the border colour via OUT ($FE), c |
Sound directly in the language:
| Command | What it does |
|---|---|
BEEP duration, pitch | Generate a tone on the 1-bit speaker; pitch is semitones above middle C; duration in seconds |
Hardware access from BASIC:
| Command | What it does |
|---|---|
PEEK addr | Read a byte from memory |
POKE addr, value | Write a byte to memory |
IN port | Read an I/O port |
OUT port, value | Write an I/O port |
RANDOMIZE USR addr | Call 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:
scoreandscoreboardare different variables. Spaces inside names are silently stripped —my scoreis the same variable asmyscore. Names can include digits, but not as the first character. - String variables must be single-letter +
$:a$throughz$, no more.name$is not accepted. FORloop variables must be single-letter:FOR i = 1 TO 10.FOR counter = 1 TO 10fails.- 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
| Command | Purpose |
|---|---|
LET x = 5 | Assignment — LET is mandatory, unlike most other BASICs |
PRINT "x = "; x | Output; ; separates fields without a space |
INPUT a | Numeric input (full line editor opens for entry) |
INPUT a$ | String input |
IF condition THEN statement | Conditional — no ELSE |
FOR i = 1 TO 10 ... NEXT i | Loop |
GOSUB 1000 ... RETURN | Subroutine |
GO TO 100 | Jump — note the space; GOTO is not accepted as a keyword |
RND | Pseudo-random number 0-1 |
CLS | Clear screen |
RESTORE / READ / DATA | Inline 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:
- Type in listings from magazines. First contact with the language. See type-in programs.
- Modify the listings. Change a colour, an enemy speed, a score. The first taste of authorship.
- Write a first original program in BASIC. Usually a menu-driven adventure, a simple arcade game, or a calculator.
- Hit the speed wall. Real-time action games are visibly too slow in BASIC.
- Move to machine code. Initially with hand-assembly via
POKEs; then with an assembler; then natively. See machine code for beginners. - Build hybrid programs. BASIC wrapper handling menus and high scores; machine code routines invoked via
RANDOMIZE USRfor 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
- ZX Spectrum
- Type-in programs — How readers learnt BASIC.
- Machine code for beginners — The next step on the ladder.
- UDG — User-defined graphics, a BASIC and assembly feature.
- ZX Spectrum hardware ports — What
INandOUTare talking to.