diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index 0993a78153131bf066e91aa36ea95e7aeb66e830..cc935b031c9b01ca382946bd715e07eb3e863237 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 5e5097a0392fc2a4b92bfd730875a201eb9ddd8c..7abe24f1dc537385cb727b82400dec445127c17c 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 c5c2e032af49023ac065d87e8828cd877e8fa1b2..2c5528b6779dbf9ed8a5bfa248e7ad8fa2786ce8 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 e584b92ec7922f86eeae6b7dc8fa4397a863b751..629d6d582b188f3311d82773a606f6d9c62881f1 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 a179252e3402b6988ec0804855e22952b2e74d95..c01fd6d4e5963b1211dff5e8af56053fc9e6eb2e 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 f305fe90f247301e2efb990e283e3602435dc33f..c3827fa00db751e66dbf65619662588ee0081793 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 92d7bfb52c11c5fbc999005b6097199c472af90b..b3fbb7962e4ea7d630f72b7785710f8c75c622e7 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 73cd2c7bba36d6e277a8490c10f9b630ec5ab543..a594706a9c070b6223987d4f8cc7b1df6b2017af 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 11ab096d9bb28af3ccd4714647dcff0cf579f9af..fd3f91e65b64a46cf914ee1b345ca57f3b35ead6 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 9d46eecbe36ce089fe6a156767856efed49badb8..df3a17491b27525700df40467a8513dab40a15d7 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 e47fe81885cd87e9aac23b3704ee5978485dfeb1..104924d0398132025b33c6d5aef5b3bd194461e4 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 f28b368066b6da963757a0df6b20090fc493510b..755739700491bbdef5774d67ae73042a40e6736f 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 946948f5ec5ef043888c4a3bc763114f5977747c..5de75c95868e6bf472a500ffb780cde9b946bce9 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 24469f03e441301d245ad347b9c3d645a1efc6ec..af636bae35640c44e106c24c000a47cb750c65a8 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 1a8445a430d16fcb8b1c179a6feeb3d1e0f376b9..ea8dffaabee0b59b4df0431c10a67b9c5507ec8d 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 76fc340e96b4d80c279d2c878323529c184e6eb0..fdb45fd85ddb9a5aaf085b40cbde209f965818ad 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 1a9da95767c67edc295afc430137083a635fe1e4..22ee0c7d75b746653f626e7c9e651eeb4af987b9 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 2864e6617e5002328ffeee5db9107a6dbaa029e2..8522efd5013dd2cc07c5328e3b3a10bf00323427 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 f8b1ca81669a1e9ae868a0ba932dcae1434c2263..277dfe2405b30d0802fb288abe357d3e17903dbf 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<s64>(Core::Timing::BASE_C constexpr s64 gyroscope_update_ticks = static_cast<s64>(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<Controller_Gesture>(HidController::Gesture); // Homebrew doesn't try to activate some controllers, so we activate them by default - GetController<Controller_NPad>(HidController::NPad).ActivateController(); - GetController<Controller_Touchscreen>(HidController::Touchscreen).ActivateController(); + GetController<Controller_NPad>(HidController::NPad).ActivateController(system); + GetController<Controller_Touchscreen>(HidController::Touchscreen).ActivateController(system); GetController<Controller_Stubbed>(HidController::Unknown1).SetCommonHeaderOffset(0x4c00); GetController<Controller_Stubbed>(HidController::Unknown2).SetCommonHeaderOffset(0x4e00); GetController<Controller_Stubbed>(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<size_t>(controller)]->ActivateController(); + controllers[static_cast<size_t>(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<IAppletResource> Hid::GetAppletResource() { if (applet_resource == nullptr) { - applet_resource = std::make_shared<IAppletResource>(); + applet_resource = std::make_shared<IAppletResource>(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<IAppletResource>(); + applet_resource = std::make_shared<IAppletResource>(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<Hid>()->InstallAsService(service_manager); +void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { + std::make_shared<Hid>(system)->InstallAsService(service_manager); std::make_shared<HidBus>()->InstallAsService(service_manager); std::make_shared<HidDbg>()->InstallAsService(service_manager); std::make_shared<HidSys>()->InstallAsService(service_manager); diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 2fd6d9fc705ee476ec8b52d8ac6c31284ae24032..bf8dbdc0e87c17967421f85a3ea654ff61a30420 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<IAppletResource> { public: - IAppletResource(); + IAppletResource(Core::System& system); ~IAppletResource() override; void ActivateController(HidController controller); @@ -70,6 +70,7 @@ private: Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; Core::Timing::EventType* pad_update_event; + Core::System& system; std::array<std::unique_ptr<ControllerBase>, static_cast<size_t>(HidController::MaxControllers)> controllers{}; @@ -77,7 +78,7 @@ private: class Hid final : public ServiceFramework<Hid> { public: - Hid(); + Hid(Core::System& system); ~Hid() override; std::shared_ptr<IAppletResource> GetAppletResource(); @@ -126,12 +127,13 @@ private: void SwapNpadAssignment(Kernel::HLERequestContext& ctx); std::shared_ptr<IAppletResource> 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