-
Notifications
You must be signed in to change notification settings - Fork 0
/
a2
executable file
·176 lines (152 loc) · 3.74 KB
/
a2
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
set -e # Exit on error
AOUT=$PWD/OUT.6502
function bash
{
echo alias a2=$(realpath $0) \;
type _a2_completions | tail +2
echo \;
echo complete -D -F _a2_completions -o bashdefault -o default a2 \;
}
# https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins
function _a2_completions
{
if [ "${#COMP_WORDS[@]}" == "2" ]
then
COMPREPLY=($(compgen -W "bash build clean compile help run" "${COMP_WORDS[-1]}"))
elif [ "${COMP_WORDS[-1]}" == "-" ]
then
COMPREPLY=($(compgen -W "-o" "${COMP_WORDS[-1]}"))
fi
}
function build
{
case $1 in
-o) shift
AOUT=$1
shift
;;
esac
make
compile $*
deps
deps/a2asm <(compile $*) >$AOUT
echo "Apple DOS 3.3 binary written to:"
echo " $AOUT"
}
function clean
{
rm -rf ./deps ./build
make clean
}
function compile
{
set -o pipefail
./compile $* | expand -t16
set +o pipefail
}
function deps
{
if [ ! -d deps/a2asm.git ]
then
mkdir -p deps/a2asm.git
git clone --depth=1 https://github.com/taeber/a2asm deps/a2asm.git
pushd deps/a2asm.git
go build -o ../a2asm cmd/a2asm/main.go
popd
fi
if [ ! -f deps/MASTER.DSK ]
then
curl -L 'https://github.com/AppleWin/AppleWin/raw/master/bin/MASTER.DSK' >deps/MASTER.DSK
fi
if java -version 2>/dev/null
then
if [ ! -f deps/ac.jar ]
then
curl -L 'https://github.com/AppleCommander/AppleCommander/releases/download/v1-5-0/AppleCommander-ac-1.5.0.jar' >deps/ac.jar
fi
else
if [ ! -d deps/dos33fsprogs.git ]
then
git clone --depth=1 https://github.com/deater/dos33fsprogs deps/dos33fsprogs.git
pushd deps/dos33fsprogs.git/utils/dos33fs-utils
make dos33
cp dos33 ../../../
popd
fi
fi
}
function openurl
{
open $1 || xdg-open $1
}
function run
{
DISK=$PWD/build/DISK.DSK
if [ "$1" != "" ]
then
AOUT="$1"
fi
echo "Building disk for 6502 binary:"
echo " $AOUT"
mkdir -p build
cp deps/MASTER.DSK "$DISK"
if [ -f deps/dos33 ]
then
deps/dos33 "$DISK" save b "$AOUT" PROG
else
java -jar deps/ac.jar -dos "$DISK" PROG B <$AOUT
fi
echo ""
echo "Your build disk is at:"
echo " $DISK"
echo ""
echo "Launching emulator"
if [ ! -f /Applications/Ample.app/Contents/MacOS/mame64 ]
then
openurl 'https://www.scullinsteel.com/apple2/e'
return
fi
echo ""
echo " ]BRUN PROG"
echo ""
pushd ~/Library/Application\ Support/Ample >/dev/null
/Applications/Ample.app/Contents/MacOS/mame64 \
apple2e -skip_gameinfo -nosamples -window -nomax -flop1 "$DISK"
popd >/dev/null
}
function vm
{
if [ "$1" != "" ]
then
AOUT="$1"
fi
./vm "$AOUT"
}
case "$1" in
bash|build|clean|compile|run|vm)
$*
;;
help|*)
echo "A2 is a tool for managing A2 source code."
echo ""
echo "Usage:"
echo ""
echo " a2 <command> [arguments]"
echo ""
echo "The commands are:"
echo ""
echo " help view this help message"
echo " bash adds bash tab completion for a2"
echo " build compile and assemble A2 into 6502 binary"
echo " clean delete build files and dependencies"
echo " compile compile A2 into 6502 assembly"
echo " run run a 6502 binary in an emulator"
echo " vm run a 6502 binary from your console"
echo ""
echo "For Bash, you can add an a2 alias with tab completion with:"
echo ""
echo " eval \$(./a2 bash)"
echo ""
;;
esac