#!/usr/bin/bash

if [ $# -eq 0 ]
then
    echo "usage: setcountrycode [jp|us|eu]"
    echo " Sets the country code on disc."
    exit 0
fi

if [ $1 != "jp" -a $1 != "us" -a $1 != "eu" ]
then
    echo "Illegal argument. Do nothing and exit."
    exit 1
fi

if [ "$NDEV" = "" ]
then
    echo "NDEV is not found. Do nothing and exit."
    exit 0
fi

if [ "$NDEV" != "" ]
then
    echo "NDEV detected"

    #
    # change NDEV configuration
    #

    if [ $1 = "jp" ]
    then
        if $REVOLUTION_SDK_ROOT/x86/bin/tickleBI3 -o "$REVOLUTION_SDK_ROOT/X86/bin/rvl.bin" 0x0 0
        then
            echo "Successfully done. Set the country code for the disc to Japan."
        else
            echo "Failed to set the country code on disc."
            exit 1
        fi
    elif [ $1 = "us" ]
    then
        if $REVOLUTION_SDK_ROOT/x86/bin/tickleBI3 -o "$REVOLUTION_SDK_ROOT/X86/bin/rvl.bin" 0x0 1
        then
            echo "Successfully done. Set the country code for the disc to US."
        else
            echo "Failed to set the country code on disc."
            exit 1
        fi
    elif [ $1 = "eu" ]
    then
        if $REVOLUTION_SDK_ROOT/x86/bin/tickleBI3 -o "$REVOLUTION_SDK_ROOT/X86/bin/rvl.bin" 0x0 2
        then
            echo "Successfully done. Set the country code for the disc to Europe."
        else
            echo "Failed to set the country code on disc."
            exit 1
        fi
    fi

fi

echo
echo "**********************************************************************"
echo "* If you make master data, you must execute ndrun before you do so!! *"
echo "**********************************************************************"
echo
