@if "%_ECHOON%" == "" echo off :: ############################################################################### :: # :: # Copyright (C) 2009-2013 Nintendo. All rights reserved. :: # :: # These coded instructions, statements, and computer programs contain :: # proprietary information of Nintendo of America Inc. and/or Nintendo :: # Company Ltd., and are protected by Federal copyright law. They may :: # not be disclosed to third parties or copied or duplicated in any form, :: # in whole or in part, without the prior written consent of Nintendo.:::: :: # :: ############################################################################### :: ************************************************************ :: * CAFE - Environment :: ************************************************************ :: From here, variable changes to do not affect environment (unless that's what was asked) for %%i in (%*) do if /i "%%~i" == "-setenv" goto :DONT_SETLOCAL SETLOCAL :DONT_SETLOCAL if NOT DEFINED USE_EXI_AS_DEBUG_CHANNEL ( set USE_EXI_AS_DEBUG_CHANNEL=1 ) :: Default location of CAFE_ROOT (location of cafe.bat) set CAFE_ROOT_DOS=%~dp0 if NOT "%CAFE_ROOT_DOS:~-2%" == ":\" set CAFE_ROOT_DOS=%CAFE_ROOT_DOS:~0,-1% REM if NOT "%CAFE_ROOT%" == "" for %%i in (%CAFE_ROOT%) do set CAFE_ROOT_DOS=%%~fi REM *** REM Set options REM Anything pre-set in the environment takes REM effect, unless overriden by commandline options. if "%USE_MULTI%" == "1" set SESSION_MANAGER=1&& REM Another name for this option REM Commandline (per-invocation) options. Takes precedence. if "%~1" == "" goto :getopt_done set _CMDLINE=%* set CAFE_SHELL_ARGS= REM make sure we don't misinterpret any metacharacters set _CMDLINE=%_CMDLINE:&=$amper$% set _CMDLINE=%_CMDLINE:|=$pipebar$% set _CMDLINE=%_CMDLINE:>=$gtrthan$% set _CMDLINE=%_CMDLINE:<=$lessthan$% setlocal enabledelayedexpansion && REM hackery for percent signs set _CMDLINE=!_CMDLINE:%%=$percent$! endlocal && set _CMDLINE=%_CMDLINE% set _CMDLINE=%_CMDLINE:"=$quote$% call :getopt_loop %_CMDLINE% set _CMDLINE= REM Aborting because of _USAGE? if not "%_USAGE%" == "" set _USAGE=&& goto :END goto :getopt_done :getopt_loop if "%~1" == "" goto :eof REM Keep processing arguments progressively for /f "tokens=1,*" %%i in ("%*") do call :getopt %%~i&call :getopt_loop %%~j goto :eof :getopt set _ARG=%* if not defined _ARG goto :getopt_done for %%i in (-h -help --help) do if "%_ARG:$quote$=%" == "%%i" goto :usage if "%_ARG:$quote$=%" == "-?" goto :usage && REM "-?" doesn't work in "for" loop 8-( if /i "%_ARG:$quote$=%" == "-default" set _SETDEFAULTS=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-setenv" set _CAFE_SETENV=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-cafex" set USE_CAFEX=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-nocafex" set USE_CAFEX=0&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-multi" set SESSION_MANAGER=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-nomulti" set SESSION_MANAGER=0&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-session" set SESSION_MANAGER=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-nosession" set SESSION_MANAGER=0&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-syncsession" set DO_SYNC_SESSION=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-nosyncsession" set DO_SYNC_SESSION=0&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-pcfsoversata" set USE_PCFS_OVER_SATA=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-nopcfsoversata" set USE_PCFS_OVER_SATA=0&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-cygwin" set USE_CYGWIN=1&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-nocygwin" set USE_CYGWIN=0&& goto :getopt_next if /i "%_ARG:$quote$=%" == "-bridge" set _BRIDGE_ARGS=2&& goto :getopt_next if "%_BRIDGE_ARGS%" EQU "2" set BRIDGE_CURRENT_NAME=%_ARG:$quote$="% if "%_BRIDGE_ARGS%" EQU "1" set BRIDGE_CURRENT_IP_ADDRESS=%_ARG:$quote$="% if "%_BRIDGE_ARGS%" GTR "0" set /a _BRIDGE_ARGS=_BRIDGE_ARGS - 1 && goto :getopt_next REM It's not an argument we recognize; add it to the command to be launched. REM Translate all the metacharacters back. for /f "delims=" %%i in ("%_ARG:$amper$=&%") do set _ARG=%%i for /f "delims=" %%i in ("%_ARG:$pipebar$=|%") do set _ARG=%%i for /f "delims=" %%i in ("%_ARG:$gtrthan$=>%") do set _ARG=%%i for /f "delims=" %%i in ("%_ARG:$lessthan$=<%") do set _ARG=%%i setlocal enabledelayedexpansion for /f "delims=" %%i in ("!_ARG:$percent$=%%!") do set _ARG=%%i endlocal && set CAFE_SHELL_ARGS=%CAFE_SHELL_ARGS% %_ARG:$quote$="% :getopt_next set _ARG= goto :eof :getopt_done if "%_BRIDGE_ARGS%" GTR "0" echo Not enough arguments for -bridge option!&& set _BRIDGE_ARGS=&& goto :usage set _BRIDGE_ARGS= REM Read defaults from config file, for anything that's not set yet. set _CONFIG=%APPDATA%\Nintendo\cafe.defaults if NOT EXIST "%_CONFIG%" goto :update_config for /f "tokens=1,2 delims==" %%i in (%_CONFIG%) do call :set_config_value %%i %%j if not exist "%APPDATA%\disable_pcfs_over_sata" goto :update_config REM old "pcfs_over_sata" sentinel exists; update to new config file set USE_PCFS_OVER_SATA=0 set _SETDEFAULTS=1 del /f "%APPDATA%\disable_pcfs_over_sata" 2>nul goto :update_config :set_config_value if "%USE_CAFEX%" == "" if /i "%1" == "USE_CAFEX" set USE_CAFEX=%2 if "%SESSION_MANAGER%" == "" if /i "%1" == "SESSION_MANAGER" set SESSION_MANAGER=%2 if "%SESSION_MANAGER%" == "" if /i "%1" == "USE_MULTI" set SESSION_MANAGER=%2 if "%DO_SYNC_SESSION%" == "" if /i "%1" == "DO_SYNC_SESSION" set DO_SYNC_SESSION=%2 if "%USE_PCFS_OVER_SATA%" == "" if /i "%1" == "USE_PCFS_OVER_SATA" set USE_PCFS_OVER_SATA=%2 if "%USE_CYGWIN%" == "" if /i "%1" == "USE_CYGWIN" set USE_CYGWIN=%2 goto :eof :update_config REM rewrite config file if requested; NOT "thread-safe"! if "%_SETDEFAULTS%" == "" goto :config_done set _CONFIG="%_CONFIG%" for %%i in (%_CONFIG%) do md %%~dpi 2>nul del /f %_CONFIG% 2>nul copy /y NUL %_CONFIG% 1>nul 2>nul if NOT EXIST %_CONFIG% echo WARNING! Could not save options as default! && goto :config_done for %%i in (%_CONFIG%) do if NOT "%%~zi" == "0" echo WARNING! Could not save options as default! && goto :config_done if NOT "%USE_CAFEX%" == "" >>%_CONFIG% echo USE_CAFEX=%USE_CAFEX% if NOT "%SESSION_MANAGER%" == "" >>%_CONFIG% echo SESSION_MANAGER=%SESSION_MANAGER% if NOT "%DO_SYNC_SESSION%" == "" >>%_CONFIG% echo DO_SYNC_SESSION=%DO_SYNC_SESSION% if NOT "%USE_PCFS_OVER_SATA%" == "" >>%_CONFIG% echo USE_PCFS_OVER_SATA=%USE_PCFS_OVER_SATA% if NOT "%USE_CYGWIN%" == "" >>%_CONFIG% echo USE_CYGWIN=%USE_CYGWIN% :config_done set _CONFIG= REM Built in defaults for anything that's not set yet. if "%USE_CAFEX%" == "" set USE_CAFEX=1 if "%USE_PCFS_OVER_SATA%" == "" set USE_PCFS_OVER_SATA=1 if "%SESSION_MANAGER%"=="" set SESSION_MANAGER=0 if "%USE_CYGWIN%" == "" set USE_CYGWIN=1 :: ************************************************************ :: Windows paths (DOS) :: For this script only so Windows can start Cygwin :: NOTE: In cafe.bat shell, this is just "/" if "%USE_CYGWIN%" == "0" goto :no_cygwin_path if "%MSYS_PATH%" == "" if exist C:\MinGW\msys\1.0\msys.bat set MSYS_PATH=C:\MinGW\msys\1.0 if "%CYGWIN_PATH%" == "" if exist C:\cygwin set CYGWIN_PATH=C:\cygwin if "%CYGWIN_PATH%" == "" if not "%MSYS_PATH%" == "" set CYGWIN_PATH=%MSYS_PATH% if "%CYGWIN_PATH%" == "" goto cygwin_error if not exist %CYGWIN_PATH% echo %CYGWIN_PATH% not found! && goto cygwin_error if not "%CAFE_TERM_USE%" == "" if not exist "%CAFE_TERM_USE%" echo %CAFE_TERM_USE% not found! && goto cygwin_error if not exist %CYGWIN_PATH%\bin\mintty.exe if not exist %CYGWIN_PATH%\bin\bash.exe echo bash.exe/mintty.exe not found in %CYGWIN_PATH%\bin! && goto cygwin_error :no_cygwin_path if "%USE_CYGWIN%" == "0" goto :no_use_cygwin if not exist %CYGWIN_PATH%\bin\cygcheck.exe goto :no_check_cygcheck :: ************************************************************ :: Cygwin paths (UNIX) for /F "usebackq delims=" %%s in (`%CYGWIN_PATH%\bin\cygcheck -c cygwin ^| %CYGWIN_PATH%\bin\grep -m 1 "^cygwin .*1.7"`) do (set CYGCHECK=%%s) if "%CYGCHECK%" == "" echo WARNING: This version of cygwin is not supported. The expected version is 1.7.x for /f %%i in ('%CYGWIN_PATH%\bin\uname -m 2^>nul') do if "%%i" == "x86_64" echo WARNING: 64-bit Cygwin is not supported. You should install the 32-bit version! :no_check_cygcheck REM Find Cygwin or MSYS/MinGW version of cygpath.exe set _CYGPATH_DIR=%CYGWIN_PATH%\bin if not exist %_CYGPATH_DIR%\cygpath.exe set _CYGPATH_DIR=%CAFE_ROOT_DOS%\system\bin\tool\msys if not exist %_CYGPATH_DIR%\cygpath.exe set _CYGPATH_DIR=%CAFE_ROOT_DOS%\system\src\tool\bin\msys if not exist %_CYGPATH_DIR%\cygpath.exe echo Could not find cygpath.exe in your environment! && goto :END :no_use_cygwin :: Convert CAFE_ROOT_DOS to UNIX-style path :: NOTE: If CAFE_ROOT_DOS is a directory under CYGWIN_PATH (i.e. home), please :: manually set CAFE_ROOT below to use /cygdrive/ as starting path that the build system requires. :: An alternative is to set your enviroment variable HOME to your home :: directory using UNIX-style (e.g., /cygdrive/c/Users/me) :: call:convert_dos_to_unix_path "CAFE_ROOT","%CAFE_ROOT_DOS%" :: Default environment for disc emulation directory if not set by Windows :: Clear the default flags in case we call cafe.bat from another cafe.bat. set CAFE_CONTENT_DEFAULT= set CAFE_META_DEFAULT= set CAFE_SAVE_DEFAULT= set CAFE_SLC_DEFAULT= set CAFE_MLC_DEFAULT= if "%CAFE_CONTENT_DIR%"=="" ( set CAFE_CONTENT_DEFAULT=1 set CAFE_CONTENT_DIR=%CAFE_ROOT%/data/disc/content ) call:convert_dos_to_unix_path "CAFE_CONTENT_DIR","%CAFE_CONTENT_DIR%" :: Default environment for FSA /vol/meta if not set by Windows if "%CAFE_META_DIR%"=="" ( set CAFE_META_DEFAULT=1 set CAFE_META_DIR=%CAFE_ROOT%/data/disc/meta ) call:convert_dos_to_unix_path "CAFE_META_DIR","%CAFE_META_DIR%" :: Default environment for FSA /vol/save if not set by Windows if "%CAFE_SAVE_DIR%"=="" ( set CAFE_SAVE_DEFAULT=1 set CAFE_SAVE_DIR=%CAFE_ROOT%/data/save ) call:convert_dos_to_unix_path "CAFE_SAVE_DIR","%CAFE_SAVE_DIR%" :: Default environment for SLC emulation directory if not set by Windows if "%CAFE_SLC_DIR%"=="" ( set CAFE_SLC_DEFAULT=1 set CAFE_SLC_DIR=%CAFE_ROOT%/data/slc ) call:convert_dos_to_unix_path "CAFE_SLC_DIR","%CAFE_SLC_DIR%" :: Default environment for MLC emulation directory if not set by Windows if "%CAFE_MLC_DIR%"=="" ( set CAFE_MLC_DEFAULT=1 set CAFE_MLC_DIR=%CAFE_ROOT%/data/mlc ) call:convert_dos_to_unix_path "CAFE_MLC_DIR","%CAFE_MLC_DIR%" :: Default Mastering Tools directory if "%CAFE_MASTERING_TOOLS%"=="" set CAFE_MASTERING_TOOLS=%CAFE_ROOT%/system/bin/tool/mastering if "%CAFE_MASTERING_TOOLS%"=="%CAFE_ROOT%/system/bin/tool/mastering" set PATH=%CAFE_MASTERING_TOOLS%;%PATH% call:convert_dos_to_unix_path "CAFE_MASTERING_TOOLS","%CAFE_MASTERING_TOOLS%" :: Default TEMP directory if "%CAFE_TEMP%"=="" set CAFE_TEMP=%CAFE_ROOT%/temp/%USERNAME% if not exist "%CAFE_ROOT_DOS%/temp/%USERNAME%" mkdir "%CAFE_ROOT_DOS%/temp/%USERNAME%" call:convert_dos_to_unix_path "CAFE_TEMP","%CAFE_TEMP%" :: Default boot mode :: Causes a system to boot from PCFS or NAND if "%CAFE_BOOT_MODE%" =="" set CAFE_BOOT_MODE=PCFS :: SDK_VER set SDK_VER=0.00.00 if not exist "%CAFE_ROOT_DOS%/system/include/sdk_ver.h" goto :no_sdk_ver for /F "usebackq tokens=1,2,3" %%i in ("%CAFE_ROOT_DOS%/system/include/sdk_ver.h") do if "%%i" == "#define" if "%%j" == "CAFE_OS_SDK_VERSION" set ver=%%k if not "%ver%" == "" set SDK_VER=%ver:~0,-4%.%ver:~-4,-2%.%ver:~-2% :no_sdk_ver :: Check if HBM app.xml files are present set SHOW_HBM_WARNING=0 if %USE_CYGWIN% == 1 ( call:convert_unix_to_dos_path "CAFE_MLC_DIR_DOS", %CAFE_MLC_DIR% ) else set CAFE_MLC_DIR_DOS=%CAFE_MLC_DIR% if not exist "%CAFE_MLC_DIR_DOS%\sys\title\00050030\1001000a\code\app.xml" set SHOW_HBM_WARNING=1 if not exist "%CAFE_MLC_DIR_DOS%\sys\title\00050030\1001010a\code\app.xml" set SHOW_HBM_WARNING=1 if not exist "%CAFE_MLC_DIR_DOS%\sys\title\00050030\1001020a\code\app.xml" set SHOW_HBM_WARNING=1 if %SHOW_HBM_WARNING% == 1 ( if %CAFE_BOOT_MODE% == PCFS ( echo Warning: Some system applications on the system might be missing. If the system fails to boot, please reinstall the SDK to restore the missing system applications and run cafeupdate. ) ) :: ************************************************************ :: Green Hills paths set GHS_ROOT_FROM_ENV="%GHS_ROOT%" if not "%GHS_ROOT%"=="" goto ghs_root_set :: No GHS_ROOT specified. :: Accept an installed version as new as the one in the first set below, :: otherwise search for increasingly older versions until the oldest allowed. set GHS_ROOT=C:\ghs\multi5322 :ghs_root_set :: Now have a selected version. Sanity check it. if exist "%GHS_ROOT%\multi.exe" goto multi_ok echo. echo ************************************* echo WARNING: GHS MULTI.EXE not found at %GHS_ROOT%\ echo. echo YOU MUST ACQUIRE AND INSTALL MULTI TO BUILD echo. echo ************************************* set CAFE_GHS_VERSION="bad" goto done_set_toolchain :multi_ok if exist "%GHS_ROOT%\gversion.exe" goto version_ok echo. echo ************************************* echo WARNING: GHS GVERSION.EXE not found at %GHS_ROOT%\ echo. echo THERE IS SOMETHING WRONG WITH YOUR GHS INSTALLATION echo. echo ************************************* set CAFE_GHS_VERSION="bad" goto done_set_toolchain :version_ok :: assume correct version, check_ghs_version will set version to last :: incorrect version seen set CAFE_GHS_VERSION_EXPECT=v5.3.22 P0 :: because of windows treating v5.3.1 as greater than v5.3.1 P1 :: if there is not a patch number add " P0" set CAFE_GHS_VERCMP_EXPECT=v5.3.22 P0 set CAFE_GHS_VERSION=%CAFE_GHS_VERSION_EXPECT% set CAFE_GHS_VERCMP=%CAFE_GHS_VERCMP_EXPECT% :: check minimum versions supported call:check_ghs_version asppc, "v5.3.22", " P0" call:check_ghs_version ccppc, "v5.3.22", " P0" call:check_ghs_version cxppc, "v5.3.22", " P0" call:check_ghs_version ecomppc, "v5.3.22", " P0" call:check_ghs_version dblink, "v5.3.22", " P0" call:check_ghs_version elxr, "v5.3.22", " P0" call:check_ghs_version multi, "v5.3.22", " P0" call:check_ghs_version cafeserv, "v5.3.22", " P0" :: GUI version must check the date :: call:check_ghs_version_date cafeserv, "v5.0.6", " P0", 1297317659, "Wed Feb 09 22:00:59 PST 2011" if "%CAFE_GHS_VERSION%"=="" set CAFE_GHS_VERSION="unknown" call:convert_dos_to_unix_path "GHS_ROOT","%GHS_ROOT%" set CAFE_GHS_TLS_AVAILABLE=FALSE if "%CAFE_GHS_VERSION%" GEQ "v5.3.20" ( set CAFE_GHS_TLS_AVAILABLE=TRUE ) set CAFE_GHS_SUPPORTS_MAKERPL_DBG_SOURCE_ROOT=FALSE if "%CAFE_GHS_VERSION%" GEQ "v5.3.21" ( set CAFE_GHS_SUPPORTS_MAKERPL_DBG_SOURCE_ROOT=TRUE ) set CAFE_GHS_SUPPORTS_MAKERPL_DBG_SOURCE_ROOT=FALSE if "%CAFE_GHS_VERSION%" GEQ "v5.3.21" ( set CAFE_GHS_SUPPORTS_MAKERPL_DBG_SOURCE_ROOT=TRUE ) if "%CAFE_GHS_VERCMP%" GEQ "%CAFE_GHS_VERCMP_EXPECT%" goto ghs_version_ok echo. echo ********************************************************** echo Newer version of GHS tools %CAFE_GHS_VERSION_EXPECT% is available please update echo. echo Copy MULTI5322_Nintendo.zip. echo Expand and run MULTI5322_Nintendo/setup_windows.exe. echo Do not install over 5.3.21. Install to echo a new directory, for example: echo C:/ghs/multi5322 echo. echo then exit cafe.bat and rerun cafe.bat echo. if not "GHS_ROOT_FROM_ENV"=="" ( echo If you have GHS_ROOT set in your environment to point to echo %GHS_ROOT% echo please update the system environment variable "GHS_ROOT" echo (Windows Control Panel - System - Advanced System Settings echo - Environment Variables) ) echo ********************************************************** :ghs_version_ok :done_set_toolchain :: ************************************************************ :: SDK environment variables set TOOLCHAIN=ghs set USE_GHS=1 set CAFE_USE_RPZ=0 set Platform= set PLATFORM=cafe :: Default output [cattoucan | toucan] if "%CAFE_CONSOLE%"=="" set CAFE_CONSOLE=cattoucan :: Default hardware board connected to PC for [catdevmp|catdev4] if "%CAFE_HARDWARE%"=="" set CAFE_HARDWARE=catdevmp :: ************************************************************ :: ************************************************************ :: * :: * DO NOT MODIFY BELOW HERE :: * :: ************************************************************ :: PATH (Cygwin will add Windows PATH environment variable) set PATH=%CAFE_ROOT%/system/bin/tool;%CAFE_ROOT%/system/bin/win32;%PATH% REM If we're in an MSYS window, not Cygwin, add special MSYS-related tools to the PATH if NOT "%USE_CYGWIN%" == "0" if not exist %CYGWIN_PATH%\bin\cygwin1.dll set PATH=%PATH%;%_CYGPATH_DIR% :: Cygwin setup if NOT "%USE_CYGWIN%" == "0" set CYGWIN=nodosfilewarning :: ************************************************************ :: Bridge environment variables if "%USE_SINGLE_CGI%" == "" set USE_SINGLE_CGI=1 if not "%BRIDGE_CURRENT_NAME%"=="" goto :skip_mion if not exist "%MION_BRIDGE_TOOLS%\getbridgeconfig.exe" goto skip_mion :mion_name for /f "usebackq tokens=5" %%i in (`"%MION_BRIDGE_TOOLS%\getbridgeconfig.exe" -default`) do ( set BRIDGE_CURRENT_NAME=%%i goto mion_ip_address ) :mion_ip_address for /f "usebackq skip=1 tokens=5" %%i in (`"%MION_BRIDGE_TOOLS%\getbridgeconfig.exe" -default`) do ( set BRIDGE_CURRENT_IP_ADDRESS=%%i ) :skip_mion :: Match boot mode w/ what is running on the CAT-DEV if "%BRIDGE_CURRENT_IP_ADDRESS%"=="" goto nand_mode_set set MIONPS_PATH=%CAFE_ROOT_DOS%\system\bin\tool\mionps.exe if not exist "%MIONPS_PATH%" set MIONPS_PATH=%CAFE_ROOT_DOS%\system\src\tool\mionps\bin\win32\mionps.exe :: Match SDK Version w/ what is running on the CAT-DEV for /f "tokens=1,2,3,4 delims= " %%G in ('"%MIONPS_PATH%" %BRIDGE_CURRENT_IP_ADDRESS% 2 3 4 5') do (set NAND_MODE_BIT=%%G&set SDK_MAJ_VER=%%H&set SDK_MIN_VER=%%I&set SDK_MIC_VER=%%J); if "%NAND_MODE_BIT%"=="ERROR!" ( echo *** Your CAT-DEV is not accessible. It might be powered off or offline *** goto nand_mode_set ) set SDK_MIN_VER=0%SDK_MIN_VER% set SDK_MIN_VER=%SDK_MIN_VER:~-2% set SDK_MIC_VER=0%SDK_MIC_VER% set SDK_MIC_VER=%SDK_MIC_VER:~-2% if not "%SDK_MAJ_VER%.%SDK_MIN_VER%.%SDK_MIC_VER%" == "%SDK_VER%" ( echo. echo !!! Your CAT-DEV is not at the same level as this SDK. !!! echo SDK Version: %SDK_VER% CAT-DEV SDK Version: %SDK_MAJ_VER%.%SDK_MIN_VER%.%SDK_MIC_VER% echo !!! Please run cafeupdate to get them in sync. !!! echo. ) :nand_mode_set if "%NAND_MODE_BIT%"=="1" ( set CAFE_BOOT_MODE=NAND ) :: ************************************************************ :: Set the session specific variables and paths call:initsession if "%ERRORLEVEL%"=="5" ( exit /b %ERRORLEVEL% ) REM Clean up temporary variables set _CYGPATH_DIR= :: ************************************************************ :: If the extra arguments exist, skip echos. if DEFINED CAFE_SHELL_ARGS goto RUN_BASH @echo ========================================================== @echo Welcome to the Nintendo CAFE! @echo ========================================================== @echo Environment initialized for this session only. @echo SDK_VER = %SDK_VER% @echo CAFE_ROOT = %CAFE_ROOT% @echo CAFE_HARDWARE = %CAFE_HARDWARE% @echo CAFE_BOOT_MODE = %CAFE_BOOT_MODE% @if /i "%TOOLCHAIN%"=="ghs" echo GHS_ROOT = %GHS_ROOT% @if /i "%TOOLCHAIN%"=="ghs" echo CAFE_GHS_VERSION = "%CAFE_GHS_VERSION%" @echo CAFE_CONTENT_DIR = %CAFE_CONTENT_DIR% @echo CAFE_SAVE_DIR = %CAFE_SAVE_DIR% @echo CAFE_META_DIR = %CAFE_META_DIR% @echo CAFE_SLC_DIR = %CAFE_SLC_DIR% @echo CAFE_MLC_DIR = %CAFE_MLC_DIR% if "%BRIDGE_CURRENT_NAME%"=="" goto DONOTECHOMION @echo Current bridge = %BRIDGE_CURRENT_NAME% @echo Bridge IP Addr = %BRIDGE_CURRENT_IP_ADDRESS% :DONOTECHOMION @if "%SESSION_MANAGER%"=="1" ( @echo SESSION_NAME = %SESSION_NAME% @echo HIO_OUT_PORT = %SESSION_HIO_OUT_PORT% @echo CAFE_DATA_DIR = %CAFE_DATA_DIR% ) @echo. @echo ---------------------------------------------------------- :RUN_BASH if "%USE_CYGWIN%" == "0" goto :USE_CMD :: Copy cafe.sh in /etc/profile.d to update the title md %CYGWIN_PATH%\etc\profile.d >nul 2>&1 if "%SESSION_MANAGER%"=="1" copy "%CAFE_ROOT_DOS%\system\bin\tool\cafe_profile.sh" "%CYGWIN_PATH%\etc\profile.d\cafe.sh" > nul :: The extra arguments are for the buildsystem if "%CAFE_USE_MINTTY%" == "" goto USE_ENV if not exist "%CYGWIN_PATH%\bin\mintty.exe" goto USE_BASH echo Running mintty. %CYGWIN_PATH%\bin\mintty -e %CYGWIN_PATH%\bin\bash --login -i %* goto EXIT :USE_ENV if "%CAFE_TERM_USE%" == "" goto USE_BASH if not exist "%CAFE_TERM_USE%" goto USE_BASH echo Running user supplied terminal or shell. call %CAFE_TERM_USE% goto EXIT :USE_BASH %CYGWIN_PATH%\bin\bash --login -i %CAFE_SHELL_ARGS% goto :EXIT :USE_CMD set _TITLE=Nintendo CAFE if NOT "%BRIDGE_CURRENT_NAME%" == "" set _TITLE=%_TITLE% for %BRIDGE_CURRENT_NAME% (%BRIDGE_CURRENT_IP_ADDRESS%) REM If we're not opening a new window, just change the title and exit. if "%_CAFE_SETENV%" == "" goto :USE_CMD_NEWWINDOW title %_TITLE% set _CAFE_SETENV= set _TITLE= if DEFINED CAFE_SHELL_ARGS call %CAFE_SHELL_ARGS% goto :EXIT :USE_CMD_NEWWINDOW REM We want to update the title bar, but just for this invocation. Since we can't REM read the value of the current title bar, we'll just create a little batch file REM which sets the title, then when it exits the original title will be reset. set _TEMPSCRIPT=%CAFE_TEMP%\tmpcafe_%RANDOM%%BRIDGE_CURRENT_IP_ADDRESS%.bat del /f /q %_TEMPSCRIPT% >nul 2>&1 echo @title %_TITLE% > %_TEMPSCRIPT% if DEFINED CAFE_SHELL_ARGS >> %_TEMPSCRIPT% echo @cmd /c %CAFE_SHELL_ARGS% if DEFINED CAFE_SHELL_ARGS cmd /c %_TEMPSCRIPT% if NOT DEFINED CAFE_SHELL_ARGS cmd /k %_TEMPSCRIPT% set _TEMP_ERRORLEVEL=%ERRORLEVEL% del /f /q %_TEMPSCRIPT% >nul 2>&1 set ERRORLEVEL=%_TEMP_ERRORLEVEL% set _TEMP_ERRORLEVEL= set _TITLE= set _TEMPSCRIPT= goto :EXIT :EXIT :: Propagate error code from bash exit /b %ERRORLEVEL% :: ************************************************************ :: * :: * FUNCTIONS :: * :: ************************************************************ :convert_dos_to_unix_path if "%USE_CYGWIN%" == "0" for %%i in (%2) do set %~1=%%~fi& goto :eof for /F "delims=" %%s in ('%_CYGPATH_DIR%\cygpath "%~2"') do (set %~1=%%s) goto :eof :convert_unix_to_dos_path for /F "delims=" %%s in ('%_CYGPATH_DIR%\cygpath.exe -w "%~2"') do (set %~1=%%s) goto :eof :initsession :: See if we have a Current Bridge set. If not, disable multi-session :: this can happen right after install before setting the default bridge if "%BRIDGE_CURRENT_NAME%"=="" ( set SESSION_MANAGER=0 ) if not "%SESSION_MANAGER%"=="1" goto :no_session_manager :: See if SessionManager is available. If not, fail soince we are enabled for multi-session if not exist "%MION_BRIDGE_TOOLS%\SessionManager.dll" ( echo. echo ERROR: SessionManager.dll not found and multi-CATDEV is enabled! echo. Please install HostBridge version 3.2.2.3+ or disable the multi-CATDEV feature. set /p x= exit /b 5 ) :: Call the SessionManager to get the session information for /f "usebackq tokens=1,2,3,4,5,6,7" %%a in (`"%MION_BRIDGE_TOOLS%\SessionManagerUtil" -p NAME DEBUG_OUT DEBUG_CONTROL HIO_OUT LAUNCH_CTRL NET_MANAGE PCFS_SATA`) do ( set SESSION_NAME=%%a set SESSION_DEBUG_OUT_PORT=%%b set SESSION_DEBUG_CONTROL_PORT=%%c set SESSION_HIO_OUT_PORT=%%d set SESSION_LAUNCH_CTRL_PORT=%%e set SESSION_NET_MANAGE_PORT=%%f set SESSION_PCFS_SATA_PORT=%%g ) set SESSION_PATH_PREFIX=%SESSION_NAME%_ call :convert_dos_to_unix_path CAFE_DATA_DIR "%CAFE_ROOT%/%SESSION_PATH_PREFIX%data" if "%CAFE_CONTENT_DEFAULT%"=="1" call :convert_dos_to_unix_path CAFE_CONTENT_DIR "%CAFE_DATA_DIR%/disc/content" if "%CAFE_META_DEFAULT%"=="1" call :convert_dos_to_unix_path CAFE_META_DIR "%CAFE_DATA_DIR%/disc/meta" if "%CAFE_SAVE_DEFAULT%"=="1" call :convert_dos_to_unix_path CAFE_SAVE_DIR "%CAFE_DATA_DIR%/save" if "%CAFE_SLC_DEFAULT%"=="1" call :convert_dos_to_unix_path CAFE_SLC_DIR "%CAFE_DATA_DIR%/slc" if "%CAFE_MLC_DEFAULT%"=="1" call :convert_dos_to_unix_path CAFE_MLC_DIR "%CAFE_DATA_DIR%/mlc" call :convert_dos_to_unix_path CAFE_DATA_TMP "%CAFE_DATA_DIR%/tmp" if "%DO_SYNC_SESSION%" == "0" set CAFERUN_OPTION_NO_DATA_SYNC=1 goto :eof :no_session_manager :: SessionManager disabled or not present set SESSION_NAME= set SESSION_DEBUG_OUT_PORT=6001 set SESSION_DEBUG_CONTROL_PORT=6002 set SESSION_HIO_OUT_PORT=6003 set SESSION_LAUNCH_CTRL_PORT=6006 set SESSION_NET_MANAGE_PORT=6008 set SESSION_PCFS_SATA_PORT=7500 set SESSION_PATH_PREFIX= call :convert_dos_to_unix_path CAFE_DATA_DIR "%CAFE_ROOT%/data" goto :eof :check_ghs_version :: Expect something like (without quotes; note trailing space): :: "C:\ghs\multi5317\asppc: Green Hills Software, MULTI v5.3.17 Nintendo " for /f "usebackq tokens=6,*" %%i in (`"%GHS_ROOT%\gversion" -nomtime -quiet 1 %GHS_ROOT%\%~1`) do ( set verstr=%%i %%j set verbase=%%i ) for /f "tokens=1,2,3 delims=. " %%i in ("%verbase%") do ( set v1=%%i set v2=%%j set v3=%%k ) for /f "tokens=1,2,3 delims=. " %%i in ("%~2%") do ( set in_v1=%%i set in_v2=%%j set in_v3=%%k ) set /a delta=%v3% - %in_v3% set delta=%delta:-=N% set verstr=%verstr: Nintendo = % :: remove upto 7 trailing blanks set verstr=%verstr%XXXXX set verstr=%verstr: XXXXX=XXXXX% set verstr=%verstr: XXXXX=XXXXX% set verstr=%verstr: XXXXX=XXXXX% set verstr=%verstr:XXXXX=% if "%verbase%" == "%verstr%" ( set vercmp=%verstr% P0 ) else ( set vercmp=%verstr% ) set fixversion=%verbase:*.% if "%~2%~3" == "%vercmp%" goto :ghs_verok :: if versions don't match and have not been changed yet change them if not "%CAFE_GHS_VERCMP%" == "%CAFE_GHS_VERCMP_EXPECT%" goto :ghs_noverchange set CAFE_GHS_VERCMP=%vercmp% set CAFE_GHS_VERSION=%verstr% :ghs_noverchange if "%in_v1% %in_v2%" NEQ "%v1% %v2%" ( echo "%in_v1% %in_v2% vs %v1% %v2%" echo Warning: %~1 %verstr% version is not supported expect %~2 goto :ghs_verok ) if "%delta%" GEQ "N" ( echo Warning: %~1 %verstr% version is older than %~2 :: ) else ( :: echo Info: %~1 %verstr% version is newer than %~2 ) :ghs_verok set verstr= set vercmp= set verbase= goto :eof :check_ghs_version_date for /f "usebackq skip=1 tokens=3" %%i in (`"%GHS_ROOT%\gversion" -value 0 %GHS_ROOT%\%~1`) do ( set verdatenum=%%i ) if "%~4" == "%verdatenum%" goto :ghs_verdateok for /f "usebackq tokens=6,*" %%i in (`"%GHS_ROOT%\gversion" -nomtime -quiet 1 %GHS_ROOT%\%~1`) do ( set verstr=%%i %%j set verbase=%%i ) set verstr=%verstr: Nintendo = % set verstr=%verstr%XXXXX set verstr=%verstr: XXXXX=XXXXX% set verstr=%verstr: XXXXX=XXXXX% set verstr=%verstr: XXXXX=XXXXX% set verstr=%verstr:XXXXX=% if "%verbase%" == "%verstr%" ( set vercmp=%verstr% P0 ) else ( set vercmp=%verstr% ) for /f "usebackq skip=2 tokens=4,*" %%i in (`"%GHS_ROOT%\gversion" %GHS_ROOT%\%~1`) do ( set verdatestr=%verstr% %%i %%j ) :: remove upto 7 trailing blanks set verdatestr=%verdatestr%XXXXX set verdatestr=%verdatestr: XXXXX=XXXXX% set verdatestr=%verdatestr: XXXXX=XXXXX% set verdatestr=%verdatestr: XXXXX=XXXXX% set verdatestr=%verdatestr:XXXXX=% if "%verdatenum%" LSS "%~4" ( echo Warning: %~1 %verdatestr% version is older then expected %~2 %~5 ) else ( echo Info: %~1 %verdatestr% version is newer than %~2 %~5 ) :: only change if it is not already changed :: this assumes no mixed installations :: and date compares have confusing version strings :: as in v5.0.6 is newer then v5.3.0 P2 if "%CAFE_GHS_VERCMP%" == "%CAFE_GHS_VERCMP_EXPECT%" ( set CAFE_GHS_VERSION=%verdatestr% set CAFE_GHS_VERCMP=%verdatestr% ) :ghs_verdateok set verstr= set verstr2= set verdatestr= goto :eof :cygwin_error echo Error: Can't find Cygwin. Please set CYGWIN_PATH or use install_cygwin.bat pause exit /b 1 goto :eof :usage echo. echo ================================================== echo NINTENDO CAFE ENVIRONMENT! echo ================================================== echo. echo Usage: %~nx0 [options] [shell command] echo. echo Options: echo -cafex Use CafeX to run applications (default) echo -nocafex Do not use CafeX; uses Cygwin shell scripts echo -multi Enable multisession CAFE support echo -nomulti Do not enable multisession support (default) echo -syncsession Copy per-session files (default) echo -nosyncsession Do not copy files; data files shared across sessions echo -pcfsoversata Enable PCFS over SATA (default) echo -nopcfsoversata Disable PCFS over SATA; use PCFS over SDIO echo -cygwin Use Cygwin (default) echo -nocygwin Do not use Cygwin; for running apps only echo -setenv With -nocygwin, modify the current environment echo instead of opening a new window for Cafe echo. echo -bridge ^ ^ echo Temporarily set current bridge for this window echo. echo -default Save these settings for future use echo. echo Any shell command is executed automatically in the CAFE environment. set _USAGE=1 goto :eof :END ENDLOCAL