@echo off

::Note: asm5900.exe does NOT return an error code when it fails, the comparisons here will not work
:: unless this is resolved by the author of that software.  Therefore you must watch the output to
:: be sure your project is building correctly.

asm5900 -o:PS1LOGO.BIN PS1LOGO.S
IF NOT %errorlevel%==0 GOTO error

asm5900 -o:PS1LOGO2.BIN PS1LOGO2.S
IF NOT %errorlevel%==0 GOTO error

copy PS1LOGO.BIN FILES\BOOT\BM\PS1LOGO.BIN
copy PS1LOGO2.BIN FILES\BOOT\BM\PS1LOGO2.BIN

asm5900 -o:OSDHOOK.BIN OSDHOOK.S
IF NOT %errorlevel%==0 GOTO error

asm5900 -o:LOAD10.BIN LOAD10.S
IF NOT %errorlevel%==0 GOTO error

ccigen -v10 LOAD10.BIN OSDHOOK.BIN FWARE10.CCI
IF NOT %errorlevel%==0 GOTO error

copy FWARE10.CCI FILES\FWARE10.CCI

asm5900 -o:LOAD11.BIN LOAD11.S
IF NOT %errorlevel%==0 GOTO error

ccigen -v11 LOAD11.BIN OSDHOOK.BIN FWARE11.CCI
IF NOT %errorlevel%==0 GOTO error

copy FWARE11.CCI FILES\FWARE11.CCI

asm5900 -o:LOADDF.BIN LOADDF.S
IF NOT %errorlevel%==0 GOTO error

ccigen -v20 LOADDF.BIN OSDHOOK.BIN FWAREDF.CCI
IF NOT %errorlevel%==0 GOTO error

copy FWAREDF.CCI FILES\FWAREDF.CCI

copy BOOTMENU.PBT FILES\BOOT\BM\BOOTMENU.PBT

cd-tool -o cc-upgrade.bin -e "main()" cc-upg-builder.lua
IF NOT %errorlevel%==0 GOTO error

echo Crystal Chip firmware and upgrade disc image created successfully.
GOTO end

:error
echo !!! Firmware building stopped due to error. !!!

:end
pause
