#!/bin/sh # Produce a per-instruction trace of Donkey Kong's 8035 sound MCU from MAME. # # Verified against MAME 0.285 on 2026-09-12; see docs/mame-oracle.md for what # each flag does and why, and for the gotchas (error.log lands in the current # working directory; `tracelog` produces nothing; there is no `psw` symbol). # # scripts/mame/trace_dkong.sh [outdir] # # Environment: # MAME path to the binary (default /usr/games/mame) # ROMPATH MAME ROM collection (default $MAME_ROMPATH, MAME's non-merged sets) # MACHINE machine to run (default dkong) # TRACE_START_FRAME / TRACE_STOP_FRAME / TRACE_IDLE passed to the Lua script # # Outputs land in $outdir (default ./traces, which is gitignored): # dkong_soundcpu.txt one disassembled line per instruction # error.log the matching register line per instruction # Neither is ever committed, and no ROM is copied anywhere. set -eu MAME=${MAME:-/usr/games/mame} ROMPATH="${ROMPATH:-${MAME_ROMPATH:?set MAME_ROMPATH (or ROMPATH) to the MAME non-merged ROM folder}}" MACHINE=${MACHINE:-dkong} OUTDIR=${1:-traces} HERE=$(cd "$(dirname "$0")" && pwd) mkdir -p "$OUTDIR" cd "$OUTDIR" rm -f error.log "${TRACE_FILE:-dkong_soundcpu.txt}" "$MAME" "$MACHINE" \ -rompath "$ROMPATH" \ -homepath . -cfg_directory ./cfg -nvram_directory ./nvram \ -video none -sound none -nothrottle \ -noreadconfig -skip_gameinfo \ -debug -debugger none -log \ -autoboot_script "$HERE/trace_dkong.lua" echo "instructions: $(wc -l < "${TRACE_FILE:-dkong_soundcpu.txt}")" echo "register lines: $(grep -c '^[0-9A-F]\{3\} A=' error.log || true)"