Cover of ZX Spectrum Assembly: white title on black under a Z80 listing, the ZX logo, the rainbow stripes of the Spectrum, and a line drawing of the rubber-key Spectrum on a cyan grid.
ZX SpectrumOn Amazon

ZX Spectrum Assembly

Z80 code on the 48K and the 128K, measured on the machine: two complete games, and every screen photographed

by Aravind J. Deshmukh and Henry Radclyffe

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

Code for every chapter →

Part I Before the first byte

  1. 01The machine with rubber keys: what the ZX Spectrum is, and why it is programmed this way
  2. 02Numbers a computer understands: bits, bytes, hexadecimal, and two's complement
  3. 03Inside the case: the Z80, the ULA, the ROM, and the memory map
  4. 04Setting up the development environment on Windows, macOS, and Linux
  5. 05Your first program: a coloured border, assembled, loaded, and photographed
  6. 06Seeing inside the machine: the Fuse debugger

Part II The Z80 language

  1. 07Registers, flags, and the shape of a Z80 instruction
  2. 08Moving data: LD and every addressing mode
  3. 09Arithmetic: eight-bit and sixteen-bit sums, carries, and BCD
  4. 10Logic, bits, shifts, and rotates
  5. 11Making decisions: the flags, JP, JR, DJNZ, and conditional returns
  6. 12Subroutines and the stack: CALL, RET, PUSH, POP, and the shadow registers
  7. 13Blocks, tables, and the index registers: LDIR, IX, IY, and lookup tables
  8. 14Counting T-states: what an instruction costs on a 3.5 MHz Z80
  9. 15sjasmplus: labels, macros, includes, devices, and the snapshot
  10. 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

  1. 17Taking the machine: interrupts, IM 1 and IM 2, and a frame of your own
  2. 18How a frame is built: 312 lines of 224 T-states, and 69,888 in all
  3. 19The screen memory: 6,144 bytes in an order nobody would choose
  4. 20Attributes: ink, paper, bright, flash, and the eight-by-eight cell
  5. 21Attribute clash: why it happens, and five ways to live with it
  6. 22Plotting and drawing: pixels, lines, and fast address arithmetic
  7. 23Software sprites: shifting, masking, XOR, and pre-shifted graphics
  8. 24Drawing against the beam: flicker, tearing, and when to draw
  9. 25Contended memory: who owns the bus while the ULA reads the screen
  10. 26The border: stripes, timing, and the border as a measuring instrument
  11. 27Scrolling: pixel, character, and attribute scrolling, and what each costs
  12. 28Fonts and text: a character set of your own
  13. 29Racing the beam: changing the attributes line by line
  14. 30The floating bus: reading what the ULA is reading
  15. 31Fast copies: the stack as a blitter, and a screen drawn off-screen

Part IV Making it a game machine

  1. 32The frame loop: the interrupt as a heartbeat, fifty times a second
  2. 33Reading the keyboard: eight half-rows, ghosting, and redefinable keys
  3. 34Joysticks: Kempston, Sinclair, and cursor
  4. 35The beeper: one bit of sound, and the T-states it costs
  5. 36An engine for sound effects and music on the beeper
  6. 37Memory discipline: where things live in 48K, and why above 32768
  7. 38Collisions: attribute tests, bounding boxes, and pixel-exact checks
  8. 39Score, text, and a status line that never flickers
  9. 40Random numbers, the R register, and game states
  10. 41The frame budget: fitting a game into 69,888 T-states

Part V Two complete games

  1. 42The first game I: a single-screen arcade game, from specification to snapshot
  2. 43The first game II: sound, score, difficulty, and the finished tape
  3. 44The second game I: a flip-screen world, rooms in memory, and a map
  4. 45The second game II: enemies, items, music, and the finished tape
  5. 46Where to go next: three projects, sketched

Part VI Beyond the 48K

  1. 47The 128K machines: paging, the second screen, and memory that moves
  2. 48The AY-3-8912: three channels, noise, and envelopes
  3. 49An AY music player that runs from the interrupt
  4. 50Tape: the ROM loader, headers, and a loader of your own
  5. 51One program, five machines: 48K, 128K, +2A, +3, and their timings
  6. 52Optimisation: T-states, unrolled loops, and self-modifying code

Part VII The rest of the craft

  1. 53Compression: RLE, and a packer for screens and levels
  2. 54Title screens, loading screens, and attract mode
  3. 55Testing on real hardware: real Spectrums, real tapes, modern interfaces
  4. 56Releasing your work: TAP, TZX, inlays, and the Spectrum scene today

Appendices

  1. AThe Z80 instruction set, with measured T-states
  2. BThe undocumented Z80: SLL, the index-register halves, and the hidden flags
  3. CThe ULA and the ports: $FE, $7FFD, $FFFD, $BFFD, and the floating bus
  4. DScreen address tables: every bitmap row and every attribute row
  5. EThe fifteen colours, measured, and what they become in grey
  6. FContention tables: the pattern, measured, on the 48K and the 128K
  7. Gsjasmplus and Fuse command reference
  8. HTroubleshooting: what a broken screen is telling you
  9. IWorkshop solutions, every chapter
  10. JGlossary and reading paths
  11. KThe first game: the complete source, commented
  12. LThe second game: the complete source, commented
  13. 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.