Skip to main content

z80-python

A readable, pure-Python Z80 instruction-core reference implementation.

z80-python is deliberately a CPU core rather than a complete computer or arcade emulator. A host subclass supplies 16-bit memory and I/O access; the core executes one instruction at a time and returns its documented T-state total.

Validation status

The extracted core has passed:

  • all 1,604 local SingleStepTests/z80 opcode/prefix vector files, comprising 1,604,000 state transitions; and
  • ZEXDOC and ZEXALL long-sequence CRC exercisers under both CPython 3.12 and PyPy 3.11.

See validation evidence for exact hashes, commands, results, and scope limits. This does not claim cycle-accurate bus behavior, a complete Z80 machine, CP/M, interrupt lifecycle handling, or a Galaxian board.

Install

Until the first PyPI release, install directly from GitHub:

python -m pip install "git+https://github.com/alewman/z80-python.git"

The planned PyPI distribution name is z80-python.

The public import is z80_python, intentionally distinct from the unrelated existing z80 distribution on PyPI.

Minimal host

from z80_python import Z80CPU


class Machine(Z80CPU):
    def __init__(self) -> None:
        super().__init__()
        self.memory = bytearray(0x10000)
        self.ports = bytearray(0x10000)

    def read_byte(self, addr: int) -> int:
        return self.memory[addr & 0xFFFF]

    def write_byte(self, addr: int, value: int) -> None:
        self.memory[addr & 0xFFFF] = value & 0xFF

    def read_port(self, addr: int) -> int:
        return self.ports[addr & 0xFFFF]

    def write_port(self, addr: int, value: int) -> None:
        self.ports[addr & 0xFFFF] = value & 0xFF


cpu = Machine()
cpu.memory[:3] = bytes((0x3E, 0x2A, 0x3C))  # LD A,2Ah; INC A
assert cpu.step() == 7
assert cpu.step() == 4
assert cpu.a == 0x2B

step() is the public one-instruction entry point. decode_and_execute() is retained as a supported historical name. CPU registers and modeled state are directly readable and writable; the host owns memory, devices, and reset policy.

Development and validation

python -m pip install -e ".[dev]"
python -m pytest -q
python -m ruff check .
python examples/minimal_z80_host.py

The vector corpus and ZEX binaries are external artifacts, intentionally not bundled in releases. Fetch the pinned vector corpus with python scripts/fetch_test_vectors.py, then rerun the test suite. See validation evidence for ZEX instructions.

Project records

License

MIT. External validation artifacts have their own licenses and are not bundled.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z80_python-0.1.0.tar.gz (95.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

z80_python-0.1.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file z80_python-0.1.0.tar.gz.

File metadata

  • Download URL: z80_python-0.1.0.tar.gz
  • Upload date:
  • Size: 95.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for z80_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e7e043cb83eb835365f1c64c0c65e679313e4c1b1130ae7c7acd1c177d4a1ae9
MD5 9689bd353b223f99290f5d4ba65b990a
BLAKE2b-256 358920db0668d092c3089cb201ca4e2225051be806ad9379096f7530685c85a1

See more details on using hashes here.

File details

Details for the file z80_python-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: z80_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for z80_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae30c319ae9461f8189f0ea63fde92a508f55d8553cb276fcb87ae978612a35e
MD5 19f6e46a4791a580c2725a8c68395a41
BLAKE2b-256 ce9f1646f2ae37d5c992a00f128244f315e659dbf9e1de2eeec161c0f7333b4c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page