Sinclair BASIC
The Spectrum's programming language
Sinclair BASIC gave ZX Spectrum users an accessible programming environment, teaching a generation of British developers despite its quirks and limitations.
Sinclair BASIC came built into every ZX Spectrum, providing immediate access to programming. Its keyword entry system used single keypresses for commands, avoiding typos and fitting in limited ROM. While slower than machine code, Sinclair BASIC enabled rapid prototyping and taught fundamentals to countless bedroom coders who later became professional developers.
Fast facts
- Platform: ZX Spectrum (and ZX81).
- Implementation: ROM-based interpreter.
- Memory: 16 KB ROM for BASIC and system.
- Input method: Single-key keyword entry.
Keyword entry system
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.
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.
Numeric handling
Floating point everywhere:
- All numbers stored as floating point.
- No integer type.
- Slower calculations.
- Memory overhead.
- Precision issues at extremes.
String handling
Dynamic strings:
- VAR$ for string variables.
- Slicing: a$(2 TO 5).
- Concatenation with +.
- Memory fragmentation possible.
Graphics commands
Direct screen access:
10 BORDER 0: PAPER 0: INK 7: CLS
20 FOR n = 0 TO 175
30 PLOT n, n
40 DRAW 255-n*2, 0
50 NEXT n
Coordinate system: 256x176 pixel addressable.
Attribute system
Colour limitations:
- 8x8 character cells.
- One INK, one PAPER per cell.
- BRIGHT and FLASH per cell.
- “Colour clash” constraint.
Sound capabilities
BEEP command:
- Two parameters: duration, pitch.
- Monophonic (one note at a time).
- Duration in seconds.
- Pitch in semitones from middle C.
10 BEEP 0.5, 0: REM Middle C for half second
20 BEEP 0.5, 12: REM One octave up
Performance limitations
Why games used machine code:
- Interpreted, not compiled.
- Floating point overhead.
- Slow for action games.
- Adequate for adventures, puzzles.
- Often used for game setup, menus.
Machine code integration
Hybrid approaches:
- USR function calls machine code.
- PEEK and POKE for memory access.
- Load machine code routines.
- BASIC for logic, assembly for speed.
Common extensions
Third-party enhancements:
- Beta BASIC: Additional commands.
- Laser BASIC: Graphics extensions.
- Mega BASIC: Enhanced features.
- Loaded from tape, extended language.
Educational impact
Learning outcomes:
- Logical thinking.
- Debugging skills.
- Understanding memory.
- Foundation for other languages.
- Direct hardware interaction.
Commercial games in BASIC
Some published titles:
- Text adventures (common).
- Strategy games.
- Educational software.
- Early type-in games from magazines.
Most commercial action games required assembly.
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.
Legacy
Sinclair BASIC introduced programming to a generation of British computer users. Its accessibility, despite limitations, created the foundation for the UK games industry. Many successful developers cite typing in BASIC listings as their introduction to programming.
Why Sinclair BASIC matters for Code Like It’s 198x
The Project’s BASIC track — 16 games at the Usborne bar — 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.