#!/bin/bash # Run a Z-80 image on the Verilog CPU and on tools/z80emu.py and compare traces. # scripts/cpusim.sh image.mem [input-file] [max-clocks] set -e cd "$(dirname "$0")/.." ROOT=$(pwd) IMG=$(realpath "$1") INP=$(realpath "${2:-/dev/null}") MAX=${3:-20000000} source scripts/vivado_env.sh mkdir -p sim/cpu cd sim/cpu xvlog -d IMAGE="\"$IMG\"" -d INPUT="\"$INP\"" "$ROOT/rtl/z80_cpu.v" "$ROOT/sim/tb_cpu.v" >/dev/null xelab -debug off tb_cpu -s tb_cpu >/dev/null xsim tb_cpu -R -testplusarg max=$MAX | grep -v -e '^INFO' -e '^#' -e '^\*\*' -e '^Vivado' -e '^ *\*\*\*\*' -e '^source' -e '^run' -e '^exit' -e '^\$finish' -e '^Time:' -e '^Copyright' python3 "$ROOT/tools/z80emu.py" "${IMG%.mem}.bin" --input "$INP" --trace trace_sw.txt \ --max "$(wc -l < trace_hw.txt)" > out_sw.txt python3 "$ROOT/tools/cmptrace.py" trace_sw.txt trace_hw.txt cmp -s mem_sw.txt mem_hw.txt && echo "memory 8000-FFFF matches" || { echo "MEMORY DIFFERS"; exit 1; }