@echo off
:: If the source file is "C:\GCCVB\EXAMPLE\EXAMPLE.C" call compile.bat as follows:
:: compile C:\GCCVB\EXAMPLE\ EXAMPLE [FILE2.C] ... [FILEn.C]
:: Note the space between the path and filename!
:: Note also that only the 2nd and subsequent files have extensions.

SET C_INCLUDE_PATH=C:\GCCVB\INCLUDE
SET LIBRARY_PATH=C:\GCCVB\LIB
PATH C:\GCCVB\BIN;C:\;C:\WINDOWS;C:\WINDOWS\COMMAND

if exist %1%2.VB del %1%2.VB > NUL
cd C:\gccVB\BIN
:: ----- Build Header -----
as %1%2.vbh -o %1%2.$$h
objcopy -S -O binary %1%2.$$h %1%2.hdr
if exist %1%2.$$h del %1%2.$$h > NUL

:: ----- Build ROM -----
gcc -nodefaultlibs -mv810 -x c -Tvb.ld -o %1%2.O %1%2.C %3 %4 %5 %6 %7 %8 %9
cd %1
C:\gccVB\BIN\objcopy -S -O binary %1%2.O %1%2.VB

:: - Uncomment line below to get an assembly listing of the binary.
:: C:\gccVB\BIN\objdump -d %1%2.O > %1%2.S

:: ----- Pad ROM/add header -----
copy /b %1%2.VB /b + %1%2.hdr %1%2.VB /b /y > NUL
padromvb.exe %1%2.VB 15 > NUL
if exist %1%2.O del %1%2.O > NUL
if exist %1%2.hdr del %1%2.hdr > NUL
