#!/bin/sh # Produce a per-instruction MB88xx trace from MAME. See docs/mame-oracle.md. # # ./scripts/mame/trace_mcu.sh [frames] [outdir] [game] # TRACE_MCU=:51xx:mcu ./scripts/mame/trace_mcu.sh 2500 out-51xx # # Writes $outdir/error.log (the trace) and $outdir/FILE (MAME's disassembly # of the same instructions). Neither may be committed; both are gitignored. # ROMs are read in place through -rompath and are never copied. set -eu FRAMES=${1:-800} OUTDIR=${2:-trace-out} GAME=${3:-galaga} MCU=${TRACE_MCU:-:54xx:mcu} MAME=${MAME:-/usr/games/mame} ROMPATH="${ROMPATH:-${MAME_ROMPATH:?set MAME_ROMPATH (or ROMPATH) to the MAME non-merged ROM folder}}" SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) LUA="$SCRIPT_DIR/trace_mcu.lua" mkdir -p "$OUTDIR" OUTDIR=$(CDPATH= cd -- "$OUTDIR" && pwd) rm -f "$OUTDIR/error.log" "$OUTDIR/FILE" # error.log and FILE land in the CURRENT WORKING DIRECTORY, not -homepath. cd "$OUTDIR" TRACE_MCU="$MCU" TRACE_FRAMES="$FRAMES" \ timeout -s KILL 1800 "$MAME" "$GAME" \ -rompath "$ROMPATH" \ -video none -sound none -nothrottle -noreadconfig -skip_gameinfo \ -debug -debugger none -log \ -homepath "$OUTDIR" \ -cfg_directory "$OUTDIR/cfg" \ -nvram_directory "$OUTDIR/nvram" \ -snapshot_directory "$OUTDIR/snap" \ -autoboot_script "$LUA" # Drop MAME's three startup lines; keep the six-field trace records. awk 'NF==6' "$OUTDIR/error.log" > "$OUTDIR/trace.txt" printf '%s: %s instructions, %s frames of %s\n' \ "$MCU" "$(wc -l < "$OUTDIR/trace.txt")" "$FRAMES" "$GAME" printf 'last line (PA PC A Y flags cycles): %s\n' "$(tail -1 "$OUTDIR/trace.txt")"