@echo off

rem   This is dobbc.btm v1.0 for the 4DOS/4NT command processor from JP Software.

rem   Run this script in a directory containing BBC files and *.INF files.

rem   If no parameter is given, an image named "image.ssd" will be placed in 
rem   the BeebEm\discims directory.  Otherwise the parameter will be used as
rem   the resulting image name.  Do *not* give an extension to this parameter,
rem   as .SSD (or .DSD) will be appended automatically!

rem   If the current directory is empty of files, but contains subdirectories
rem   "0" and "2", two single sided images will be made in %TEMP.  Next, these
rem   images will be joined to one double sided image (*.DSD) named as given above.

rem   Send feedback on this script to rsc@nvg.ntnu.no

setlocal
set image=%1
if "%image"=="" set image=c:\private\bbc\beebem\discims\image
if exist *.inf goto makessd
if not exist 0 goto nofileserror
if not exist 2 goto nofileserror

rem   Recursively handle the two subdirectories to produce two .SSD files.

cd 0
call dobbc %temp\0
cd ..\2
call dobbc %temp\2
cd ..

rem   Now join them.  BeebEm only supports single density images
rem   (10 sectors per track, as opposed to double, which has 18).

bbcim -interss sd %temp\0.ssd %temp\2.ssd %image.dsd
del %temp\0.ssd %temp\2.ssd
goto done

:makessd

rem   Make a .SSD from the files in the current directory.
rem   The %@sfn[] function makes a short file name to make things a bit
rem   easier on bbcim.

del %image%.ssd
except (*.inf *.INF) for %%f in (*) bbcim -a %image%.ssd %@sfn["%f"]
goto done

:nofileserror
echo No *.inf files found, and directories "0" and "2" not found.
goto done

:done
set image=
