cfg_u.cpp 5.3 KB

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