-
Notifications
You must be signed in to change notification settings - Fork 1
/
asm6805
executable file
·57 lines (45 loc) · 1.63 KB
/
asm6805
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
IMAGE_NAME=timex-datalink-assembler
IMAGE_VERSION=0.3.0
IMAGE_VERSIONED_TAG="$IMAGE_NAME:v$IMAGE_VERSION"
IMAGE_LATEST_TAG="$IMAGE_NAME:latest"
SCRIPT_REALPATH=$(realpath "$0")
SCRIPT_NAME=$(basename "$SCRIPT_REALPATH")
DOCKER_DIR="$(dirname "$SCRIPT_REALPATH")/docker"
# If anything goes wrong, stop the script while still calling the trap.
set -eE
# Display usage if no arguments are passed to the script.
if [ -z "$1" ]; then
printf "%s\n" \
"Usage: $SCRIPT_NAME ASSEMBLY_FILE [OUTPUT_FILE]" \
"Assemble a WristApp or sound scheme for the Timex Datalink 150 and 150s." \
"" \
"ASSEMBLY_FILE is a path to a ZSM assembly file." \
"OUTPUT_FILE is a path to write the ZAP or SPC file (defaults to out.zap or out.spc)." \
"" \
"ZSM format documentation: <https://www.toebes.com/Datalink/wristapps.html>"
exit 1
fi
if [ ! -e "$1" ]; then
printf '%s %s\n' "$1" "does not exist!" 1>&2
exit 1
fi
# If an argument for the output file was passed, use it. Otherwise, use out.zap.
if [ -n "$2" ]; then
output_file=$2
elif grep -q '^;Sound:' "$1"; then
output_file=out.spc
else
output_file=out.zap
fi
# If the output file already exists, immediately exit.
if [ -e "$output_file" ]; then
echo "$output_file already exists!" 1>&2
exit 1
fi
# Build the Docker image if it doesn't exist.
if ! docker image inspect "$IMAGE_VERSIONED_TAG" &> /dev/null; then
docker build "$DOCKER_DIR" --tag "$IMAGE_VERSIONED_TAG" --tag "$IMAGE_LATEST_TAG"
fi
# Assemble the program with Toebes' assembler with a wrapper script.
docker run --rm --interactive "$IMAGE_VERSIONED_TAG" /root/VAsm6805-wrapper < "$1" > "$output_file"