@echo off

:main
echo -- COMPILING SNES POWERPAK SOFTWARE --

set module=SA
call :module

set module=SB
call :module

set module=SC
call :module

set module=SD
call :module

set module=SG
call :module

set module=SI
call :module

set module=SM
call :module

set module=SN
call :module

set module=SO
call :module

set module=SP
call :module

set module=SQ
call :module

set module=SU
call :module

echo -- generating CONFIG.TXT --
zerofill -f -q 0x200 out\POWERPAK\CONFIG.TXT

echo -- generating LASTSNES.TXT --
zerofill -f -q 0x200 out\POWERPAK\LASTSNES.TXT

echo -- generating LOG.TXT --
zerofill -f -q 0x800 out\POWERPAK\LOG.TXT

echo -- copying TOPLEVEL.BIT --
copy TOPLEVEL.BIT out\POWERPAK\TOPLEVEL.BIT

echo -- preparing SOUNDBANK --
smconv -s -o soundbnk "music\parforceritt_b2_downsampled.it"

echo -- compiling LOADER.BIN --
echo [objects] > loader.lnk
echo loader.o >> loader.lnk
wla-65816 -oi loader.asm loader.o
wlalink -rsi loader.lnk loader.sfc
copy loader.sfc out\loader.bin
head -c 98304 loader.sfc > out\POWERPAK\UPDATE.BIN
del loader.o
del loader.lnk

goto :done

:module
echo -- compiling %module%.MAP --
echo [objects] > %module%.lnk
echo %module%.o >> %module%.lnk
wla-65816 -oi %module%.asm %module%.o
wlalink -rsi %module%.lnk %module%.sfc
head -c 5120 %module%.sfc > out\POWERPAK\%module%.MAP
del %module%.o
del %module%.lnk
goto :eof

:done
echo -- FINISHED! --
pause
