# 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-11-19): 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 compared to NanoBoyAdvance's run as a closed box, 7,000,000 multiplies judged by zayd's hardware-fuzzed model, and 15 of jsmolka's and alyosha-tas's CPU test ROMs in a minimal harness, among them the eight hardware tests of the LDM^ glitch. On 2026-11-19 every piece first written with NanoBoyAdvance's source open was removed unread and rewritten from ARM's documents, GBATEK, the hardware test ROMs and closed-box runs ([`docs/provenance.md`](docs/provenance.md)); every gate scores as before or better ([`docs/status.md`](docs/status.md)). 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. NanoBoyAdvance and mGBA are built and run as closed boxes, never read (`referees/README.md`). ```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 the NBA driver (`$EMU_TOOLS_GPL/tools/arm7tdmi-python/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 the package and its tests; `_multiply.py`'s carry model is zaydlang's (zlib, notice kept in the file and in `NOTICE`). The fetched material keeps its own terms, recorded per entry in the pin lists. The tools in `referees/` link mGBA (MPL-2.0) and zaydlang's model (Zlib) and keep those licences; the NBA referee's driver links NanoBoyAdvance (GPL-3.0-or-later) and is kept outside this repository (`$EMU_TOOLS_GPL/tools/arm7tdmi-python/nba`). All are built locally and never distributed (`referees/README.md`). `tests/hw/thumb_undefined/` builds its ROM with the cartridge header logo copied from a cartridge image you supply; the logo is not in this repository.