Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1KB

  1. #!/usr/bin/env bash
  2. # Calls tools/emul/zasm/zasm in a convenient manner by wrapping specified
  3. # paths to include in a single CFS file and then pass that file to zasm.
  4. # Additionally, it takes a "-o" argument to set the initial ".org" of the
  5. # binary. For example, "zasm.sh -o 4f < foo.asm" assembles foo.asm as if it
  6. # started with the line ".org 0x4f00".
  7. # readlink -f doesn't work with macOS's implementation
  8. # so, if we can't get readlink -f to work, try python with a realpath implementation
  9. ABS_PATH=$(readlink -f "$0" || python -c "import os; print(os.path.realpath('$0'))")
  10. usage() { echo "Usage: $0 [-o <hexorg>] <paths-to-include>..." 1>&2; exit 1; }
  11. org='00'
  12. while getopts ":o:" opt; do
  13. case "${opt}" in
  14. o)
  15. org=${OPTARG}
  16. ;;
  17. *)
  18. usage
  19. ;;
  20. esac
  21. done
  22. shift $((OPTIND-1))
  23. # wrapper around ./emul/zasm/zasm that prepares includes CFS prior to call
  24. DIR=$(dirname "${ABS_PATH}")
  25. ZASMBIN="${DIR}/emul/zasm/zasm"
  26. CFSPACK="${DIR}/cfspack/cfspack"
  27. INCCFS=$(mktemp)
  28. "${CFSPACK}" -p "*.h" -p "*.asm" -p "*.bin" "$@" > "${INCCFS}"
  29. "${ZASMBIN}" "${org}" "${INCCFS}"
  30. RES=$?
  31. rm "${INCCFS}"
  32. exit $RES