@echo Bas2PkG (prepare transfer to Pokecom GO) is running...
@rem Use this script only to create asc files for Pokecom GO
@rem open console,
@rem change to directory and start batch with "bas2PkG FILENAM"
@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 ANDDIRPG=Phone\pokecom
set fnamex=.BAS
set fnamedp=%BASDIR%\
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%;*.PRG;*.ASC;*.SPP;*.SHA;*.shp" "%1"
if not exist %fnamef% (
             echo Error: File %fnamef% does not exist! - Ctrl+C
             goto end
)

bas2img --pc=%SHARPC% %fnamef% %TEMP%\%fnamen%.TMP %BAS2OPT% --quiet
if errorlevel 1 goto end
echo.
echo Bas2img has created an image from the BASIC file.
rem pause

set fnamex=.asc
if exist %fnamedp%\%fnamen%%fnamex% (
    echo Backup existing file %fnamedp%\%fnamen%%fnamex% to *.bak...
    copy %fnamedp%\%fnamen%%fnamex% %fnamedp%%fnamen%.bak
	echo.
)
echo Wav2bin creates a newly formatted %fnamex% file from the image.
rem @echo on
wav2bin  --pc=%SHARPC% --img %TEMP%\%fnamen%.TMP --type=bas %fnamedp%\%fnamen%%fnamex% --utf8=esc --width=0n -w8
rem --quiet
@echo off
if errorlevel 1 goto end
echo.
rem pause

rem copy "%fnamedp%\%fnamen%%fnamex%" %ANDDIRPG%
rem if exist "%ANDDIR%\%fnamedp%\%fnamen%%fnamex%" goto note
echo NOTE:
echo 1. Please copy %fnamen%%fnamex% from %fnamedp%
echo    to your Android device into the app directory:
echo    %ANDDIRPG% 
:note 
echo 2. Use the menu inside of your emulator application to load...
echo    the BASIC file  "%fnamen%%fnamex%" 
echo.
pause

del %TEMP%\%fnamen%.TMP
start "%fnamen%" %EDITOR% %fnamedp%%fnamen%%fnamex%
goto :EOF
:end
pause