
ZX Spectrum Assembly
Z80 code on the 48K and the 128K, measured on the machine: two complete games, and every screen photographed
Understand the machine. Build two complete games.
Learn Z80 assembly on the Spectrum 48K and 128K, from binary and hexadecimal to screen memory, colour, sound and hardware timing.
Then turn that knowledge into two complete games, Grin Alley and Lantern Keep. Follow timings measured in Fuse, 206 captured screens and workshops in all 56 chapters.
Understand the Spectrum, one measured routine at a time.
Inside the book
- Z80 instructions, flags, addressing and T-states
- Screen memory, attributes, sprites and scrolling
- ULA, contention, interrupts and frame timing
- Keyboard, joysticks, beeper and AY sound
- Grin Alley and Lantern Keep: two complete games
- 128K paging, tape loaders and TAP/TZX releases
What makes this book different
Two complete games
Grin Alley and Lantern Keep are built from the specification to the finished tape, and their whole source is printed and commented.
Measured on the machine
The timings are measured in Fuse, on the 48K and on the 128K, not copied from a table.
206 captured screens
Every screen in the book was captured from the program that draws it.
Workshops in all 56 chapters
Every chapter has its workshop, and appendix I solves them all.
Contents
7 parts, 56 chapters
Part I Before the first byte
01The machine with rubber keys: what the ZX Spectrum is, and why it is programmed this way
02Numbers a computer understands: bits, bytes, hexadecimal, and two's complement
03Inside the case: the Z80, the ULA, the ROM, and the memory map
04Setting up the development environment on Windows, macOS, and Linux
05Your first program: a coloured border, assembled, loaded, and photographed
06Seeing inside the machine: the Fuse debugger
Part II The Z80 language
07Registers, flags, and the shape of a Z80 instruction
08Moving data: LD and every addressing mode
09Arithmetic: eight-bit and sixteen-bit sums, carries, and BCD
10Logic, bits, shifts, and rotates
11Making decisions: the flags, JP, JR, DJNZ, and conditional returns
12Subroutines and the stack: CALL, RET, PUSH, POP, and the shadow registers
13Blocks, tables, and the index registers: LDIR, IX, IY, and lookup tables
14Counting T-states: what an instruction costs on a 3.5 MHz Z80
15sjasmplus: labels, macros, includes, devices, and the snapshot
16The ROM as a library: printing, the system variables, and when to leave it alone
Part III The screen, the attributes, and the contended bus
17Taking the machine: interrupts, IM 1 and IM 2, and a frame of your own
18How a frame is built: 312 lines of 224 T-states, and 69,888 in all
19The screen memory: 6,144 bytes in an order nobody would choose
20Attributes: ink, paper, bright, flash, and the eight-by-eight cell
21Attribute clash: why it happens, and five ways to live with it
22Plotting and drawing: pixels, lines, and fast address arithmetic
23Software sprites: shifting, masking, XOR, and pre-shifted graphics
24Drawing against the beam: flicker, tearing, and when to draw
25Contended memory: who owns the bus while the ULA reads the screen
26The border: stripes, timing, and the border as a measuring instrument
27Scrolling: pixel, character, and attribute scrolling, and what each costs
28Fonts and text: a character set of your own
29Racing the beam: changing the attributes line by line
30The floating bus: reading what the ULA is reading
31Fast copies: the stack as a blitter, and a screen drawn off-screen
Part IV Making it a game machine
32The frame loop: the interrupt as a heartbeat, fifty times a second
33Reading the keyboard: eight half-rows, ghosting, and redefinable keys
34Joysticks: Kempston, Sinclair, and cursor
35The beeper: one bit of sound, and the T-states it costs
36An engine for sound effects and music on the beeper
37Memory discipline: where things live in 48K, and why above 32768
38Collisions: attribute tests, bounding boxes, and pixel-exact checks
39Score, text, and a status line that never flickers
40Random numbers, the R register, and game states
41The frame budget: fitting a game into 69,888 T-states
Part V Two complete games
42The first game I: a single-screen arcade game, from specification to snapshot
43The first game II: sound, score, difficulty, and the finished tape
44The second game I: a flip-screen world, rooms in memory, and a map
45The second game II: enemies, items, music, and the finished tape
46Where to go next: three projects, sketched
Part VI Beyond the 48K
47The 128K machines: paging, the second screen, and memory that moves
48The AY-3-8912: three channels, noise, and envelopes
49An AY music player that runs from the interrupt
50Tape: the ROM loader, headers, and a loader of your own
51One program, five machines: 48K, 128K, +2A, +3, and their timings
52Optimisation: T-states, unrolled loops, and self-modifying code
Part VII The rest of the craft
53Compression: RLE, and a packer for screens and levels
54Title screens, loading screens, and attract mode
55Testing on real hardware: real Spectrums, real tapes, modern interfaces
56Releasing your work: TAP, TZX, inlays, and the Spectrum scene today
Appendices
- AThe Z80 instruction set, with measured T-states
- BThe undocumented Z80: SLL, the index-register halves, and the hidden flags
- CThe ULA and the ports: $FE, $7FFD, $FFFD, $BFFD, and the floating bus
- DScreen address tables: every bitmap row and every attribute row
- EThe fifteen colours, measured, and what they become in grey
- FContention tables: the pattern, measured, on the 48K and the 128K
- Gsjasmplus and Fuse command reference
- HTroubleshooting: what a broken screen is telling you
- IWorkshop solutions, every chapter
- JGlossary and reading paths
- KThe first game: the complete source, commented
- LThe second game: the complete source, commented
- MIndex
Errata
Corrections
No errors have been reported for this edition yet.
Found a mistake? Open an issue on GitHub or write to [email protected], with the page number and what it should say.