1 |
dbug |
70 |
@ECHO OFF |
2 |
dbug |
1243 |
::ECHO ON |
3 |
dbug |
70 |
|
4 |
|
|
:: |
5 |
|
|
:: Initial checks to verify that everything is fine. |
6 |
|
|
:: |
7 |
|
|
IF "%OSDK%"=="" GOTO ErCfg |
8 |
|
|
IF "%1"=="" GOTO ErNoFile |
9 |
|
|
|
10 |
|
|
:: |
11 |
|
|
:: Set the default name for the final executable |
12 |
|
|
:: if no name has been specified |
13 |
|
|
:: |
14 |
|
|
IF NOT "%OSDKNAME%"=="" GOTO Name |
15 |
|
|
SET OSDKNAME=OSDK |
16 |
|
|
:Name |
17 |
|
|
|
18 |
dbug |
1002 |
:: |
19 |
|
|
:: Set the default tape name for the final executable |
20 |
|
|
:: if no name has been specified |
21 |
|
|
:: |
22 |
|
|
IF NOT "%OSDKTAPNAME%"=="" GOTO TapName |
23 |
|
|
SET OSDKTAPNAME=OSDK |
24 |
|
|
:TapName |
25 |
dbug |
70 |
|
26 |
|
|
:: |
27 |
|
|
:: Set the default assembly adress |
28 |
|
|
:: if no adress has been specified |
29 |
|
|
:: |
30 |
|
|
IF NOT "%OSDKADDR%"=="" GOTO Adress |
31 |
|
|
SET OSDKADDR=$600 |
32 |
|
|
:Adress |
33 |
|
|
|
34 |
|
|
:: |
35 |
|
|
:: Set the optimize level to 2 |
36 |
|
|
:: if no level has been specified |
37 |
|
|
:: |
38 |
|
|
IF NOT "%OSDKCOMP%"=="" GOTO Comp |
39 |
|
|
SET OSDKCOMP=-O2 |
40 |
|
|
:Comp |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
SET OSDKB=%OSDK%\BIN |
45 |
|
|
SET OSDKT=%OSDK%\TMP |
46 |
dbug |
1356 |
SET OSDKLINKLIST= |
47 |
dbug |
70 |
SET TMP=%OSDKT% |
48 |
|
|
SET TEMP=%OSDKT% |
49 |
|
|
SET OCC=%OSDK% |
50 |
|
|
SET LCC65=%OSDK% |
51 |
|
|
SET LCC65DIR=%OSDK% |
52 |
dbug |
1527 |
SET OSDKVERSION=1.15 |
53 |
dbug |
70 |
|
54 |
|
|
:: |
55 |
|
|
:: Create a build directory if it does not exist |
56 |
|
|
:: Mike: Seems to fail creating the folder under Wine, resulting in a failed build |
57 |
|
|
:: Mike: What about testing for BUILD\. instead ? |
58 |
|
|
:: |
59 |
|
|
IF EXIST BUILD\NUL GOTO NoBuild |
60 |
|
|
MD BUILD |
61 |
|
|
:NoBuild |
62 |
|
|
|
63 |
dbug |
1002 |
|
64 |
|
|
:: |
65 |
|
|
:: Make sure that temp folder is entirelly empty before attempting a new build |
66 |
|
|
:: Will guarantee we do not have side effects between builds |
67 |
|
|
:: |
68 |
|
|
::ECHO ON |
69 |
|
|
RMDIR /s /q %OSDKT%\ >NUL |
70 |
|
|
MD %OSDKT% >NUL |
71 |
|
|
::IF EXIST %OSDKT%\NUL GOTO NoTmp |
72 |
|
|
::MD %OSDKT% |
73 |
dbug |
70 |
:NoTmp |
74 |
dbug |
1002 |
::ECHO OFF |
75 |
dbug |
70 |
|
76 |
dbug |
1002 |
|
77 |
dbug |
70 |
:: |
78 |
|
|
:: Display a compilation message |
79 |
|
|
:: Note: Should find a way to disable the adress display for BASIC programs... kind of lame |
80 |
|
|
:: |
81 |
dbug |
1513 |
ECHO Building the program %OSDKNAME% at adress %OSDKADDR% [OSDK %OSDKVERSION%] |
82 |
dbug |
70 |
|
83 |
|
|
|
84 |
|
|
:: |
85 |
|
|
:: Delete old files. |
86 |
|
|
:: This way we are sure nothing remains if the build fails |
87 |
|
|
:: |
88 |
|
|
IF NOT EXIST BUILD\symbols GOTO NoSymbol |
89 |
|
|
DEL BUILD\symbols >NUL |
90 |
|
|
:NoSymbol |
91 |
|
|
|
92 |
|
|
IF NOT EXIST BUILD\final.out GOTO NoFinal |
93 |
|
|
DEL BUILD\final.out >NUL |
94 |
|
|
:NoFinal |
95 |
|
|
|
96 |
|
|
IF NOT EXIST BUILD\xaerr.txt GOTO NoError |
97 |
|
|
DEL BUILD\xaerr.txt >NUL |
98 |
|
|
:NoError |
99 |
|
|
|
100 |
|
|
IF NOT EXIST BUILD\%OSDKNAME%.tap GOTO NoTape |
101 |
|
|
DEL BUILD\%OSDKNAME%.tap >NUL |
102 |
|
|
:NoTape |
103 |
|
|
|
104 |
|
|
:: Delete the eventual composite BASIC file |
105 |
|
|
IF NOT EXIST %OSDKT%\%OSDKNAME%.bas GOTO NoBas |
106 |
|
|
DEL %OSDKT%\%OSDKNAME%.bas >NUL |
107 |
|
|
:NoBas |
108 |
|
|
|
109 |
dbug |
1002 |
:: Delete eventual compressed files |
110 |
|
|
IF NOT EXIST BUILD\*.pak GOTO NoPak |
111 |
|
|
DEL BUILD\*.pak >NUL |
112 |
|
|
:NoPak |
113 |
dbug |
70 |
|
114 |
dbug |
1002 |
IF NOT EXIST BUILD\%OSDKPACK%.* GOTO NoPakFiles |
115 |
|
|
DEL BUILD\%OSDKPACK%.* >NUL |
116 |
|
|
:NoPakFiles |
117 |
|
|
|
118 |
|
|
|
119 |
dbug |
70 |
:: |
120 |
|
|
:: Create a BATCH file that will be used |
121 |
|
|
:: to later link all the part of the program |
122 |
|
|
:: |
123 |
|
|
::ECHO *=%OSDKADDR% >%OSDKT%\adress.tmp |
124 |
|
|
::ECHO %OSDKB%\link65.exe %OSDKLINK% -d %OSDK%\lib/ -o %OSDKT%\linked.s -s %OSDKT%\ -f -q %1 %2 %3 %4 %5 %6 %7 %8 %9 >%OSDKT%\link.bat |
125 |
dbug |
1002 |
::ECHO %OSDKB%\link65.exe %OSDKLINK% -d %OSDK%\lib/ -o %OSDKT%\linked.ss -s %OSDKT%\ -f -q %OSDKFILE% >%OSDKT%\link.bat |
126 |
dbug |
1356 |
::ECHO %OSDKB%\link65.exe %OSDKLINK% -d %OSDK%\lib/ -o %OSDKT%\linked.s -s %OSDKT%\ -f -q %OSDKFILE% >%OSDKT%\link.bat |
127 |
dbug |
70 |
|
128 |
|
|
|
129 |
|
|
:: |
130 |
|
|
:: Compile/Assemble files |
131 |
|
|
:: depending of their type |
132 |
|
|
:: |
133 |
|
|
:FileLoop |
134 |
|
|
IF "%1"=="" GOTO Finished |
135 |
|
|
|
136 |
|
|
::ECHO %1 >%OSDKT%\linktemp.txt |
137 |
|
|
::COPY /b %OSDKT%\link.bat+%OSDKT%\linktemp.txt %OSDKT%\link.bat |
138 |
|
|
::ECHO %1 >>%OSDKT%\link.bat |
139 |
|
|
|
140 |
|
|
IF EXIST "%1.C" GOTO Compile |
141 |
|
|
IF EXIST "%1.S" GOTO Assemble |
142 |
|
|
IF EXIST "%1.ASM" GOTO Assemble |
143 |
|
|
IF EXIST "%1.BAS" GOTO Basic |
144 |
|
|
|
145 |
|
|
:: |
146 |
|
|
:: Outputs a "file not found" error message |
147 |
|
|
:: if the file is not a C or S file |
148 |
|
|
:: |
149 |
|
|
ECHO == ERROR -- |
150 |
|
|
ECHO The file "%1" is not a C, assembly code or BASIC file (.C/.S/.BAS suffix) |
151 |
|
|
ECHO You should specify the name of the files without any extension. The files have |
152 |
|
|
ECHO to be all in the same level directory and should not have the same names. |
153 |
|
|
ECHO -- ERROR == |
154 |
|
|
IF "%OSDKBRIEF%"=="" PAUSE |
155 |
|
|
GOTO End |
156 |
|
|
|
157 |
|
|
|
158 |
|
|
:Compile |
159 |
|
|
IF "%OSDKBRIEF%"=="" ECHO Compiling %1.C |
160 |
|
|
|
161 |
|
|
IF "%OSDKBRIEF%"=="" ECHO - preprocess |
162 |
|
|
:: the -DATMOS is for Contiki |
163 |
dbug |
1527 |
%OSDKB%\cpp.exe -lang-c++ -I %OSDK%\include -D__16BIT__ -D__NOFLOAT__ -DATMOS -DOSDKNAME_%OSDKNAME% -DOSDKVER=\"%OSDKVERSION%\" -nostdinc %1.c %OSDKT%\%1.c |
164 |
dbug |
70 |
|
165 |
|
|
IF "%OSDKBRIEF%"=="" ECHO - compile |
166 |
|
|
%OSDKB%\compiler.exe -N%1 %OSDKCOMP% %OSDKT%\%1.c >%OSDKT%\%1.c2 |
167 |
|
|
IF ERRORLEVEL 1 GOTO ErFailure |
168 |
|
|
|
169 |
|
|
IF "%OSDKBRIEF%"=="" ECHO - convert C to assembly code |
170 |
dbug |
1513 |
%OSDKB%\cpp.exe -lang-c++ -imacros %OSDK%\macro\macros.h -DXA -traditional -P %OSDKT%\%1.c2 %OSDKT%\%1.s |
171 |
dbug |
70 |
|
172 |
|
|
IF "%OSDKBRIEF%"=="" ECHO - cleanup output |
173 |
|
|
::%OSDKB%\tr < %OSDKT%\%1.s > %OSDKT%\%1 |
174 |
|
|
%OSDKB%\macrosplitter.exe %OSDKT%\%1.s %OSDKT%\%1 |
175 |
dbug |
1356 |
SET OSDKLINKLIST=%OSDKLINKLIST% %OSDKT%\%1 |
176 |
dbug |
70 |
SHIFT |
177 |
|
|
GOTO FileLoop |
178 |
|
|
|
179 |
|
|
|
180 |
|
|
:: |
181 |
|
|
:: This is the sequence of instructions necessary to build an assembly code file. |
182 |
|
|
:: Assembler files are just copied over in the temp folder since there is no particular |
183 |
|
|
:: modifications to do. Anyway we need to make sure that the directory structure is kept |
184 |
|
|
:: at the correct place. |
185 |
|
|
:: |
186 |
|
|
:Assemble |
187 |
|
|
IF "%OSDKBRIEF%"=="" ECHO Assembling %1.S |
188 |
|
|
|
189 |
|
|
:: Create the directory structure |
190 |
dbug |
1002 |
XCOPY /Y /T %1.S %OSDKT%\ |
191 |
dbug |
70 |
|
192 |
|
|
:: Copy the file |
193 |
dbug |
1356 |
COPY %1.S %OSDKT%\%1.s /Y >NUL |
194 |
|
|
SET OSDKLINKLIST=%OSDKLINKLIST% %1.s |
195 |
dbug |
70 |
SHIFT |
196 |
|
|
GOTO FileLoop |
197 |
|
|
|
198 |
|
|
:Basic |
199 |
|
|
IF "%OSDKBRIEF%"=="" ECHO Converting BASIC program %1.BAS |
200 |
|
|
|
201 |
|
|
ECHO #file %1.BAS >> %OSDKT%\%OSDKNAME%.bas |
202 |
|
|
TYPE %1.BAS >> %OSDKT%\%OSDKNAME%.bas |
203 |
|
|
|
204 |
|
|
SHIFT |
205 |
|
|
GOTO FileLoop |
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
:: |
210 |
|
|
:: Perform final linking and binary conversion |
211 |
|
|
:: of compiled files |
212 |
|
|
:: |
213 |
|
|
:Finished |
214 |
|
|
|
215 |
|
|
:: Do we have a BASIC program ? |
216 |
|
|
IF NOT EXIST %OSDKT%\%OSDKNAME%.bas GOTO Link |
217 |
|
|
|
218 |
dbug |
1002 |
::ECHO Generating line numbers |
219 |
|
|
::%OSDKB%\Labels2Num %OSDKT%\%OSDKNAME%.bas %OSDKT%\%OSDKNAME%.bas2 1 1 |
220 |
dbug |
70 |
|
221 |
|
|
ECHO Generating TAPE file |
222 |
dbug |
1002 |
%OSDKB%\Bas2Tap -b2t1 -color1 %OSDKT%\%OSDKNAME%.bas build\%OSDKNAME%.tap |
223 |
|
|
|
224 |
dbug |
70 |
IF ERRORLEVEL 1 GOTO ErFailure |
225 |
|
|
GOTO End |
226 |
|
|
|
227 |
|
|
:Link |
228 |
dbug |
1356 |
:: |
229 |
|
|
:: Create a BATCH file that will be used |
230 |
|
|
:: to later link all the part of the program |
231 |
|
|
:: |
232 |
dbug |
70 |
ECHO Linking |
233 |
dbug |
1356 |
::ECHO %OSDKLINKLIST% |
234 |
|
|
cd |
235 |
|
|
ECHO %OSDKB%\link65.exe %OSDKLINK% -d %OSDK%\lib/ -o %OSDKT%\linked.s -f -q %OSDKLINKLIST% >%OSDKT%\link.bat |
236 |
|
|
::ECHO %OSDKB%\link65.exe %OSDKLINK% -d %OSDK%\lib/ -o %OSDKT%\linked.s -s %OSDKT%\ -f -q %OSDKFILE% >%OSDKT%\link.bat |
237 |
|
|
::pause |
238 |
dbug |
70 |
CALL %OSDKT%\link.bat |
239 |
|
|
IF ERRORLEVEL 1 GOTO ErFailure |
240 |
|
|
::ECHO Optimising size |
241 |
dbug |
1002 |
::%OSDKB%\opt65.exe %OSDKT%\linked.s > %OSDKT%\linked_optimised.s |
242 |
dbug |
70 |
|
243 |
|
|
|
244 |
|
|
:: |
245 |
|
|
:: Assemble the big file |
246 |
dbug |
1356 |
:: (-W -C are meant to disallow the 65816 and 65c02 instructions) |
247 |
dbug |
70 |
::%OSDKB%\xa.exe %OSDKT%\linked.s -o final.out -e xaerr.txt -l xalbl.txt |
248 |
|
|
ECHO Assembling |
249 |
dbug |
1402 |
%OSDKB%\xa.exe -W -C %OSDKT%\linked.s -o build\final.out -e build\xaerr.txt -l build\symbols -bt %OSDKADDR% -DASSEMBLER=XA %OSDKXAPARAMS% -DOSDKNAME_%OSDKNAME% |
250 |
dbug |
70 |
IF NOT EXIST "build\final.out" GOTO ErFailure |
251 |
|
|
|
252 |
dbug |
1002 |
|
253 |
dbug |
70 |
:: |
254 |
dbug |
1002 |
:: Executable compression test |
255 |
|
|
:: |
256 |
|
|
IF "%OSDKPACKADDR%"=="" GOTO EndPack |
257 |
|
|
|
258 |
|
|
IF "%OSDKBRIEF%"=="" ECHO Compressing |
259 |
|
|
%OSDK%\bin\FilePack -p0 build\final.out %OSDKT%\final.pak |
260 |
|
|
|
261 |
|
|
IF "%OSDKBRIEF%"=="" ECHO - Converting binary to text format |
262 |
|
|
%OSDK%\bin\bin2txt -s1 -f2 %OSDKT%\final.pak %OSDKT%\final_pak.s _PackedStart >NUL |
263 |
|
|
|
264 |
|
|
IF "%OSDKBRIEF%"=="" ECHO - Appending depacking code |
265 |
|
|
COPY %OSDKT%\final_fp.s+%OSDKB%\unpack.s+%OSDKT%\final_pak.s %OSDKT%\pak_linked.s >NUL |
266 |
|
|
|
267 |
|
|
IF "%OSDKBRIEF%"=="" ECHO - Assembling |
268 |
|
|
%OSDKB%\xa.exe %OSDKT%\pak_linked.s -o build\final.out -e %OSDKT%\xaerr.txt -l %OSDKT%\symbols -bt %OSDKPACKADDR% |
269 |
|
|
IF NOT EXIST "build\final.out" GOTO ErFailure |
270 |
|
|
|
271 |
|
|
:: The new start address is the packed executable load address |
272 |
|
|
set OSDKADDR=%OSDKPACKADDR% |
273 |
|
|
|
274 |
|
|
:EndPack |
275 |
|
|
|
276 |
|
|
|
277 |
|
|
:: |
278 |
dbug |
70 |
:: Append the tape header |
279 |
|
|
:: |
280 |
|
|
ECHO Creating final program %OSDKNAME%.TAP |
281 |
|
|
%OSDKB%\header.exe %OSDKHEAD% build\final.out build\%OSDKNAME%.tap %OSDKADDR% |
282 |
dbug |
1002 |
%OSDKB%\taptap.exe ren build\%OSDKNAME%.tap %OSDKTAPNAME% 0 |
283 |
|
|
|
284 |
dbug |
70 |
:BuildOk |
285 |
|
|
ECHO Build of %OSDKNAME%.tap finished |
286 |
|
|
|
287 |
|
|
|
288 |
|
|
:: |
289 |
dbug |
1002 |
:: Generate the DSK file. If OSDKFILE is empty we assume (hm hmmm) that the caller is packaging itself with floppybuilder. (WIP) |
290 |
dbug |
70 |
:: |
291 |
|
|
IF "%OSDKDISK%"=="" GOTO EndBuildDisk |
292 |
dbug |
1002 |
IF "%OSDKFILE%"=="" GOTO EndBuildDisk |
293 |
|
|
|
294 |
dbug |
1156 |
::%OSDK%\bin\DskTool.exe -n%OSDKDNAME% -i%OSDKINIST% %OSDKDISK% build\%OSDKNAME%.tap build\%OSDKNAME%.dsk |
295 |
dbug |
1341 |
%OSDK%\bin\tap2dsk.exe -n%OSDKDNAME% -i%OSDKINIST% %OSDKDISK% build\%OSDKNAME%.tap build\%OSDKNAME%.dsk |
296 |
dbug |
70 |
%OSDK%\bin\old2mfm.exe build\%OSDKNAME%.DSK |
297 |
dbug |
1002 |
|
298 |
dbug |
70 |
:EndBuildDisk |
299 |
|
|
|
300 |
|
|
:: |
301 |
|
|
:: End of build |
302 |
|
|
:: |
303 |
|
|
GOTO End |
304 |
|
|
|
305 |
|
|
|
306 |
|
|
:: |
307 |
|
|
:: Outputs a "Unable to create program" error message |
308 |
|
|
:: |
309 |
|
|
:ErFailure |
310 |
|
|
ECHO ERROR : Build failed. |
311 |
|
|
IF "%OSDKBRIEF%"=="" PAUSE |
312 |
|
|
GOTO End |
313 |
|
|
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
:: |
317 |
|
|
:: Outputs a "no files" error message |
318 |
|
|
:: |
319 |
|
|
:ErNoFile |
320 |
|
|
ECHO == ERROR -- |
321 |
|
|
ECHO This batch file is supposed to compile files. |
322 |
|
|
ECHO You should specify one or more files to compile. |
323 |
|
|
ECHO -- ERROR == |
324 |
|
|
IF "%OSDKBRIEF%"=="" PAUSE |
325 |
|
|
GOTO End |
326 |
|
|
|
327 |
|
|
|
328 |
|
|
:: |
329 |
|
|
:: Outputs a "configuration" error message |
330 |
|
|
:: |
331 |
|
|
:ErCfg |
332 |
|
|
ECHO == ERROR -- |
333 |
|
|
ECHO The Oric SDK was not configured properly |
334 |
|
|
ECHO You should have a OSDK environment variable setted to the location of the SDK |
335 |
|
|
ECHO -- ERROR == |
336 |
|
|
IF "%OSDKBRIEF%"=="" PAUSE |
337 |
|
|
GOTO End |
338 |
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
:End |