Metadata-Version: 2.5 Name: arm7tdmi-python Version: 0.1.0.dev0 Summary: Readable, pure-Python ARM7TDMI (ARMv4T, Game Boy Advance CPU) 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 :: 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 # arm7tdmi-python A readable, pure-Python **ARM7TDMI** CPU core (architecture ARMv4T: ARM and Thumb): the processor inside the Game Boy Advance, the Nintendo DS's second CPU and many embedded and arcade boards. This repository is only the CPU. The board, [gba-python](../gba-python), owns everything else: memory map, waitstates, the cartridge prefetch buffer, DMA, interrupts' sources, HALT. **Status (2026-10-22): the core is built; rungs 0 to 4 pass** (local git only). The decode tables, every bus schedule in [`docs/timing.md`](docs/timing.md), the whole SingleStepTests ARM7TDMI corpus (2,192,923 gated cases; a detector, it is emulator-derived) with the internal cycles checked against NanoBoyAdvance's, 7,000,000 multiplies judged by zayd's hardware-fuzzed model, and jsmolka's and alyosha-tas's CPU test ROMs in a minimal harness. The disassembler, debugger and console are built (2026-11-04, "Tools" below). Rung 5 runs through [gba-python](../gba-python). Results and every exclusion are in [`docs/validation.md`](docs/validation.md) "Results". The documents in [`docs/`](docs/README.md) hold every fact with its source and tier; [docs/handoff-brief.md](docs/handoff-brief.md) is the build brief. The core follows [z80-python](https://github.com/alewman/z80-python)'s shape: host-owned memory passed in as callables, no dependencies, CPython and PyPy (Python 3.11+). Like sm83-python it makes **one bus callback per CPU cycle, internal cycles included**, each carrying the address, the width (8/16/32) and whether it is sequential: the GBA times every access by those, and the board, not the core, turns them into clocks. ## Tools A disassembler, a debugger and a console, at the family's bar (z80-python, sm83-python): ```sh python -m arm7tdmi_python ROM.gba # run to a branch to itself, print R12 python -m arm7tdmi_python ROM.gba --trace run.jsonl # every bus cycle as JSON Lines python -m arm7tdmi_python ROM.gba --debug # the command debugger python -m arm7tdmi_python ROM.gba --debug -c "break 0x080001A4" -c c -c "cycles" --batch python -m arm7tdmi_python multiboot.bin --at 0x02000000 # a raw image anywhere; ELF files too ``` - **`disasm`**: ARM and Thumb in ARM's pre-UAL syntax, classified by the core's own decode tables. Undefined and reserved encodings print as what the ARM7TDMI does, with the docs item in a comment. A detector run against mGBA and MAME covers every Thumb halfword and 131,072 ARM words, and every remaining difference is named ([docs/disassembly.md](docs/disassembly.md)). - **`debug`**: `DebugSession` with: - breakpoints, run-until and step-over; - bus watchpoints that see internal and coprocessor cycles, with every cycle typed N/S/I/C; - step records decoded from the pipeline. It works on the core or on a board ([docs/debugging.md](docs/debugging.md)). - **`console`**: `CommandDebugger` with registers, banks, PSRs, memory, listings, bus cycles, IRQ/FIQ lines and image loading. ## What is fetched Nothing third-party is committed. `scripts/fetch_references.py` rebuilds `reference/` from `scripts/pinned_files.json` (4 documents pinned by SHA-256: ARM's Technical Reference Manual, the 1995 data sheet with the instruction set chapters, GBATEK, and the multiply-carry research) and `scripts/pinned_repos.json` (12 repositories at full commit SHAs, sparse where large): the SingleStepTests ARM7TDMI corpus (2.25 M cases), jsmolka's and alyosha-tas's test ROMs, ARMWrestler, FuzzARM, the mGBA test suite, and the ARM cores of NanoBoyAdvance, mGBA, ares, SkyEmu and MAME 0.285. ```sh python scripts/fetch_references.py # everything missing (~1 GB) python scripts/fetch_references.py --skip SingleStepTests-ARM7TDMI # without the 840 MB corpus python scripts/fetch_references.py --verify # check what is present python scripts/build_referees.py # NanoBoyAdvance's ARM core as a referee python scripts/referee_sst.py # score it against the corpus python scripts/sst_census.py # what the corpus holds python scripts/multiply_model.py # corpus multiplies vs the model ``` They need `git`, `curl`, `gcc` and `g++` (C++20). No sudo. ## Scripts | Script | What | | --- | --- | | `scripts/fetch_references.py` | the pinned documents, test programs and source trees | | `scripts/build_referees.py` | builds `referees/nba/` against the pinned NanoBoyAdvance, zayd's multiply model, and `referees/mgba/` (mGBA's disassembler) | | `scripts/referee_sst.py` | runs the referee over every corpus file: state and bus agreement, I-cycle histograms | | `scripts/sst_census.py` | measures the corpus: cases, ARM/Thumb, transactions, unaligned accesses, mode changes, refills | | `scripts/multiply_model.py` | runs zayd's hardware-fuzzed multiply model on every corpus multiply: results, carry, `m` | | `scripts/disasm_judge.py` | the disassembler against mGBA's (built by `build_referees.py`), MAME's `unidasm` and GNU objdump, as detectors, and a round trip through GNU as (binutils from gba-python's pinned Arm toolchain) | ## Licence MIT (see `LICENSE`), for what is in this repository. The fetched material keeps its own terms, recorded per entry in the pin lists; the referee binary links GPL-3.0 NanoBoyAdvance code and is built locally, never distributed.