cpu-z80n

Guides writing and reviewing Z80N assembly for ZX Spectrum Next with z88dk.

1.1k|206|Updated Mar 16, 2016
One-click install
npx skills add https://github.com/z88dk/z88dk --skill cpu-z80n-z88dk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpu-z80n
Source: https://github.com/z88dk/z88dk/tree/main/.agents/skills/cpu-z80n
Command: npx skills add https://github.com/z88dk/z88dk --skill cpu-z80n-z88dk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct assembly for the ZX Spectrum Next's extended Z80N CPU requires knowing Next-only opcodes, the NextReg I/O model, and the copper co-processor, and this Skill provides a condensed agent map so you avoid guessing encodings or inventing register numbers. ## Core Features & Use Cases - Next-only opcode reference: Covers Z80N instructions like mul de, nextreg, swapnib, mirror a, and the ldirx/lddx block-copy family with encodings and timing, all requiring the -mz80n assembler flag. - NextReg access patterns: Documents the $243B/$253B port pair, the nextreg opcode, and z88dk C helpers such as ZXN_NEXTREG and ZXN_READ_REG from include/arch/zxn.h. - Copper co-processor programming: Explains the 16-bit WAIT/MOVE instruction words, upload via NextReg $60-$62, run modes, and HALT/looping strategies. - Use Case: When reviewing Next assembly that configures the MMU or writes a copper display list, use this Skill to verify opcodes against z80asm fixtures and confirm register numbers against zxn.h instead of loading the entire SpecNext wiki. ## Quick Start Ask the assistant to write or review ZX Spectrum Next assembly using the +zxn target and -mz80n flag, for example a routine that uses mul de and nextreg writes.

Frequently Asked Questions about cpu-z80n

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Z80N extended opcodes in z88dk?

Assemble with the -mz80n flag and target +zxn so z80asm accepts Next-only instructions like mul de, nextreg, swapnib, and the ldirx block-copy family. Plain -mz80 will reject or ignore these opcodes.

How do I write to NextReg registers on the ZX Spectrum Next?

Write the register index to port $243B, then read or write data at port $253B, or use the nextreg opcode in Z80N assembly. In C, use the ZXN_NEXTREG, ZXN_WRITE_REG, and ZXN_READ_REG helpers from include/arch/zxn.h.

What is the copper on the ZX Spectrum Next?

The copper is a co-processor that changes Next Registers at chosen scanline and horizontal positions using 16-bit WAIT and MOVE instructions. Programs are uploaded byte-by-byte via NextReg $60 with the write index and run mode set through $61 and $62.

Does the Z80N mul instruction affect flags?

No, mul de computes D times E into DE as an unsigned 16-bit product in 8 T-states and does not modify flags. It is encoded as ED 30 and is useful in multiply-heavy paths such as math32 float routines.

Why does z80asm reject my ZX Spectrum Next assembly?

Next-only opcodes require the -mz80n flag; plain -mz80 rejects them. Check the fixture files src/z80asm/dev/cpu/cpu_test_z80n_ok.asm and cpu_test_z80n_err.asm to confirm which forms assemble and which must fail.

How do I stop a copper program after one frame?

End a non-looping copper program with HALT, which is a WAIT for line 511 that never completes. For looping programs, let the copper PC wrap and use run mode c=%11 to reset the CPC on every VBlank.