From b52deed4ddfc9a16aa9cca605352f7134234b73e Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 6 Jun 2024 23:06:34 +0200 Subject: [PATCH] cellGem: Fix raw mouse connection state --- rpcs3/Emu/Cell/Modules/cellGem.cpp | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index 870b98da92..3f4538a36b 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -325,6 +325,7 @@ public: case move_handler::raw_mouse: { auto& handler = g_fxo->get(); + std::lock_guard mouse_lock(handler.mutex); // Make sure that the mouse handler is initialized handler.Init(std::min(attribute.max_connect, CELL_GEM_MAX_NUM)); @@ -891,7 +892,7 @@ static bool mouse_input_to_pad(const u32 mouse_no, be_t& digital_buttons, b return false; } - const auto& mouse_data = ::at32(handler.GetMice(), mouse_no); + const Mouse& mouse_data = ::at32(handler.GetMice(), mouse_no); const auto is_pressed = [&mouse_data](MouseButtonCodes button) -> bool { return !!(mouse_data.buttons & button); }; digital_buttons = 0; @@ -1514,7 +1515,9 @@ error_code cellGemGetInfo(vm::ptr info) // TODO: Support connecting PlayStation Move controllers - if (g_cfg.io.move == move_handler::fake) + switch (g_cfg.io.move) + { + case move_handler::fake: { gem.connected_controllers = 0; @@ -1538,6 +1541,39 @@ error_code cellGemGetInfo(vm::ptr info) gem.controllers[i].port = 0; } } + break; + } + case move_handler::raw_mouse: + { + gem.connected_controllers = 0; + + auto& handler = g_fxo->get(); + std::lock_guard mouse_lock(handler.mutex); + + const MouseInfo& info = handler.GetInfo(); + + for (u32 i = 0; i < CELL_GEM_MAX_NUM; i++) + { + const bool connected = i < gem.attribute.max_connect && info.status[i] == CELL_MOUSE_STATUS_CONNECTED; + + if (connected) + { + gem.connected_controllers++; + gem.controllers[i].status = CELL_GEM_STATUS_READY; + gem.controllers[i].port = port_num(i); + } + else + { + gem.controllers[i].status = CELL_GEM_STATUS_DISCONNECTED; + gem.controllers[i].port = 0; + } + } + break; + } + default: + { + break; + } } info->max_connect = gem.attribute.max_connect;