@echo off 

if not exist \Emu\bgb\bgb.exe goto EmulatorFail

set BuildFile=%1
set BuildPath=%2
if exist \utils\SelectedBuildFile.bat call \utils\SelectedBuildFile.bat 

cd %BuildPath%
if not %BuildPath:~0,1%==%CD:~0,1% goto InvalidPath


\Utils\Vasm\vasmZ80_OldStyle_win32.exe %BuildFile% -chklabels -nocase -gbz80 -Dvasm=1 -DBuildGMB=1 -Fbin -o \RelGB\cart.gb -L \RelGB\Listing.txt
if not "%errorlevel%"=="0" goto Abandon
rem taskkill -im VisualBoyAdvance.exe
rem copy Z:\Emu\VisualBoyAdvance\gbc.ini Z:\Emu\VisualBoyAdvance\vba.ini
rem start Z:\Emu\VisualBoyAdvance\VisualBoyAdvance.exe Z:\RelGB\cart.gb


\utils\rgbfix.exe -v -p 0 \RelGB\cart.gb
\Emu\bgb\bgb.exe \RelGB\cart.gb

goto Abandon


:InvalidPath
echo Error: ASM file must be on same drive as devtools 
echo File: %BuildPath%\%BuildFile% 
echo Devtools Drive: %CD:~0,1% 
goto Abandon


:EmulatorFail
echo Error: Can't find \Emu\bgb\bgb.exe
:Abandon
if "%3"=="nopause" exit
pause
