-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.bat
306 lines (238 loc) · 8.51 KB
/
build.bat
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
@ECHO OFF
CLS & TITLE Building v80...
CD %~dp0
ECHO:
SET DIR_BIN=%~dp0bin
REM # the v0 (bootstrap) PC assembler and linker is WLA-DX:
REM # this is our "source of ground truth" to ensure v80
REM # is assembling the correct opcodes etc.
SET WLA_Z80="%DIR_BIN%\wla-dx\wla-z80.exe" -x
SET WLA_6502="%DIR_BIN%\wla-dx\wla-6502.exe" -x
SET WLA_LINK="%DIR_BIN%\wla-dx\wlalink.exe" -A -S
SET WLA_DEBUG=-DDEBUG=1
REM # RunCPM "emulator"
SET DIR_RUNCPM=%DIR_BIN%\RunCPM
SET BIN_RUNCPM="%DIR_RUNCPM%\RunCPM.exe"
REM # NTVCM, CP/M Virtual Machine
REM # https://github.com/davidly/ntvcm
SET DIR_NTVCM=%DIR_BIN%\ntvcm
SET BIN_NTVCM="%DIR_NTVCM%\ntvcm.exe" -l -p
REM # VBinDiff for visual difference comparing
REM # https://www.cjmweb.net/vbindiff/
SET BIN_VBINDIFF="%DIR_BIN%\vbindiff\VBinDiff.exe"
REM # create / clean build directory
SET DIR_BUILD=%~dp0build
IF NOT EXIST "%DIR_BUILD%" MKDIR "%DIR_BUILD%"
DEL /F /Q "%DIR_BUILD%\*.*"
REM # clear RunCPM cache
IF NOT EXIST "%DIR_RUNCPM%\A\0" MKDIR "%DIR_RUNCPM%\A\0" >NUL
DEL /F /Q "%DIR_RUNCPM%\A\0\*.*" >NUL 2>&1
REM # build v80 assembler [v0] from WLA-DX source:
REM # ==========================================================================
REM # this builds "v80_wla.com", the WLA version of v80
%WLA_Z80% -v ^
-I "v0" ^
-o "%DIR_BUILD%\v80_wla.o" ^
"v80.wla"
IF ERRORLEVEL 1 GOTO:ERR
%WLA_LINK% -v -b ^
"v0\link.ini" ^
"%DIR_BUILD%\v80_wla.com"
IF ERRORLEVEL 1 GOTO:ERR
ECHO:
REM # build & run tests:
REM # --------------------------------------------------------------------------
SET DIR_TEST=%~dp0test
REM # copy test v80/v65 files to build directory for running tests
COPY /N /Y "%DIR_TEST%\*.v??" /A "%DIR_BUILD%" /A >NUL
REM # copy the COM files into the RunCPM disk directory
REM # "/N" forces an 8.3 file-name in the destination
COPY /N /Y "%DIR_BUILD%\*.com" /B "%DIR_RUNCPM%\A\0" /B >NUL
REM # copy test v80/v65 files
COPY /N /Y "%DIR_TEST%\*.v??" /A "%DIR_RUNCPM%\A\0" /A >NUL
REM # assemble "test.v80" using the WLA-built [v0] version of v80
CALL :v80_wla "test.v80"
REM # do binary comparisons:
REM # - all Z80 instructions
CALL :RunTestWLA z80
REM # - relative jump distances
CALL :RunTestWLA jr
REM DEL /F /Q "%DIR_BIN%\agon\sdcard\v80\*.*"
REM COPY /N /Y "release\v80.com" /B "%DIR_BIN%\agon\sdcard\v80\V80.COM" /B
REM COPY /N /Y "v1\*.v80" /A "%DIR_BIN%\agon\sdcard\v80\*.v80" /A
REM
REM PUSHD "%DIR_BIN%\agon"
REM "fab-agon-emulator.exe" --scale integer --mode 3
REM POPD & EXIT
REM # if no errors, use v80 to assemble itself
REM # ==========================================================================
REM # copy v80 [v1] source into build directory
COPY /N /Y "v1\*.v??" /B "%DIR_BUILD%" /A >NUL
REM # and to RunCPM
COPY /N /Y "v1\*.v??" /A "%DIR_RUNCPM%\A\0" /A >NUL
REM # do a 1st-generation build of v80 [v1] using v80 [v0]!
CALL :v80_wla "cpm_z80.v80" "v80.com"
REM # do binary comparisons:
REM # - all Z80 instructions
CALL :RunTestZ80 z80
REM REM # do a 2nd-generation build of v80, i.e. v80 [v1] building v80 [v1]
REM CALL :v80_z80 cpm_z80 v80_2nd.com
REM
REM REM # compare 1st and 2nd generation builds
REM FC /B "%DIR_BUILD%\v80.com" "%DIR_BUILD%\v80_2nd.com" >NUL
REM IF ERRORLEVEL 1 START "" %BIN_VBINDIFF% "%DIR_BUILD%\v80.com"
REM # 6502:
REM # ==========================================================================
REM # use v80 to assemble a version of v80 that assembles 6502 code...
CALL :v80 "cpm_6502.v80" "v65.com"
REM # copy v65 to RunCPM's directory
COPY /N /Y "%DIR_BUILD%\v65.com" /B "%DIR_RUNCPM%\A\0" /B >NUL
REM # verify 6502 assembling
CALL :RunTest6502 6502
REM # ==========================================================================
REM # if no errors, copy v80 binary to release folder
ECHO * Populate release folder...
COPY /N /Y "%DIR_BUILD%\v*.com" /B "release\v*.com" /B >NUL
ECHO [OK.]
GOTO :END
REM ////////////////////////////////////////////////////////////////////////////
:RunTestWLA
REM # ==========================================================================
REM # run a comparison between WLA-DX-Z80 [PC] & v80_wla [v0]
REM # --------------------------------------------------------------------------
REM # build "%~1.wla" with WLA-DX [PC],
CALL :wla_z80 %~1
REM # and "%~1.v80" with v80_wla [v0]
CALL :v80_wla %~1.v80
REM # compare the two files:
FC /B ^
"%DIR_BUILD%\%~1_wla.com" ^
"%DIR_BUILD%\%~1.com" >NUL
IF ERRORLEVEL 1 ^
START "" %BIN_VBINDIFF% ^
"%DIR_BUILD%\%~1_wla.com" ^
"%DIR_BUILD%\%~1.com" ^
& GOTO:ERR
GOTO:EOF
:RunTestZ80
REM # ==========================================================================
REM # run a comparison between WLA-DX-Z80 [PC] & v80 [v1]
REM # --------------------------------------------------------------------------
REM # build "%~1.wla" with WLA-DX & "%~1.v80" with v80
CALL :wla_z80 %~1
CALL :v80 %~1.v80
REM # compare the two files
FC /B ^
"%DIR_BUILD%\%~1_wla.com" ^
"%DIR_BUILD%\%~1.com" >NUL
IF ERRORLEVEL 1 ^
START "" %BIN_VBINDIFF% ^
"%DIR_BUILD%\%~1_wla.com" ^
"%DIR_BUILD%\%~1.com" ^
& GOTO:ERR
GOTO:EOF
:wla_z80
REM # ==========================================================================
REM # assemble .wla source with WLA-DX-Z80
REM # --------------------------------------------------------------------------
ECHO * wla-z80.exe %~1.wla
REM # assmeble file to test.o, regardless of input name
%WLA_Z80% ^
-I "%DIR_TEST%" ^
-o "%DIR_BUILD%\test.o" ^
"%DIR_TEST%\%~1.wla"
IF ERRORLEVEL 1 GOTO:ERR
REM # link test.o to input-named *_wla.com file
%WLA_LINK% ^
-b "%DIR_TEST%\link.ini" ^
"%DIR_BUILD%\%~1_wla.com"
IF ERRORLEVEL 1 GOTO:ERR
GOTO:EOF
:v80_wla
REM # ==========================================================================
REM # assemble a .v80 file using the WLA-built [v0] version of v80
REM # --------------------------------------------------------------------------
ECHO * v80_wla.com %~1 %~2
PUSHD "%DIR_BUILD%"
%BIN_NTVCM% v80_wla.com %~1 %~2 > %~n1.sym
IF ERRORLEVEL 1 TYPE %~n1.sym
REM # if NTVCM hits a HALT instruction, launch RunCPM
REM # TODO: prefill the input buffer with the same invocation used
IF %ERRORLEVEL% EQU -1 GOTO :runCPM
IF ERRORLEVEL 1 GOTO:ERR
POPD
GOTO:EOF
:v80
REM # ==========================================================================
REM # assemble with v80
REM # --------------------------------------------------------------------------
ECHO * v80.com %~1 %~2
PUSHD "%DIR_BUILD%"
%BIN_NTVCM% v80.com %~1 %~2 > %~n1.sym
IF ERRORLEVEL 1 TYPE %~n1.sym
REM # if NTVCM hits a HALT instruction, launch RunCPM
IF %ERRORLEVEL% EQU -1 GOTO :runCPM
IF ERRORLEVEL 1 GOTO:ERR
POPD
GOTO:EOF
:runCPM
REM # --------------------------------------------------------------------------
POPD
COPY /N /Y "%DIR_BUILD%\v80.com" /B "%DIR_RUNCPM%\A\0\v80.com" /B >NUL
START "RunCPM" /D "%DIR_RUNCPM%" %BIN_RUNCPM% & GOTO:ERR
GOTO:ERR
:RunTest6502
REM # ==========================================================================
REM # run a comparison between WLA-DX-6502 & v65
REM # --------------------------------------------------------------------------
REM # build "%~1.wla" with WLA-DX-6502 [PC],
CALL :wla_6502 %~1
REM # and "%~1.v65" with v65
CALL :v65 %~1.v65
REM # compare the two files:
FC /B ^
"%DIR_BUILD%\%~1_wla.prg" ^
"%DIR_BUILD%\%~1.prg" >NUL
IF ERRORLEVEL 1 ^
START "" %BIN_VBINDIFF% ^
"%DIR_BUILD%\%~1_wla.prg" ^
"%DIR_BUILD%\%~1.prg" ^
& GOTO:ERR
GOTO:EOF
:wla_6502
REM # ==========================================================================
REM # assemble with WLA-DX-6502
REM # --------------------------------------------------------------------------
ECHO * wla-6502.exe %~1.wla
REM # assmeble file to test.o, regardless of input name
%WLA_6502% ^
-I "%DIR_TEST%" ^
-o "%DIR_BUILD%\test.o" ^
"%DIR_TEST%\%~1.wla"
IF ERRORLEVEL 1 GOTO:ERR
REM # link test.o to input-named *_wla.prg file
%WLA_LINK% ^
-b "%DIR_TEST%\link.ini" ^
"%DIR_BUILD%\%~1_wla.prg"
IF ERRORLEVEL 1 GOTO:ERR
GOTO:EOF
:v65
REM # ==========================================================================
REM # assemble with v65
REM # --------------------------------------------------------------------------
ECHO * v65.com %~1 %~2
PUSHD "%DIR_BUILD%"
%BIN_NTVCM% v65.com %~1 %~2 > %~n1.sym
IF ERRORLEVEL 1 TYPE %~n1.sym
REM # if NTVCM hits a HALT instruction, launch RunCPM
IF %ERRORLEVEL% EQU -1 POPD & START "RunCPM" /D "%DIR_RUNCPM%" %BIN_RUNCPM% & GOTO:ERR
IF ERRORLEVEL 1 GOTO:ERR
POPD
ECHO:
GOTO:EOF
REM ////////////////////////////////////////////////////////////////////////////
:ERR
ECHO ! ERROR
EXIT 1
:END
EXIT 0