From 4b19e55fcce21cec0155ce5c4d5fcce3d9d27f48 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 19 Sep 2019 01:50:08 +0300 Subject: [PATCH] Use g_fxo for cellKb, cellMouse Use init_mutex --- rpcs3/Emu/Cell/Modules/cellKb.cpp | 56 +++++++++++++------ rpcs3/Emu/Cell/Modules/cellMouse.cpp | 84 ++++++++++++++-------------- rpcs3/Emu/Io/KeyboardHandler.h | 4 ++ rpcs3/Emu/Io/MouseHandler.h | 3 + rpcs3/Emu/System.cpp | 2 + rpcs3/Emu/System.h | 4 +- rpcs3/main_application.cpp | 24 +++++--- 7 files changed, 108 insertions(+), 69 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index b409695417..9c82278a0b 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -33,15 +33,16 @@ error_code cellKbInit(u32 max_connect) { sys_io.warning("cellKbInit(max_connect=%d)", max_connect); - auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (handler) + const auto init = handler->init.init(); + + if (!init) return CELL_KB_ERROR_ALREADY_INITIALIZED; if (max_connect == 0 || max_connect > CELL_KB_MAX_KEYBOARDS) return CELL_KB_ERROR_INVALID_PARAMETER; - handler = fxm::import(Emu.GetCallbacks().get_kb_handler); handler->Init(std::min(max_connect, 7u)); return CELL_OK; @@ -51,9 +52,14 @@ error_code cellKbEnd() { sys_io.notice("cellKbEnd()"); - if (!fxm::remove()) + const auto handler = g_fxo->get(); + + const auto init = handler->init.reset(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; + // TODO return CELL_OK; } @@ -61,9 +67,11 @@ error_code cellKbClearBuf(u32 port_no) { sys_io.trace("cellKbClearBuf(port_no=%d)", port_no); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) + const auto init = handler->init.access(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; if (port_no >= CELL_KB_MAX_KEYBOARDS) @@ -233,9 +241,11 @@ error_code cellKbGetInfo(vm::ptr info) { sys_io.trace("cellKbGetInfo(info=*0x%x)", info); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) + const auto init = handler->init.access(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; if (!info) @@ -260,9 +270,11 @@ error_code cellKbRead(u32 port_no, vm::ptr data) { sys_io.trace("cellKbRead(port_no=%d, data=*0x%x)", port_no, data); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) + const auto init = handler->init.access(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; if (port_no >= CELL_KB_MAX_KEYBOARDS || !data) @@ -292,9 +304,11 @@ error_code cellKbSetCodeType(u32 port_no, u32 type) { sys_io.trace("cellKbSetCodeType(port_no=%d, type=%d)", port_no, type); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) + const auto init = handler->init.access(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; if (port_no >= CELL_KB_MAX_KEYBOARDS || type > CELL_KB_CODETYPE_ASCII) @@ -317,9 +331,11 @@ error_code cellKbSetLEDStatus(u32 port_no, u8 led) { sys_io.trace("cellKbSetLEDStatus(port_no=%d, led=%d)", port_no, led); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) + const auto init = handler->init.access(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; if (port_no >= CELL_KB_MAX_KEYBOARDS) @@ -343,9 +359,11 @@ error_code cellKbSetReadMode(u32 port_no, u32 rmode) { sys_io.trace("cellKbSetReadMode(port_no=%d, rmode=%d)", port_no, rmode); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) + const auto init = handler->init.access(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; if (port_no >= CELL_KB_MAX_KEYBOARDS || rmode > CELL_KB_RMODE_PACKET) @@ -368,9 +386,11 @@ error_code cellKbGetConfiguration(u32 port_no, vm::ptr config) { sys_io.trace("cellKbGetConfiguration(port_no=%d, config=*0x%x)", port_no, config); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) + const auto init = handler->init.access(); + + if (!init) return CELL_KB_ERROR_UNINITIALIZED; if (port_no >= CELL_KB_MAX_KEYBOARDS) diff --git a/rpcs3/Emu/Cell/Modules/cellMouse.cpp b/rpcs3/Emu/Cell/Modules/cellMouse.cpp index 7d48d25a4b..c67fc41791 100644 --- a/rpcs3/Emu/Cell/Modules/cellMouse.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMouse.cpp @@ -34,19 +34,18 @@ error_code cellMouseInit(u32 max_connect) { sys_io.warning("cellMouseInit(max_connect=%d)", max_connect); - auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (handler) - { + const auto init = handler->init.init(); + + if (!init) return CELL_MOUSE_ERROR_ALREADY_INITIALIZED; - } if (max_connect == 0 || max_connect > CELL_MAX_MICE) { return CELL_MOUSE_ERROR_INVALID_PARAMETER; } - handler = fxm::import(Emu.GetCallbacks().get_mouse_handler); handler->Init(std::min(max_connect, 7u)); return CELL_OK; @@ -56,12 +55,12 @@ error_code cellMouseClearBuf(u32 port_no) { sys_io.trace("cellMouseClearBuf(port_no=%d)", port_no); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } if (port_no >= CELL_MAX_MICE) { @@ -93,11 +92,14 @@ error_code cellMouseEnd() { sys_io.notice("cellMouseEnd()"); - if (!fxm::remove()) - { - return CELL_MOUSE_ERROR_UNINITIALIZED; - } + const auto handler = g_fxo->get(); + const auto init = handler->init.reset(); + + if (!init) + return CELL_MOUSE_ERROR_UNINITIALIZED; + + // TODO return CELL_OK; } @@ -105,12 +107,12 @@ error_code cellMouseGetInfo(vm::ptr info) { sys_io.trace("cellMouseGetInfo(info=*0x%x)", info); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } if (!info) { @@ -132,12 +134,12 @@ error_code cellMouseInfoTabletMode(u32 port_no, vm::ptr inf { sys_io.trace("cellMouseInfoTabletMode(port_no=%d, info=*0x%x)", port_no, info); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } // only check for port_no here. Tests show that valid ports lead to ERROR_FATAL with disconnected devices regardless of info if (port_no >= CELL_MAX_MICE) @@ -169,12 +171,12 @@ error_code cellMouseGetData(u32 port_no, vm::ptr data) { sys_io.trace("cellMouseGetData(port_no=%d, data=*0x%x)", port_no, data); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } if (port_no >= CELL_MAX_MICE || !data) { @@ -217,12 +219,12 @@ error_code cellMouseGetDataList(u32 port_no, vm::ptr data) { sys_io.warning("cellMouseGetDataList(port_no=%d, data=0x%x)", port_no, data); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } if (port_no >= CELL_MAX_MICE || !data) { @@ -263,12 +265,12 @@ error_code cellMouseSetTabletMode(u32 port_no, u32 mode) { sys_io.warning("cellMouseSetTabletMode(port_no=%d, mode=%d)", port_no, mode); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } // only check for port_no here. Tests show that valid ports lead to ERROR_FATAL with disconnected devices regardless of info if (port_no >= CELL_MAX_MICE) @@ -299,12 +301,12 @@ error_code cellMouseGetTabletDataList(u32 port_no, vm::ptr(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } if (port_no >= CELL_MAX_MICE || !data) { @@ -344,12 +346,12 @@ error_code cellMouseGetRawData(u32 port_no, vm::ptr data) { sys_io.warning("cellMouseGetRawData(port_no=%d, data=*0x%x)", port_no, data); - const auto handler = fxm::get(); + const auto handler = g_fxo->get(); - if (!handler) - { + const auto init = handler->init.access(); + + if (!init) return CELL_MOUSE_ERROR_UNINITIALIZED; - } if (port_no >= CELL_MAX_MICE || !data) { diff --git a/rpcs3/Emu/Io/KeyboardHandler.h b/rpcs3/Emu/Io/KeyboardHandler.h index 469b5e033f..14bcc4689e 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.h +++ b/rpcs3/Emu/Io/KeyboardHandler.h @@ -4,6 +4,8 @@ #include +#include "util/init_mutex.hpp" + extern u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode); // (TODO: Can it be problematic to place SysCalls in middle of nowhere?) enum QtKeys @@ -107,4 +109,6 @@ public: std::vector& GetButtons(const u32 keyboard) { return m_keyboards[keyboard].m_buttons; } KbData& GetData(const u32 keyboard) { return m_keyboards[keyboard].m_data; } KbConfig& GetConfig(const u32 keyboard) { return m_keyboards[keyboard].m_config; } + + stx::init_mutex init; }; diff --git a/rpcs3/Emu/Io/MouseHandler.h b/rpcs3/Emu/Io/MouseHandler.h index 2222512586..ebea3cc793 100644 --- a/rpcs3/Emu/Io/MouseHandler.h +++ b/rpcs3/Emu/Io/MouseHandler.h @@ -2,6 +2,7 @@ #include #include "Utilities/mutex.h" +#include "util/init_mutex.hpp" // TODO: HLE info (constants, structs, etc.) should not be available here @@ -255,4 +256,6 @@ public: MouseDataList& GetDataList(const u32 mouse) { return m_mice[mouse].m_datalist; } MouseTabletDataList& GetTabletDataList(const u32 mouse) { return m_mice[mouse].m_tablet_datalist; } MouseRawData& GetRawData(const u32 mouse) { return m_mice[mouse].m_rawdata; } + + stx::init_mutex init; }; diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index aa52b9994d..21ddc1c1f2 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1517,6 +1517,8 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa g_fxo->init(); fxm::import(Emu.GetCallbacks().get_gs_render); // TODO: must be created in appropriate sys_rsx syscall Emu.GetCallbacks().init_pad_handler(m_title_id); + Emu.GetCallbacks().init_kb_handler(); + Emu.GetCallbacks().init_mouse_handler(); network_thread_init(); } else if (ppu_prx.open(elf_file) == elf_error::ok) diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index e71c6e2093..521f0d1049 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -217,8 +217,8 @@ struct EmuCallbacks std::function reset_pads; std::function enable_pads; std::function handle_taskbar_progress; // (type, value) type: 0 for reset, 1 for increment, 2 for set_limit - std::function()> get_kb_handler; - std::function()> get_mouse_handler; + std::function init_kb_handler; + std::function init_mouse_handler; std::function init_pad_handler; std::function()> get_gs_frame; std::function()> get_gs_render; diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index 321611ce2c..4af3b61178 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -71,33 +71,41 @@ EmuCallbacks main_application::CreateCallbacks() pad::get_current_handler()->SetEnabled(enable); }; - callbacks.get_kb_handler = [=]() -> std::shared_ptr + callbacks.init_kb_handler = [=]() { switch (keyboard_handler type = g_cfg.io.keyboard) { - case keyboard_handler::null: return std::make_shared(); + case keyboard_handler::null: + { + g_fxo->init(); + break; + } case keyboard_handler::basic: { - basic_keyboard_handler* ret = new basic_keyboard_handler(); + basic_keyboard_handler* ret = g_fxo->init(); ret->moveToThread(get_thread()); ret->SetTargetWindow(m_game_window); - return std::shared_ptr(ret); + break; } default: fmt::throw_exception("Invalid keyboard handler: %s", type); } }; - callbacks.get_mouse_handler = [=]() -> std::shared_ptr + callbacks.init_mouse_handler = [=]() { switch (mouse_handler type = g_cfg.io.mouse) { - case mouse_handler::null: return std::make_shared(); + case mouse_handler::null: + { + g_fxo->init(); + break; + } case mouse_handler::basic: { - basic_mouse_handler* ret = new basic_mouse_handler(); + basic_mouse_handler* ret = g_fxo->init(); ret->moveToThread(get_thread()); ret->SetTargetWindow(m_game_window); - return std::shared_ptr(ret); + break; } default: fmt::throw_exception("Invalid mouse handler: %s", type); }