Metadata-Version: 2.5 Name: i8080-python Version: 0.1.0.dev0 Summary: Readable, pure-Python Intel 8080A instruction-core reference implementation 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.12 Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: 3.14 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.16.8; extra == 'dev' Description-Content-Type: text/markdown # i8080-python A readable, dependency-free Intel 8080A **instruction core**, in the shape of [z80-python](https://github.com/alewman/z80-python) and [6502-python](https://github.com/alewman/6502-python). The host owns memory and the 256 I/O ports and supplies `read_byte`, `write_byte`, `read_port`, `write_port`. The core owns registers, flags, instruction semantics, Intel's documented state counts, and the INT/INTE/HLT/RESET lifecycle at instruction boundaries. Every correctness claim is pinned to an external oracle whose tier is stated. ## Status Certified at commit `6c08ccd` (2026-09-18) on Linux x86_64, CPython 3.14.4 and PyPy 7.3.20 (Python 3.11.13). Every rung of the ladder in [docs/handoff-brief.md](docs/handoff-brief.md) passes: | Rung | Oracle and tier | Result | | --- | --- | --- | | 1. Per-opcode tests | Intel's summary table [UM p. 4-15] and flag rules, transcribed by hand (the specification) | all 256 opcodes; 1,315 tests pass on both interpreters | | 2. `8080PRE`, `TST8080` | self-checking CP/M programs (specification-derived) | `8080 Preliminary tests complete`; `CPU IS OPERATIONAL` | | 3. `8080EXM` | **hardware-captured**: CRCs from 13 real 8080A chips | **all 25 CRCs match**, 160 s under PyPy, 31.5 min under CPython | | 3. `CPUTEST` (opt-in) | self-checking, proprietary, not fetched by default | `CPU TESTS OK` | | 4. Lifecycle | Intel's manuals, section by section; no hardware oracle exists | 18 tests pass | | 5. MAME lockstep, `invaders`, 60 frames | MAME 0.285 (emulator-derived, a detector) | 230,313 instructions and 102 interrupt acceptances identical | The instruction set is **verified against real 8080A hardware** where 8080EXM reaches: every documented ALU, INR/DCR, INX/DCX, DAD, load, store, MVI, MOV, rotate, and DAA instruction, with all eight flag bits. State counts, branches, I/O, and the interrupt lifecycle are checked against the manuals and **cross-checked against an emulator** (MAME, and superzazu/8080's state totals, which every exerciser run matches exactly). The twelve undocumented opcodes follow emulator consensus and are unverified on hardware. The pinned hashes, commands, and timings are in [docs/validation.md](docs/validation.md). ## Using it ```python from i8080_python import I8080CPU class Machine(I8080CPU): def __init__(self): super().__init__() self.memory = bytearray(0x10000) def read_byte(self, addr): return self.memory[addr] def write_byte(self, addr, value): self.memory[addr] = value def read_port(self, port): # 0..255 return 0xFF def write_port(self, port, value): pass cpu = Machine() cpu.memory[0:2] = bytes((0x3E, 0x2A)) # MVI A,2AH assert cpu.step() == 7 and cpu.a == 0x2A ``` `step()` runs one instruction or one lifecycle boundary and returns its state count. Interrupts are requested between steps with the byte the board puts on the bus, `request_interrupt(0xCF)` for `RST 1`. The request is level-held and is accepted when INTE allows, after the EI delay. RESET is `request_reset()` / `clear_reset()`. `capture_state()` returns an immutable `CPUState`. `disassemble()` decodes Intel syntax from a side-effect-free reader. `trace_steps()` produces the JSON Lines conformance trace described in [docs/trace-schema.md](docs/trace-schema.md). Stated limitations: only one-byte instructions can be injected on interrupt acknowledge (the 8228's three-byte `CALL` is refused), and the halt idle (7 states) and RESET (3 states) counts are modeling choices, documented as such. ## Reading the code `src/i8080_python/` has one mixin per group of Intel's instruction-set chapter: `_transfer.py`, `_arithmetic.py`, `_logical.py`, `_branch.py`, `_machine.py` (stack, I/O, machine control). `_dispatch.py` holds one explicit if-chain over all 256 bytes, and every handler's docstring starts with its Intel mnemonic, so `grep -n "DAA" src/` finds the code. `tests/test_readability.py` enforces that the way the oracles enforce correctness. ## Reproducing the certification ```text python -m pip install -e ".[dev]" python scripts/fetch_exercisers.py # pinned by SHA-256; --include-cputest is opt-in python -m pytest -q # rungs 1, 2, 4 (and 5 if the trace exists) python -m validation.cpm tests/exercisers/8080EXM.COM # rung 3; use PyPy python scripts/mame_trace.py # MAME 0.285 + invaders ROM set python -m validation.mame_lockstep tests/mame_traces/run60/error.log # rung 5 ``` CI runs rungs 1, 2, and 4 on every push (CPython 3.12-3.14, PyPy 3.11) and 8080EXM weekly under PyPy. ## The chip and the boards The Intel 8080 (1974) was replaced within months by the **8080A**, a corrected mask with the same instruction set. The boards below carry the 8080A or a second source of it. The most widely emulated user is Space Invaders: - **Taito 8080 boards** (1978 onward): Space Invaders, Space Invaders Part II, Lunar Rescue, Space Chaser, Balloon Bomber, Polaris, Indian Battle. MAME models these in `src/mame/midw8080/8080bw.cpp`. - **Midway 8080 black-and-white boards** (1975-1980, Dave Nutting Associates / Midway): Gun Fight, Sea Wolf, 280-ZZZAP, Boot Hill, Clowns, Space Invaders M (Midway's licensed set, MAME `invaders`), Space Invaders II. MAME models these in `src/mame/midw8080/mw8080bw.cpp`, with a 1.9968 MHz 8080 and two interrupts per frame. The board lists above are restated from the `GAME` tables of those two MAME 0.285 source files (BSD-3-Clause), not copied. ### Scope decision: 8080A only, 8085 differences noted The core targets the Intel 8080A as the arcade boards use it. The 8085 shares the instruction set but differs in ways that matter to an emulator, and the documents mark each place where they diverge rather than modeling the 8085: | Area | 8080A | 8085 | | --- | --- | --- | | Flags | S Z 0 AC 0 P 1 CY; bits 5, 3, 1 fixed | undocumented V (bit 1) and K/X5 (bit 5) flags | | `ANA`/`ANI` auxiliary carry | OR of bit 3 of the two operands | always set | | Opcodes 08/10/18/20/28/30/38, CB, D9, DD, ED, FD | NOP, JMP, RET, CALL aliases | DSUB, ARHL, RDEL, RIM, LDHI, SIM, LDSI, RSTV, SHLX, JNK, LHLX, JK | | States | e.g. MOV r,r 5, CALL 17, Jcc always 10, XTHL 18 | MOV r,r 4, CALL 18, Jcc 7/10, XTHL 16; many others differ | | Interrupts | INT with a bus-supplied instruction | plus TRAP, RST 5.5/6.5/7.5 | AMD's 9080A/8080A second sources clear AC on `ANA` and fail the Intel CRCs; the core models Intel. The original non-A 8080 is out of scope; its differences are electrical and timing-related, not architectural (see [docs/start-here.md](docs/start-here.md)). ## Documents See [docs/README.md](docs/README.md) for the index and the reading order. ## License MIT (this repository's code, documents, and scripts). The exercisers, MAME, and ROM sets are external and keep their own licenses; none is bundled. The fetch script downloads the GPL-2.0 exerciser programs into an ignored directory and fetches the one proprietary program only when asked.