# Galemu A readable, deterministic Python emulator for the original 1979 Namco **Galaxian** arcade board. Galemu executes the original game through the independently validated [z80-python](https://github.com/alewman/z80-python) core and models the board around it: memory, inputs, vblank NMI scheduling, tile and object video, starfield, bullets, and discrete sound. The result is a playable pygame application and a real-machine proof that the standalone Z80 core works in a non-trivial host. > **ROM notice:** This repository contains no Galaxian ROMs, graphics, PROMs, or > gameplay recordings. Supply a legally obtained MAME `galaxian` parent set. Do not > commit or redistribute those assets. ## Features - Real Z80 program execution through `z80-python==0.3.0`. - Direct loading from the standard MAME `galaxian.zip`; no manual extraction required. - Strict size, CRC32, and SHA-1 verification of every program, graphics, and palette file. - Deterministic board timing at $2000/33$ Hz with immutable snapshots and structured events. - Hardware-oriented tiles, sprites, bullets, palette, starfield, controls, and vblank NMI. - Playable pygame display and FFmpeg-backed H.264/AAC recording. - Circuit-structured, deterministic approximation of Galaxian's analog sound board. ## Quick start Requires Python 3.12 or newer. ```text git clone https://github.com/alewman/galemu.git cd galemu python -m venv .venv .venv\Scripts\activate python -m pip install -e ".[display]" ``` Place the legally obtained MAME archive at `rom/galaxian.zip`, without extracting it: ```text python -m galemu --rom-path rom/galaxian.zip --display --scale 3 ``` An extracted directory still works when useful: ```text python -m galemu --rom-path rom/galaxian --display --scale 3 ``` The loader accepts flat or nested archive members and handles filename case differences, but it accepts only the exact verified Namco parent set documented in [the ROM manifest](docs/rom-manifest.md). It reads members in memory and never extracts them to disk. ### Windows launchers Double-click `run-galemu.bat` for the shortest setup. On first launch it creates `.venv` and installs the pinned emulator dependencies. It prefers `rom/galaxian.zip` and falls back to the extracted `rom/galaxian/` directory. ### Controls | Key | Action | | --- | --- | | Left / Right | Move player 1 | | Space | Fire | | 5 | Insert coin | | 1 / 2 | Start one / two players | | Escape | Close the window | ## Validation Correctness is established at several independent boundaries: - every required ROM is matched to MAME's parent-set size, CRC32, and SHA-1 identity; - deterministic boot tests assert exact CPU state, timing, memory, and mapped device events; - deep-boot tests prove the real program initializes the board and accepts its first vblank NMI at the expected instruction and T-state boundary; - multi-frame and controlled-input tests prove repeatable gameplay-visible behavior; and - pure video, device, scheduler, audio, recording, and trace transforms have ROM-free tests. The CPU dependency is separately certified against 1,604,000 SingleStepTests transitions and both ZEXDOC and ZEXALL under CPython and PyPy. Galemu is the integration proof: the validated instruction core is driving a real 1979 arcade program and a complete host board. This project was developed with extensive AI assistance. AI output is not treated as evidence: executable checks, external ROM identities, deterministic traces, and observed real-program behavior are the authority. ## Architecture Galemu keeps processor and machine responsibilities explicit: - `z80-python` owns instruction semantics and processor lifecycle; - `GalaxianBoard` owns memory, I/O, inputs, device writes, and frame/NMI scheduling; - pure video modules decode ROM graphics and compose native frames; - `FrameComposer` bridges board snapshots to the optional pygame presentation layer; and - structured events feed deterministic traces, sound synthesis, and recording. The code favors ordinary Python and testable transforms over generated tables or hidden framework state. Start with [the machine-layer plan](docs/machine-layer-plan.md) for the implemented boundaries and [the hardware documentation](docs/README.md) for source-backed board details. ## Recording Install [FFmpeg](https://ffmpeg.org/) so `ffmpeg` is on `PATH`, then run: ```text python -m galemu --rom-path rom/galaxian.zip --display --scale 3 --record demo.mp4 ``` `record-demo.bat` provides the same Windows workflow. Close the window or press Escape to finalize the file. Recordings are ignored by Git because they are derived from proprietary ROM content. ## Accuracy and scope Video, board timing, controls, gameplay, and the complete sound path are implemented. The game is playable, and there are no known audible sound defects. Sound follows the original discrete circuit's signal graph—including the rising noise-modulated FIRE sweep and the resonant HIT explosion—but remains a signal-level approximation rather than a transistor- accurate simulation of component tolerances and analog filtering. Galemu is an instruction-timed board emulator, not a cycle-accurate electrical simulation. It targets the original Namco `galaxian` parent set, not every Galaxian clone or derivative. ## Development Install the development tools and run the ordinary quality gate: ```text python -m pip install -e ".[display,dev]" python -m pytest -q python -m ruff check . ``` The full ROM-free suite runs in a clean clone; tests requiring a local parent set skip automatically. Supplying `rom/galaxian/` enables the existing extracted-set evidence tests. ROM archives, extracted ROMs, recordings, virtual environments, and tool caches are ignored. ## License Galemu's original source code is licensed under the [MIT License](LICENSE). This license does not grant rights to Galaxian ROMs, artwork, audio, trademarks, or other proprietary assets.