Metadata-Version: 2.4
Name: z80-python
Version: 0.1.1
Summary: Readable, pure-Python Z80 instruction-core reference implementation
Project-URL: Homepage, https://github.com/alewman/z80-python
Project-URL: Repository, https://github.com/alewman/z80-python
Project-URL: Issues, https://github.com/alewman/z80-python/issues
Author: alewman
License: MIT License
        
        Copyright (c) 2026 alewman
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: System :: Emulators
Requires-Python: >=3.11
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.15; extra == 'dev'
Description-Content-Type: text/markdown

# 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](docs/validation.md) 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

```text
python -m pip install z80-python
```

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

## Minimal host

```python
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

```text
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](docs/validation.md) for ZEX instructions.

## Project records

- [Validation evidence and scope](docs/validation.md)
- [Undocumented behavior notes](docs/undocumented-behavior.md)
- [AI-assisted development and validation](docs/ai-assisted-development.md)
- [Extraction provenance](docs/provenance.md)
- [Contribution guidance](CONTRIBUTING.md)

## License

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