
ZX SpectrumIn preparation
ZX Spectrum Assembly
From the Z80 to a Complete Demo
Programming the ZX Spectrum, cycle by cycle
In preparation
This book is being written. Its page will offer it on every Amazon store as soon as it is published.
The code
The code will be published here together with the book.
Every pixel has an address. Every cycle has a cost.
A practical guide to programming the ZX Spectrum: from Z80 instructions to video memory, from colour to hardware synchronisation.
Registers and addressing, bitmaps and attributes, the ULA and contended memory: every topic connects code to the behaviour of the machine, with progressive examples and development tools.
Understand the Spectrum, one instruction at a time.
Inside the book
- Z80: registers, instructions and addressing modes
- Bitmaps, attributes and colour handling
- ULA, contended memory and timing
- Interrupts, keyboard, joystick and the main loop
- Beeper, sound effects and an introduction to AY sound
- Development tools, debugging and practical examples
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