diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/emu_window.h | 52 | ||||
| -rw-r--r-- | src/common/file_util.cpp | 51 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 2 | ||||
| -rw-r--r-- | src/common/logging/log.h | 2 | ||||
| -rw-r--r-- | src/common/string_util.cpp | 16 | ||||
| -rw-r--r-- | src/common/string_util.h | 2 |
6 files changed, 97 insertions, 28 deletions
diff --git a/src/common/emu_window.h b/src/common/emu_window.h index a0ae4c9fa..7c3486dea 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h | |||
| @@ -105,7 +105,7 @@ public: | |||
| 105 | * @todo Fix this function to be thread-safe. | 105 | * @todo Fix this function to be thread-safe. |
| 106 | * @return PadState object indicating the current pad state | 106 | * @return PadState object indicating the current pad state |
| 107 | */ | 107 | */ |
| 108 | const Service::HID::PadState GetPadState() const { | 108 | Service::HID::PadState GetPadState() const { |
| 109 | return pad_state; | 109 | return pad_state; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| @@ -116,11 +116,59 @@ public: | |||
| 116 | * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and | 116 | * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and |
| 117 | * `pressed` is true if the touch screen is currently being pressed | 117 | * `pressed` is true if the touch screen is currently being pressed |
| 118 | */ | 118 | */ |
| 119 | const std::tuple<u16, u16, bool> GetTouchState() const { | 119 | std::tuple<u16, u16, bool> GetTouchState() const { |
| 120 | return std::make_tuple(touch_x, touch_y, touch_pressed); | 120 | return std::make_tuple(touch_x, touch_y, touch_pressed); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | /** | 123 | /** |
| 124 | * Gets the current accelerometer state (acceleration along each three axis). | ||
| 125 | * Axis explained: | ||
| 126 | * +x is the same direction as LEFT on D-pad. | ||
| 127 | * +y is normal to the touch screen, pointing outward. | ||
| 128 | * +z is the same direction as UP on D-pad. | ||
| 129 | * Units: | ||
| 130 | * 1 unit of return value = 1/512 g (measured by hw test), | ||
| 131 | * where g is the gravitational acceleration (9.8 m/sec2). | ||
| 132 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 133 | * @todo Implement accelerometer input in front-end. | ||
| 134 | * @return std::tuple of (x, y, z) | ||
| 135 | */ | ||
| 136 | std::tuple<s16, s16, s16> GetAccelerometerState() const { | ||
| 137 | // stubbed | ||
| 138 | return std::make_tuple(0, -512, 0); | ||
| 139 | } | ||
| 140 | |||
| 141 | /** | ||
| 142 | * Gets the current gyroscope state (angular rates about each three axis). | ||
| 143 | * Axis explained: | ||
| 144 | * +x is the same direction as LEFT on D-pad. | ||
| 145 | * +y is normal to the touch screen, pointing outward. | ||
| 146 | * +z is the same direction as UP on D-pad. | ||
| 147 | * Orientation is determined by right-hand rule. | ||
| 148 | * Units: | ||
| 149 | * 1 unit of return value = (1/coef) deg/sec, | ||
| 150 | * where coef is the return value of GetGyroscopeRawToDpsCoefficient(). | ||
| 151 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 152 | * @todo Implement gyroscope input in front-end. | ||
| 153 | * @return std::tuple of (x, y, z) | ||
| 154 | */ | ||
| 155 | std::tuple<s16, s16, s16> GetGyroscopeState() const { | ||
| 156 | // stubbed | ||
| 157 | return std::make_tuple(0, 0, 0); | ||
| 158 | } | ||
| 159 | |||
| 160 | /** | ||
| 161 | * Gets the coefficient for units conversion of gyroscope state. | ||
| 162 | * The conversion formula is r = coefficient * v, | ||
| 163 | * where v is angular rate in deg/sec, | ||
| 164 | * and r is the gyroscope state. | ||
| 165 | * @return float-type coefficient | ||
| 166 | */ | ||
| 167 | f32 GetGyroscopeRawToDpsCoefficient() const { | ||
| 168 | return 14.375f; // taken from hw test, and gyroscope's document | ||
| 169 | } | ||
| 170 | |||
| 171 | /** | ||
| 124 | * Returns currently active configuration. | 172 | * Returns currently active configuration. |
| 125 | * @note Accesses to the returned object need not be consistent because it may be modified in another thread | 173 | * @note Accesses to the returned object need not be consistent because it may be modified in another thread |
| 126 | */ | 174 | */ |
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index c3061479a..9ada09f8a 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -85,7 +85,7 @@ bool Exists(const std::string &filename) | |||
| 85 | StripTailDirSlashes(copy); | 85 | StripTailDirSlashes(copy); |
| 86 | 86 | ||
| 87 | #ifdef _WIN32 | 87 | #ifdef _WIN32 |
| 88 | int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); | 88 | int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); |
| 89 | #else | 89 | #else |
| 90 | int result = stat64(copy.c_str(), &file_info); | 90 | int result = stat64(copy.c_str(), &file_info); |
| 91 | #endif | 91 | #endif |
| @@ -102,7 +102,7 @@ bool IsDirectory(const std::string &filename) | |||
| 102 | StripTailDirSlashes(copy); | 102 | StripTailDirSlashes(copy); |
| 103 | 103 | ||
| 104 | #ifdef _WIN32 | 104 | #ifdef _WIN32 |
| 105 | int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); | 105 | int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); |
| 106 | #else | 106 | #else |
| 107 | int result = stat64(copy.c_str(), &file_info); | 107 | int result = stat64(copy.c_str(), &file_info); |
| 108 | #endif | 108 | #endif |
| @@ -138,7 +138,7 @@ bool Delete(const std::string &filename) | |||
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | #ifdef _WIN32 | 140 | #ifdef _WIN32 |
| 141 | if (!DeleteFile(Common::UTF8ToTStr(filename).c_str())) | 141 | if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) |
| 142 | { | 142 | { |
| 143 | LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", | 143 | LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", |
| 144 | filename.c_str(), GetLastErrorMsg()); | 144 | filename.c_str(), GetLastErrorMsg()); |
| @@ -160,7 +160,7 @@ bool CreateDir(const std::string &path) | |||
| 160 | { | 160 | { |
| 161 | LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); | 161 | LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); |
| 162 | #ifdef _WIN32 | 162 | #ifdef _WIN32 |
| 163 | if (::CreateDirectory(Common::UTF8ToTStr(path).c_str(), nullptr)) | 163 | if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr)) |
| 164 | return true; | 164 | return true; |
| 165 | DWORD error = GetLastError(); | 165 | DWORD error = GetLastError(); |
| 166 | if (error == ERROR_ALREADY_EXISTS) | 166 | if (error == ERROR_ALREADY_EXISTS) |
| @@ -241,7 +241,7 @@ bool DeleteDir(const std::string &filename) | |||
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | #ifdef _WIN32 | 243 | #ifdef _WIN32 |
| 244 | if (::RemoveDirectory(Common::UTF8ToTStr(filename).c_str())) | 244 | if (::RemoveDirectoryW(Common::UTF8ToUTF16W(filename).c_str())) |
| 245 | return true; | 245 | return true; |
| 246 | #else | 246 | #else |
| 247 | if (rmdir(filename.c_str()) == 0) | 247 | if (rmdir(filename.c_str()) == 0) |
| @@ -257,8 +257,13 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename) | |||
| 257 | { | 257 | { |
| 258 | LOG_TRACE(Common_Filesystem, "%s --> %s", | 258 | LOG_TRACE(Common_Filesystem, "%s --> %s", |
| 259 | srcFilename.c_str(), destFilename.c_str()); | 259 | srcFilename.c_str(), destFilename.c_str()); |
| 260 | #ifdef _WIN32 | ||
| 261 | if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str()) == 0) | ||
| 262 | return true; | ||
| 263 | #else | ||
| 260 | if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) | 264 | if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) |
| 261 | return true; | 265 | return true; |
| 266 | #endif | ||
| 262 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", | 267 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
| 263 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 268 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 264 | return false; | 269 | return false; |
| @@ -270,7 +275,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) | |||
| 270 | LOG_TRACE(Common_Filesystem, "%s --> %s", | 275 | LOG_TRACE(Common_Filesystem, "%s --> %s", |
| 271 | srcFilename.c_str(), destFilename.c_str()); | 276 | srcFilename.c_str(), destFilename.c_str()); |
| 272 | #ifdef _WIN32 | 277 | #ifdef _WIN32 |
| 273 | if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE)) | 278 | if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str(), FALSE)) |
| 274 | return true; | 279 | return true; |
| 275 | 280 | ||
| 276 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", | 281 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
| @@ -358,7 +363,7 @@ u64 GetSize(const std::string &filename) | |||
| 358 | 363 | ||
| 359 | struct stat64 buf; | 364 | struct stat64 buf; |
| 360 | #ifdef _WIN32 | 365 | #ifdef _WIN32 |
| 361 | if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0) | 366 | if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0) |
| 362 | #else | 367 | #else |
| 363 | if (stat64(filename.c_str(), &buf) == 0) | 368 | if (stat64(filename.c_str(), &buf) == 0) |
| 364 | #endif | 369 | #endif |
| @@ -432,16 +437,16 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo | |||
| 432 | 437 | ||
| 433 | #ifdef _WIN32 | 438 | #ifdef _WIN32 |
| 434 | // Find the first file in the directory. | 439 | // Find the first file in the directory. |
| 435 | WIN32_FIND_DATA ffd; | 440 | WIN32_FIND_DATAW ffd; |
| 436 | 441 | ||
| 437 | HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd); | 442 | HANDLE handle_find = FindFirstFileW(Common::UTF8ToUTF16W(directory + "\\*").c_str(), &ffd); |
| 438 | if (handle_find == INVALID_HANDLE_VALUE) { | 443 | if (handle_find == INVALID_HANDLE_VALUE) { |
| 439 | FindClose(handle_find); | 444 | FindClose(handle_find); |
| 440 | return false; | 445 | return false; |
| 441 | } | 446 | } |
| 442 | // windows loop | 447 | // windows loop |
| 443 | do { | 448 | do { |
| 444 | const std::string virtual_name(Common::TStrToUTF8(ffd.cFileName)); | 449 | const std::string virtual_name(Common::UTF16ToUTF8(ffd.cFileName)); |
| 445 | #else | 450 | #else |
| 446 | struct dirent dirent, *result = nullptr; | 451 | struct dirent dirent, *result = nullptr; |
| 447 | 452 | ||
| @@ -465,7 +470,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo | |||
| 465 | found_entries += ret_entries; | 470 | found_entries += ret_entries; |
| 466 | 471 | ||
| 467 | #ifdef _WIN32 | 472 | #ifdef _WIN32 |
| 468 | } while (FindNextFile(handle_find, &ffd) != 0); | 473 | } while (FindNextFileW(handle_find, &ffd) != 0); |
| 469 | FindClose(handle_find); | 474 | FindClose(handle_find); |
| 470 | #else | 475 | #else |
| 471 | } | 476 | } |
| @@ -572,15 +577,23 @@ void CopyDir(const std::string &source_path, const std::string &dest_path) | |||
| 572 | // Returns the current directory | 577 | // Returns the current directory |
| 573 | std::string GetCurrentDir() | 578 | std::string GetCurrentDir() |
| 574 | { | 579 | { |
| 575 | char *dir; | ||
| 576 | // Get the current working directory (getcwd uses malloc) | 580 | // Get the current working directory (getcwd uses malloc) |
| 581 | #ifdef _WIN32 | ||
| 582 | wchar_t *dir; | ||
| 583 | if (!(dir = _wgetcwd(nullptr, 0))) { | ||
| 584 | #else | ||
| 585 | char *dir; | ||
| 577 | if (!(dir = getcwd(nullptr, 0))) { | 586 | if (!(dir = getcwd(nullptr, 0))) { |
| 578 | 587 | #endif | |
| 579 | LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", | 588 | LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", |
| 580 | GetLastErrorMsg()); | 589 | GetLastErrorMsg()); |
| 581 | return nullptr; | 590 | return nullptr; |
| 582 | } | 591 | } |
| 592 | #ifdef _WIN32 | ||
| 593 | std::string strDir = Common::UTF16ToUTF8(dir); | ||
| 594 | #else | ||
| 583 | std::string strDir = dir; | 595 | std::string strDir = dir; |
| 596 | #endif | ||
| 584 | free(dir); | 597 | free(dir); |
| 585 | return strDir; | 598 | return strDir; |
| 586 | } | 599 | } |
| @@ -588,7 +601,11 @@ std::string GetCurrentDir() | |||
| 588 | // Sets the current directory to the given directory | 601 | // Sets the current directory to the given directory |
| 589 | bool SetCurrentDir(const std::string &directory) | 602 | bool SetCurrentDir(const std::string &directory) |
| 590 | { | 603 | { |
| 604 | #ifdef _WIN32 | ||
| 605 | return _wchdir(Common::UTF8ToUTF16W(directory).c_str()) == 0; | ||
| 606 | #else | ||
| 591 | return chdir(directory.c_str()) == 0; | 607 | return chdir(directory.c_str()) == 0; |
| 608 | #endif | ||
| 592 | } | 609 | } |
| 593 | 610 | ||
| 594 | #if defined(__APPLE__) | 611 | #if defined(__APPLE__) |
| @@ -613,9 +630,9 @@ std::string& GetExeDirectory() | |||
| 613 | static std::string exe_path; | 630 | static std::string exe_path; |
| 614 | if (exe_path.empty()) | 631 | if (exe_path.empty()) |
| 615 | { | 632 | { |
| 616 | TCHAR tchar_exe_path[2048]; | 633 | wchar_t wchar_exe_path[2048]; |
| 617 | GetModuleFileName(nullptr, tchar_exe_path, 2048); | 634 | GetModuleFileNameW(nullptr, wchar_exe_path, 2048); |
| 618 | exe_path = Common::TStrToUTF8(tchar_exe_path); | 635 | exe_path = Common::UTF16ToUTF8(wchar_exe_path); |
| 619 | exe_path = exe_path.substr(0, exe_path.find_last_of('\\')); | 636 | exe_path = exe_path.substr(0, exe_path.find_last_of('\\')); |
| 620 | } | 637 | } |
| 621 | return exe_path; | 638 | return exe_path; |
| @@ -900,7 +917,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[]) | |||
| 900 | { | 917 | { |
| 901 | Close(); | 918 | Close(); |
| 902 | #ifdef _WIN32 | 919 | #ifdef _WIN32 |
| 903 | _tfopen_s(&m_file, Common::UTF8ToTStr(filename).c_str(), Common::UTF8ToTStr(openmode).c_str()); | 920 | _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str()); |
| 904 | #else | 921 | #else |
| 905 | m_file = fopen(filename.c_str(), openmode); | 922 | m_file = fopen(filename.c_str(), openmode); |
| 906 | #endif | 923 | #endif |
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 4c86151ab..cfbfbc2a7 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -46,8 +46,10 @@ namespace Log { | |||
| 46 | SUB(Service, NIM) \ | 46 | SUB(Service, NIM) \ |
| 47 | SUB(Service, NWM) \ | 47 | SUB(Service, NWM) \ |
| 48 | SUB(Service, CAM) \ | 48 | SUB(Service, CAM) \ |
| 49 | SUB(Service, CECD) \ | ||
| 49 | SUB(Service, CFG) \ | 50 | SUB(Service, CFG) \ |
| 50 | SUB(Service, DSP) \ | 51 | SUB(Service, DSP) \ |
| 52 | SUB(Service, DLP) \ | ||
| 51 | SUB(Service, HID) \ | 53 | SUB(Service, HID) \ |
| 52 | SUB(Service, SOC) \ | 54 | SUB(Service, SOC) \ |
| 53 | SUB(Service, IR) \ | 55 | SUB(Service, IR) \ |
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index e4c39c308..4f6856f3d 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -61,8 +61,10 @@ enum class Class : ClassType { | |||
| 61 | Service_NIM, ///< The NIM (Network interface manager) service | 61 | Service_NIM, ///< The NIM (Network interface manager) service |
| 62 | Service_NWM, ///< The NWM (Network wlan manager) service | 62 | Service_NWM, ///< The NWM (Network wlan manager) service |
| 63 | Service_CAM, ///< The CAM (Camera) service | 63 | Service_CAM, ///< The CAM (Camera) service |
| 64 | Service_CECD, ///< The CECD service | ||
| 64 | Service_CFG, ///< The CFG (Configuration) service | 65 | Service_CFG, ///< The CFG (Configuration) service |
| 65 | Service_DSP, ///< The DSP (DSP control) service | 66 | Service_DSP, ///< The DSP (DSP control) service |
| 67 | Service_DLP, ///< The DLP (Download Play) service | ||
| 66 | Service_HID, ///< The HID (Human interface device) service | 68 | Service_HID, ///< The HID (Human interface device) service |
| 67 | Service_SOC, ///< The SOC (Socket) service | 69 | Service_SOC, ///< The SOC (Socket) service |
| 68 | Service_IR, ///< The IR service | 70 | Service_IR, ///< The IR service |
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 6d6fc591f..f0aa072db 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -320,27 +320,27 @@ std::u16string UTF8ToUTF16(const std::string& input) | |||
| 320 | #endif | 320 | #endif |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | static std::string UTF16ToUTF8(const std::wstring& input) | 323 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) |
| 324 | { | 324 | { |
| 325 | auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); | 325 | auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); |
| 326 | 326 | ||
| 327 | std::string output; | 327 | std::wstring output; |
| 328 | output.resize(size); | 328 | output.resize(size); |
| 329 | 329 | ||
| 330 | if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr)) | 330 | if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()))) |
| 331 | output.clear(); | 331 | output.clear(); |
| 332 | 332 | ||
| 333 | return output; | 333 | return output; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) | 336 | std::string UTF16ToUTF8(const std::wstring& input) |
| 337 | { | 337 | { |
| 338 | auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); | 338 | auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); |
| 339 | 339 | ||
| 340 | std::wstring output; | 340 | std::string output; |
| 341 | output.resize(size); | 341 | output.resize(size); |
| 342 | 342 | ||
| 343 | if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()))) | 343 | if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr)) |
| 344 | output.clear(); | 344 | output.clear(); |
| 345 | 345 | ||
| 346 | return output; | 346 | return output; |
diff --git a/src/common/string_util.h b/src/common/string_util.h index c5c474c6f..89d9f133e 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -95,7 +95,7 @@ std::string CP1252ToUTF8(const std::string& str); | |||
| 95 | std::string SHIFTJISToUTF8(const std::string& str); | 95 | std::string SHIFTJISToUTF8(const std::string& str); |
| 96 | 96 | ||
| 97 | #ifdef _WIN32 | 97 | #ifdef _WIN32 |
| 98 | 98 | std::string UTF16ToUTF8(const std::wstring& input); | |
| 99 | std::wstring UTF8ToUTF16W(const std::string& str); | 99 | std::wstring UTF8ToUTF16W(const std::string& str); |
| 100 | 100 | ||
| 101 | #ifdef _UNICODE | 101 | #ifdef _UNICODE |