Sinclair ZX Spectrum
Production-ready patterns for Sinclair ZX Spectrum development
Rendering
8 patternsAttribute Clash
The Spectrum stores one ink-and-paper colour per 8×8 cell, so pixels and colour live on different grids — the source of colour clash. Understanding it, and the design craft that turns the constraint into the platform's look.
Attribute Writing
Write colours directly to attribute memory for fast, flicker-free graphics without touching pixel data.
Bitmap Addressing
Turn an (x, y) pixel into a Spectrum screen address — where consecutive lines are nowhere near each other in memory. The interleaved layout that every Spectrum drawing routine has to reckon with.
Character Printing
Print ASCII characters to the screen using the ROM character set. Direct display file access for fast text rendering.
Masked Sprites
The Spectrum has no hardware sprites, so a moving object is drawn by hand — AND a mask to punch a hole in the background, OR the image into it — with pre-shifted copies for pixel-accurate, fast movement.
Numeric Display
Convert a number (0-99) to two ASCII digits and print them. Essential for scores and counters.
Progress Bar (BASIC)
Horizontal progress bar with colour thresholds — blue through yellow, red, to white. Useful for health, temperature, or timers.
Seven-Segment Digits (BASIC)
Draw large seven-segment display digits using PLOT/DRAW. Cell-aligned with 1px outline. 10 DATA strings define all digits 0-9.
Input
1 patternAudio
5 patternsAY Envelopes and Noise
Let the AY shape a note's volume in hardware and add its noise channel — a decaying pluck from the envelope generator, an explosion from noise, each fired with a single register write.
AY Music
Step a note pattern once per interrupt, handing each of the AY's three channels its note from a period table — a full three-voice tune that plays in the background while the game runs.
AY Tone
Play a tone on the 128K's AY-3-8912 sound chip — select a register through port $FFFD, write it through $BFFD, and the chip holds the note on its own while the CPU gets on with the game.
Beeper Music
Play an actual melody on the Spectrum's one-bit speaker — a note table for pitch, a length per note — and coax two or more voices from that single bit with phase accumulators.
Sound Beep
Generate a simple beep or tone by toggling the speaker bit. Rising or falling pitch for feedback sounds.
Physics
1 patternFramework
4 patternsGame Loop (HALT)
Frame-synchronised game loop using the HALT instruction. Locks to 50Hz for consistent timing across all Spectrums.
Screen Frame (BASIC)
Draw a 1-cell border around the play area with title and footer bars. The standard game screen layout.
State Machine Loop
Organise game flow with distinct states (title, playing, game over). Clean separation of game phases.
Text Utilities (BASIC)
Centre text on any row and clear rows — two tiny subroutines used in every BASIC game.