/**
 ******************************************************************************
 * Xenia : Xbox 360 Emulator Research Project                                 *
 ******************************************************************************
 * Copyright 2025 Ben Vanik. All rights reserved.                             *
 * Released under the BSD license - see LICENSE in the root for more details. *
 ******************************************************************************
 */

#ifndef XENIA_KERNEL_XBOXKRNL_XBOXKRNL_XCONFIG_H_
#define XENIA_KERNEL_XBOXKRNL_XBOXKRNL_XCONFIG_H_

#include <cstdint>
#include <map>

namespace xe {
namespace kernel {
namespace xboxkrnl {

enum X_CONFIG_CATEGORY : uint16_t {
  XCONFIG_STATIC_CATEGORY = 0x00,
  XCONFIG_STATISTIC_CATEGORY = 0x01,
  XCONFIG_SECURED_CATEGORY = 0x02,
  XCONFIG_USER_CATEGORY = 0x03,
  XCONFIG_XNET_MACHINE_ACCOUNT_CATEGORY = 0x04,
  XCONFIG_XNET_PARAMETERS_CATEGORY = 0x05,
  XCONFIG_MEDIA_CENTER_CATEGORY = 0x06,
  XCONFIG_CONSOLE_CATEGORY = 0x07,
  XCONFIG_DVD_CATEGORY = 0x08,
  XCONFIG_IPTV_CATEGORY = 0x09,
  XCONFIG_SYSTEM_CATEGORY = 0x0A,
  XCONFIG_DEVKIT_CATEGORY = 0x0B
};

enum XCONFIG_STATIC_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_STATIC_FIRST_POWER_ON_DATE = 0x01,
  XCONFIG_STATIC_SMC_CONFIG = 0x02
};

enum XCONFIG_STATISTIC_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_STATISTICS_XUID_MAC_ADDRESS = 0x01,
  XCONFIG_STATISTICS_XUID_COUNT = 0x02,
  XCONFIG_STATISTICS_ODD_FAILURES = 0x03,
  XCONFIG_STATISTICS_HDD_SMART_DATA = 0x04,
  XCONFIG_STATISTICS_UEM_ERRORS = 0x05,
  XCONFIG_STATISTICS_FPM_ERRORS = 0x06,
  XCONFIG_STATISTICS_LAST_REPORT_TIME = 0x07,
  XCONFIG_STATISTICS_BUG_CHECK_DATA = 0x08,
  XCONFIG_STATISTICS_TEMPERATURE = 0x09,
  XCONFIG_STATISTICS_XEKEYS_WRITE_FAILURE = 0x0A
};

enum XCONFIG_SECURED_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_SECURED_MAC_ADDRESS = 0x01,
  XCONFIG_SECURED_AV_REGION = 0x02,
  XCONFIG_SECURED_GAME_REGION = 0x03,
  XCONFIG_SECURED_DVD_REGION = 0x04,
  XCONFIG_SECURED_RESET_KEY = 0x05,
  XCONFIG_SECURED_SYSTEM_FLAGS = 0x06,
  XCONFIG_SECURED_POWER_MODE = 0x07,
  XCONFIG_SECURED_ONLINE_NETWORK_ID = 0x08,
  XCONFIG_SECURED_POWER_VCS_CONTROL = 0x09
};

enum XCONFIG_USER_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_USER_TIME_ZONE_BIAS = 0x01,
  XCONFIG_USER_TIME_ZONE_STD_NAME = 0x02,
  XCONFIG_USER_TIME_ZONE_DLT_NAME = 0x03,
  XCONFIG_USER_TIME_ZONE_STD_DATE = 0x04,
  XCONFIG_USER_TIME_ZONE_DLT_DATE = 0x05,
  XCONFIG_USER_TIME_ZONE_STD_BIAS = 0x06,
  XCONFIG_USER_TIME_ZONE_DLT_BIAS = 0x07,
  XCONFIG_USER_DEFAULT_PROFILE = 0x08,
  XCONFIG_USER_LANGUAGE = 0x09,
  XCONFIG_USER_VIDEO_FLAGS = 0x0A,
  XCONFIG_USER_AUDIO_FLAGS = 0x0B,
  XCONFIG_USER_RETAIL_FLAGS = 0x0C,
  XCONFIG_USER_DEVKIT_FLAGS = 0x0D,
  XCONFIG_USER_COUNTRY = 0x0E,
  XCONFIG_USER_PC_FLAGS = 0x0F,
  XCONFIG_USER_SMB_CONFIG = 0x10,
  XCONFIG_USER_LIVE_PUID = 0x11,
  XCONFIG_USER_LIVE_CREDENTIALS = 0x12,
  XCONFIG_USER_AV_COMPOSITE_SCREENSZ = 0x13,
  XCONFIG_USER_AV_COMPONENT_SCREENSZ = 0x14,
  XCONFIG_USER_AV_VGA_SCREENSZ = 0x15,
  XCONFIG_USER_PC_GAME = 0x16,
  XCONFIG_USER_PC_PASSWORD = 0x17,
  XCONFIG_USER_PC_MOVIE = 0x18,
  XCONFIG_USER_PC_GAME_RATING = 0x19,
  XCONFIG_USER_PC_MOVIE_RATING = 0x1A,
  XCONFIG_USER_PC_HINT = 0x1B,
  XCONFIG_USER_PC_HINT_ANSWER = 0x1C,
  XCONFIG_USER_PC_OVERRIDE = 0x1D,
  XCONFIG_USER_MUSIC_PLAYBACK_MODE = 0x1E,
  XCONFIG_USER_MUSIC_VOLUME = 0x1F,
  XCONFIG_USER_MUSIC_FLAGS = 0x20,
  XCONFIG_USER_ARCADE_FLAGS = 0x21,
  XCONFIG_USER_PC_VERSION = 0x22,
  XCONFIG_USER_PC_TV = 0x23,
  XCONFIG_USER_PC_TV_RATING = 0x24,
  XCONFIG_USER_PC_EXPLICIT_VIDEO = 0x25,
  XCONFIG_USER_PC_EXPLICIT_VIDEO_RATING = 0x26,
  XCONFIG_USER_PC_UNRATED_VIDEO = 0x27,
  XCONFIG_USER_PC_UNRATED_VIDEO_RATING = 0x28,
  XCONFIG_USER_VIDEO_OUTPUT_BLACK_LEVELS = 0x29,
  XCONFIG_USER_VIDEO_PLAYER_DISPLAY_MODE = 0x2A,
  XCONFIG_USER_ALTERNATE_VIDEO_TIMING_ID = 0x2B,
  XCONFIG_USER_VIDEO_DRIVER_OPTIONS = 0x2C,
  XCONFIG_USER_MUSIC_UI_FLAGS = 0x2D,
  XCONFIG_USER_VIDEO_MEDIA_SOURCE_TYPE = 0x2E,
  XCONFIG_USER_MUSIC_MEDIA_SOURCE_TYPE = 0x2F,
  XCONFIG_USER_PHOTO_MEDIA_SOURCE_TYPE = 0x30
};

enum XCONFIG_XNET_CATEGORY_ENTRIES : uint8_t { XCONFIG_XNET_DATA = 0x01 };

enum XCONFIG_MEDIA_CENTER_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_MEDIA_CENTER_MEDIA_PLAYER = 0x01,
  XCONFIG_MEDIA_CENTER_XESLED_VERSION = 0x02,
  XCONFIG_MEDIA_CENTER_XESLED_TRUST_SECRET = 0x03,
  XCONFIG_MEDIA_CENTER_XESLED_TRUST_CODE = 0x04,
  XCONFIG_MEDIA_CENTER_XESLED_HOST_ID = 0x05,
  XCONFIG_MEDIA_CENTER_XESLED_KEY = 0x06,
  XCONFIG_MEDIA_CENTER_XESLED_HOST_MAC_ADDRESS = 0x07,
  XCONFIG_MEDIA_CENTER_SERVER_UUID = 0x08,
  XCONFIG_MEDIA_CENTER_SERVER_NAME = 0x09,
  XCONFIG_MEDIA_CENTER_SERVER_FLAG = 0x0A
};

enum XCONFIG_CONSOLE_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_CONSOLE_SCREEN_SAVER = 0x01,
  XCONFIG_CONSOLE_AUTO_SHUT_OFF = 0x02,
  XCONFIG_CONSOLE_WIRELESS_SETTINGS = 0x03,
  XCONFIG_CONSOLE_CAMERA_SETTINGS = 0x04,
  XCONFIG_CONSOLE_PLAYTIMERDATA = 0x05,
  XCONFIG_CONSOLE_MEDIA_DISABLEAUTOLAUNCH = 0x06,
  XCONFIG_CONSOLE_KEYBOARD_LAYOUT = 0x07,
  XCONFIG_CONSOLE_PC_TITLE_EXEMPTIONS = 0x08,
  XCONFIG_CONSOLE_NUI = 0x09,
  XCONFIG_CONSOLE_VOICE = 0x0A,
  XCONFIG_CONSOLE_RETAIL_EX_FLAGS = 0x0B,
  XCONFIG_CONSOLE_DASH_FIRST_USE_TUTORIAL_FLAGS = 0x0C,
  XCONFIG_CONSOLE_TV_DIAGONAL_SIZE_IN_CM = 0x0D,
  XCONFIG_CONSOLE_NETWORKSTORAGEDEVICE_SERIALNUMBER = 0x0E,
  XCONFIG_CONSOLE_DISCOVERABLE = 0x0F,
  XCONFIG_CONSOLE_LIVE_TV_PROVIDER = 0x10
};

enum XCONFIG_DVD_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_DVD_VOLUME_ID = 0x01,
  XCONFIG_DVD_BOOKMARK = 0x02
};

enum XCONFIG_IPTV_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_IPTV_SERVICE_PROVIDER_NAME = 0x01,
  XCONFIG_IPTV_PROVISIONING_SERVER_URL = 0x02,
  XCONFIG_IPTV_SUPPORT_INFO = 0x03,
  XCONFIG_IPTV_BOOTSTRAP_SERVER_URL = 0x04
};

enum XCONFIG_SYSTEM_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_SYSTEM_ALARM_TIME = 0x01,
  XCONFIG_SYSTEM_PREVIOUS_FLASH_VERSION = 0x02
};

enum XCONFIG_DEVKIT_CATEGORY_ENTRIES : uint8_t {
  XCONFIG_DEVKIT_USBD_ROOT_HUB_PORT_DISABLE_MASK = 0x01,
  XCONFIG_DEVKIT_XAM_FEATURE_ENABLE_DISABLE_MASK = 0x02,
  XCONFIG_DEVKIT_KIOSK_ID = 0x03
};

// XCONFIG_SECURED_AV_REGION
enum X_AV_REGION : uint32_t {
  NTSCM = 0x00400100,
  NTSCJ = 0x00400200,
  PAL = 0x00400400,
  PAL_50 = 0x00800300,
};

// XCONFIG_USER_VIDEO_FLAGS
enum X_VIDEO_FLAGS : uint32_t {
  RatioNormal = 0x00000000,
  Widescreen = 0x00010000,
};

// XCONFIG_USER_AV_COMPONENT_SCREENSZ
const static std::map<uint32_t, int32_t> XHDTVResolution = {
    {0, 0x028001E0},   // 480p
    {8, 0x050002D0},   // 720p, always widescreen
    {16, 0x07800438},  // 1080, interlaced added in 1888, always widescreen
};

// XCONFIG_USER_AV_COMPONENT_SCREENSZ
const static std::map<uint32_t, int32_t> XVGAResolution = {
    // Existed since 1888
    {0, 0x028001E0},   // 680x480
    {5, 0x035001E0},   // 848x480
    {6, 0x04000300},   // 1024x768
    {8, 0x050002D0},   // 1280x720
    {9, 0x05000300},   // 1280x768
    {12, 0x05500300},  // 1360x768
    // added in later Versions
    {11, 0x05000400},  // 1280x1024
    {13, 0x05A00384},  // 1440x900
    {14, 0x0690041A},  // 1680x1050
    {16, 0x07800438},  // 1920x1080
};

// XCONFIG_USER_AUDIO_FLAGS
enum X_AUDIO_FLAGS : uint32_t {
  // Audio Mode Analog
  DolbyProLogic = 0x00000001,
  AnalogMono = 0x00000002,
  // Audio Mode Digital
  DigitalStereo = 0x00000000,
  DolbyDigital = 0x00010000,
  DolbyDigitalWithWMAPRO = 0x00030000,
  // Special Flags
  StereoBypass = 0x00000003,
  LowLatency = 0x80000000,
};

// XCONFIG_USER_RETAIL_FLAGS
enum X_RETAIL_FLAGS : uint32_t {
  // Clock
  DSTOff = 0x00000002,
  TwentyFourHourClock = 0x00000008,

  // Startup
  DashboardStartup = 0x00000080,
  IPTVStartup = 0x00000800,
  DiscStartup = 0x00002000,
  MCXDownloaderStartup = 0x00020000,
  // IPTV
  IPTVEnabled = 0x00001000,
  IPTVDVRENABLED = 0x00080000,
  IPTVDisabled = 0x02000000,
  // Kinect
  KinectInitialized = 0x20000000,
  KinectDisabled = 0x80000000,

  // Other
  DashboardInitialized = 0x00000040,
  BackgroundDownloadOn = 0x00010000,
};

// XCONFIG_USER_PC_FLAGS
enum X_PC_FLAGS : uint8_t {
  XBLAllowed = 0x01,
  XBLMembershipCreationAllowed = 0x02,
  XboxOneGameAllowed = 0x04,
  PCEnabled = 0x80,
};

// XCONFIG_USER_PC_GAMES
enum X_PC_GAMES_FLAGS : uint32_t {
  EarlyChildhoodMax = 0x00000000,
  EveryoneMax = 0x00000002,
  Everyone_10Max = 0x00000004,
  TeenMax = 0x00000006,
  MatureMax = 0x00000008,
  NoGameRestrictions = 0x000000FF,
};

// XCONFIG_USER_PC_PASSWORD
enum X_PC_PASSWORD_FLAGS : uint32_t {
  XButton = 0x00000001,
  YButton = 0x00000002,
  LeftButton = 0x00000003,
  RightButton = 0x00000004,
  UPButton = 0x00000005,
  DownButton = 0x00000006,
  LTButton = 0x00000009,
  RTButton = 0x0000000A,
  LBButton = 0x0000000B,
  RBButton = 0x0000000C,
};

// XCONFIG_USER_PC_MOVIE
enum X_PC_MOVIE_FLAGS : uint32_t {
  GeneralAudiences = 0x00000001,
  ParentalGuidance = 0x00000003,
  ParentalGuidance13 = 0x00000004,
  Restricted = 0x00000006,
  NoMovieRestrictions = 0x000000FF,
};

// XCONFIG_USER_PC_GAME_RATING
enum X_PC_GAME_RATING_FLAGS : uint32_t {
  DefaultGame = 0x00000000,
};

// XCONFIG_USER_PC_MOVIE_RATING
enum X_PC_MOVIE_RATING_FLAGS : uint32_t {
  DefaultMovie = 0x00000000,
};

// XCONFIG_USER_ARCADE_FLAGS
enum X_ARCADE_FLAGS : uint32_t {
  AutoDownloadOff = 0x00000000,
  AutoDownloadNewReleases = 0x00000001,
};

// XCONFIG_USER_PC_VERSION
enum X_PC_VERSION : uint32_t {
  VersionOne = 0x00000001,
};

// XCONFIG_USER_PC_TV
enum X_PC_TV : uint32_t {
  TVG = 0X00000006,
  TVPG = 0X00000008,
  TV14 = 0X0000000a,
  TVMatureAudience = 0x0000000C,
  NoTVRestrictions = 0X000000FF,
};

// XCONFIG_USER_PC_TV_RATING
enum X_PC_TV_RATING : uint32_t {
  DefaultTV = 0X00000000,
};

// XCONFIG_USER_PC_EXPLICIT_VIDEO
enum X_PC_EXPLICIT_VIDEO : uint32_t {
  ExplicitVideoAllowed = 0X000000FF,
  ExplicitVideoBanned = 0X00000000,
};

// XCONFIG_USER_PC_EXPLICIT_VIDEO_RATING
enum X_PC_EXPLICIT_VIDEO_RATING : uint32_t {
  ExplicitAllowed = 0X00000000,
};

// XCONFIG_USER_PC_UNRATED_VIDEO
enum X_PC_EXPLICIT_UNRATED : uint32_t {
  ExplicitUnratedBanned = 0X00000000,
  UnratedALL = 0X000000FF,
};

// XCONFIG_USER_PC_UNRATED_VIDEO_RATING
enum X_PC_EXPLICIT_UNRATED_RATING : uint32_t {
  DefaultExplicitUnrated = 0X00000000,
};

// XCONFIG_USER_VIDEO_OUTPUT_BLACK_LEVELS
enum X_BLACK_LEVEL : uint32_t {
  High = 0x00000100,
  Intermediate = 0x00000200,
  LevelNormal = 0x00000300,
};

// XCONFIG_CONSOLE_SCREENSAVER
enum X_SCREENSAVER : uint32_t {
  ScreensaverOn = 0x000A,
  ScreensaverOff = 0x1000,
};

// XCONFIG_CONSOLE_AUTO_SHUTDOWN
enum X_AUTO_SHUTDOWN : uint32_t {
  AutoShutdownOff = 0x0000,
  AutoShutdownOneHr = 0x003C,
  AutoShutdownSixHr = 0x0168,
};

// XCONFIG_CONSOLE_CAMERA_SETTINGS
enum X_CAMERA_FLAGS : uint32_t {
  // Room
  RoomAuto = 0x00000000,
  DarkWall = 0x00000001,
  LightWall = 0x00000002,
  // Lighting
  LightingAuto = 0x00000000,
  Incandescent = 0x00000004,
  Flourescent = 0x00000008,
  Daylight = 0x0000000C,
  // Flourescent Anti-Flicker
  AntiFlickerAuto = 0x00000000,
  AntiFlickerOn = 0x00000001,
  AntiFlickerOff = 0x00000002,
  // Default
  AutoAll = 0x00000001,
};

// XCONFIG_CONSOLE_KEYBOARD_LAYOUT
enum X_KEYBOARD_LAYOUT : uint16_t {
  KeyboardDefault = 0x0000,
  EnglishQWERTY = 0x0001,
};

}  // namespace xboxkrnl
}  // namespace kernel
}  // namespace xe

#endif  // XENIA_KERNEL_XBOXKRNL_XBOXKRNL_XCONFIG_H_
