From 318095f9b9d1825a704591ba57f668b2d55c243d Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 9 Jun 2019 16:03:22 +0200 Subject: [PATCH] Port yuzu-emu/yuzu#2249: "ipc_helpers: Allow pushing and popping floating-point values" (#4702) Certain values that are passed through the IPC buffer are actually floating point values, not solely integral values. --- src/core/hle/ipc_helpers.h | 30 ++++++++++++++++++++++++++++++ src/core/hle/service/hid/hid.cpp | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 01282a69b0..8176f0bbb6 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -141,6 +141,20 @@ inline void RequestBuilder::Push(u64 value) { Push(static_cast(value >> 32)); } +template <> +inline void RequestBuilder::Push(f32 value) { + u32 integral; + std::memcpy(&integral, &value, sizeof(u32)); + Push(integral); +} + +template <> +inline void RequestBuilder::Push(f64 value) { + u64 integral; + std::memcpy(&integral, &value, sizeof(u64)); + Push(integral); +} + template <> inline void RequestBuilder::Push(bool value) { Push(static_cast(value)); @@ -341,6 +355,22 @@ inline s32 RequestParser::Pop() { return data; } +template <> +inline f32 RequestParser::Pop() { + const u32 value = Pop(); + float real; + std::memcpy(&real, &value, sizeof(real)); + return real; +} + +template <> +inline f64 RequestParser::Pop() { + const u64 value = Pop(); + f64 real; + std::memcpy(&real, &value, sizeof(real)); + return real; +} + template <> inline bool RequestParser::Pop() { return Pop() != 0; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index ad63ab7a26..667ee12c4d 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -331,7 +331,7 @@ void Module::Interface::GetGyroscopeLowRawToDpsCoefficient(Kernel::HLERequestCon IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); - rb.PushRaw(gyroscope_coef); + rb.Push(gyroscope_coef); } void Module::Interface::GetGyroscopeLowCalibrateParam(Kernel::HLERequestContext& ctx) {