2019-10-11 06:21:37 +11:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-01-01 05:32:09 +11:00
|
|
|
# Calls emul/zasm/zasm in a convenient manner by wrapping specified
|
2019-11-16 01:57:53 +11:00
|
|
|
# paths to include in a single CFS file and then pass that file to zasm.
|
|
|
|
# Additionally, it takes a "-o" argument to set the initial ".org" of the
|
|
|
|
# binary. For example, "zasm.sh -o 4f < foo.asm" assembles foo.asm as if it
|
|
|
|
# started with the line ".org 0x4f00".
|
|
|
|
|
2019-12-16 01:38:01 +11:00
|
|
|
# The -a flag makes us switch to the AVR assembler
|
|
|
|
|
2019-10-11 06:21:37 +11:00
|
|
|
# readlink -f doesn't work with macOS's implementation
|
|
|
|
# so, if we can't get readlink -f to work, try python with a realpath implementation
|
2019-10-16 13:41:44 +11:00
|
|
|
ABS_PATH=$(readlink -f "$0" || python -c "import os; print(os.path.realpath('$0'))")
|
2019-12-16 01:38:01 +11:00
|
|
|
DIR=$(dirname "${ABS_PATH}")
|
2020-01-01 05:32:09 +11:00
|
|
|
ZASMBIN="${DIR}/zasm/zasm"
|
2019-06-03 05:50:59 +10:00
|
|
|
|
2019-12-16 01:38:01 +11:00
|
|
|
usage() { echo "Usage: $0 [-a] [-o <hexorg>] <paths-to-include>..." 1>&2; exit 1; }
|
2019-11-16 01:57:53 +11:00
|
|
|
|
|
|
|
org='00'
|
2019-12-16 01:38:01 +11:00
|
|
|
while getopts ":ao:" opt; do
|
2019-11-16 01:57:53 +11:00
|
|
|
case "${opt}" in
|
2019-12-16 01:38:01 +11:00
|
|
|
a)
|
2020-01-01 05:32:09 +11:00
|
|
|
ZASMBIN="${DIR}/zasm/avra"
|
2019-12-16 01:38:01 +11:00
|
|
|
;;
|
2019-11-16 01:57:53 +11:00
|
|
|
o)
|
|
|
|
org=${OPTARG}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2020-01-01 05:32:09 +11:00
|
|
|
# wrapper around ./zasm/zasm that prepares includes CFS prior to call
|
|
|
|
CFSPACK="${DIR}/../tools/cfspack/cfspack"
|
2019-06-03 09:54:37 +10:00
|
|
|
INCCFS=$(mktemp)
|
|
|
|
|
2019-12-12 12:57:23 +11:00
|
|
|
"${CFSPACK}" -p "*.h" -p "*.asm" -p "*.bin" "$@" > "${INCCFS}"
|
2019-06-03 09:54:37 +10:00
|
|
|
|
2019-11-16 01:57:53 +11:00
|
|
|
"${ZASMBIN}" "${org}" "${INCCFS}"
|
2019-06-03 09:54:37 +10:00
|
|
|
RES=$?
|
|
|
|
rm "${INCCFS}"
|
|
|
|
exit $RES
|