#!/bin/bash # Check the assembler as SDCC compiles it for the Z-80 (it has had code # generation bugs, see s_copy in monitor.c): assemble every opcode form with # monitor/test/asm-z80.c in tools/z80emu.py and compare with the PC build. # Takes about two minutes. set -e cd "$(dirname "$0")" T=$(mktemp -d) sdasz80 -o $T/crt0.rel ../basic/crt0.s cp asm.c asmtab.h $T/ && cp test/asm-z80.c $T/t.c (cd $T && sdcc -mz80 --opt-code-size --max-allocs-per-node 20000 --std-sdcc11 -c t.c 2>/dev/null && sdcc -mz80 --no-std-crt0 --code-loc 0x0080 --data-loc 0x8000 -o t.ihx crt0.rel t.rel) python3 ../tools/ihx2mem.py $T/t.ihx $T/t.bin $T/t.mem >/dev/null gcc -O1 -w -o $T/mon monitor.c $T/mon | awk -F'\t' '$2 != "NOP*" && $2 !~ /^DB /{print $2}' > $T/lines.txt (cat $T/lines.txt; echo) > $T/input.txt $T/mon line < $T/lines.txt > $T/host.txt python3 ../tools/z80emu.py $T/t.bin --input $T/input.txt --max 400000000 2>&1 | grep -v '^\[' | tr -d '\r' | tail -n +2 > $T/z80.txt if diff $T/z80.txt $T/host.txt > /dev/null; then echo "Z-80 build matches the PC build on $(wc -l < $T/lines.txt) lines" else echo "Z-80 BUILD DIFFERS:"; diff $T/z80.txt $T/host.txt | head; exit 1 fi