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.

45 lines
1.3KB

  1. #!/usr/bin/env bash
  2. # Calls 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. # The -a flag makes us switch to the AVR assembler
  8. # readlink -f doesn't work with macOS's implementation
  9. # so, if we can't get readlink -f to work, try python with a realpath implementation
  10. ABS_PATH=$(readlink -f "$0" || python -c "import os; print(os.path.realpath('$0'))")
  11. DIR=$(dirname "${ABS_PATH}")
  12. ZASMBIN="${DIR}/zasm/zasm"
  13. usage() { echo "Usage: $0 [-a] [-o <hexorg>] <paths-to-include>..." 1>&2; exit 1; }
  14. org='00'
  15. while getopts ":ao:" opt; do
  16. case "${opt}" in
  17. a)
  18. ZASMBIN="${DIR}/zasm/avra"
  19. ;;
  20. o)
  21. org=${OPTARG}
  22. ;;
  23. *)
  24. usage
  25. ;;
  26. esac
  27. done
  28. shift $((OPTIND-1))
  29. # wrapper around ./zasm/zasm that prepares includes CFS prior to call
  30. CFSPACK="${DIR}/../tools/cfspack/cfspack"
  31. INCCFS=$(mktemp)
  32. "${CFSPACK}" -p "*.h" -p "*.asm" -p "*.bin" "$@" > "${INCCFS}"
  33. "${ZASMBIN}" "${org}" "${INCCFS}"
  34. RES=$?
  35. rm "${INCCFS}"
  36. exit $RES