////////////////////////////////////////////////////////////////////////////////
//
// File   : Asura_PS3_DiscBootGame.cpp
// Author : Anthony Gregson
//
// Copyright (C) 2009 Rebellion, All Rights Reserved.
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Include Files...
////////////////////////////////////////////////////////////////////////////////
#include "Core/Asura.h"

// Own header
#include "Utility/Asura_PS3_DiscBootGame.h"

// Asura independent
#include "Core/Asura_String.h"
#include "Debugging/Asura_Assert.h"

// Library headers
#include <sysutil/sysutil_discgame.h>

char Asura_PS3_DiscBootGame::s_szProductCode[uASURA_PS3_PRODUCT_CODE_LENGTH];
u_int Asura_PS3_DiscBootGame::s_uParentalLevel = 0;

void Asura_PS3_DiscBootGame::Initialise()
{
	CellDiscGameSystemFileParam xBootDiscInfo;
	memset(&xBootDiscInfo, 0, sizeof(xBootDiscInfo));
	const int iReturnValue = cellDiscGameGetBootDiscInfo(&xBootDiscInfo);
	if (iReturnValue == CELL_DISCGAME_RET_OK)
	{
		Asura_PrintfToBfr(s_szProductCode, xBootDiscInfo.titleId, uASURA_PS3_PRODUCT_CODE_LENGTH, true);
		s_uParentalLevel = xBootDiscInfo.parentalLevel;
	}
	else
	{
		// If we're not booting from the disc (i.e. development versions), this is expected.
		Asura_Assertf(iReturnValue == static_cast<int>(CELL_DISCGAME_ERROR_NOT_DISCBOOT), ("Asura_PS3_DiscBootGame::Initialise, cellDiscGameGetBootDiscInfo FAILED, 0x%08x", iReturnValue));
		Asura_PrintfToBfr(s_szProductCode, "BLUX99999", uASURA_PS3_PRODUCT_CODE_LENGTH, true);
		s_uParentalLevel = 0;
	}
}

void Asura_PS3_DiscBootGame::Shutdown()
{
}

const char* Asura_PS3_DiscBootGame::GetLeadProductCode()
{
#ifdef ASURA_PS3_LEAD_PRODUCT_CODE
	// If we're going to have a specified lead SKU for a region then that product code needs to be defined in.
	return ASURA_PS3_LEAD_PRODUCT_CODE;
#else //#ifdef ASURA_PS3_LEAD_PRODUCT_CODE
	// Otherwise we can use the code we get from the boot info.
	return GetProductCode();
#endif //#else //#ifdef ASURA_PS3_LEAD_PRODUCT_CODE
}
