cfg_u.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "common/log.h"
  5. #include "core/hle/hle.h"
  6. #include "core/hle/service/cfg_u.h"
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. // Namespace CFG_U
  9. namespace CFG_U {
  10. static const std::array<const char*, 187> country_codes = {
  11. nullptr, "JP", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 0-7
  12. "AI", "AG", "AR", "AW", "BS", "BB", "BZ", "BO", // 8-15
  13. "BR", "VG", "CA", "KY", "CL", "CO", "CR", "DM", // 16-23
  14. "DO", "EC", "SV", "GF", "GD", "GP", "GT", "GY", // 24-31
  15. "HT", "HN", "JM", "MQ", "MX", "MS", "AN", "NI", // 32-39
  16. "PA", "PY", "PE", "KN", "LC", "VC", "SR", "TT", // 40-47
  17. "TC", "US", "UY", "VI", "VE", nullptr, nullptr, nullptr, // 48-55
  18. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 56-63
  19. "AL", "AU", "AT", "BE", "BA", "BW", "BG", "HR", // 64-71
  20. "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", // 72-79
  21. "HU", "IS", "IE", "IT", "LV", "LS", "LI", "LT", // 80-87
  22. "LU", "MK", "MT", "ME", "MZ", "NA", "NL", "NZ", // 88-95
  23. "NO", "PL", "PT", "RO", "RU", "RS", "SK", "SI", // 96-103
  24. "ZA", "ES", "SZ", "SE", "CH", "TR", "GB", "ZM", // 104-111
  25. "ZW", "AZ", "MR", "ML", "NE", "TD", "SD", "ER", // 112-119
  26. "DJ", "SO", "AD", "GI", "GG", "IM", "JE", "MC", // 120-127
  27. "TW", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 128-135
  28. "KR", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 136-143
  29. "HK", "MO", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 144-151
  30. "ID", "SG", "TH", "PH", "MY", nullptr, nullptr, nullptr, // 152-159
  31. "CN", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 160-167
  32. "AE", "IN", "EG", "OM", "QA", "KW", "SA", "SY", // 168-175
  33. "BH", "JO", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 176-183
  34. "SM", "VA", "BM", // 184-186
  35. };
  36. /**
  37. * CFG_User::GetCountryCodeString service function
  38. * Inputs:
  39. * 1 : Country Code ID
  40. * Outputs:
  41. * 1 : Result of function, 0 on success, otherwise error code
  42. * 2 : Country's 2-char string
  43. */
  44. static void GetCountryCodeString(Service::Interface* self) {
  45. u32* cmd_buffer = Service::GetCommandBuffer();
  46. u32 country_code_id = cmd_buffer[1];
  47. if (country_code_id >= country_codes.size()) {
  48. ERROR_LOG(KERNEL, "requested country code id=%d is invalid", country_code_id);
  49. cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw;
  50. return;
  51. }
  52. const char* code = country_codes[country_code_id];
  53. if (code != nullptr) {
  54. cmd_buffer[1] = 0;
  55. cmd_buffer[2] = code[0] | (code[1] << 8);
  56. } else {
  57. cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw;
  58. DEBUG_LOG(KERNEL, "requested country code id=%d is not set", country_code_id);
  59. }
  60. }
  61. /**
  62. * CFG_User::GetCountryCodeID service function
  63. * Inputs:
  64. * 1 : Country Code 2-char string
  65. * Outputs:
  66. * 1 : Result of function, 0 on success, otherwise error code
  67. * 2 : Country Code ID
  68. */
  69. static void GetCountryCodeID(Service::Interface* self) {
  70. u32* cmd_buffer = Service::GetCommandBuffer();
  71. u16 country_code = cmd_buffer[1];
  72. u16 country_code_id = -1;
  73. for (u32 i = 0; i < country_codes.size(); ++i) {
  74. const char* code_string = country_codes[i];
  75. if (code_string != nullptr) {
  76. u16 code = code_string[0] | (code_string[1] << 8);
  77. if (code == country_code) {
  78. country_code_id = i;
  79. break;
  80. }
  81. }
  82. }
  83. cmd_buffer[1] = 0;
  84. cmd_buffer[2] = country_code_id;
  85. }
  86. const Interface::FunctionInfo FunctionTable[] = {
  87. {0x00010082, nullptr, "GetConfigInfoBlk2"},
  88. {0x00020000, nullptr, "SecureInfoGetRegion"},
  89. {0x00030000, nullptr, "GenHashConsoleUnique"},
  90. {0x00040000, nullptr, "GetRegionCanadaUSA"},
  91. {0x00050000, nullptr, "GetSystemModel"},
  92. {0x00060000, nullptr, "GetModelNintendo2DS"},
  93. {0x00070040, nullptr, "unknown"},
  94. {0x00080080, nullptr, "unknown"},
  95. {0x00090040, GetCountryCodeString, "GetCountryCodeString"},
  96. {0x000A0040, GetCountryCodeID, "GetCountryCodeID"},
  97. };
  98. ////////////////////////////////////////////////////////////////////////////////////////////////////
  99. // Interface class
  100. Interface::Interface() {
  101. Register(FunctionTable, ARRAY_SIZE(FunctionTable));
  102. }
  103. Interface::~Interface() {
  104. }
  105. } // namespace