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.
Overview
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
Unique Sinclair approach:
- Each key had multiple functions (modes).
- K mode: keywords on single press.
- L mode: letters.
- Reduced typos.
- Faster entry once learned.
- Unusual for newcomers.
| Key | K mode | L mode |
|---|---|---|
| P | P | |
| G | GO TO | G |
| I | INPUT | I |
Language features
Sinclair BASIC capabilities:
| Feature | Support |
|---|---|
| Graphics | PLOT, DRAW, CIRCLE |
| Sound | BEEP (frequency, duration) |
| Colour | INK, PAPER, BORDER |
| User-defined graphics | UDG characters |
| Screen | PRINT AT x,y |
| Attributes | BRIGHT, FLASH |
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.
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.