#!/usr/bin/env bash # make-iigs-disk.sh - Build the JOEYLIB ProDOS disk image (joey.2mg) that # run-iigs-mame.sh and run-iigs.sh mount as the data disk (flop4). It holds # the launchable example binaries as ProDOS type $B3 (S16 / GS-OS apps) in a # volume named JOEYLIB, so GS/OS Finder lists and launches them. # # A 3.5" floppy caps at 800KB, which cannot hold every example at once. # Examples are added in priority order (small primitive demos first); any that # would overflow the volume are skipped with a warning rather than corrupting # the image. Override the set with JOEY_DISK_EXAMPLES="DRAW SPRITE ...". # # Usage: scripts/make-iigs-disk.sh [output.2mg] # Requires: toolchains/env.sh sourced (LLVM816_ROOT), built IIgs examples. set -euo pipefail repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) : "${LLVM816_ROOT:?make-iigs-disk.sh: source toolchains/env.sh first}" CADIUS="${CADIUS:-$LLVM816_ROOT/tools/cadius/cadius}" BINDIR="${BINDIR:-$repo/build/iigs/bin}" OUT="${1:-$BINDIR/joey.2mg}" VOL=JOEYLIB [ -x "$CADIUS" ] || { echo "make-iigs-disk.sh: cadius not found at $CADIUS" >&2; exit 2; } # Priority order: small primitive demos first so DRAW/PATTERN/etc. always fit; # the large AGI build lands last and is dropped if the floppy is full. order=(${JOEY_DISK_EXAMPLES:-DRAW PATTERN KEYS JOY SPRITE UBER ADV2 ADV AGI}) work=$(mktemp -d -t joeylib-disk.XXXXXX) trap 'rm -rf "$work"' EXIT rm -f "$OUT" "$CADIUS" CREATEVOLUME "$OUT" "$VOL" 800KB >/dev/null freeBlocks() { "$CADIUS" CATALOG "$OUT" 2>/dev/null \ | grep -oE 'Free : [0-9]+' | grep -oE '[0-9]+' | head -1 } added=() skipped=() for name in "${order[@]}"; do bin="$BINDIR/$name" [ -f "$bin" ] || continue sz=$(stat -c%s "$bin") # data blocks + one index block per 256 data blocks + a little dir slack need=$(( (sz + 511) / 512 + (sz + 131071) / 131072 + 2 )) if [ "$need" -gt "$(freeBlocks)" ]; then skipped+=("$name") continue fi # ProDOS type $B3 (S16/GS-OS application), aux $0000. cp "$bin" "$work/$name#B30000" "$CADIUS" ADDFILE "$OUT" "/$VOL" "$work/$name#B30000" >/dev/null rm -f "$work/$name#B30000" if "$CADIUS" CATALOG "$OUT" 2>/dev/null | grep -qE "^ $name +S16"; then added+=("$name") else skipped+=("$name") fi done echo "iigs-disk: $OUT (volume /$VOL)" echo " added: ${added[*]:-none}" if [ ${#skipped[@]} -gt 0 ]; then echo " SKIPPED (800KB floppy full): ${skipped[*]}" echo " -> mount a single-example disk via JOEY_DISK_EXAMPLES=\"NAME\" $0" fi