From 28181919a60c21d9c217fd56b9994fa7778a87c4 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Sat, 21 Sep 2019 18:43:43 +1000 Subject: Deglobalize System: Hid --- .../service/hid/controllers/controller_base.cpp | 4 ++-- .../hle/service/hid/controllers/controller_base.h | 8 +++++-- src/core/hle/service/hid/controllers/debug_pad.cpp | 2 +- src/core/hle/service/hid/controllers/debug_pad.h | 2 +- src/core/hle/service/hid/controllers/gesture.cpp | 2 +- src/core/hle/service/hid/controllers/gesture.h | 2 +- src/core/hle/service/hid/controllers/keyboard.cpp | 2 +- src/core/hle/service/hid/controllers/keyboard.h | 2 +- src/core/hle/service/hid/controllers/mouse.cpp | 2 +- src/core/hle/service/hid/controllers/mouse.h | 2 +- src/core/hle/service/hid/controllers/npad.cpp | 4 ++-- src/core/hle/service/hid/controllers/npad.h | 2 +- src/core/hle/service/hid/controllers/stubbed.cpp | 2 +- src/core/hle/service/hid/controllers/stubbed.h | 2 +- .../hle/service/hid/controllers/touchscreen.cpp | 2 +- src/core/hle/service/hid/controllers/touchscreen.h | 2 +- src/core/hle/service/hid/controllers/xpad.cpp | 2 +- src/core/hle/service/hid/controllers/xpad.h | 2 +- src/core/hle/service/hid/hid.cpp | 27 +++++++++++----------- src/core/hle/service/hid/hid.h | 8 ++++--- 20 files changed, 44 insertions(+), 37 deletions(-) (limited to 'src/core') diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index 0993a7815..cc935b031 100644 --- a/src/core/hle/service/hid/controllers/controller_base.cpp +++ b/src/core/hle/service/hid/controllers/controller_base.cpp @@ -9,12 +9,12 @@ namespace Service::HID { ControllerBase::ControllerBase() = default; ControllerBase::~ControllerBase() = default; -void ControllerBase::ActivateController() { +void ControllerBase::ActivateController(Core::System& system) { if (is_activated) { OnRelease(); } is_activated = true; - OnInit(); + OnInit(system); } void ControllerBase::DeactivateController() { diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h index 5e5097a03..7abe24f1d 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h @@ -11,6 +11,10 @@ namespace Core::Timing { class CoreTiming; } +namespace Core { +class System; +} + namespace Service::HID { class ControllerBase { public: @@ -18,7 +22,7 @@ public: virtual ~ControllerBase(); // Called when the controller is initialized - virtual void OnInit() = 0; + virtual void OnInit(Core::System& system) = 0; // When the controller is released virtual void OnRelease() = 0; @@ -30,7 +34,7 @@ public: // Called when input devices should be loaded virtual void OnLoadInputDevices() = 0; - void ActivateController(); + void ActivateController(Core::System& system); void DeactivateController(); diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index c5c2e032a..2c5528b67 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp @@ -17,7 +17,7 @@ enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right }; Controller_DebugPad::Controller_DebugPad() = default; Controller_DebugPad::~Controller_DebugPad() = default; -void Controller_DebugPad::OnInit() {} +void Controller_DebugPad::OnInit(Core::System& system) {} void Controller_DebugPad::OnRelease() {} diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h index e584b92ec..629d6d582 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h @@ -20,7 +20,7 @@ public: ~Controller_DebugPad() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index a179252e3..c01fd6d4e 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp @@ -13,7 +13,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00; Controller_Gesture::Controller_Gesture() = default; Controller_Gesture::~Controller_Gesture() = default; -void Controller_Gesture::OnInit() {} +void Controller_Gesture::OnInit(Core::System& system) {} void Controller_Gesture::OnRelease() {} diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index f305fe90f..c3827fa00 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h @@ -16,7 +16,7 @@ public: ~Controller_Gesture() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 92d7bfb52..b3fbb7962 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp @@ -15,7 +15,7 @@ constexpr u8 KEYS_PER_BYTE = 8; Controller_Keyboard::Controller_Keyboard() = default; Controller_Keyboard::~Controller_Keyboard() = default; -void Controller_Keyboard::OnInit() {} +void Controller_Keyboard::OnInit(Core::System& system) {} void Controller_Keyboard::OnRelease() {} diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h index 73cd2c7bb..a594706a9 100644 --- a/src/core/hle/service/hid/controllers/keyboard.h +++ b/src/core/hle/service/hid/controllers/keyboard.h @@ -19,7 +19,7 @@ public: ~Controller_Keyboard() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index 11ab096d9..fd3f91e65 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp @@ -14,7 +14,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400; Controller_Mouse::Controller_Mouse() = default; Controller_Mouse::~Controller_Mouse() = default; -void Controller_Mouse::OnInit() {} +void Controller_Mouse::OnInit(Core::System& system) {} void Controller_Mouse::OnRelease() {} void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h index 9d46eecbe..df3a17491 100644 --- a/src/core/hle/service/hid/controllers/mouse.h +++ b/src/core/hle/service/hid/controllers/mouse.h @@ -18,7 +18,7 @@ public: ~Controller_Mouse() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index e47fe8188..104924d03 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -167,8 +167,8 @@ void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) { controller.battery_level[2] = BATTERY_FULL; } -void Controller_NPad::OnInit() { - auto& kernel = Core::System::GetInstance().Kernel(); +void Controller_NPad::OnInit(Core::System& system) { + auto& kernel = system.Kernel(); styleset_changed_event = Kernel::WritableEvent::CreateEventPair( kernel, Kernel::ResetType::Automatic, "npad:NpadStyleSetChanged"); diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index f28b36806..755739700 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -24,7 +24,7 @@ public: ~Controller_NPad() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp index 946948f5e..5de75c958 100644 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ b/src/core/hle/service/hid/controllers/stubbed.cpp @@ -12,7 +12,7 @@ namespace Service::HID { Controller_Stubbed::Controller_Stubbed() = default; Controller_Stubbed::~Controller_Stubbed() = default; -void Controller_Stubbed::OnInit() {} +void Controller_Stubbed::OnInit(Core::System& system) {} void Controller_Stubbed::OnRelease() {} diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/stubbed.h index 24469f03e..af636bae3 100644 --- a/src/core/hle/service/hid/controllers/stubbed.h +++ b/src/core/hle/service/hid/controllers/stubbed.h @@ -14,7 +14,7 @@ public: ~Controller_Stubbed() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index 1a8445a43..ea8dffaab 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp @@ -16,7 +16,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400; Controller_Touchscreen::Controller_Touchscreen() = default; Controller_Touchscreen::~Controller_Touchscreen() = default; -void Controller_Touchscreen::OnInit() {} +void Controller_Touchscreen::OnInit(Core::System& system) {} void Controller_Touchscreen::OnRelease() {} diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index 76fc340e9..fdb45fd85 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h @@ -18,7 +18,7 @@ public: ~Controller_Touchscreen() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp index 1a9da9576..22ee0c7d7 100644 --- a/src/core/hle/service/hid/controllers/xpad.cpp +++ b/src/core/hle/service/hid/controllers/xpad.cpp @@ -13,7 +13,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00; Controller_XPad::Controller_XPad() = default; Controller_XPad::~Controller_XPad() = default; -void Controller_XPad::OnInit() {} +void Controller_XPad::OnInit(Core::System& system) {} void Controller_XPad::OnRelease() {} diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h index 2864e6617..8522efd50 100644 --- a/src/core/hle/service/hid/controllers/xpad.h +++ b/src/core/hle/service/hid/controllers/xpad.h @@ -16,7 +16,7 @@ public: ~Controller_XPad() override; // Called when the controller is initialized - void OnInit() override; + void OnInit(Core::System& system) override; // When the controller is released void OnRelease() override; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index f8b1ca816..277dfe240 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -42,13 +42,14 @@ constexpr s64 accelerometer_update_ticks = static_cast(Core::Timing::BASE_C constexpr s64 gyroscope_update_ticks = static_cast(Core::Timing::BASE_CLOCK_RATE / 100); constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000; -IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") { +IAppletResource::IAppletResource(Core::System& system) + : ServiceFramework("IAppletResource"), system(system) { static const FunctionInfo functions[] = { {0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"}, }; RegisterHandlers(functions); - auto& kernel = Core::System::GetInstance().Kernel(); + auto& kernel = system.Kernel(); shared_mem = Kernel::SharedMemory::Create( kernel, nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite, Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); @@ -66,15 +67,15 @@ IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") { MakeController(HidController::Gesture); // Homebrew doesn't try to activate some controllers, so we activate them by default - GetController(HidController::NPad).ActivateController(); - GetController(HidController::Touchscreen).ActivateController(); + GetController(HidController::NPad).ActivateController(system); + GetController(HidController::Touchscreen).ActivateController(system); GetController(HidController::Unknown1).SetCommonHeaderOffset(0x4c00); GetController(HidController::Unknown2).SetCommonHeaderOffset(0x4e00); GetController(HidController::Unknown3).SetCommonHeaderOffset(0x5000); // Register update callbacks - auto& core_timing = Core::System::GetInstance().CoreTiming(); + auto& core_timing = system.CoreTiming(); pad_update_event = core_timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) { UpdateControllers(userdata, cycles_late); @@ -88,7 +89,7 @@ IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") { } void IAppletResource::ActivateController(HidController controller) { - controllers[static_cast(controller)]->ActivateController(); + controllers[static_cast(controller)]->ActivateController(system); } void IAppletResource::DeactivateController(HidController controller) { @@ -96,7 +97,7 @@ void IAppletResource::DeactivateController(HidController controller) { } IAppletResource ::~IAppletResource() { - Core::System::GetInstance().CoreTiming().UnscheduleEvent(pad_update_event, 0); + system.CoreTiming().UnscheduleEvent(pad_update_event, 0); } void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) { @@ -108,7 +109,7 @@ void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) { } void IAppletResource::UpdateControllers(u64 userdata, s64 cycles_late) { - auto& core_timing = Core::System::GetInstance().CoreTiming(); + auto& core_timing = system.CoreTiming(); const bool should_reload = Settings::values.is_device_reload_pending.exchange(false); for (const auto& controller : controllers) { @@ -141,13 +142,13 @@ private: std::shared_ptr Hid::GetAppletResource() { if (applet_resource == nullptr) { - applet_resource = std::make_shared(); + applet_resource = std::make_shared(system); } return applet_resource; } -Hid::Hid() : ServiceFramework("hid") { +Hid::Hid(Core::System& system) : ServiceFramework("hid"), system(system) { // clang-format off static const FunctionInfo functions[] = { {0, &Hid::CreateAppletResource, "CreateAppletResource"}, @@ -286,7 +287,7 @@ void Hid::CreateAppletResource(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); if (applet_resource == nullptr) { - applet_resource = std::make_shared(); + applet_resource = std::make_shared(system); } IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -1053,8 +1054,8 @@ void ReloadInputDevices() { Settings::values.is_device_reload_pending.store(true); } -void InstallInterfaces(SM::ServiceManager& service_manager) { - std::make_shared()->InstallAsService(service_manager); +void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { + std::make_shared(system)->InstallAsService(service_manager); std::make_shared()->InstallAsService(service_manager); std::make_shared()->InstallAsService(service_manager); std::make_shared()->InstallAsService(service_manager); diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 2fd6d9fc7..bf8dbdc0e 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -42,7 +42,7 @@ enum class HidController : std::size_t { class IAppletResource final : public ServiceFramework { public: - IAppletResource(); + IAppletResource(Core::System& system); ~IAppletResource() override; void ActivateController(HidController controller); @@ -70,6 +70,7 @@ private: Kernel::SharedPtr shared_mem; Core::Timing::EventType* pad_update_event; + Core::System& system; std::array, static_cast(HidController::MaxControllers)> controllers{}; @@ -77,7 +78,7 @@ private: class Hid final : public ServiceFramework { public: - Hid(); + Hid(Core::System& system); ~Hid() override; std::shared_ptr GetAppletResource(); @@ -126,12 +127,13 @@ private: void SwapNpadAssignment(Kernel::HLERequestContext& ctx); std::shared_ptr applet_resource; + Core::System& system; }; /// Reload input devices. Used when input configuration changed void ReloadInputDevices(); /// Registers all HID services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager); +void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); } // namespace Service::HID -- cgit v1.2.3