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: * @todo Fix this function to be thread-safe. * @return PadState object indicating the current pad state */ - const Service::HID::PadState GetPadState() const { + Service::HID::PadState GetPadState() const { return pad_state; } @@ -116,11 +116,59 @@ public: * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and * `pressed` is true if the touch screen is currently being pressed */ - const std::tuple<u16, u16, bool> GetTouchState() const { + std::tuple<u16, u16, bool> GetTouchState() const { return std::make_tuple(touch_x, touch_y, touch_pressed); } /** + * Gets the current accelerometer state (acceleration along each three axis). + * Axis explained: + * +x is the same direction as LEFT on D-pad. + * +y is normal to the touch screen, pointing outward. + * +z is the same direction as UP on D-pad. + * Units: + * 1 unit of return value = 1/512 g (measured by hw test), + * where g is the gravitational acceleration (9.8 m/sec2). + * @note This should be called by the core emu thread to get a state set by the window thread. + * @todo Implement accelerometer input in front-end. + * @return std::tuple of (x, y, z) + */ + std::tuple<s16, s16, s16> GetAccelerometerState() const { + // stubbed + return std::make_tuple(0, -512, 0); + } + + /** + * Gets the current gyroscope state (angular rates about each three axis). + * Axis explained: + * +x is the same direction as LEFT on D-pad. + * +y is normal to the touch screen, pointing outward. + * +z is the same direction as UP on D-pad. + * Orientation is determined by right-hand rule. + * Units: + * 1 unit of return value = (1/coef) deg/sec, + * where coef is the return value of GetGyroscopeRawToDpsCoefficient(). + * @note This should be called by the core emu thread to get a state set by the window thread. + * @todo Implement gyroscope input in front-end. + * @return std::tuple of (x, y, z) + */ + std::tuple<s16, s16, s16> GetGyroscopeState() const { + // stubbed + return std::make_tuple(0, 0, 0); + } + + /** + * Gets the coefficient for units conversion of gyroscope state. + * The conversion formula is r = coefficient * v, + * where v is angular rate in deg/sec, + * and r is the gyroscope state. + * @return float-type coefficient + */ + f32 GetGyroscopeRawToDpsCoefficient() const { + return 14.375f; // taken from hw test, and gyroscope's document + } + + /** * Returns currently active configuration. * @note Accesses to the returned object need not be consistent because it may be modified in another thread */ 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) StripTailDirSlashes(copy); #ifdef _WIN32 - int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); + int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); #else int result = stat64(copy.c_str(), &file_info); #endif @@ -102,7 +102,7 @@ bool IsDirectory(const std::string &filename) StripTailDirSlashes(copy); #ifdef _WIN32 - int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info); + int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); #else int result = stat64(copy.c_str(), &file_info); #endif @@ -138,7 +138,7 @@ bool Delete(const std::string &filename) } #ifdef _WIN32 - if (!DeleteFile(Common::UTF8ToTStr(filename).c_str())) + if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) { LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", filename.c_str(), GetLastErrorMsg()); @@ -160,7 +160,7 @@ bool CreateDir(const std::string &path) { LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); #ifdef _WIN32 - if (::CreateDirectory(Common::UTF8ToTStr(path).c_str(), nullptr)) + if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr)) return true; DWORD error = GetLastError(); if (error == ERROR_ALREADY_EXISTS) @@ -241,7 +241,7 @@ bool DeleteDir(const std::string &filename) } #ifdef _WIN32 - if (::RemoveDirectory(Common::UTF8ToTStr(filename).c_str())) + if (::RemoveDirectoryW(Common::UTF8ToUTF16W(filename).c_str())) return true; #else if (rmdir(filename.c_str()) == 0) @@ -257,8 +257,13 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename) { LOG_TRACE(Common_Filesystem, "%s --> %s", srcFilename.c_str(), destFilename.c_str()); +#ifdef _WIN32 + if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str()) == 0) + return true; +#else if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) return true; +#endif LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); return false; @@ -270,7 +275,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) LOG_TRACE(Common_Filesystem, "%s --> %s", srcFilename.c_str(), destFilename.c_str()); #ifdef _WIN32 - if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE)) + if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str(), FALSE)) return true; LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", @@ -358,7 +363,7 @@ u64 GetSize(const std::string &filename) struct stat64 buf; #ifdef _WIN32 - if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0) + if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0) #else if (stat64(filename.c_str(), &buf) == 0) #endif @@ -432,16 +437,16 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo #ifdef _WIN32 // Find the first file in the directory. - WIN32_FIND_DATA ffd; + WIN32_FIND_DATAW ffd; - HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd); + HANDLE handle_find = FindFirstFileW(Common::UTF8ToUTF16W(directory + "\\*").c_str(), &ffd); if (handle_find == INVALID_HANDLE_VALUE) { FindClose(handle_find); return false; } // windows loop do { - const std::string virtual_name(Common::TStrToUTF8(ffd.cFileName)); + const std::string virtual_name(Common::UTF16ToUTF8(ffd.cFileName)); #else struct dirent dirent, *result = nullptr; @@ -465,7 +470,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo found_entries += ret_entries; #ifdef _WIN32 - } while (FindNextFile(handle_find, &ffd) != 0); + } while (FindNextFileW(handle_find, &ffd) != 0); FindClose(handle_find); #else } @@ -572,15 +577,23 @@ void CopyDir(const std::string &source_path, const std::string &dest_path) // Returns the current directory std::string GetCurrentDir() { - char *dir; // Get the current working directory (getcwd uses malloc) +#ifdef _WIN32 + wchar_t *dir; + if (!(dir = _wgetcwd(nullptr, 0))) { +#else + char *dir; if (!(dir = getcwd(nullptr, 0))) { - +#endif LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", GetLastErrorMsg()); return nullptr; } +#ifdef _WIN32 + std::string strDir = Common::UTF16ToUTF8(dir); +#else std::string strDir = dir; +#endif free(dir); return strDir; } @@ -588,7 +601,11 @@ std::string GetCurrentDir() // Sets the current directory to the given directory bool SetCurrentDir(const std::string &directory) { +#ifdef _WIN32 + return _wchdir(Common::UTF8ToUTF16W(directory).c_str()) == 0; +#else return chdir(directory.c_str()) == 0; +#endif } #if defined(__APPLE__) @@ -613,9 +630,9 @@ std::string& GetExeDirectory() static std::string exe_path; if (exe_path.empty()) { - TCHAR tchar_exe_path[2048]; - GetModuleFileName(nullptr, tchar_exe_path, 2048); - exe_path = Common::TStrToUTF8(tchar_exe_path); + wchar_t wchar_exe_path[2048]; + GetModuleFileNameW(nullptr, wchar_exe_path, 2048); + exe_path = Common::UTF16ToUTF8(wchar_exe_path); exe_path = exe_path.substr(0, exe_path.find_last_of('\\')); } return exe_path; @@ -900,7 +917,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[]) { Close(); #ifdef _WIN32 - _tfopen_s(&m_file, Common::UTF8ToTStr(filename).c_str(), Common::UTF8ToTStr(openmode).c_str()); + _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str()); #else m_file = fopen(filename.c_str(), openmode); #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 { SUB(Service, NIM) \ SUB(Service, NWM) \ SUB(Service, CAM) \ + SUB(Service, CECD) \ SUB(Service, CFG) \ SUB(Service, DSP) \ + SUB(Service, DLP) \ SUB(Service, HID) \ SUB(Service, SOC) \ 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 { Service_NIM, ///< The NIM (Network interface manager) service Service_NWM, ///< The NWM (Network wlan manager) service Service_CAM, ///< The CAM (Camera) service + Service_CECD, ///< The CECD service Service_CFG, ///< The CFG (Configuration) service Service_DSP, ///< The DSP (DSP control) service + Service_DLP, ///< The DLP (Download Play) service Service_HID, ///< The HID (Human interface device) service Service_SOC, ///< The SOC (Socket) service 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) #endif } -static std::string UTF16ToUTF8(const std::wstring& input) +static std::wstring CPToUTF16(u32 code_page, const std::string& input) { - auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); + auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); - std::string output; + std::wstring output; output.resize(size); - if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr)) + if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()))) output.clear(); return output; } -static std::wstring CPToUTF16(u32 code_page, const std::string& input) +std::string UTF16ToUTF8(const std::wstring& input) { - auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); + auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); - std::wstring output; + std::string output; output.resize(size); - if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()))) + if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr)) output.clear(); 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); std::string SHIFTJISToUTF8(const std::string& str); #ifdef _WIN32 - +std::string UTF16ToUTF8(const std::wstring& input); std::wstring UTF8ToUTF16W(const std::string& str); #ifdef _UNICODE |