@echo on

set romtool="%~dp0tool\romtool"
REM You literally can't name the variable XDELTA or it fucks it up.
REM Incredible software design, thank you.
set xdeltapath="%~dp0tool\xdelta3-3_0_11\xdelta3-3.0.11-i686"

REM If you're looking at this file, you probably can just ignore
REM this part and the path setup, and skip to :perform

IF "%~1"=="" GOTO :argerr

:pathset
set workpath=%~dp0work\
set patchpath=%~dp0patches\
if not exist "%workpath%" mkdir "%workpath%"
set inpath=%~1\
set outdir=%~dp0
set outname=%outdir%RSG_EX_STV
set outmultiname=%outdir%file.13
set outbinname="%outname%.bin"
set outbinmultiname="%outmultiname%"

:perform
@ECHO Creating baseline patch EPROM...
%romtool% -e "%workpath%STVPRG.BIN" "%inpath%mpr20958.7" "%inpath%mpr20959.2" "%inpath%mpr20960.3" "%inpath%mpr20961.4" "%inpath%mpr20962.5"
%romtool% -p "%workpath%EPROM.BIN" "%workpath%STVPRG.BIN"

@ECHO Patching EPROM...
%xdeltapath% -f -d -s "%workpath%EPROM.BIN" "%patchpath%EPROM.xdelta3" %outbinname%

@ECHO Creating multigame-compatible ROM file...
%romtool% -i %outbinmultiname% %outbinname%

@ECHO Done!
@pause
@exit /b 0

:argerr
@ECHO Please drag your ROM folder onto this batch.
@pause
@exit /b -1
