z80-assemblylisted
Install: claude install-skill dtz-labs/zx-skills
# Z80 assembly for the ZX Spectrum
This skill helps you write **correct, fast Z80 machine code** for the ZX Spectrum
(and close compatibles) and get it running: write the source → assemble it to a
loadable file → load and debug it in the emulator. It covers the CPU itself, the
Spectrum's hardware quirks (especially the non-linear screen), the common
assemblers, and how to bridge to BASIC via `USR`.
The reference files hold the depth. **Read the relevant reference before writing
non-trivial code** — Z80/Spectrum work has many traps: the display file is *not*
linearly laid out, half the "instructions" you want are flag-dependent, IM2
needs a carefully aligned vector table, and timing depends on *contended* memory.
Guessing produces code that crashes the machine or corrupts BASIC.
## Workflow
1. **Decide where the code lives and how it is reached.** A standalone program
(`.sna`/autostart `.tap`) gets control at a fixed address. A BASIC helper is
`RANDOMIZE USR addr` — then you MUST protect that memory first with
`CLEAR addr-1` (lower RAMTOP) or place code in a safe area. Returning a value
to BASIC: leave it in **BC** (`USR` reads BC). See `references/examples.md` and
the BASIC-interfacing notes below.
2. **Write the source.** Pick an assembler (default **sjasmplus**) and follow its
syntax/directives — `ORG`, `DB/DEFB`, `DW/DEFW`, `DS`, `EQU`, `MACRO`, modules.
Keep labels meaningful; comment T-state-critical loops. See
`references/assemblers.md`. For