#!/bin/bash
# m68kasm.sh file.s origin_hex out.bin  -- assemble 68000 code at a fixed address with GNU as (SGDK docker image)
set -e
S=$(realpath "$1"); D=$(dirname "$S"); B=$(basename "$S" .s); ORG=$2; OUT=$(realpath -m "$3")
docker run --rm --user $(id -u):$(id -g) -v "$D":/w -w /w --entrypoint sh ghcr.io/stephane-d/sgdk -c \
 "m68k-elf-as -m68000 -o /tmp/$B.o $B.s && m68k-elf-ld -Ttext=0x$ORG -e _start -o /tmp/$B.elf /tmp/$B.o && m68k-elf-objcopy -O binary /tmp/$B.elf /tmp/$B.bin && cat /tmp/$B.bin" > "$OUT"
ls -l "$OUT" | awk '{print $5" bytes"}'
