@echo off
SET GAMES_LIST=games.list
SET OUTPUT_UNIF=multirom.unf
SET OUTPUT_BIN=multirom.bin
SET MENU_IMAGE=menu.png
SET MAX_SIZE=32
SET SORT_GAMES=TRUE
SET TILES_CONVERTER=tools\TilesConverter.exe
SET COMBINER=tools\CoolboyCombiner.exe
SET NESASM=tools\nesasm.exe
rem SET NESASM=%NESASM% --symbols=%OUTPUT_UNIF% --symbols-offset=24 -iWss 
SET OFFSETS_FILE=offsets.xml
SET REPORT_FILE=report.txt
SET VERSION=1

if exist menu.nes del menu.nes
if exist menu_pattern0.dat del menu_pattern0.dat
if exist menu_nametable0.dat del menu_nametable0.dat
if exist menu_nametable1.dat del menu_nametable1.dat
if exist menu_palette0.dat del menu_palette0.dat
if exist menu_pattern1.dat del menu_pattern1.dat
if exist menu_palette1.dat del menu_palette1.dat
if exist games.asm del games.asm
if exist *.nl del *.nl
if exist %OFFSETS_FILE% del %OFFSETS_FILE%
if exist %REPORT_FILE% del %REPORT_FILE%
if exist %OUTPUT_UNIF% del %OUTPUT_UNIF%
if exist %OUTPUT_BIN% del %OUTPUT_BIN%
if "%1"=="clean" exit 0
if /I %SORT_GAMES% NEQ TRUE SET NOSORTP=--nosort
@echo on
%TILES_CONVERTER% %MENU_IMAGE% menu_pattern0.dat menu_nametable0.dat menu_palette0.dat
@if %ERRORLEVEL% neq 0 goto error
%TILES_CONVERTER% menu_sprites.png menu_pattern1.dat menu_nametable1.dat menu_palette1.dat
@if %ERRORLEVEL% neq 0 goto error
%COMBINER% prepare --games %GAMES_LIST% --asm games.asm --maxsize %MAX_SIZE% --offsets %OFFSETS_FILE% --report %REPORT_FILE% %NOSORTP% --ver %VERSION% --no-flash
@if %ERRORLEVEL% neq 0 goto error
%NESASM% menu.asm
@if %ERRORLEVEL% neq 0 goto error
%COMBINER% combine --loader menu.nes --offsets %OFFSETS_FILE% --unif %OUTPUT_UNIF% --bin %OUTPUT_BIN% --ver %VERSION%
@if %ERRORLEVEL% neq 0 goto error
@if exist %OUTPUT_UNIF% echo Seems like everything is fine! %OUTPUT_UNIF% created.
@pause
@exit 0
:error
@echo Oops, something is wrong!
@pause
exit 1
