#include "stdafx.h"
#include "Emu/SysCalls/SysCalls.h"
#include "Emu/SysCalls/SC_FUNC.h"

enum
{
	CELL_SYSUTIL_SYSTEMPARAM_ID_LANG							= 0x0111,
	CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN				= 0x0112,
	CELL_SYSUTIL_SYSTEMPARAM_ID_DATE_FORMAT						= 0x0114,
	CELL_SYSUTIL_SYSTEMPARAM_ID_TIME_FORMAT						= 0x0115,
	CELL_SYSUTIL_SYSTEMPARAM_ID_TIMEZONE						= 0x0116,
	CELL_SYSUTIL_SYSTEMPARAM_ID_SUMMERTIME						= 0x0117,
	CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL				= 0x0121,
	CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL0_RESTRICT	= 0x0123,
	CELL_SYSUTIL_SYSTEMPARAM_ID_CURRENT_USER_HAS_NP_ACCOUNT		= 0x0141,
	CELL_SYSUTIL_SYSTEMPARAM_ID_CAMERA_PLFREQ					= 0x0151,
	CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_RUMBLE						= 0x0152,
	CELL_SYSUTIL_SYSTEMPARAM_ID_KEYBOARD_TYPE					= 0x0153,
	CELL_SYSUTIL_SYSTEMPARAM_ID_JAPANESE_KEYBOARD_ENTRY_METHOD	= 0x0154,
	CELL_SYSUTIL_SYSTEMPARAM_ID_CHINESE_KEYBOARD_ENTRY_METHOD	= 0x0155,
	CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_AUTOOFF						= 0x0156,
};

enum
{
	CELL_SYSUTIL_LANG_JAPANESE		= 0,
	CELL_SYSUTIL_LANG_ENGLISH_US	= 1,
	CELL_SYSUTIL_LANG_FRENCH		= 2,
	CELL_SYSUTIL_LANG_SPANISH		= 3,
	CELL_SYSUTIL_LANG_GERMAN		= 4,
	CELL_SYSUTIL_LANG_ITALIAN		= 5,
	CELL_SYSUTIL_LANG_DUTCH			= 6,
	CELL_SYSUTIL_LANG_PORTUGUESE_PT	= 7,
	CELL_SYSUTIL_LANG_RUSSIAN		= 8,
	CELL_SYSUTIL_LANG_KOREAN		= 9,
	CELL_SYSUTIL_LANG_CHINESE_T		= 10,
	CELL_SYSUTIL_LANG_CHINESE_S		= 11,
	CELL_SYSUTIL_LANG_FINNISH		= 12,
	CELL_SYSUTIL_LANG_SWEDISH		= 13,
	CELL_SYSUTIL_LANG_DANISH		= 14,
	CELL_SYSUTIL_LANG_NORWEGIAN		= 15,
	CELL_SYSUTIL_LANG_POLISH		= 16,
	CELL_SYSUTIL_LANG_PORTUGUESE_BR	= 17,
	CELL_SYSUTIL_LANG_ENGLISH_GB	= 18,
};

enum
{
	CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CIRCLE = 0,
	CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CROSS	= 1,
};

enum
{
	CELL_SYSUTIL_DATE_FMT_YYYYMMDD = 0,
	CELL_SYSUTIL_DATE_FMT_DDMMYYYY = 1,
	CELL_SYSUTIL_DATE_FMT_MMDDYYYY = 2,
};

enum
{
	CELL_SYSUTIL_TIME_FMT_CLOCK12 = 0,
	CELL_SYSUTIL_TIME_FMT_CLOCK24 = 1,
};

enum
{
	CELL_SYSUTIL_GAME_PARENTAL_OFF		= 0,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL01	= 1,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL02	= 2,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL03	= 3,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL04	= 4,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL05	= 5,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL06	= 6,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL07	= 7,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL08	= 8,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL09	= 9,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL10	= 10,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL11	= 11,
};

enum
{
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL0_RESTRICT_OFF	= 0,
	CELL_SYSUTIL_GAME_PARENTAL_LEVEL0_RESTRICT_ON	= 1,
};

enum
{
	CELL_SYSUTIL_CAMERA_PLFREQ_DISABLED			= 0,
	CELL_SYSUTIL_CAMERA_PLFREQ_50HZ				= 1,
	CELL_SYSUTIL_CAMERA_PLFREQ_60HZ				= 2,
	CELL_SYSUTIL_CAMERA_PLFREQ_DEVCIE_DEPEND	= 4,
};

enum
{
	CELL_SYSUTIL_PAD_RUMBLE_OFF	= 0,
	CELL_SYSUTIL_PAD_RUMBLE_ON	= 1,
};

void cellSysutil_init();
Module cellSysutil(0x0015, cellSysutil_init);

int cellVideoOutGetDeviceInfo(u32 videoOut, u32 deviceIndex, mem_struct_ptr_t<CellVideoOutDeviceInfo> info)
{
	cellSysutil.Error("Unimplemented function: cellVideoOutGetDeviceInfo(videoOut=%u, deviceIndex=%u, info_addr=0x%x)",
		videoOut, deviceIndex, info.GetAddr());

	if(deviceIndex) return CELL_VIDEO_OUT_ERROR_DEVICE_NOT_FOUND;

	//info->portType = CELL_VIDEO_OUT_PORT_HDMI;
	info->colorSpace = Emu.GetGSManager().GetColorSpace();
	//info->latency = ;
	//info->availableModeCount = ;
	//info->state = CELL_VIDEO_OUT_DEVICE_STATE_AVAILABLE;
	//info->rgbOutputRange = ;
	
	return CELL_OK;
}

int cellSysutilGetSystemParamInt(int id, mem32_t value)
{
	cellSysutil.Log("cellSysutilGetSystemParamInt(id=0x%x, value_addr=0x%x)", id, value.GetAddr());

	if(!value.IsGood())
	{
		return CELL_EFAULT;
	}

	switch(id)
	{
	case CELL_SYSUTIL_SYSTEMPARAM_ID_LANG:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_LANG");
		value = CELL_SYSUTIL_LANG_ENGLISH_US;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN");
		value = CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CROSS;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_DATE_FORMAT:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_DATE_FORMAT");
		value = CELL_SYSUTIL_DATE_FMT_DDMMYYYY;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_TIME_FORMAT:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_TIME_FORMAT");
		value = CELL_SYSUTIL_TIME_FMT_CLOCK24;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_TIMEZONE:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_TIMEZONE");
		value = 3;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_SUMMERTIME:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_SUMMERTIME");
		value = 1;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL");
		value = CELL_SYSUTIL_GAME_PARENTAL_OFF;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL0_RESTRICT:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL0_RESTRICT");
		value = CELL_SYSUTIL_GAME_PARENTAL_LEVEL0_RESTRICT_OFF;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_CURRENT_USER_HAS_NP_ACCOUNT:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_CURRENT_USER_HAS_NP_ACCOUNT");
		value = 0;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_CAMERA_PLFREQ:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_CAMERA_PLFREQ");
		value = CELL_SYSUTIL_CAMERA_PLFREQ_DISABLED;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_RUMBLE:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_RUMBLE");
		value = CELL_SYSUTIL_PAD_RUMBLE_OFF;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_KEYBOARD_TYPE:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_KEYBOARD_TYPE");
		value = 0;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_JAPANESE_KEYBOARD_ENTRY_METHOD:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_JAPANESE_KEYBOARD_ENTRY_METHOD");
		value = 0;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_CHINESE_KEYBOARD_ENTRY_METHOD:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_CHINESE_KEYBOARD_ENTRY_METHOD");
		value = 0;
	break;

	case CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_AUTOOFF:
		cellSysutil.Warning("cellSysutilGetSystemParamInt: CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_AUTOOFF");
		value = 0;
	break;

	default:
		return CELL_EINVAL;
	}

	return CELL_OK;
}

void cellSysutil_init()
{
	cellSysutil.AddFunc(0x0bae8772, cellVideoOutConfigure);
	cellSysutil.AddFunc(0x189a74da, cellSysutilCheckCallback);
	cellSysutil.AddFunc(0x1e930eef, cellVideoOutGetDeviceInfo);
	cellSysutil.AddFunc(0x40e895d3, cellSysutilGetSystemParamInt);
	cellSysutil.AddFunc(0x887572d5, cellVideoOutGetState);
	cellSysutil.AddFunc(0x9d98afa0, cellSysutilRegisterCallback);
	cellSysutil.AddFunc(0xe558748d, cellVideoOutGetResolution);
}