@echo Wav2Bas is running...
@rem open console, change to directory
@rem and start batch with "wav2bas FILENAM" (without .wav)
@rem FileToOpen needed: http://www.horstmuc.de/win/wfile.zip
@echo off
if not exist GetFName.cmd (
	%~d0
	cd %~dp0
)
if not exist GetFName.cmd if exist ..\GetFName.cmd cd ..
call SHARPSET
set fnamex=.WAV
set fnamedp=%RECDIR%\
if "%RECDIR%" == "" set fnamedp=%WAVDIR%\
set fnamen=%1
set fnamef=%fnamedp%%fnamen%%fnamex%

Rem Note: Filenames with 1-7 characters are recommended!
if not exist %fnamef% call GetFName %fnamedp% "*%fnamex%;*.tap;*.IMG;*.ST" "%1"
if not exist %fnamef% (
             echo Error: File %fnamef% does not exist! - Ctrl+C
             goto end
)

rem @echo on
wav2bin --pc=%SHARPC% --type=c %fnamef% %BASDIR%\%fnamen%.c %WAV2OPT% -w! %2 %3 %4
@echo off
rem if errorlevel 9 goto skip1
if errorlevel 1 goto error

:skip1
echo ---------------------------------------------
echo.
echo Please read the messages above!
pause

start "%fnamen%" %BASDIR%\%fnamen%.c
goto :EOF

:error
if errorlevel 10 goto E10
if errorlevel 9 goto E9
if errorlevel 8 goto E8
if errorlevel 7 goto E7
if errorlevel 6 goto E6
if errorlevel 5 goto E5
if errorlevel 4 goto E4
if errorlevel 3 goto E3
if errorlevel 2 goto E2
if errorlevel 1 goto E1
echo bad error value
goto end

:E10
echo To many minor errors found in the wav file!
echo Last error: %ERRORLEVEL%
goto end
:E9
echo Synchronisation not found or lost inside wav file!
goto end
:E8
echo Checksum error or unexpected end of file!
goto end
:E7
echo Format of the wav file or SHARP data is illegal!
goto end
:E6
echo Buffer/Memory overflow or to long lines!
goto end
:E5
echo File I/O-Error!
goto end
:E4
echo Invalid BASIC line numbers!
goto end
:E3
echo Invalid argument or unsupported device!
goto end
:E2
echo Invalid bit structure of a byte !
goto end
:E1
echo Argument Syntax Error!

:end
pause