#!/usr/bin/env bash # Check out the megadrive-python reference at the frozen pin and install it, with exactly # the four cores its pyproject pins, into a PyPy virtual environment, so the lockstep # gate runs against that board. # Usage: scripts/fetch_megadrivepython.sh [destination] # MEGADRIVE_PYTHON_SOURCE overrides where it is cloned from (a local clone will do); # PYTHON names the interpreter (PyPy by default, which runs the reference fastest). set -euo pipefail # 6303613: megadrive-python's history reset (2026-11-21), which pins m68000-python # 4454d54 (the core m68000-rust 8a5bbb7 transcribes). The tags megadrive-rust-pin-1 and # -pin-2 named the removed history; no new tag is made while the clean-up settles, so the # pin is the commit. # 3e2325f (2026-11-21): a stopped 68000 wakes for VINT again (IPL_SYNC_WHILE_STOPPED). # 1e8dcd3 (2026-11-23): save states (src/megadrive_python/state.py, docs/save-states.md), # which scripts/md_trace.py's --save-at and --rewind-at use; no change to the board's # behaviour since 3e2325f. # efd80fc (2026-11-23): the drawing switch gates only the pixels, the SVP's ROM DMA one # word late (Virtua Racing's speedometer), the host's undrawn_frame; state version 2. COMMIT=${MEGADRIVE_PYTHON_COMMIT:-efd80fcea2e1fc28a0b26396d24868233277b260} SOURCE=${MEGADRIVE_PYTHON_SOURCE:-git@github.com:alewman/megadrive-python.git} DEST=${1:-"$(dirname "$0")/../external/megadrive-python"} PYTHON=${PYTHON:-$(command -v pypy3.11 || command -v python3)} if [ ! -d "$DEST/.git" ]; then git clone -q "$SOURCE" "$DEST" fi git -C "$DEST" fetch -q origin git -C "$DEST" checkout -q --detach "$COMMIT" if [ ! -x "$DEST/.venv/bin/python" ]; then "$PYTHON" -m venv "$DEST/.venv" fi # The FM chip and the PSG: the reference names them unpinned (no remotes when it was # written), so they are pinned here, by the revisions the lockstep gate was last run on. # The repositories are private: fetched over SSH. *_COMMIT overrides each. GH=git+ssh://git@github.com/alewman YM2612=${YM2612_PYTHON_COMMIT:-1324639e82dbac49664dfe2ec80c761565dab14b} SN76489=${SN76489_PYTHON_COMMIT:-f06cbedbd52b1a8daf05693bb3441f3480c28e96} "$DEST/.venv/bin/python" -m pip install -q --force-reinstall --no-deps \ "ym2612-python @ $GH/ym2612-python@$YM2612" "sn76489-python @ $GH/sn76489-python@$SN76489" # pip keeps an installed core whose pin changed (an old m68000-python survived a repin # that way), so the reference's pinned cores are uninstalled first and come back at its pins. "$DEST/.venv/bin/python" -m pip uninstall -q -y m68000-python z80-python || true "$DEST/.venv/bin/python" -m pip install -q -e "$DEST" # Virtua Racing's DSP, which the board loads if it is there. SSP1601_PYTHON_SOURCE overrides # where it comes from, for as long as it has no remote; the default is a checkout beside # this repository. SSP=${SSP1601_PYTHON_SOURCE:-"$(cd "$(dirname "$0")/../.." && pwd)/ssp1601-python"} "$DEST/.venv/bin/python" -m pip install -q "$SSP" "$DEST/.venv/bin/python" -m pip freeze | grep -E "python @ git" || true echo "megadrive-python $(git -C "$DEST" rev-parse --short HEAD) installed in $DEST/.venv"