2019-10-10 15:21:37 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-11-15 09:57:53 -05:00
|
|
|
# Calls tools/emul/zasm/zasm in a convenient manner by wrapping specified
|
|
|
|
# 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-10-10 15:21:37 -04: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-15 22:41:44 -04:00
|
|
|
ABS_PATH=$(readlink -f "$0" || python -c "import os; print(os.path.realpath('$0'))")
|
2019-06-02 15:50:59 -04:00
|
|
|
|
2019-11-15 09:57:53 -05:00
|
|
|
usage() { echo "Usage: $0 [-o <hexorg>] <paths-to-include>..." 1>&2; exit 1; }
|
|
|
|
|
|
|
|
org='00'
|
|
|
|
while getopts ":o:" opt; do
|
|
|
|
case "${opt}" in
|
|
|
|
o)
|
|
|
|
org=${OPTARG}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2019-06-02 15:50:59 -04:00
|
|
|
# wrapper around ./emul/zasm/zasm that prepares includes CFS prior to call
|
2019-10-10 15:21:37 -04:00
|
|
|
DIR=$(dirname "${ABS_PATH}")
|
2019-06-02 15:50:59 -04:00
|
|
|
ZASMBIN="${DIR}/emul/zasm/zasm"
|
2019-06-02 19:54:37 -04:00
|
|
|
CFSPACK="${DIR}/cfspack/cfspack"
|
|
|
|
INCCFS=$(mktemp)
|
|
|
|
|
|
|
|
for p in "$@"; do
|
2019-07-11 21:21:54 -04:00
|
|
|
"${CFSPACK}" "${p}" "*.h" >> "${INCCFS}"
|
|
|
|
"${CFSPACK}" "${p}" "*.asm" >> "${INCCFS}"
|
2019-11-07 11:52:29 -05:00
|
|
|
"${CFSPACK}" "${p}" "*.bin" >> "${INCCFS}"
|
2019-06-02 19:54:37 -04:00
|
|
|
done
|
|
|
|
|
2019-11-15 09:57:53 -05:00
|
|
|
"${ZASMBIN}" "${org}" "${INCCFS}"
|
2019-06-02 19:54:37 -04:00
|
|
|
RES=$?
|
|
|
|
rm "${INCCFS}"
|
|
|
|
exit $RES
|