-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.sh
75 lines (54 loc) · 2.24 KB
/
convert.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
INPUT_FILE=$1
OUTPUT_FILE=$2
MODE=$3
if [[ $# -ne 3 ]] # Ensure proper number of arguments
then
echo "Incorrect number of arguments supplied. Proper syntax is ./convert.sh <input name> <output name> <mode>"
echo "<input name>: Input file to specified operation."
echo "<output name>: Output file to specified operation."
echo "<mode>: Use 'var' to convert an eZ80 Studio AppVar to assembly source, or 'asm' to convert assembly source to an eZ80 Studio AppVar."
exit 1
fi
if [[ ! -f $INPUT_FILE ]] # Ensure the specified file exists
then
echo "The specified file does not exist. Please ensure that the file and path specified were correct and try again."
exit 1
fi
if [[ $MODE == "var" ]] # Convert AppVar to assembly source file
then
echo "Converting from AppVar..."
convbin -j 8x -k bin -i $INPUT_FILE -o $OUTPUT_FILE
echo "AppVar converted successfully."
echo "Removing header..."
sed -i 's/\xEF\x7A//g' $OUTPUT_FILE # Remove header
echo "Header removed."
elif [[ $MODE == "asm" ]] # Convert assembly source file to AppVar
then
echo "Adding header..."
echo -n -e '\xEF\x7A' | cat - $INPUT_FILE > temp_$INPUT_FILE
if [[ ! -f temp_$INPUT_FILE ]] # Ensure the specified file exists
then
echo "The header was not able to be added. Ensure you are in the directory with your input file and try again."
exit 1
fi
echo "Header added succesfully."
echo "Converting newlines..."
sed -i 's/\r\n/\n/g' temp_$INPUT_FILE # Get rid of windows garbage (Hopefully nothing goes wrong here)
echo "Newlines converted succesfully."
echo "Converting tabs..."
sed -i 's/\t/ /g' temp_$INPUT_FILE
echo "Tabs converted succesfully."
echo "Converting to AppVar format..."
convbin -j bin -k 8xv -i temp_$INPUT_FILE -o $OUTPUT_FILE.8xv -n $OUTPUT_FILE
if [[ ! -f $OUTPUT_FILE.8xv ]] # Ensure the file got created
then
echo "The conversion failed. Please ensure convbin is installed on your system and try again."
exit 1
fi
rm temp_$INPUT_FILE
else
echo "Invalid mode. Use 'var' to convert an eZ80 Studio AppVar to assembly source, or 'asm' to convert assembly source to an eZ80 Studio AppVar."
exit 1
fi
echo "Success!"