@echo off 
if not exist \Emu\Xm7\Win32\XM7.exe  goto EmulatorFail
if not exist \Emu\Xm7\Win32\*.ROM  goto RomFail
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

rem Compile program
\Utils\Asw\bin\asw %BuildFile% -CPU 6809  -L -olist \BldFM7\Listing.txt  -D BuildFM7 -o \BldFM7\prog.bld
if not "%errorlevel%"=="0" goto Abandon

rem Create Binary
\Utils\Asw\bin\p2bin \BldFM7\prog.bld \BldFM7\PROG.2B0 -l 0
if not "%errorlevel%"=="0" goto Abandon

rem Copy Template Disk
cd \BldFM7\
copy Startup_Template.D77 Startup.D77

rem Add program to disk
\Utils\ftools_00\fmwrite startup.d77 PROG.2b0

rem Launch Emulator 
cd \Emu\Xm7\Win32\
\Emu\Xm7\Win32\XM7.exe \BldFM7\startup.d77

rem \Utils\ftools_00\fmdir startup.d77


rem C:\myprog\ftools_00>fmencode color.bas
rem C:\myprog\ftools_00>fmwrite nosys_blank.d77 color.0A0
rem FMENCODE.exe t.s

exit

:InvalidPath
echo Error: ASM file must be on same drive as devtools 
echo File: %BuildPath%\%BuildFile% 
echo Devtools Drive: %CD:~0,1% 
goto Abandon
:RomFail
echo Error: Can't find roms
echo please put FM7 Roms into \Emu\Xm7\Win32\
echo Sorry... For Legal reasons I cannot provide them :-(
goto Abandon
:EmulatorFail
echo Error: Can't find \Emu\Xm7\Win32\XM7.exe
:Abandon
if "%3"=="nopause" exit
pause
