@echo off 
if not exist \Emu\Jynx\Jynx-Windows-32bit.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 -Dvasm=1  -L \BldCLX\Listing.txt -DBuildCLX=1 -Fbin -o "\BldCLX\program.bin"

if not "%errorlevel%"=="0" goto Abandon
cd \BldCLX

copy program.bin program.bld

\Utils\BinaryTools.exe checksum program.bin 0 -1 program.bld -1
\Utils\BinaryTools.exe checksum program.bin 0 -1 program.bld -1

\Utils\BinaryTools.exe value16 length program.bin header.bin 9

\Utils\BinaryTools.exe bytes program.bld -1 $00 $65 $65
\Utils\BinaryTools.exe bytes header.bin 11 $00 $65 

copy /b header.bin + program.bld /b \RelCLX\program.tap


ver|find "Windows XP">nul
if %Errorlevel%==0 Goto OSXP

\Emu\Jynx\Jynx-Windows-32bit.exe --run \RelCLX\program.tap
goto Abandon
:OSXP
\Emu\Pale\pale.exe "\RelCLX\program.tap"
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\Jynx\Jynx-Windows-32bit.exe
:Abandon
if "%3"=="nopause" exit
pause