#!/usr/bin/env bash # Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License. # See LICENSE.md for license information. # SPDX-License-Identifier: MIT # # clang-smoke.sh - End-to-end smoke test of the llvm-mos w65816 IIgs # build path. Compiles a tiny C main that calls JoeyLib's ported asm # (jlIigsInitRowLut), links it with clang-build.sh, runs it under MAME's # apple2gs, and verifies the LUT the asm computed. # # This proves the whole toolchain end to end: clang -> llvm-mc -> # link816 -> runnable IIgs image -> correct runtime result. Exit 0 on # success. Needs the toolchain:iigs install (make exports its paths). set -euo pipefail : "${LLVM816_ROOT:?LLVM816_ROOT unset: run ./install.sh install toolchain:iigs, then use make or source toolchains/env.sh}" : "${MAME:?MAME unset: run ./install.sh install emulator:iigs}" : "${IIGS_ROMPATH:?IIGS_ROMPATH unset: run ./install.sh install emulator:iigs}" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO="$(cd "$HERE/../../.." && pwd)" RUN_IN_MAME="$LLVM816_ROOT/scripts/runInMame.sh" [ -x "$RUN_IN_MAME" ] || { echo "clang-smoke: $RUN_IN_MAME missing" >&2; exit 1; } # runInMame.sh takes MAME and MAME_ROMPATH from the environment, so it # runs the installer's patched MAME against the installer's ROM set. export MAME export MAME_ROMPATH="$IIGS_ROMPATH" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT # jlgRowOffsetLut[5] = 5 * 160 = 800 = 0x0320. Publish it to a 24-bit # address MAME can read back (bank 2 is clear of IIgs ROM scribbling). cat > "$tmp/smoke.c" <<'EOF' #include extern void jlIigsInitRowLut(void); extern uint16_t jlgRowOffsetLut[]; int main(void) { jlIigsInitRowLut(); *(volatile uint16_t *)0x025000 = jlgRowOffsetLut[5]; return 0; } EOF # runInMame.sh raw-loads the image at $00:1000 and jumps there, so the # smoke needs a BARE binary -- NOT the ExpressLoad GS/OS OMF (crt0Gsos.o, # Loader-relocated) that clang-build.sh now emits. Build it directly with # the bare crt0.o at --text-base 0x1000. link816 dead-strips the unused # runtime, so offering libgcc/libc/extras is free. echo "[clang-smoke] building bare smoke.bin (crt0.o, --text-base 0x1000)" RT="$LLVM816_ROOT/runtime" CLANG="$LLVM816_ROOT/tools/llvm-mos-build/bin/clang" LLVM_MC="$LLVM816_ROOT/tools/llvm-mos-build/bin/llvm-mc" LINK="$LLVM816_ROOT/tools/link816" "$CLANG" --target=w65816 -O2 -ffreestanding -ffunction-sections \ -I"$RT/include" -c "$tmp/smoke.c" -o "$tmp/smoke.o" "$LLVM_MC" -arch=w65816 -filetype=obj \ "$REPO/src/iigs/joeyDraw.s" -o "$tmp/joeyDraw.o" "$LINK" -o "$tmp/smoke.bin" --text-base 0x1000 \ "$RT/crt0.o" "$RT/libgcc.o" "$RT/libc.o" "$RT/extras.o" \ "$tmp/smoke.o" "$tmp/joeyDraw.o" echo "[clang-smoke] running under MAME apple2gs, checking jlgRowOffsetLut[5] == 0x0320" bash "$RUN_IN_MAME" "$tmp/smoke.bin" --check 0x025000=0320 echo "[clang-smoke] PASS"