From f34a09b39ffba84e737e036e606b839ad9be4c01 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Wed, 10 Aug 2022 14:50:29 +1200 Subject: [PATCH 01/93] Enforce minimum supported versions of GCC and Clang We already have a minimum required version of MSVC --- CMakeLists.txt | 31 +++++++++++++++++++++++++------ Contributing.md | 3 ++- Readme.md | 10 ++++++---- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2530c1a0ef..ccb05cc3c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,31 @@ if (MSVC) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() +set(COMPILER ${CMAKE_CXX_COMPILER_ID}) +if (COMPILER STREQUAL "GNU") + set(COMPILER "GCC") # perfer printing GCC instead of GNU +endif() + +# Enforce minimium compiler versions that support the c++20 features we use +set (GCC_min_version 10) +set (Clang_min_version 11) +set (AppleClang_min_version 12.0.5) +set (min_xcode_version "12.5.1") # corrosponding xcode version for AppleClang_min_version +set (MSVC_min_version 14.32) +set (min_vs_version "2022 17.2.3") # corrosponding Visual Studio version for MSVC_min_version + +message(STATUS "Using ${COMPILER} ${CMAKE_CXX_COMPILER_VERSION}") + +if ("-" STREQUAL "${${COMPILER}_min_version}-") + message(WARNING "Unknown compiler ${COMPILER}, assuming it is new enough") +else() + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${${COMPILER}_min_version}) + message(FATAL_ERROR "Requires GCC ${GCC_min_version}, Clang ${Clang_min_version}," + " AppleClang ${AppleClang_min_version} (Xcode ${min_xcode_version})," + " or MSVC ${MSVC_min_version} (Visual Studio ${min_vs_version}) or higher") + endif() +endif() + # Name of the Dolphin distributor. If you redistribute Dolphin builds (forks, # unofficial builds) please consider identifying your distribution with a # unique name here. @@ -255,12 +280,6 @@ else() " Enable generic build if you really want a JIT-less binary.") endif() - -# Enforce minimum GCC version -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) - message(FATAL_ERROR "Dolphin requires at least GCC 7.0 (found ${CMAKE_CXX_COMPILER_VERSION})") -endif() - if(CMAKE_GENERATOR MATCHES "Ninja") check_and_add_flag(DIAGNOSTICS_COLOR -fdiagnostics-color) elseif(CMAKE_GENERATOR MATCHES "Visual Studio") diff --git a/Contributing.md b/Contributing.md index a78436d5df..21c6a96888 100644 --- a/Contributing.md +++ b/Contributing.md @@ -173,7 +173,8 @@ Summary: - [Classes and Structs](#cpp-code-classes-and-structs) ## General -- The codebase currently uses C++17. +- The codebase currently uses C++20, though not all compilers support all C++20 features. + - See CMakeLists.txt "Enforce minimium compiler versions" for the currently supported compilers. - Use the [nullptr](https://en.cppreference.com/w/cpp/language/nullptr) type over the macro `NULL`. - If a [range-based for loop](https://en.cppreference.com/w/cpp/language/range-for) can be used instead of container iterators, use it. - Obviously, try not to use `goto` unless you have a *really* good reason for it. diff --git a/Readme.md b/Readme.md index 7723fc1fc0..7262e6173f 100644 --- a/Readme.md +++ b/Readme.md @@ -53,10 +53,12 @@ The "Debug" solution configuration is significantly slower, more verbose and les ## Building for Linux and macOS -Dolphin requires [CMake](https://cmake.org/) for systems other than Windows. Many libraries are -bundled with Dolphin and used if they're not installed on your system. CMake -will inform you if a bundled library is used or if you need to install any -missing packages yourself. You may refer to the [wiki](https://github.com/dolphin-emu/dolphin/wiki/Building-for-Linux) for more information. +Dolphin requires [CMake](https://cmake.org/) for systems other than Windows. +You need a recent version of GCC or Clang with decent c++20 support. CMake will +inform you if your compiler is too old. +Many libraries are bundled with Dolphin and used if they're not installed on +your system. CMake will inform you if a bundled library is used or if you need +to install any missing packages yourself. You may refer to the [wiki](https://github.com/dolphin-emu/dolphin/wiki/Building-for-Linux) for more information. Make sure to pull submodules before building: ```sh From a306da2f80ab3d08b674cfc3ed35ee85536669e6 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Thu, 23 Feb 2023 15:27:57 +1300 Subject: [PATCH 02/93] Bump requried Clang to 12 (AppleClang 13.0.0) --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ccb05cc3c6..6717d3a401 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,9 +45,9 @@ endif() # Enforce minimium compiler versions that support the c++20 features we use set (GCC_min_version 10) -set (Clang_min_version 11) -set (AppleClang_min_version 12.0.5) -set (min_xcode_version "12.5.1") # corrosponding xcode version for AppleClang_min_version +set (Clang_min_version 12) +set (AppleClang_min_version 13.0.0) +set (min_xcode_version "13.0") # corrosponding xcode version for AppleClang_min_version set (MSVC_min_version 14.32) set (min_vs_version "2022 17.2.3") # corrosponding Visual Studio version for MSVC_min_version From 72d08f6c8022dd1181270029980e64d9b70e9ce3 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Fri, 7 Apr 2023 15:40:14 -0400 Subject: [PATCH 03/93] InputCommon: Remove OSX (IOKit) input backend --- Source/Core/InputCommon/CMakeLists.txt | 6 - .../ControllerInterface.cpp | 20 +- .../InputCommon/ControllerInterface/OSX/OSX.h | 12 - .../ControllerInterface/OSX/OSX.mm | 222 ------------ .../ControllerInterface/OSX/OSXJoystick.h | 90 ----- .../ControllerInterface/OSX/OSXJoystick.mm | 342 ------------------ .../ControllerInterface/OSX/RunLoopStopper.h | 40 -- 7 files changed, 1 insertion(+), 731 deletions(-) delete mode 100644 Source/Core/InputCommon/ControllerInterface/OSX/OSX.h delete mode 100644 Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm delete mode 100644 Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h delete mode 100644 Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm delete mode 100644 Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index 597a90291f..a0993f9689 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -107,11 +107,6 @@ if(WIN32) ) elseif(APPLE) target_sources(inputcommon PRIVATE - ControllerInterface/OSX/OSX.h - ControllerInterface/OSX/OSX.mm - ControllerInterface/OSX/OSXJoystick.h - ControllerInterface/OSX/OSXJoystick.mm - ControllerInterface/OSX/RunLoopStopper.h ControllerInterface/Quartz/Quartz.h ControllerInterface/Quartz/Quartz.mm ControllerInterface/Quartz/QuartzKeyboardAndMouse.h @@ -124,7 +119,6 @@ elseif(APPLE) ${CARBON_LIBRARY} ${COCOA_LIBRARY} ${FORCEFEEDBACK_LIBRARY} - ${IOK_LIBRARY} ) target_compile_options(inputcommon PRIVATE -fobjc-arc diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 5b7e27ffe1..004454dd29 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -16,7 +16,6 @@ #include "InputCommon/ControllerInterface/Xlib/XInput2.h" #endif #ifdef CIFACE_USE_OSX -#include "InputCommon/ControllerInterface/OSX/OSX.h" #include "InputCommon/ControllerInterface/Quartz/Quartz.h" #endif #ifdef CIFACE_USE_SDL @@ -61,7 +60,7 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi) // nothing needed #endif #ifdef CIFACE_USE_OSX -// nothing needed for OSX and Quartz +// nothing needed for Quartz #endif #ifdef CIFACE_USE_SDL m_input_backends.emplace_back(ciface::SDL::CreateInputBackend(this)); @@ -114,18 +113,6 @@ void ControllerInterface::RefreshDevices(RefreshReason reason) if (!m_is_init) return; -#ifdef CIFACE_USE_OSX - if (m_wsi.type == WindowSystemType::MacOS) - { - std::lock_guard lk_pre_population(m_pre_population_mutex); - // This is needed to stop its threads before locking our mutexes, to avoid deadlocks - // (in case it tried to add a device after we had locked m_devices_population_mutex). - // There doesn't seem to be an easy to way to repopulate OSX devices without restarting its - // hotplug thread. This should not remove its devices, and if it did, calls should be ignored. - ciface::OSX::DeInit(); - } -#endif - // We lock m_devices_population_mutex here to make everything simpler. // Multiple devices classes have their own "hotplug" thread, and can add/remove devices at any // time, while actual writes to "m_devices" are safe, the order in which they happen is not. That @@ -174,10 +161,6 @@ void ControllerInterface::RefreshDevices(RefreshReason reason) #ifdef CIFACE_USE_OSX if (m_wsi.type == WindowSystemType::MacOS) { - { - std::lock_guard lk_pre_population(m_pre_population_mutex); - ciface::OSX::Init(); - } ciface::Quartz::PopulateDevices(m_wsi.render_window); } #endif @@ -233,7 +216,6 @@ void ControllerInterface::Shutdown() // nothing needed #endif #ifdef CIFACE_USE_OSX - ciface::OSX::DeInit(); ciface::Quartz::DeInit(); #endif #ifdef CIFACE_USE_ANDROID diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.h b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.h deleted file mode 100644 index 6bb05c5543..0000000000 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2010 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -namespace ciface::OSX -{ -void Init(); -void DeInit(); - -void DeviceElementDebugPrint(const void*, void*); -} // namespace ciface::OSX diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm deleted file mode 100644 index 2d0651b6bd..0000000000 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "InputCommon/ControllerInterface/OSX/OSX.h" - -#include - -#include -#include -#include - -#include "Common/Logging/Log.h" -#include "Common/StringUtil.h" -#include "Common/Thread.h" - -#include "InputCommon/ControllerInterface/ControllerInterface.h" -#include "InputCommon/ControllerInterface/OSX/OSXJoystick.h" -#include "InputCommon/ControllerInterface/OSX/RunLoopStopper.h" - -namespace ciface::OSX -{ -constexpr CFTimeInterval FOREVER = 1e20; -static std::thread s_hotplug_thread; -static RunLoopStopper s_stopper; -static IOHIDManagerRef HIDManager = nullptr; -static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput"); - -void DeviceElementDebugPrint(const void* value, void* context) -{ - IOHIDElementRef e = (IOHIDElementRef)value; - bool recurse = false; - if (context) - recurse = *(bool*)context; - - std::string type = ""; - switch (IOHIDElementGetType(e)) - { - case kIOHIDElementTypeInput_Axis: - type = "axis"; - break; - case kIOHIDElementTypeInput_Button: - type = "button"; - break; - case kIOHIDElementTypeInput_Misc: - type = "misc"; - break; - case kIOHIDElementTypeInput_ScanCodes: - type = "scancodes"; - break; - case kIOHIDElementTypeOutput: - type = "output"; - break; - case kIOHIDElementTypeFeature: - type = "feature"; - break; - case kIOHIDElementTypeCollection: - type = "collection"; - break; - } - - std::string c_type = ""; - if (type == "collection") - { - switch (IOHIDElementGetCollectionType(e)) - { - case kIOHIDElementCollectionTypePhysical: - c_type = "physical"; - break; - case kIOHIDElementCollectionTypeApplication: - c_type = "application"; - break; - case kIOHIDElementCollectionTypeLogical: - c_type = "logical"; - break; - case kIOHIDElementCollectionTypeReport: - c_type = "report"; - break; - case kIOHIDElementCollectionTypeNamedArray: - c_type = "namedArray"; - break; - case kIOHIDElementCollectionTypeUsageSwitch: - c_type = "usageSwitch"; - break; - case kIOHIDElementCollectionTypeUsageModifier: - c_type = "usageModifier"; - break; - } - } - - c_type.append(" "); - NSLog(@"%s%s%spage: 0x%x usage: 0x%x name: %@ " - "lmin: %ld lmax: %ld pmin: %ld pmax: %ld", - type.c_str(), type == "collection" ? ":" : "", type == "collection" ? c_type.c_str() : " ", - IOHIDElementGetUsagePage(e), IOHIDElementGetUsage(e), - IOHIDElementGetName(e), // usually just nullptr - IOHIDElementGetLogicalMin(e), IOHIDElementGetLogicalMax(e), IOHIDElementGetPhysicalMin(e), - IOHIDElementGetPhysicalMax(e)); - - if ((type == "collection") && recurse) - { - CFArrayRef elements = IOHIDElementGetChildren(e); - CFRange range = {0, CFArrayGetCount(elements)}; - // this leaks...but it's just debug code, right? :D - CFArrayApplyFunction(elements, range, DeviceElementDebugPrint, nullptr); - } -} - -static void DeviceDebugPrint(IOHIDDeviceRef device) -{ -#if 0 -#define shortlog(x) NSLog(@"%s: %@", x, IOHIDDeviceGetProperty(device, CFSTR(x))); - NSLog(@"-------------------------"); - NSLog(@"Got Device: %@", - IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey))); - shortlog(kIOHIDTransportKey) - shortlog(kIOHIDVendorIDKey) - shortlog(kIOHIDVendorIDSourceKey) - shortlog(kIOHIDProductIDKey) - shortlog(kIOHIDVersionNumberKey) - shortlog(kIOHIDManufacturerKey) - shortlog(kIOHIDProductKey) - shortlog(kIOHIDSerialNumberKey) - shortlog(kIOHIDCountryCodeKey) - shortlog(kIOHIDLocationIDKey) - shortlog(kIOHIDDeviceUsageKey) - shortlog(kIOHIDDeviceUsagePageKey) - shortlog(kIOHIDDeviceUsagePairsKey) - shortlog(kIOHIDPrimaryUsageKey) - shortlog(kIOHIDPrimaryUsagePageKey) - shortlog(kIOHIDMaxInputReportSizeKey) - shortlog(kIOHIDMaxOutputReportSizeKey) - shortlog(kIOHIDMaxFeatureReportSizeKey) - shortlog(kIOHIDReportIntervalKey) - shortlog(kIOHIDReportDescriptorKey) -#endif -} - -static std::string GetDeviceRefName(IOHIDDeviceRef inIOHIDDeviceRef) -{ - const NSString* name = reinterpret_cast( - IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductKey))); - return (name != nullptr) ? std::string(StripWhitespace([name UTF8String])) : "Unknown device"; -} - -static void DeviceRemovalCallback(void* inContext, IOReturn inResult, void* inSender, - IOHIDDeviceRef inIOHIDDeviceRef) -{ - g_controller_interface.RemoveDevice([&inIOHIDDeviceRef](const auto* device) { - const Joystick* joystick = dynamic_cast(device); - if (joystick && joystick->IsSameDevice(inIOHIDDeviceRef)) - return true; - - return false; - }); -} - -static void DeviceMatchingCallback(void* inContext, IOReturn inResult, void* inSender, - IOHIDDeviceRef inIOHIDDeviceRef) -{ - DeviceDebugPrint(inIOHIDDeviceRef); - std::string name = GetDeviceRefName(inIOHIDDeviceRef); - - // Add a device if it's of a type we want - if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick) || - IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad) || - IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, - kHIDUsage_GD_MultiAxisController)) - { - g_controller_interface.AddDevice(std::make_shared(inIOHIDDeviceRef, name)); - } -} - -void Init() -{ - HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - if (!HIDManager) - ERROR_LOG_FMT(CONTROLLERINTERFACE, "Failed to create HID Manager reference"); - - IOHIDManagerSetDeviceMatching(HIDManager, nullptr); - if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) - ERROR_LOG_FMT(CONTROLLERINTERFACE, "Failed to open HID Manager"); - - // Callbacks for acquisition or loss of a matching device - IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, DeviceMatchingCallback, nullptr); - IOHIDManagerRegisterDeviceRemovalCallback(HIDManager, DeviceRemovalCallback, nullptr); - - // Match devices that are plugged in right now - IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop); - while (CFRunLoopRunInMode(OurRunLoop, 0, TRUE) == kCFRunLoopRunHandledSource) - { - }; - IOHIDManagerUnscheduleFromRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop); - - // Enable hotplugging - s_hotplug_thread = std::thread([] { - Common::SetCurrentThreadName("IOHIDManager Hotplug Thread"); - NOTICE_LOG_FMT(CONTROLLERINTERFACE, "IOHIDManager hotplug thread started"); - - IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop); - s_stopper.AddToRunLoop(CFRunLoopGetCurrent(), OurRunLoop); - CFRunLoopRunInMode(OurRunLoop, FOREVER, FALSE); - s_stopper.RemoveFromRunLoop(CFRunLoopGetCurrent(), OurRunLoop); - IOHIDManagerUnscheduleFromRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop); - - NOTICE_LOG_FMT(CONTROLLERINTERFACE, "IOHIDManager hotplug thread stopped"); - }); -} - -void DeInit() -{ - if (HIDManager) - { - s_stopper.Signal(); - s_hotplug_thread.join(); - - // This closes all devices as well - IOHIDManagerClose(HIDManager, kIOHIDOptionsTypeNone); - CFRelease(HIDManager); - HIDManager = nullptr; - } -} -} // namespace ciface::OSX diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h deleted file mode 100644 index ba701d7e16..0000000000 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2010 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include - -#include - -#include "InputCommon/ControllerInterface/CoreDevice.h" -#include "InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h" - -namespace ciface::OSX -{ -class Joystick : public ForceFeedback::ForceFeedbackDevice -{ -private: - class Button : public Input - { - public: - Button(IOHIDElementRef element, IOHIDDeviceRef device) : m_element(element), m_device(device) {} - std::string GetName() const override; - ControlState GetState() const override; - - private: - const IOHIDElementRef m_element; - const IOHIDDeviceRef m_device; - }; - - class Axis : public Input - { - public: - enum direction - { - positive = 0, - negative - }; - - Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir); - std::string GetName() const override; - ControlState GetState() const override; - - private: - const IOHIDElementRef m_element; - const IOHIDDeviceRef m_device; - std::string m_name; - const direction m_direction; - float m_neutral; - float m_scale; - }; - - class Hat : public Input - { - public: - enum direction - { - up = 0, - right, - down, - left - }; - - Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir); - std::string GetName() const override; - ControlState GetState() const override; - - private: - const IOHIDElementRef m_element; - const IOHIDDeviceRef m_device; - const char* m_name; - const direction m_direction; - }; - -public: - Joystick(IOHIDDeviceRef device, std::string name); - ~Joystick(); - - std::string GetName() const override; - std::string GetSource() const override; - bool IsSameDevice(const IOHIDDeviceRef) const; - -private: - const IOHIDDeviceRef m_device; - const std::string m_device_name; - - void AddElements(CFArrayRef elements, std::set& cookies); - - ForceFeedback::FFDeviceAdapterReference m_ff_device; -}; -} // namespace ciface::OSX diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm deleted file mode 100644 index 82ad68e205..0000000000 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "InputCommon/ControllerInterface/OSX/OSXJoystick.h" - -#include -#include - -#include -#include - -#include "Common/Logging/Log.h" -#include "Common/StringUtil.h" - -namespace ciface::OSX -{ -void Joystick::AddElements(CFArrayRef elements, std::set& cookies) -{ - for (int i = 0; i < CFArrayGetCount(elements); i++) - { - IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i); - - const uint32_t type = IOHIDElementGetType(e); - - switch (type) - { - case kIOHIDElementTypeCollection: - AddElements(IOHIDElementGetChildren(e), cookies); - continue; - case kIOHIDElementTypeOutput: - continue; - } - - IOHIDElementCookie cookie = IOHIDElementGetCookie(e); - - // Check for any existing elements with the same cookie - if (cookies.count(cookie) > 0) - continue; - - cookies.insert(cookie); - - const uint32_t usage = IOHIDElementGetUsage(e); - - switch (usage) - { - // Axis - case kHIDUsage_GD_X: - case kHIDUsage_GD_Y: - case kHIDUsage_GD_Z: - case kHIDUsage_GD_Rx: - case kHIDUsage_GD_Ry: - case kHIDUsage_GD_Rz: - case kHIDUsage_GD_Slider: - case kHIDUsage_GD_Dial: - case kHIDUsage_GD_Wheel: - case kHIDUsage_GD_Hatswitch: - // Simulator - case kHIDUsage_Sim_Accelerator: - case kHIDUsage_Sim_Brake: - case kHIDUsage_Sim_Rudder: - case kHIDUsage_Sim_Throttle: - { - if (usage == kHIDUsage_GD_Hatswitch) - { - AddInput(new Hat(e, m_device, Hat::up)); - AddInput(new Hat(e, m_device, Hat::right)); - AddInput(new Hat(e, m_device, Hat::down)); - AddInput(new Hat(e, m_device, Hat::left)); - } - else - { - AddAnalogInputs(new Axis(e, m_device, Axis::negative), - new Axis(e, m_device, Axis::positive)); - } - break; - } - // Buttons - case kHIDUsage_GD_DPadUp: - case kHIDUsage_GD_DPadDown: - case kHIDUsage_GD_DPadRight: - case kHIDUsage_GD_DPadLeft: - case kHIDUsage_GD_Start: - case kHIDUsage_GD_Select: - case kHIDUsage_GD_SystemMainMenu: - AddInput(new Button(e, m_device)); - break; - - default: - // Catch any easily identifiable axis and buttons that slipped through - if (type == kIOHIDElementTypeInput_Button) - { - AddInput(new Button(e, m_device)); - break; - } - - const uint32_t usage_page = IOHIDElementGetUsagePage(e); - - if (usage_page == kHIDPage_Button || usage_page == kHIDPage_Consumer) - { - AddInput(new Button(e, m_device)); - break; - } - - if (type == kIOHIDElementTypeInput_Axis) - { - AddAnalogInputs(new Axis(e, m_device, Axis::negative), - new Axis(e, m_device, Axis::positive)); - break; - } - - NOTICE_LOG_FMT(CONTROLLERINTERFACE, - "Unknown IOHIDElement, ignoring (Usage: {:x}, Type: {:x})", usage, - IOHIDElementGetType(e)); - - break; - } - } -} -Joystick::Joystick(IOHIDDeviceRef device, std::string name) - : m_device(device), m_device_name(name), m_ff_device(nullptr) -{ - CFArrayRef elements = IOHIDDeviceCopyMatchingElements(m_device, nullptr, kIOHIDOptionsTypeNone); - std::set known_cookies; - AddElements(elements, known_cookies); - - // Force Feedback - FFCAPABILITIES ff_caps; - if (SUCCEEDED( - ForceFeedback::FFDeviceAdapter::Create(IOHIDDeviceGetService(m_device), &m_ff_device)) && - SUCCEEDED(FFDeviceGetForceFeedbackCapabilities(m_ff_device->m_device, &ff_caps))) - { - InitForceFeedback(m_ff_device, ff_caps.numFfAxes); - } -} - -Joystick::~Joystick() -{ - DeInitForceFeedback(); - - if (m_ff_device) - m_ff_device->Release(); -} - -std::string Joystick::GetName() const -{ - return m_device_name; -} - -std::string Joystick::GetSource() const -{ - return "Input"; -} - -ControlState Joystick::Button::GetState() const -{ - IOHIDValueRef value; - if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess) - return IOHIDValueGetIntegerValue(value); - else - return 0; -} - -std::string Joystick::Button::GetName() const -{ - std::ostringstream s; - s << IOHIDElementGetUsage(m_element); - return std::string("Button ").append(StripWhitespace(s.str())); -} - -Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir) - : m_element(element), m_device(device), m_direction(dir) -{ - // Need to parse the element a bit first - std::string description("unk"); - - int const usage = IOHIDElementGetUsage(m_element); - switch (usage) - { - case kHIDUsage_GD_X: - description = "X"; - break; - case kHIDUsage_GD_Y: - description = "Y"; - break; - case kHIDUsage_GD_Z: - description = "Z"; - break; - case kHIDUsage_GD_Rx: - description = "Rx"; - break; - case kHIDUsage_GD_Ry: - description = "Ry"; - break; - case kHIDUsage_GD_Rz: - description = "Rz"; - break; - case kHIDUsage_GD_Wheel: - description = "Wheel"; - break; - case kHIDUsage_Csmr_ACPan: - description = "Pan"; - break; - default: - { - IOHIDElementCookie elementCookie = IOHIDElementGetCookie(m_element); - // This axis isn't a 'well-known' one so cook a descriptive and uniquely - // identifiable name. macOS provides a 'cookie' for each element that - // will persist between sessions and identify the same physical controller - // element so we can use that as a component of the axis name - std::ostringstream s; - s << "CK-"; - s << elementCookie; - description = StripWhitespace(s.str()); - break; - } - } - - m_name = std::string("Axis ") + description; - m_name.append((m_direction == positive) ? "+" : "-"); - - m_neutral = (IOHIDElementGetLogicalMax(m_element) + IOHIDElementGetLogicalMin(m_element)) / 2.; - m_scale = 1 / fabs(IOHIDElementGetLogicalMax(m_element) - m_neutral); -} - -ControlState Joystick::Axis::GetState() const -{ - IOHIDValueRef value; - - if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess) - { - // IOHIDValueGetIntegerValue() crashes when trying - // to convert unusually large element values. - if (IOHIDValueGetLength(value) > 2) - return 0; - - float position = IOHIDValueGetIntegerValue(value); - - if (m_direction == positive && position > m_neutral) - return (position - m_neutral) * m_scale; - if (m_direction == negative && position < m_neutral) - return (m_neutral - position) * m_scale; - } - - return 0; -} - -std::string Joystick::Axis::GetName() const -{ - return m_name; -} - -Joystick::Hat::Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir) - : m_element(element), m_device(device), m_direction(dir) -{ - switch (dir) - { - case up: - m_name = "Up"; - break; - case right: - m_name = "Right"; - break; - case down: - m_name = "Down"; - break; - case left: - m_name = "Left"; - break; - default: - m_name = "unk"; - } -} - -ControlState Joystick::Hat::GetState() const -{ - IOHIDValueRef value; - - if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess) - { - int position = IOHIDValueGetIntegerValue(value); - int min = IOHIDElementGetLogicalMin(m_element); - int max = IOHIDElementGetLogicalMax(m_element); - - // if the position is outside the min or max, don't register it as a valid button press - if (position < min || position > max) - { - return 0; - } - - // normalize the position so that its lowest value is 0 - position -= min; - - switch (position) - { - case 0: - if (m_direction == up) - return 1; - break; - case 1: - if (m_direction == up || m_direction == right) - return 1; - break; - case 2: - if (m_direction == right) - return 1; - break; - case 3: - if (m_direction == right || m_direction == down) - return 1; - break; - case 4: - if (m_direction == down) - return 1; - break; - case 5: - if (m_direction == down || m_direction == left) - return 1; - break; - case 6: - if (m_direction == left) - return 1; - break; - case 7: - if (m_direction == left || m_direction == up) - return 1; - break; - }; - } - - return 0; -} - -std::string Joystick::Hat::GetName() const -{ - return m_name; -} - -bool Joystick::IsSameDevice(const IOHIDDeviceRef other_device) const -{ - return m_device == other_device; -} -} // namespace ciface::OSX diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h b/Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h deleted file mode 100644 index a749e9f85b..0000000000 --- a/Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include - -namespace ciface::OSX -{ -class RunLoopStopper -{ - CFRunLoopSourceRef m_source; - CFRunLoopRef m_runloop = nullptr; - -public: - RunLoopStopper() - { - CFRunLoopSourceContext ctx = {.version = 0, - .perform = [](void*) { CFRunLoopStop(CFRunLoopGetCurrent()); }}; - m_source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &ctx); - } - ~RunLoopStopper() { CFRelease(m_source); } - void Signal() - { - CFRunLoopSourceSignal(m_source); - if (m_runloop != nullptr) - CFRunLoopWakeUp(m_runloop); - } - void AddToRunLoop(CFRunLoopRef runloop, CFStringRef mode) - { - m_runloop = runloop; - CFRunLoopAddSource(runloop, m_source, mode); - } - void RemoveFromRunLoop(CFRunLoopRef runloop, CFStringRef mode) - { - m_runloop = nullptr; - CFRunLoopRemoveSource(runloop, m_source, mode); - } -}; -} // namespace ciface::OSX From eb6bf08170691bfee4577adcbbb9068ddd09b9ab Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sat, 8 Apr 2023 21:42:49 -0500 Subject: [PATCH 04/93] CMake: Add custom FindIconv Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/24695 --- CMake/FindIconv.cmake | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 CMake/FindIconv.cmake diff --git a/CMake/FindIconv.cmake b/CMake/FindIconv.cmake new file mode 100644 index 0000000000..d0b86fc7cb --- /dev/null +++ b/CMake/FindIconv.cmake @@ -0,0 +1,101 @@ +# Based on CMake's FindIconv.cmake +# Modified to prefer non-built-in iconv over the built-in one +# See https://gitlab.kitware.com/cmake/cmake/-/issues/24695 for details +# This file can be deleted once that issue has been closed and the fix has +# made it into a satisfactory number of cmake versions. FreeBSD is the only +# system known to hit this so far, so "satisfactory" can probably be defined +# as "enough that most FreeBSD users have a fixed cmake". + +find_path(Iconv_INCLUDE_DIR + NAMES "iconv.h" + DOC "iconv include directory") +mark_as_advanced(Iconv_INCLUDE_DIR) + +find_library(Iconv_LIBRARY + NAMES iconv libiconv + NAMES_PER_DIR + DOC "iconv library (if not in the C library)") +mark_as_advanced(Iconv_LIBRARY) + +# iconv can only be provided in libc on a POSIX system. +if(UNIX AND (NOT Iconv_INCLUDE_DIR OR NOT Iconv_LIBRARY)) + include(CMakePushCheckState) + include(CheckCXXSourceCompiles) + cmake_push_check_state(RESET) + # We always suppress the message here: Otherwise on supported systems + # not having iconv in their C library (e.g. those using libiconv) + # would always display a confusing "Looking for iconv - not found" message + set(CMAKE_FIND_QUIETLY TRUE) + # The following code will not work, but it's sufficient to see if it compiles. + # Note: libiconv will define the iconv functions as macros, so CheckSymbolExists + # will not yield correct results. + set(Iconv_IMPLICIT_TEST_CODE + " + #include + #include + int main() { + char *a, *b; + size_t i, j; + iconv_t ic; + ic = iconv_open(\"to\", \"from\"); + iconv(ic, &a, &i, &b, &j); + iconv_close(ic); + } + " + ) + check_cxx_source_compiles("${Iconv_IMPLICIT_TEST_CODE}" Iconv_IS_BUILT_IN) + cmake_pop_check_state() + if(Iconv_IS_BUILT_IN) + unset(Iconv_INCLUDE_DIR) + unset(Iconv_LIBRARY) + endif() +else() + set(Iconv_IS_BUILT_IN FALSE) +endif() + +set(_Iconv_REQUIRED_VARS) +if(Iconv_IS_BUILT_IN) + set(_Iconv_REQUIRED_VARS _Iconv_IS_BUILT_IN_MSG) + set(_Iconv_IS_BUILT_IN_MSG "built in to C library") +else() + set(_Iconv_REQUIRED_VARS Iconv_LIBRARY Iconv_INCLUDE_DIR) +endif() + +# NOTE: glibc's iconv.h does not define _LIBICONV_VERSION +if(Iconv_INCLUDE_DIR AND EXISTS "${Iconv_INCLUDE_DIR}/iconv.h") + file(STRINGS ${Iconv_INCLUDE_DIR}/iconv.h Iconv_VERSION_DEFINE REGEX "_LIBICONV_VERSION (.*)") + + if(Iconv_VERSION_DEFINE MATCHES "(0x[A-Fa-f0-9]+)") + set(Iconv_VERSION_NUMBER "${CMAKE_MATCH_1}") + # encoding -> version number: (major<<8) + minor + math(EXPR Iconv_VERSION_MAJOR "${Iconv_VERSION_NUMBER} >> 8" OUTPUT_FORMAT HEXADECIMAL) + math(EXPR Iconv_VERSION_MINOR "${Iconv_VERSION_NUMBER} - (${Iconv_VERSION_MAJOR} << 8)" OUTPUT_FORMAT HEXADECIMAL) + + math(EXPR Iconv_VERSION_MAJOR "${Iconv_VERSION_MAJOR}" OUTPUT_FORMAT DECIMAL) + math(EXPR Iconv_VERSION_MINOR "${Iconv_VERSION_MINOR}" OUTPUT_FORMAT DECIMAL) + set(Iconv_VERSION "${Iconv_VERSION_MAJOR}.${Iconv_VERSION_MINOR}") + endif() + + unset(Iconv_VERSION_DEFINE) + unset(Iconv_VERSION_NUMBER) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Iconv + REQUIRED_VARS ${_Iconv_REQUIRED_VARS} + VERSION_VAR Iconv_VERSION) + +if(Iconv_FOUND) + if(Iconv_IS_BUILT_IN) + set(Iconv_INCLUDE_DIRS "") + set(Iconv_LIBRARIES "") + else() + set(Iconv_INCLUDE_DIRS "${Iconv_INCLUDE_DIR}") + set(Iconv_LIBRARIES "${Iconv_LIBRARY}") + endif() + if(NOT TARGET Iconv::Iconv) + add_library(Iconv::Iconv INTERFACE IMPORTED) + set_property(TARGET Iconv::Iconv PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${Iconv_INCLUDE_DIRS}") + set_property(TARGET Iconv::Iconv PROPERTY INTERFACE_LINK_LIBRARIES "${Iconv_LIBRARIES}") + endif() +endif() From b9595a2230a0d6bb073c301e365d517cd8d9c8fa Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Thu, 30 Mar 2023 13:12:48 -0500 Subject: [PATCH 05/93] CMake: Use find_package and imported targets for Iconv Fixes us forgetting to add its include directories, which could result in linking to a dylib from MacPorts while using the system's header, and failing to link because they use different function names --- CMakeLists.txt | 11 ++++------- Externals/libiconv-1.14/CMakeLists.txt | 19 +++++++++++-------- Source/Core/Common/CMakeLists.txt | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3904d059d3..12d1a574f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -914,19 +914,16 @@ else() include_directories(BEFORE Externals/curl/include) endif() -if (NOT ANDROID) - find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c) - find_path(ICONV_INCLUDE_DIR NAMES iconv.h) +if(NOT ANDROID) + find_package(Iconv) endif() -if (NOT ANDROID AND ICONV_LIBRARIES AND ICONV_INCLUDE_DIR) - mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARIES) +if(TARGET Iconv::Iconv) + message(STATUS "Using shared iconv") else() check_vendoring_approved(iconv) message(STATUS "Using static iconv from Externals") - include_directories(Externals/libiconv-1.14/include) add_subdirectory(Externals/libiconv-1.14) - set(ICONV_LIBRARIES iconv) endif() if(NOT ANDROID) diff --git a/Externals/libiconv-1.14/CMakeLists.txt b/Externals/libiconv-1.14/CMakeLists.txt index 571a6f791c..9f04f671ff 100644 --- a/Externals/libiconv-1.14/CMakeLists.txt +++ b/Externals/libiconv-1.14/CMakeLists.txt @@ -1,10 +1,13 @@ -include_directories(include) -include_directories(libcharset/include) - -set(SRCS lib/iconv.c - lib/relocatable.c - libcharset/lib/localcharset.c +add_library(iconv STATIC + lib/iconv.c + lib/relocatable.c + libcharset/lib/localcharset.c +) +target_include_directories(iconv + PUBLIC + include + PRIVATE + libcharset/include ) - -add_library(iconv STATIC ${SRCS}) dolphin_disable_warnings_msvc(iconv) +add_library(Iconv::Iconv ALIAS iconv) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 8269290729..178799b888 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -156,7 +156,7 @@ PUBLIC PRIVATE ${CURL_LIBRARIES} FatFs - ${ICONV_LIBRARIES} + Iconv::Iconv ${spng_target} ${VTUNE_LIBRARIES} ) From c6f9e61d38f674d81ba8786739f9fe38490670d0 Mon Sep 17 00:00:00 2001 From: Jeffrey Bosboom Date: Thu, 13 Apr 2023 20:10:00 -0700 Subject: [PATCH 06/93] XInput2: Accept input from keyboards other than the first master XInput2 was created to support multiple pointer/keyboard pairs (often called MPX for multi-pointer X). Dolphin's XInput2 implementation has always supported MPX by creating a KeyboardMouse object per master pointer. Since commit bbb12a7, Dolphin's keyboard state is filtered by the output of XQueryKeymap. As a core X function, XQueryKeymap queries "the" keyboard, which by default is the first master keyboard. As a result, Dolphin will ignore keys pressed on other master keyboards unless the first master is simultaneously pressing the same keys. XInput2 doesn't provide a function to query the keyboard state. There is no XIQueryKeymap and the current state is not a member of the XIKeyClassInfo returned by XIQueryDevice. Instead, XInput2 allows a master pointer to be nominated as "the" pointer on a per-client basis, with "the" keyboard automatically becoming the associated master keyboard. The "documentation" [1] says passing None for the window is only for debugging purposes, but it is documented in the XISetClientPointer man page and seems to be the only way to query keyboards beyond the first. With this commit, Dolphin correctly reads keys from keyboards other than the first master keyboard. To test, use the xinput command-line utility to create a master pointer and reattach a keyboard to the associated master keyboard. [1]: https://who-t.blogspot.com/2009/07/xi2-recipes-part-6.html (the XInput2 developer's blog) --- .../Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp index e9f8d2fff2..07d8e4bfa5 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp @@ -166,6 +166,10 @@ KeyboardMouse::KeyboardMouse(Window window, int opcode, int pointer, int keyboar name = std::string(pointer_device->name); XIFreeDeviceInfo(pointer_device); + // Tell core X functions which keyboard is "the" keyboard for this + // X connection. + XISetClientPointer(m_display, None, pointer_deviceid); + { unsigned char mask_buf[(XI_LASTEVENT + 7) / 8] = {}; XISetMask(mask_buf, XI_ButtonPress); @@ -387,6 +391,10 @@ void KeyboardMouse::UpdateInput() // KeyRelease and FocusOut events are sometimes not received. // Cycling Alt-Tab and landing on the same window results in a stuck "Alt" key. // Unpressed keys are released here. + // Because we called XISetClientPointer in the constructor, XQueryKeymap + // will return the state of the associated keyboard, even if it isn't the + // first master keyboard. (XInput2 doesn't provide a function to query + // keyboard state.) std::array keyboard; XQueryKeymap(m_display, keyboard.data()); for (size_t i = 0; i != keyboard.size(); ++i) From 467b961e9cf63d7bc5cd5f0632a8b458dc397c8f Mon Sep 17 00:00:00 2001 From: Sketch <75850871+SketchMaster2001@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:10:05 -0400 Subject: [PATCH 07/93] IOS/Network/KD: Implement GetSchedulerStat --- Source/Core/Common/HttpRequest.cpp | 13 ++++ Source/Core/Common/HttpRequest.h | 1 + Source/Core/Core/IOS/Network/KD/NWC24Config.h | 2 + .../Core/Core/IOS/Network/KD/NetKDRequest.cpp | 73 +++++++++++++++++-- .../Core/Core/IOS/Network/KD/NetKDRequest.h | 16 +++- .../Core/Core/IOS/Network/KD/VFF/VFFUtil.cpp | 6 +- 6 files changed, 100 insertions(+), 11 deletions(-) diff --git a/Source/Core/Common/HttpRequest.cpp b/Source/Core/Common/HttpRequest.cpp index a8ed0d26ed..d98adf9826 100644 --- a/Source/Core/Common/HttpRequest.cpp +++ b/Source/Core/Common/HttpRequest.cpp @@ -30,6 +30,7 @@ public: void SetCookies(const std::string& cookies); void UseIPv4(); void FollowRedirects(long max); + s32 GetLastResponseCode(); Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload, size_t size, AllowedReturnCodes codes = AllowedReturnCodes::Ok_Only); @@ -76,6 +77,11 @@ std::string HttpRequest::EscapeComponent(const std::string& string) return m_impl->EscapeComponent(string); } +s32 HttpRequest::GetLastResponseCode() const +{ + return m_impl->GetLastResponseCode(); +} + HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& headers, AllowedReturnCodes codes) { @@ -143,6 +149,13 @@ bool HttpRequest::Impl::IsValid() const return m_curl != nullptr; } +s32 HttpRequest::Impl::GetLastResponseCode() +{ + s32 response_code{}; + curl_easy_getinfo(m_curl.get(), CURLINFO_RESPONSE_CODE, &response_code); + return response_code; +} + void HttpRequest::Impl::SetCookies(const std::string& cookies) { curl_easy_setopt(m_curl.get(), CURLOPT_COOKIE, cookies.c_str()); diff --git a/Source/Core/Common/HttpRequest.h b/Source/Core/Common/HttpRequest.h index 921051c9c2..85148cdec7 100644 --- a/Source/Core/Common/HttpRequest.h +++ b/Source/Core/Common/HttpRequest.h @@ -39,6 +39,7 @@ public: void SetCookies(const std::string& cookies); void UseIPv4(); void FollowRedirects(long max = 1); + s32 GetLastResponseCode() const; std::string EscapeComponent(const std::string& string); Response Get(const std::string& url, const Headers& headers = {}, AllowedReturnCodes codes = AllowedReturnCodes::Ok_Only); diff --git a/Source/Core/Core/IOS/Network/KD/NWC24Config.h b/Source/Core/Core/IOS/Network/KD/NWC24Config.h index be8f4c9bc9..0f3682449e 100644 --- a/Source/Core/Core/IOS/Network/KD/NWC24Config.h +++ b/Source/Core/Core/IOS/Network/KD/NWC24Config.h @@ -19,6 +19,8 @@ enum ErrorCode : s32 { WC24_OK = 0, WC24_ERR_FATAL = -1, + WC24_ERR_INVALID_VALUE = -3, + WC24_ERR_NULL = -5, WC24_ERR_NOT_FOUND = -13, WC24_ERR_BROKEN = -14, WC24_ERR_FILE_OPEN = -16, diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp index 8c5f80b6d4..c273a43b22 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp @@ -150,6 +150,9 @@ s32 NWC24MakeUserID(u64* nwc24_id, u32 hollywood_id, u16 id_ctr, HardwareModel h NetKDRequestDevice::NetKDRequestDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name), config{ios.GetFS()}, m_dl_list{ios.GetFS()} { + // Enable all NWC24 permissions + m_scheduler_buffer[1] = Common::swap32(-1); + m_work_queue.Reset("WiiConnect24 Worker", [this](AsyncTask task) { const IPCReply reply = task.handler(); { @@ -177,6 +180,34 @@ void NetKDRequestDevice::Update() } } +void NetKDRequestDevice::LogError(ErrorType error_type, s32 error_code) +{ + s32 new_code{}; + switch (error_type) + { + case ErrorType::Account: + new_code = -(101200 - error_code); + break; + case ErrorType::Client: + new_code = -(107300 - error_code); + break; + case ErrorType::KD_Download: + new_code = -(107200 - error_code); + break; + case ErrorType::Server: + new_code = -(117000 + error_code); + break; + } + + std::lock_guard lg(m_scheduler_buffer_lock); + + m_scheduler_buffer[32 + (m_error_count % 32)] = Common::swap32(new_code); + m_error_count++; + + m_scheduler_buffer[5] = Common::swap32(m_error_count); + m_scheduler_buffer[2] = Common::swap32(new_code); +} + NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index, const std::optional subtask_id) { @@ -194,7 +225,14 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index, if (!response) { - ERROR_LOG_FMT(IOS_WC24, "Failed to request data at {}", url); + const s32 last_response_code = m_http.GetLastResponseCode(); + ERROR_LOG_FMT(IOS_WC24, "Failed to request data at {}. HTTP Status Code: {}", url, + last_response_code); + + // On a real Wii, KD throws 107305 if it cannot connect to the host. While other issues other + // than invalid host may arise, this code is essentially a catch-all for HTTP client failure. + LogError(last_response_code ? ErrorType::Server : ErrorType::Client, + last_response_code ? last_response_code : NWC24::WC24_ERR_NULL); return NWC24::WC24_ERR_SERVER; } @@ -202,6 +240,7 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index, if (response->size() < sizeof(NWC24::WC24File)) { ERROR_LOG_FMT(IOS_WC24, "File at {} is too small to be a valid file.", url); + LogError(ErrorType::KD_Download, NWC24::WC24_ERR_BROKEN); return NWC24::WC24_ERR_BROKEN; } @@ -228,6 +267,9 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index, NWC24::ErrorCode reply = IOS::HLE::NWC24::OpenVFF(m_dl_list.GetVFFPath(entry_index), content_name, m_ios.GetFS(), file_data); + if (reply != NWC24::WC24_OK) + LogError(ErrorType::KD_Download, reply); + return reply; } @@ -249,15 +291,17 @@ IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& reques if (entry_index >= NWC24::NWC24Dl::MAX_ENTRIES) { ERROR_LOG_FMT(IOS_WC24, "NET_KD_REQ: Entry index out of range."); - WriteReturnValue(NWC24::WC24_ERR_BROKEN, request.buffer_out); - return IPCReply(NWC24::WC24_ERR_BROKEN); + LogError(ErrorType::KD_Download, NWC24::WC24_ERR_INVALID_VALUE); + WriteReturnValue(NWC24::WC24_ERR_INVALID_VALUE, request.buffer_out); + return IPCReply(IPC_SUCCESS); } if (!m_dl_list.DoesEntryExist(entry_index)) { ERROR_LOG_FMT(IOS_WC24, "NET_KD_REQ: Requested entry does not exist in download list!"); + LogError(ErrorType::KD_Download, NWC24::WC24_ERR_NOT_FOUND); WriteReturnValue(NWC24::WC24_ERR_NOT_FOUND, request.buffer_out); - return IPCReply(NWC24::WC24_ERR_NOT_FOUND); + return IPCReply(IPC_SUCCESS); } // While in theory reply will always get initialized by KDDownload, things happen. @@ -287,7 +331,7 @@ IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& reques } WriteReturnValue(reply, request.buffer_out); - return IPCReply(reply); + return IPCReply(IPC_SUCCESS); } std::optional NetKDRequestDevice::IOCtl(const IOCtlRequest& request) @@ -405,6 +449,7 @@ std::optional NetKDRequestDevice::IOCtl(const IOCtlRequest& request) } else { + LogError(ErrorType::Account, NWC24::WC24_ERR_INVALID_VALUE); WriteReturnValue(NWC24::WC24_ERR_FATAL, request.buffer_out); } } @@ -421,8 +466,24 @@ std::optional NetKDRequestDevice::IOCtl(const IOCtlRequest& request) break; case IOCTL_NWC24_GET_SCHEDULER_STAT: - INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_GET_SCHEDULER_STAT - NI"); + { + if (request.buffer_out == 0 || request.buffer_out % 4 != 0 || request.buffer_out_size < 16) + { + return_value = IPC_EINVAL; + ERROR_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_GET_SCHEDULER_STAT = IPC_EINVAL"); + break; + } + + INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_GET_SCHEDULER_STAT - buffer out size: {}", + request.buffer_out_size); + + // On a real Wii, GetSchedulerStat copies memory containing a list of error codes recorded by + // KD among other things. In most instances there will never be more than one error code + // recorded as we do not have a scheduler. + const u32 out_size = std::min(request.buffer_out_size, 256U); + memory.CopyToEmu(request.buffer_out, m_scheduler_buffer.data(), out_size); break; + } case IOCTL_NWC24_SAVE_MAIL_NOW: INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_SAVE_MAIL_NOW - NI"); diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.h b/Source/Core/Core/IOS/Network/KD/NetKDRequest.h index aae52a11f5..cb8af0d3f5 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.h +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include @@ -16,8 +17,6 @@ namespace IOS::HLE { -constexpr const char DL_CNT_PATH[] = "/" WII_WC24CONF_DIR "/dlcnt.bin"; - // KD is the IOS module responsible for implementing WiiConnect24 functionality. // It can perform HTTPS downloads, send and receive mail via SMTP, and execute a // JavaScript-like language while the Wii is in standby mode. @@ -52,11 +51,24 @@ private: return std::nullopt; } + enum class ErrorType + { + Account, + KD_Download, + Client, + Server, + }; + + void LogError(ErrorType error_type, s32 error_code); + NWC24::NWC24Config config; NWC24::NWC24Dl m_dl_list; Common::WorkQueueThread m_work_queue; std::mutex m_async_reply_lock; + std::mutex m_scheduler_buffer_lock; std::queue m_async_replies; + u32 m_error_count = 0; + std::array m_scheduler_buffer{}; // TODO: Maybe move away from Common::HttpRequest? Common::HttpRequest m_http{std::chrono::minutes{1}}; }; diff --git a/Source/Core/Core/IOS/Network/KD/VFF/VFFUtil.cpp b/Source/Core/Core/IOS/Network/KD/VFF/VFFUtil.cpp index 16ba1b1ad7..4a1389c626 100644 --- a/Source/Core/Core/IOS/Network/KD/VFF/VFFUtil.cpp +++ b/Source/Core/Core/IOS/Network/KD/VFF/VFFUtil.cpp @@ -267,7 +267,7 @@ ErrorCode OpenVFF(const std::string& path, const std::string& filename, if (!temp) { ERROR_LOG_FMT(IOS_WC24, "Failed to open VFF at: {}", path); - return_value = WC24_ERR_NOT_FOUND; + return_value = WC24_ERR_FILE_OPEN; return; } @@ -281,7 +281,7 @@ ErrorCode OpenVFF(const std::string& path, const std::string& filename, { // The VFF is most likely broken. ERROR_LOG_FMT(IOS_WC24, "Failed to mount VFF at: {}", path); - return_value = WC24_ERR_BROKEN; + return_value = WC24_ERR_FILE_READ; return; } @@ -290,7 +290,7 @@ ErrorCode OpenVFF(const std::string& path, const std::string& filename, { // The VFF is most likely broken. ERROR_LOG_FMT(IOS_WC24, "Failed to mount VFF at: {}", path); - return_value = WC24_ERR_BROKEN; + return_value = WC24_ERR_FILE_READ; return; } From 5fa27704c850cbeeb9dc54979d99f7ea96f8f9e7 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Fri, 21 Apr 2023 14:02:53 -0700 Subject: [PATCH 08/93] Qt: Rename GraphicsBool to ConfigBool GraphicsBool is used by the panes in the Graphics config window to create checkboxes that change their associated config setting, and update their own state when something else changes the config setting. Despite its current name nothing about this class is particular to the Graphics window, so renaming it to ConfigBool better reflects its purpose. This should also make it less confusing when ConfigBools are eventually added to the other config windows. --- Source/Core/DolphinQt/CMakeLists.txt | 4 +- .../ConfigBool.cpp} | 8 +-- .../ConfigBool.h} | 4 +- .../Config/Graphics/AdvancedWidget.cpp | 62 +++++++++---------- .../Config/Graphics/AdvancedWidget.h | 60 +++++++++--------- .../Config/Graphics/EnhancementsWidget.cpp | 20 +++--- .../Config/Graphics/EnhancementsWidget.h | 18 +++--- .../Config/Graphics/GeneralWidget.cpp | 19 +++--- .../DolphinQt/Config/Graphics/GeneralWidget.h | 16 ++--- .../DolphinQt/Config/Graphics/HacksWidget.cpp | 36 +++++------ .../DolphinQt/Config/Graphics/HacksWidget.h | 28 ++++----- Source/Core/DolphinQt/DolphinQt.vcxproj | 4 +- 12 files changed, 139 insertions(+), 140 deletions(-) rename Source/Core/DolphinQt/Config/{Graphics/GraphicsBool.cpp => ConfigControls/ConfigBool.cpp} (74%) rename Source/Core/DolphinQt/Config/{Graphics/GraphicsBool.h => ConfigControls/ConfigBool.h} (70%) diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index f4bbaf268d..1ef8c0cb64 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -41,6 +41,8 @@ add_executable(dolphin-emu Config/CheatWarningWidget.h Config/CommonControllersWidget.cpp Config/CommonControllersWidget.h + Config/ConfigControls/ConfigBool.cpp + Config/ConfigControls/ConfigBool.h Config/ControllerInterface/ControllerInterfaceWindow.cpp Config/ControllerInterface/ControllerInterfaceWindow.h Config/ControllerInterface/DualShockUDPClientAddServerDialog.cpp @@ -73,8 +75,6 @@ add_executable(dolphin-emu Config/Graphics/EnhancementsWidget.h Config/Graphics/GeneralWidget.cpp Config/Graphics/GeneralWidget.h - Config/Graphics/GraphicsBool.cpp - Config/Graphics/GraphicsBool.h Config/Graphics/GraphicsChoice.cpp Config/Graphics/GraphicsChoice.h Config/Graphics/GraphicsInteger.cpp diff --git a/Source/Core/DolphinQt/Config/Graphics/GraphicsBool.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigBool.cpp similarity index 74% rename from Source/Core/DolphinQt/Config/Graphics/GraphicsBool.cpp rename to Source/Core/DolphinQt/Config/ConfigControls/ConfigBool.cpp index 33ca546f48..89ab9c15be 100644 --- a/Source/Core/DolphinQt/Config/Graphics/GraphicsBool.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigBool.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "DolphinQt/Config/Graphics/GraphicsBool.h" +#include "DolphinQt/Config/ConfigControls/ConfigBool.h" #include #include @@ -11,10 +11,10 @@ #include "DolphinQt/Settings.h" -GraphicsBool::GraphicsBool(const QString& label, const Config::Info& setting, bool reverse) +ConfigBool::ConfigBool(const QString& label, const Config::Info& setting, bool reverse) : ToolTipCheckBox(label), m_setting(setting), m_reverse(reverse) { - connect(this, &QCheckBox::toggled, this, &GraphicsBool::Update); + connect(this, &QCheckBox::toggled, this, &ConfigBool::Update); setChecked(Config::Get(m_setting) ^ reverse); connect(&Settings::Instance(), &Settings::ConfigChanged, this, [this] { @@ -27,7 +27,7 @@ GraphicsBool::GraphicsBool(const QString& label, const Config::Info& setti }); } -void GraphicsBool::Update() +void ConfigBool::Update() { Config::SetBaseOrCurrent(m_setting, static_cast(isChecked() ^ m_reverse)); } diff --git a/Source/Core/DolphinQt/Config/Graphics/GraphicsBool.h b/Source/Core/DolphinQt/Config/ConfigControls/ConfigBool.h similarity index 70% rename from Source/Core/DolphinQt/Config/Graphics/GraphicsBool.h rename to Source/Core/DolphinQt/Config/ConfigControls/ConfigBool.h index 2a98971bfe..21f5f62352 100644 --- a/Source/Core/DolphinQt/Config/Graphics/GraphicsBool.h +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigBool.h @@ -11,11 +11,11 @@ template class Info; } -class GraphicsBool : public ToolTipCheckBox +class ConfigBool : public ToolTipCheckBox { Q_OBJECT public: - GraphicsBool(const QString& label, const Config::Info& setting, bool reverse = false); + ConfigBool(const QString& label, const Config::Info& setting, bool reverse = false); private: void Update(); diff --git a/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp index 102e93e09b..e81dd43af2 100644 --- a/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp @@ -15,7 +15,7 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" -#include "DolphinQt/Config/Graphics/GraphicsBool.h" +#include "DolphinQt/Config/ConfigControls/ConfigBool.h" #include "DolphinQt/Config/Graphics/GraphicsChoice.h" #include "DolphinQt/Config/Graphics/GraphicsInteger.h" #include "DolphinQt/Config/Graphics/GraphicsWindow.h" @@ -50,17 +50,17 @@ void AdvancedWidget::CreateWidgets() auto* performance_layout = new QGridLayout(); performance_box->setLayout(performance_layout); - m_show_fps = new GraphicsBool(tr("Show FPS"), Config::GFX_SHOW_FPS); - m_show_ftimes = new GraphicsBool(tr("Show Frame Times"), Config::GFX_SHOW_FTIMES); - m_show_vps = new GraphicsBool(tr("Show VPS"), Config::GFX_SHOW_VPS); - m_show_vtimes = new GraphicsBool(tr("Show VBlank Times"), Config::GFX_SHOW_VTIMES); - m_show_graphs = new GraphicsBool(tr("Show Performance Graphs"), Config::GFX_SHOW_GRAPHS); - m_show_speed = new GraphicsBool(tr("Show % Speed"), Config::GFX_SHOW_SPEED); - m_show_speed_colors = new GraphicsBool(tr("Show Speed Colors"), Config::GFX_SHOW_SPEED_COLORS); + m_show_fps = new ConfigBool(tr("Show FPS"), Config::GFX_SHOW_FPS); + m_show_ftimes = new ConfigBool(tr("Show Frame Times"), Config::GFX_SHOW_FTIMES); + m_show_vps = new ConfigBool(tr("Show VPS"), Config::GFX_SHOW_VPS); + m_show_vtimes = new ConfigBool(tr("Show VBlank Times"), Config::GFX_SHOW_VTIMES); + m_show_graphs = new ConfigBool(tr("Show Performance Graphs"), Config::GFX_SHOW_GRAPHS); + m_show_speed = new ConfigBool(tr("Show % Speed"), Config::GFX_SHOW_SPEED); + m_show_speed_colors = new ConfigBool(tr("Show Speed Colors"), Config::GFX_SHOW_SPEED_COLORS); m_perf_samp_window = new GraphicsInteger(0, 10000, Config::GFX_PERF_SAMP_WINDOW, 100); m_perf_samp_window->SetTitle(tr("Performance Sample Window (ms)")); m_log_render_time = - new GraphicsBool(tr("Log Render Time to File"), Config::GFX_LOG_RENDER_TIME_TO_FILE); + new ConfigBool(tr("Log Render Time to File"), Config::GFX_LOG_RENDER_TIME_TO_FILE); performance_layout->addWidget(m_show_fps, 0, 0); performance_layout->addWidget(m_show_ftimes, 0, 1); @@ -78,12 +78,12 @@ void AdvancedWidget::CreateWidgets() auto* debugging_layout = new QGridLayout(); debugging_box->setLayout(debugging_layout); - m_enable_wireframe = new GraphicsBool(tr("Enable Wireframe"), Config::GFX_ENABLE_WIREFRAME); - m_show_statistics = new GraphicsBool(tr("Show Statistics"), Config::GFX_OVERLAY_STATS); + m_enable_wireframe = new ConfigBool(tr("Enable Wireframe"), Config::GFX_ENABLE_WIREFRAME); + m_show_statistics = new ConfigBool(tr("Show Statistics"), Config::GFX_OVERLAY_STATS); m_enable_format_overlay = - new GraphicsBool(tr("Texture Format Overlay"), Config::GFX_TEXFMT_OVERLAY_ENABLE); + new ConfigBool(tr("Texture Format Overlay"), Config::GFX_TEXFMT_OVERLAY_ENABLE); m_enable_api_validation = - new GraphicsBool(tr("Enable API Validation Layers"), Config::GFX_ENABLE_VALIDATION_LAYER); + new ConfigBool(tr("Enable API Validation Layers"), Config::GFX_ENABLE_VALIDATION_LAYER); debugging_layout->addWidget(m_enable_wireframe, 0, 0); debugging_layout->addWidget(m_show_statistics, 0, 1); @@ -95,13 +95,13 @@ void AdvancedWidget::CreateWidgets() auto* utility_layout = new QGridLayout(); utility_box->setLayout(utility_layout); - m_load_custom_textures = new GraphicsBool(tr("Load Custom Textures"), Config::GFX_HIRES_TEXTURES); + m_load_custom_textures = new ConfigBool(tr("Load Custom Textures"), Config::GFX_HIRES_TEXTURES); m_prefetch_custom_textures = - new GraphicsBool(tr("Prefetch Custom Textures"), Config::GFX_CACHE_HIRES_TEXTURES); - m_dump_efb_target = new GraphicsBool(tr("Dump EFB Target"), Config::GFX_DUMP_EFB_TARGET); - m_dump_xfb_target = new GraphicsBool(tr("Dump XFB Target"), Config::GFX_DUMP_XFB_TARGET); + new ConfigBool(tr("Prefetch Custom Textures"), Config::GFX_CACHE_HIRES_TEXTURES); + m_dump_efb_target = new ConfigBool(tr("Dump EFB Target"), Config::GFX_DUMP_EFB_TARGET); + m_dump_xfb_target = new ConfigBool(tr("Dump XFB Target"), Config::GFX_DUMP_XFB_TARGET); m_disable_vram_copies = - new GraphicsBool(tr("Disable EFB VRAM Copies"), Config::GFX_HACK_DISABLE_COPY_TO_VRAM); + new ConfigBool(tr("Disable EFB VRAM Copies"), Config::GFX_HACK_DISABLE_COPY_TO_VRAM); m_enable_graphics_mods = new ToolTipCheckBox(tr("Enable Graphics Mods")); utility_layout->addWidget(m_load_custom_textures, 0, 0); @@ -117,9 +117,9 @@ void AdvancedWidget::CreateWidgets() auto* texture_dump_box = new QGroupBox(tr("Texture Dumping")); auto* texture_dump_layout = new QGridLayout(); texture_dump_box->setLayout(texture_dump_layout); - m_dump_textures = new GraphicsBool(tr("Enable"), Config::GFX_DUMP_TEXTURES); - m_dump_base_textures = new GraphicsBool(tr("Dump Base Textures"), Config::GFX_DUMP_BASE_TEXTURES); - m_dump_mip_textures = new GraphicsBool(tr("Dump Mip Maps"), Config::GFX_DUMP_MIP_TEXTURES); + m_dump_textures = new ConfigBool(tr("Enable"), Config::GFX_DUMP_TEXTURES); + m_dump_base_textures = new ConfigBool(tr("Dump Base Textures"), Config::GFX_DUMP_BASE_TEXTURES); + m_dump_mip_textures = new ConfigBool(tr("Dump Mip Maps"), Config::GFX_DUMP_MIP_TEXTURES); texture_dump_layout->addWidget(m_dump_textures, 0, 0); @@ -131,9 +131,9 @@ void AdvancedWidget::CreateWidgets() auto* dump_layout = new QGridLayout(); dump_box->setLayout(dump_layout); - m_use_fullres_framedumps = new GraphicsBool(tr("Dump at Internal Resolution"), - Config::GFX_INTERNAL_RESOLUTION_FRAME_DUMPS); - m_dump_use_ffv1 = new GraphicsBool(tr("Use Lossless Codec (FFV1)"), Config::GFX_USE_FFV1); + m_use_fullres_framedumps = new ConfigBool(tr("Dump at Internal Resolution"), + Config::GFX_INTERNAL_RESOLUTION_FRAME_DUMPS); + m_dump_use_ffv1 = new ConfigBool(tr("Use Lossless Codec (FFV1)"), Config::GFX_USE_FFV1); m_dump_bitrate = new GraphicsInteger(0, 1000000, Config::GFX_BITRATE_KBPS, 1000); m_png_compression_level = new GraphicsInteger(0, 9, Config::GFX_PNG_COMPRESSION_LEVEL); @@ -152,14 +152,14 @@ void AdvancedWidget::CreateWidgets() auto* misc_layout = new QGridLayout(); misc_box->setLayout(misc_layout); - m_enable_cropping = new GraphicsBool(tr("Crop"), Config::GFX_CROP); + m_enable_cropping = new ConfigBool(tr("Crop"), Config::GFX_CROP); m_enable_prog_scan = new ToolTipCheckBox(tr("Enable Progressive Scan")); m_backend_multithreading = - new GraphicsBool(tr("Backend Multithreading"), Config::GFX_BACKEND_MULTITHREADING); - m_prefer_vs_for_point_line_expansion = new GraphicsBool( + new ConfigBool(tr("Backend Multithreading"), Config::GFX_BACKEND_MULTITHREADING); + m_prefer_vs_for_point_line_expansion = new ConfigBool( // i18n: VS is short for vertex shaders. tr("Prefer VS for Point/Line Expansion"), Config::GFX_PREFER_VS_FOR_LINE_POINT_EXPANSION); - m_cpu_cull = new GraphicsBool(tr("Cull Vertices on the CPU"), Config::GFX_CPU_CULL); + m_cpu_cull = new ConfigBool(tr("Cull Vertices on the CPU"), Config::GFX_CPU_CULL); misc_layout->addWidget(m_enable_cropping, 0, 0); misc_layout->addWidget(m_enable_prog_scan, 0, 1); @@ -168,7 +168,7 @@ void AdvancedWidget::CreateWidgets() misc_layout->addWidget(m_cpu_cull, 2, 0); #ifdef _WIN32 m_borderless_fullscreen = - new GraphicsBool(tr("Borderless Fullscreen"), Config::GFX_BORDERLESS_FULLSCREEN); + new ConfigBool(tr("Borderless Fullscreen"), Config::GFX_BORDERLESS_FULLSCREEN); misc_layout->addWidget(m_borderless_fullscreen, 2, 1); #endif @@ -179,9 +179,9 @@ void AdvancedWidget::CreateWidgets() experimental_box->setLayout(experimental_layout); m_defer_efb_access_invalidation = - new GraphicsBool(tr("Defer EFB Cache Invalidation"), Config::GFX_HACK_EFB_DEFER_INVALIDATION); + new ConfigBool(tr("Defer EFB Cache Invalidation"), Config::GFX_HACK_EFB_DEFER_INVALIDATION); m_manual_texture_sampling = - new GraphicsBool(tr("Manual Texture Sampling"), Config::GFX_HACK_FAST_TEXTURE_SAMPLING, true); + new ConfigBool(tr("Manual Texture Sampling"), Config::GFX_HACK_FAST_TEXTURE_SAMPLING, true); experimental_layout->addWidget(m_defer_efb_access_invalidation, 0, 0); experimental_layout->addWidget(m_manual_texture_sampling, 0, 1); diff --git a/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.h b/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.h index cd3f135470..75e0aec4bf 100644 --- a/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.h +++ b/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.h @@ -5,7 +5,7 @@ #include "DolphinQt/Config/Graphics/GraphicsWidget.h" -class GraphicsBool; +class ConfigBool; class GraphicsChoice; class GraphicsInteger; class GraphicsWindow; @@ -31,48 +31,48 @@ private: void OnEmulationStateChanged(bool running); // Debugging - GraphicsBool* m_enable_wireframe; - GraphicsBool* m_show_statistics; - GraphicsBool* m_enable_format_overlay; - GraphicsBool* m_enable_api_validation; - GraphicsBool* m_show_fps; - GraphicsBool* m_show_ftimes; - GraphicsBool* m_show_vps; - GraphicsBool* m_show_vtimes; - GraphicsBool* m_show_graphs; - GraphicsBool* m_show_speed; - GraphicsBool* m_show_speed_colors; + ConfigBool* m_enable_wireframe; + ConfigBool* m_show_statistics; + ConfigBool* m_enable_format_overlay; + ConfigBool* m_enable_api_validation; + ConfigBool* m_show_fps; + ConfigBool* m_show_ftimes; + ConfigBool* m_show_vps; + ConfigBool* m_show_vtimes; + ConfigBool* m_show_graphs; + ConfigBool* m_show_speed; + ConfigBool* m_show_speed_colors; GraphicsInteger* m_perf_samp_window; - GraphicsBool* m_log_render_time; + ConfigBool* m_log_render_time; // Utility - GraphicsBool* m_prefetch_custom_textures; - GraphicsBool* m_dump_efb_target; - GraphicsBool* m_dump_xfb_target; - GraphicsBool* m_disable_vram_copies; - GraphicsBool* m_load_custom_textures; + ConfigBool* m_prefetch_custom_textures; + ConfigBool* m_dump_efb_target; + ConfigBool* m_dump_xfb_target; + ConfigBool* m_disable_vram_copies; + ConfigBool* m_load_custom_textures; ToolTipCheckBox* m_enable_graphics_mods; // Texture dumping - GraphicsBool* m_dump_textures; - GraphicsBool* m_dump_mip_textures; - GraphicsBool* m_dump_base_textures; + ConfigBool* m_dump_textures; + ConfigBool* m_dump_mip_textures; + ConfigBool* m_dump_base_textures; // Frame dumping - GraphicsBool* m_dump_use_ffv1; - GraphicsBool* m_use_fullres_framedumps; + ConfigBool* m_dump_use_ffv1; + ConfigBool* m_use_fullres_framedumps; GraphicsInteger* m_dump_bitrate; GraphicsInteger* m_png_compression_level; // Misc - GraphicsBool* m_enable_cropping; + ConfigBool* m_enable_cropping; ToolTipCheckBox* m_enable_prog_scan; - GraphicsBool* m_backend_multithreading; - GraphicsBool* m_prefer_vs_for_point_line_expansion; - GraphicsBool* m_cpu_cull; - GraphicsBool* m_borderless_fullscreen; + ConfigBool* m_backend_multithreading; + ConfigBool* m_prefer_vs_for_point_line_expansion; + ConfigBool* m_cpu_cull; + ConfigBool* m_borderless_fullscreen; // Experimental - GraphicsBool* m_defer_efb_access_invalidation; - GraphicsBool* m_manual_texture_sampling; + ConfigBool* m_defer_efb_access_invalidation; + ConfigBool* m_manual_texture_sampling; }; diff --git a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp index dd1d67b04b..e015e7ec7b 100644 --- a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp @@ -14,7 +14,7 @@ #include "Core/Config/GraphicsSettings.h" #include "Core/ConfigManager.h" -#include "DolphinQt/Config/Graphics/GraphicsBool.h" +#include "DolphinQt/Config/ConfigControls/ConfigBool.h" #include "DolphinQt/Config/Graphics/GraphicsChoice.h" #include "DolphinQt/Config/Graphics/GraphicsRadio.h" #include "DolphinQt/Config/Graphics/GraphicsSlider.h" @@ -106,18 +106,18 @@ void EnhancementsWidget::CreateWidgets() m_pp_effect = new ToolTipComboBox(); m_configure_pp_effect = new NonDefaultQPushButton(tr("Configure")); - m_scaled_efb_copy = new GraphicsBool(tr("Scaled EFB Copy"), Config::GFX_HACK_COPY_EFB_SCALED); + m_scaled_efb_copy = new ConfigBool(tr("Scaled EFB Copy"), Config::GFX_HACK_COPY_EFB_SCALED); m_per_pixel_lighting = - new GraphicsBool(tr("Per-Pixel Lighting"), Config::GFX_ENABLE_PIXEL_LIGHTING); + new ConfigBool(tr("Per-Pixel Lighting"), Config::GFX_ENABLE_PIXEL_LIGHTING); - m_widescreen_hack = new GraphicsBool(tr("Widescreen Hack"), Config::GFX_WIDESCREEN_HACK); - m_disable_fog = new GraphicsBool(tr("Disable Fog"), Config::GFX_DISABLE_FOG); + m_widescreen_hack = new ConfigBool(tr("Widescreen Hack"), Config::GFX_WIDESCREEN_HACK); + m_disable_fog = new ConfigBool(tr("Disable Fog"), Config::GFX_DISABLE_FOG); m_force_24bit_color = - new GraphicsBool(tr("Force 24-Bit Color"), Config::GFX_ENHANCE_FORCE_TRUE_COLOR); + new ConfigBool(tr("Force 24-Bit Color"), Config::GFX_ENHANCE_FORCE_TRUE_COLOR); m_disable_copy_filter = - new GraphicsBool(tr("Disable Copy Filter"), Config::GFX_ENHANCE_DISABLE_COPY_FILTER); - m_arbitrary_mipmap_detection = new GraphicsBool(tr("Arbitrary Mipmap Detection"), - Config::GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION); + new ConfigBool(tr("Disable Copy Filter"), Config::GFX_ENHANCE_DISABLE_COPY_FILTER); + m_arbitrary_mipmap_detection = new ConfigBool(tr("Arbitrary Mipmap Detection"), + Config::GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION); int row = 0; enhancements_layout->addWidget(new QLabel(tr("Internal Resolution:")), row, 0); @@ -163,7 +163,7 @@ void EnhancementsWidget::CreateWidgets() m_3d_depth = new GraphicsSlider(0, Config::GFX_STEREO_DEPTH_MAXIMUM, Config::GFX_STEREO_DEPTH); m_3d_convergence = new GraphicsSlider(0, Config::GFX_STEREO_CONVERGENCE_MAXIMUM, Config::GFX_STEREO_CONVERGENCE, 100); - m_3d_swap_eyes = new GraphicsBool(tr("Swap Eyes"), Config::GFX_STEREO_SWAP_EYES); + m_3d_swap_eyes = new ConfigBool(tr("Swap Eyes"), Config::GFX_STEREO_SWAP_EYES); stereoscopy_layout->addWidget(new QLabel(tr("Stereoscopic 3D Mode:")), 0, 0); stereoscopy_layout->addWidget(m_3d_mode, 0, 1); diff --git a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h index ecfe4a9eb8..f980be8ede 100644 --- a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h +++ b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h @@ -7,7 +7,7 @@ #include "DolphinQt/Config/Graphics/GraphicsWidget.h" -class GraphicsBool; +class ConfigBool; class GraphicsChoice; class GraphicsSlider; class GraphicsWindow; @@ -39,19 +39,19 @@ private: ToolTipComboBox* m_texture_filtering_combo; ToolTipComboBox* m_pp_effect; QPushButton* m_configure_pp_effect; - GraphicsBool* m_scaled_efb_copy; - GraphicsBool* m_per_pixel_lighting; - GraphicsBool* m_widescreen_hack; - GraphicsBool* m_disable_fog; - GraphicsBool* m_force_24bit_color; - GraphicsBool* m_disable_copy_filter; - GraphicsBool* m_arbitrary_mipmap_detection; + ConfigBool* m_scaled_efb_copy; + ConfigBool* m_per_pixel_lighting; + ConfigBool* m_widescreen_hack; + ConfigBool* m_disable_fog; + ConfigBool* m_force_24bit_color; + ConfigBool* m_disable_copy_filter; + ConfigBool* m_arbitrary_mipmap_detection; // Stereoscopy GraphicsChoice* m_3d_mode; GraphicsSlider* m_3d_depth; GraphicsSlider* m_3d_convergence; - GraphicsBool* m_3d_swap_eyes; + ConfigBool* m_3d_swap_eyes; int m_msaa_modes; bool m_block_save; diff --git a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp index 27a2c16e56..1965b981f8 100644 --- a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp @@ -18,7 +18,7 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" -#include "DolphinQt/Config/Graphics/GraphicsBool.h" +#include "DolphinQt/Config/ConfigControls/ConfigBool.h" #include "DolphinQt/Config/Graphics/GraphicsChoice.h" #include "DolphinQt/Config/Graphics/GraphicsRadio.h" #include "DolphinQt/Config/Graphics/GraphicsWindow.h" @@ -60,8 +60,8 @@ void GeneralWidget::CreateWidgets() new GraphicsChoice({tr("Auto"), tr("Force 16:9"), tr("Force 4:3"), tr("Stretch to Window")}, Config::GFX_ASPECT_RATIO); m_adapter_combo = new ToolTipComboBox; - m_enable_vsync = new GraphicsBool(tr("V-Sync"), Config::GFX_VSYNC); - m_enable_fullscreen = new GraphicsBool(tr("Start in Fullscreen"), Config::MAIN_FULLSCREEN); + m_enable_vsync = new ConfigBool(tr("V-Sync"), Config::GFX_VSYNC); + m_enable_fullscreen = new ConfigBool(tr("Start in Fullscreen"), Config::MAIN_FULLSCREEN); m_video_box->setLayout(m_video_layout); @@ -87,12 +87,11 @@ void GeneralWidget::CreateWidgets() auto* m_options_box = new QGroupBox(tr("Other")); auto* m_options_layout = new QGridLayout(); - m_show_ping = new GraphicsBool(tr("Show NetPlay Ping"), Config::GFX_SHOW_NETPLAY_PING); + m_show_ping = new ConfigBool(tr("Show NetPlay Ping"), Config::GFX_SHOW_NETPLAY_PING); m_autoadjust_window_size = - new GraphicsBool(tr("Auto-Adjust Window Size"), Config::MAIN_RENDER_WINDOW_AUTOSIZE); - m_show_messages = - new GraphicsBool(tr("Show NetPlay Messages"), Config::GFX_SHOW_NETPLAY_MESSAGES); - m_render_main_window = new GraphicsBool(tr("Render to Main Window"), Config::MAIN_RENDER_TO_MAIN); + new ConfigBool(tr("Auto-Adjust Window Size"), Config::MAIN_RENDER_WINDOW_AUTOSIZE); + m_show_messages = new ConfigBool(tr("Show NetPlay Messages"), Config::GFX_SHOW_NETPLAY_MESSAGES); + m_render_main_window = new ConfigBool(tr("Render to Main Window"), Config::MAIN_RENDER_TO_MAIN); m_options_box->setLayout(m_options_layout); @@ -119,8 +118,8 @@ void GeneralWidget::CreateWidgets() shader_compilation_layout->addWidget(m_shader_compilation_mode[i], static_cast(i / 2), static_cast(i % 2)); } - m_wait_for_shaders = new GraphicsBool(tr("Compile Shaders Before Starting"), - Config::GFX_WAIT_FOR_SHADERS_BEFORE_STARTING); + m_wait_for_shaders = new ConfigBool(tr("Compile Shaders Before Starting"), + Config::GFX_WAIT_FOR_SHADERS_BEFORE_STARTING); shader_compilation_layout->addWidget(m_wait_for_shaders); shader_compilation_box->setLayout(shader_compilation_layout); diff --git a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.h b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.h index 7b8fa2622e..2a6c907eea 100644 --- a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.h +++ b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.h @@ -6,7 +6,7 @@ #include #include "DolphinQt/Config/Graphics/GraphicsWidget.h" -class GraphicsBool; +class ConfigBool; class GraphicsChoice; class GraphicsRadioInt; class GraphicsWindow; @@ -45,16 +45,16 @@ private: ToolTipComboBox* m_backend_combo; ToolTipComboBox* m_adapter_combo; GraphicsChoice* m_aspect_combo; - GraphicsBool* m_enable_vsync; - GraphicsBool* m_enable_fullscreen; + ConfigBool* m_enable_vsync; + ConfigBool* m_enable_fullscreen; // Options - GraphicsBool* m_show_ping; - GraphicsBool* m_autoadjust_window_size; - GraphicsBool* m_show_messages; - GraphicsBool* m_render_main_window; + ConfigBool* m_show_ping; + ConfigBool* m_autoadjust_window_size; + ConfigBool* m_show_messages; + ConfigBool* m_render_main_window; std::array m_shader_compilation_mode{}; - GraphicsBool* m_wait_for_shaders; + ConfigBool* m_wait_for_shaders; X11Utils::XRRConfiguration* m_xrr_config; }; diff --git a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp index 69291bd08f..dc7c6b3a31 100644 --- a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp @@ -13,7 +13,7 @@ #include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" -#include "DolphinQt/Config/Graphics/GraphicsBool.h" +#include "DolphinQt/Config/ConfigControls/ConfigBool.h" #include "DolphinQt/Config/Graphics/GraphicsSlider.h" #include "DolphinQt/Config/Graphics/GraphicsWindow.h" #include "DolphinQt/Config/ToolTipControls/ToolTipSlider.h" @@ -42,13 +42,13 @@ void HacksWidget::CreateWidgets() auto* efb_layout = new QGridLayout(); efb_box->setLayout(efb_layout); m_skip_efb_cpu = - new GraphicsBool(tr("Skip EFB Access from CPU"), Config::GFX_HACK_EFB_ACCESS_ENABLE, true); - m_ignore_format_changes = new GraphicsBool(tr("Ignore Format Changes"), - Config::GFX_HACK_EFB_EMULATE_FORMAT_CHANGES, true); - m_store_efb_copies = new GraphicsBool(tr("Store EFB Copies to Texture Only"), - Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM); + new ConfigBool(tr("Skip EFB Access from CPU"), Config::GFX_HACK_EFB_ACCESS_ENABLE, true); + m_ignore_format_changes = new ConfigBool(tr("Ignore Format Changes"), + Config::GFX_HACK_EFB_EMULATE_FORMAT_CHANGES, true); + m_store_efb_copies = + new ConfigBool(tr("Store EFB Copies to Texture Only"), Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM); m_defer_efb_copies = - new GraphicsBool(tr("Defer EFB Copies to RAM"), Config::GFX_HACK_DEFER_EFB_COPIES); + new ConfigBool(tr("Defer EFB Copies to RAM"), Config::GFX_HACK_DEFER_EFB_COPIES); efb_layout->addWidget(m_skip_efb_cpu, 0, 0); efb_layout->addWidget(m_ignore_format_changes, 0, 1); @@ -66,7 +66,7 @@ void HacksWidget::CreateWidgets() m_accuracy->setPageStep(1); m_accuracy->setTickPosition(QSlider::TicksBelow); m_gpu_texture_decoding = - new GraphicsBool(tr("GPU Texture Decoding"), Config::GFX_ENABLE_GPU_TEXTURE_DECODING); + new ConfigBool(tr("GPU Texture Decoding"), Config::GFX_ENABLE_GPU_TEXTURE_DECODING); auto* safe_label = new QLabel(tr("Safe")); safe_label->setAlignment(Qt::AlignRight); @@ -84,11 +84,11 @@ void HacksWidget::CreateWidgets() auto* xfb_layout = new QVBoxLayout(); xfb_box->setLayout(xfb_layout); - m_store_xfb_copies = new GraphicsBool(tr("Store XFB Copies to Texture Only"), - Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM); - m_immediate_xfb = new GraphicsBool(tr("Immediately Present XFB"), Config::GFX_HACK_IMMEDIATE_XFB); - m_skip_duplicate_xfbs = new GraphicsBool(tr("Skip Presenting Duplicate Frames"), - Config::GFX_HACK_SKIP_DUPLICATE_XFBS); + m_store_xfb_copies = + new ConfigBool(tr("Store XFB Copies to Texture Only"), Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM); + m_immediate_xfb = new ConfigBool(tr("Immediately Present XFB"), Config::GFX_HACK_IMMEDIATE_XFB); + m_skip_duplicate_xfbs = + new ConfigBool(tr("Skip Presenting Duplicate Frames"), Config::GFX_HACK_SKIP_DUPLICATE_XFBS); xfb_layout->addWidget(m_store_xfb_copies); xfb_layout->addWidget(m_immediate_xfb); @@ -100,13 +100,13 @@ void HacksWidget::CreateWidgets() other_box->setLayout(other_layout); m_fast_depth_calculation = - new GraphicsBool(tr("Fast Depth Calculation"), Config::GFX_FAST_DEPTH_CALC); + new ConfigBool(tr("Fast Depth Calculation"), Config::GFX_FAST_DEPTH_CALC); m_disable_bounding_box = - new GraphicsBool(tr("Disable Bounding Box"), Config::GFX_HACK_BBOX_ENABLE, true); - m_vertex_rounding = new GraphicsBool(tr("Vertex Rounding"), Config::GFX_HACK_VERTEX_ROUNDING); + new ConfigBool(tr("Disable Bounding Box"), Config::GFX_HACK_BBOX_ENABLE, true); + m_vertex_rounding = new ConfigBool(tr("Vertex Rounding"), Config::GFX_HACK_VERTEX_ROUNDING); m_save_texture_cache_state = - new GraphicsBool(tr("Save Texture Cache to State"), Config::GFX_SAVE_TEXTURE_CACHE_TO_STATE); - m_vi_skip = new GraphicsBool(tr("VBI Skip"), Config::GFX_HACK_VI_SKIP); + new ConfigBool(tr("Save Texture Cache to State"), Config::GFX_SAVE_TEXTURE_CACHE_TO_STATE); + m_vi_skip = new ConfigBool(tr("VBI Skip"), Config::GFX_HACK_VI_SKIP); other_layout->addWidget(m_fast_depth_calculation, 0, 0); other_layout->addWidget(m_disable_bounding_box, 0, 1); diff --git a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h index 296a467444..37b6e5e9ff 100644 --- a/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h +++ b/Source/Core/DolphinQt/Config/Graphics/HacksWidget.h @@ -5,7 +5,7 @@ #include "DolphinQt/Config/Graphics/GraphicsWidget.h" -class GraphicsBool; +class ConfigBool; class GraphicsWindow; class QLabel; class ToolTipSlider; @@ -23,27 +23,27 @@ private: void OnBackendChanged(const QString& backend_name); // EFB - GraphicsBool* m_skip_efb_cpu; - GraphicsBool* m_ignore_format_changes; - GraphicsBool* m_store_efb_copies; - GraphicsBool* m_defer_efb_copies; + ConfigBool* m_skip_efb_cpu; + ConfigBool* m_ignore_format_changes; + ConfigBool* m_store_efb_copies; + ConfigBool* m_defer_efb_copies; // Texture Cache QLabel* m_accuracy_label; ToolTipSlider* m_accuracy; - GraphicsBool* m_gpu_texture_decoding; + ConfigBool* m_gpu_texture_decoding; // External Framebuffer - GraphicsBool* m_store_xfb_copies; - GraphicsBool* m_immediate_xfb; - GraphicsBool* m_skip_duplicate_xfbs; + ConfigBool* m_store_xfb_copies; + ConfigBool* m_immediate_xfb; + ConfigBool* m_skip_duplicate_xfbs; // Other - GraphicsBool* m_fast_depth_calculation; - GraphicsBool* m_disable_bounding_box; - GraphicsBool* m_vertex_rounding; - GraphicsBool* m_vi_skip; - GraphicsBool* m_save_texture_cache_state; + ConfigBool* m_fast_depth_calculation; + ConfigBool* m_disable_bounding_box; + ConfigBool* m_vertex_rounding; + ConfigBool* m_vi_skip; + ConfigBool* m_save_texture_cache_state; void CreateWidgets(); void ConnectWidgets(); diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index 596e661219..08a9af5b9f 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -54,6 +54,7 @@ + @@ -70,7 +71,6 @@ - @@ -255,6 +255,7 @@ + @@ -270,7 +271,6 @@ - From 0948f0ef690bfc19c89d8f7bf3552806b6b36430 Mon Sep 17 00:00:00 2001 From: get <45425365+Minty-Meeo@users.noreply.github.com> Date: Mon, 17 Apr 2023 03:07:07 -0500 Subject: [PATCH 09/93] Fix PPCCache savestate behavior PR #11183 regressed the lookup table reconstruction and, for some reason, added an else clause that clobbered the dCache whenever dCache emulation is turned on. --- Source/Core/Core/PowerPC/PPCCache.cpp | 6 +++--- Source/Core/Core/PowerPC/PowerPC.cpp | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCCache.cpp b/Source/Core/Core/PowerPC/PPCCache.cpp index 03e5ef3a1a..0b3f23079a 100644 --- a/Source/Core/Core/PowerPC/PPCCache.cpp +++ b/Source/Core/Core/PowerPC/PPCCache.cpp @@ -391,11 +391,11 @@ void Cache::DoState(PointerWrap& p) if ((valid[set] & (1 << way)) != 0) { if (addrs[set][way] & CACHE_VMEM_BIT) - lookup_table_vmem[(addrs[set][way] & memory.GetFakeVMemMask()) >> 5] = 0xff; + lookup_table_vmem[(addrs[set][way] & memory.GetFakeVMemMask()) >> 5] = way; else if (addrs[set][way] & CACHE_EXRAM_BIT) - lookup_table_ex[(addrs[set][way] & memory.GetExRamMask()) >> 5] = 0xff; + lookup_table_ex[(addrs[set][way] & memory.GetExRamMask()) >> 5] = way; else - lookup_table[(addrs[set][way] & memory.GetRamMask()) >> 5] = 0xff; + lookup_table[(addrs[set][way] & memory.GetRamMask()) >> 5] = way; } } } diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index 0f88f696a8..30c9cb2b14 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -134,10 +134,6 @@ void PowerPCManager::DoState(PointerWrap& p) INFO_LOG_FMT(POWERPC, "Flushing data cache"); m_ppc_state.dCache.FlushAll(); } - else - { - m_ppc_state.dCache.Reset(); - } RoundingModeUpdated(m_ppc_state); From 4d49902b341a37393d39f7344773ece2b4ad0027 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 23 Apr 2023 20:02:11 +0200 Subject: [PATCH 10/93] IOS: Only construct DolphinDevice on EmulationKernel IOS instances. Doesn't make much sense to have this active without a game. --- Source/Core/Core/IOS/IOS.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/IOS/IOS.cpp b/Source/Core/Core/IOS/IOS.cpp index bc09da7837..3e404a76cc 100644 --- a/Source/Core/Core/IOS/IOS.cpp +++ b/Source/Core/Core/IOS/IOS.cpp @@ -544,7 +544,6 @@ void Kernel::AddCoreDevices() std::lock_guard lock(m_device_map_mutex); AddDevice(std::make_unique(*this, "/dev/fs")); AddDevice(std::make_unique(*this, "/dev/es")); - AddDevice(std::make_unique(*this, "/dev/dolphin")); } void Kernel::AddStaticDevices() @@ -553,6 +552,9 @@ void Kernel::AddStaticDevices() const Feature features = GetFeatures(GetVersion()); + // Dolphin-specific device for letting homebrew access and alter emulator state. + AddDevice(std::make_unique(*this, "/dev/dolphin")); + // OH1 (Bluetooth) AddDevice(std::make_unique(*this, "/dev/usb/oh1")); if (!Config::Get(Config::MAIN_BLUETOOTH_PASSTHROUGH_ENABLED)) From cfe36836688ae21ae32383958504fbc5f6c21660 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 23 Apr 2023 11:56:39 -0700 Subject: [PATCH 11/93] DolphinQt: use default dpi rounding mode (passthrough) --- Source/Core/DolphinQt/Main.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Source/Core/DolphinQt/Main.cpp b/Source/Core/DolphinQt/Main.cpp index 4b01bdcc27..37415224dd 100644 --- a/Source/Core/DolphinQt/Main.cpp +++ b/Source/Core/DolphinQt/Main.cpp @@ -151,15 +151,6 @@ int main(int argc, char* argv[]) const optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv); const std::vector args = parser->args(); - // setHighDpiScaleFactorRoundingPolicy was added in 5.14, but default behavior changed in 6.0 -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - // Set to the previous default behavior - QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); -#else - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); -#endif - QCoreApplication::setOrganizationName(QStringLiteral("Dolphin Emulator")); QCoreApplication::setOrganizationDomain(QStringLiteral("dolphin-emu.org")); QCoreApplication::setApplicationName(QStringLiteral("dolphin-emu")); From 8a6118bec66f174c3563a0daf152de50fded24d0 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 23 Apr 2023 21:48:13 +0200 Subject: [PATCH 12/93] Qt/NetworkWidget: Don't update if not paused. This is similar to https://github.com/dolphin-emu/dolphin/pull/11623 where the Core state change invoked by the CPUThreadGuard does indirectly cause another Update() call. --- Source/Core/DolphinQt/Debugger/NetworkWidget.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp b/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp index b9504e64ff..8f820dd68c 100644 --- a/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp @@ -239,6 +239,16 @@ void NetworkWidget::Update() if (!isVisible()) return; + if (Core::GetState() != Core::State::Paused) + { + m_socket_table->setDisabled(true); + m_ssl_table->setDisabled(true); + return; + } + + m_socket_table->setDisabled(false); + m_ssl_table->setDisabled(false); + // needed because there's a race condition on the IOS instance otherwise Core::CPUThreadGuard guard(Core::System::GetInstance()); From 27f38c6c8f20d20f5d844e3d8b47a2591e92d462 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 24 Apr 2023 08:15:55 -0400 Subject: [PATCH 13/93] Common/TraversalClient: Move interface into Common namespace Gets the interface out of the global namespace. --- Source/Core/Common/TraversalClient.cpp | 5 ++- Source/Core/Common/TraversalClient.h | 7 +++- Source/Core/Core/NetPlayClient.cpp | 21 ++++++----- Source/Core/Core/NetPlayClient.h | 8 ++-- Source/Core/Core/NetPlayServer.cpp | 32 ++++++++-------- Source/Core/Core/NetPlayServer.h | 4 +- .../Core/DolphinQt/NetPlay/NetPlayDialog.cpp | 37 ++++++++++--------- Source/Core/DolphinQt/NetPlay/NetPlayDialog.h | 4 +- 8 files changed, 66 insertions(+), 52 deletions(-) diff --git a/Source/Core/Common/TraversalClient.cpp b/Source/Core/Common/TraversalClient.cpp index b215e5d269..e384c1cca8 100644 --- a/Source/Core/Common/TraversalClient.cpp +++ b/Source/Core/Common/TraversalClient.cpp @@ -12,6 +12,8 @@ #include "Common/Random.h" #include "Core/NetPlayProto.h" +namespace Common +{ TraversalClient::TraversalClient(ENetHost* netHost, const std::string& server, const u16 port) : m_NetHost(netHost), m_Server(server), m_port(port) { @@ -304,7 +306,7 @@ int ENET_CALLBACK TraversalClient::InterceptCallback(ENetHost* host, ENetEvent* } std::unique_ptr g_TraversalClient; -Common::ENet::ENetHostPtr g_MainNetHost; +ENet::ENetHostPtr g_MainNetHost; // The settings at the previous TraversalClient reset - notably, we // need to know not just what port it's on, but whether it was @@ -348,3 +350,4 @@ void ReleaseTraversalClient() g_TraversalClient.reset(); g_MainNetHost.reset(); } +} // namespace Common diff --git a/Source/Core/Common/TraversalClient.h b/Source/Core/Common/TraversalClient.h index 40600eb8bd..b0717ae0a9 100644 --- a/Source/Core/Common/TraversalClient.h +++ b/Source/Core/Common/TraversalClient.h @@ -15,6 +15,8 @@ #include "Common/Thread.h" #include "Common/TraversalProto.h" +namespace Common +{ class TraversalClientClient { public: @@ -90,9 +92,12 @@ private: u16 m_port; u32 m_PingTime = 0; }; + extern std::unique_ptr g_TraversalClient; // the NetHost connected to the TraversalClient. -extern Common::ENet::ENetHostPtr g_MainNetHost; +extern ENet::ENetHostPtr g_MainNetHost; + // Create g_TraversalClient and g_MainNetHost if necessary. bool EnsureTraversalClient(const std::string& server, u16 server_port, u16 listen_port = 0); void ReleaseTraversalClient(); +} // namespace Common diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 56c6f08aa5..15f6e9e3ed 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -110,9 +110,9 @@ NetPlayClient::~NetPlayClient() Disconnect(); } - if (g_MainNetHost.get() == m_client) + if (Common::g_MainNetHost.get() == m_client) { - g_MainNetHost.release(); + Common::g_MainNetHost.release(); } if (m_client) { @@ -122,7 +122,7 @@ NetPlayClient::~NetPlayClient() if (m_traversal_client) { - ReleaseTraversalClient(); + Common::ReleaseTraversalClient(); } } @@ -186,11 +186,14 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay return; } - if (!EnsureTraversalClient(traversal_config.traversal_host, traversal_config.traversal_port)) + if (!Common::EnsureTraversalClient(traversal_config.traversal_host, + traversal_config.traversal_port)) + { return; - m_client = g_MainNetHost.get(); + } + m_client = Common::g_MainNetHost.get(); - m_traversal_client = g_TraversalClient.get(); + m_traversal_client = Common::g_TraversalClient.get(); // If we were disconnected in the background, reconnect. if (m_traversal_client->HasFailed()) @@ -1936,16 +1939,16 @@ void NetPlayClient::ClearBuffers() // called from ---NETPLAY--- thread void NetPlayClient::OnTraversalStateChanged() { - const TraversalClient::State state = m_traversal_client->GetState(); + const Common::TraversalClient::State state = m_traversal_client->GetState(); if (m_connection_state == ConnectionState::WaitingForTraversalClientConnection && - state == TraversalClient::State::Connected) + state == Common::TraversalClient::State::Connected) { m_connection_state = ConnectionState::WaitingForTraversalClientConnectReady; m_traversal_client->ConnectToClient(m_host_spec); } else if (m_connection_state != ConnectionState::Failure && - state == TraversalClient::State::Failure) + state == Common::TraversalClient::State::Failure) { Disconnect(); m_dialog->OnTraversalError(m_traversal_client->GetFailureReason()); diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index dbd1095204..abff9c15b1 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -68,8 +68,8 @@ public: virtual void OnDesync(u32 frame, const std::string& player) = 0; virtual void OnConnectionLost() = 0; virtual void OnConnectionError(const std::string& message) = 0; - virtual void OnTraversalError(TraversalClient::FailureReason error) = 0; - virtual void OnTraversalStateChanged(TraversalClient::State state) = 0; + virtual void OnTraversalError(Common::TraversalClient::FailureReason error) = 0; + virtual void OnTraversalStateChanged(Common::TraversalClient::State state) = 0; virtual void OnGameStartAborted() = 0; virtual void OnGolferChanged(bool is_golfer, const std::string& golfer_name) = 0; @@ -107,7 +107,7 @@ public: bool IsHost() const { return pid == 1; } }; -class NetPlayClient : public TraversalClientClient +class NetPlayClient : public Common::TraversalClientClient { public: void ThreadFunc(); @@ -325,7 +325,7 @@ private: std::string m_host_spec; std::string m_player_name; bool m_connecting = false; - TraversalClient* m_traversal_client = nullptr; + Common::TraversalClient* m_traversal_client = nullptr; std::thread m_game_digest_thread; bool m_should_compute_game_digest = false; Common::Event m_gc_pad_event; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 2359dea9c3..6969c686f3 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -98,15 +98,15 @@ NetPlayServer::~NetPlayServer() m_thread.join(); enet_host_destroy(m_server); - if (g_MainNetHost.get() == m_server) + if (Common::g_MainNetHost.get() == m_server) { - g_MainNetHost.release(); + Common::g_MainNetHost.release(); } if (m_traversal_client) { - g_TraversalClient->m_Client = nullptr; - ReleaseTraversalClient(); + Common::g_TraversalClient->m_Client = nullptr; + Common::ReleaseTraversalClient(); } } @@ -132,17 +132,19 @@ NetPlayServer::NetPlayServer(const u16 port, const bool forward_port, NetPlayUI* if (traversal_config.use_traversal) { - if (!EnsureTraversalClient(traversal_config.traversal_host, traversal_config.traversal_port, - port)) + if (!Common::EnsureTraversalClient(traversal_config.traversal_host, + traversal_config.traversal_port, port)) + { return; + } - g_TraversalClient->m_Client = this; - m_traversal_client = g_TraversalClient.get(); + Common::g_TraversalClient->m_Client = this; + m_traversal_client = Common::g_TraversalClient.get(); - m_server = g_MainNetHost.get(); + m_server = Common::g_MainNetHost.get(); - if (g_TraversalClient->HasFailed()) - g_TraversalClient->ReconnectToServer(); + if (Common::g_TraversalClient->HasFailed()) + Common::g_TraversalClient->ReconnectToServer(); } else { @@ -211,7 +213,7 @@ void NetPlayServer::SetupIndex() if (!m_traversal_client->IsConnected()) return; - session.server_id = std::string(g_TraversalClient->GetHostID().data(), 8); + session.server_id = std::string(Common::g_TraversalClient->GetHostID().data(), 8); } else { @@ -1248,15 +1250,15 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) void NetPlayServer::OnTraversalStateChanged() { - const TraversalClient::State state = m_traversal_client->GetState(); + const Common::TraversalClient::State state = m_traversal_client->GetState(); - if (g_TraversalClient->GetHostID()[0] != '\0') + if (Common::g_TraversalClient->GetHostID()[0] != '\0') SetupIndex(); if (!m_dialog) return; - if (state == TraversalClient::State::Failure) + if (state == Common::TraversalClient::State::Failure) m_dialog->OnTraversalError(m_traversal_client->GetFailureReason()); m_dialog->OnTraversalStateChanged(state); diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 223e97e457..d962205a5d 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -31,7 +31,7 @@ namespace NetPlay class NetPlayUI; struct SaveSyncInfo; -class NetPlayServer : public TraversalClientClient +class NetPlayServer : public Common::TraversalClientClient { public: void ThreadFunc(); @@ -210,7 +210,7 @@ private: bool m_abort_chunked_data = false; ENetHost* m_server = nullptr; - TraversalClient* m_traversal_client = nullptr; + Common::TraversalClient* m_traversal_client = nullptr; NetPlayUI* m_dialog = nullptr; NetPlayIndex m_index; }; diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp index 4dec815de9..2809be1d73 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp @@ -321,7 +321,7 @@ void NetPlayDialog::ConnectWidgets() &NetPlayDialog::UpdateGUI); connect(m_hostcode_action_button, &QPushButton::clicked, [this] { if (m_is_copy_button_retry) - g_TraversalClient->ReconnectToServer(); + Common::g_TraversalClient->ReconnectToServer(); else QApplication::clipboard()->setText(m_hostcode_label->text()); }); @@ -581,9 +581,9 @@ void NetPlayDialog::UpdateDiscordPresence() if (IsHosting()) { - if (g_TraversalClient) + if (Common::g_TraversalClient) { - const auto host_id = g_TraversalClient->GetHostID(); + const auto host_id = Common::g_TraversalClient->GetHostID(); if (host_id[0] == '\0') return use_default(); @@ -706,26 +706,27 @@ void NetPlayDialog::UpdateGUI() } else if (m_use_traversal) { - switch (g_TraversalClient->GetState()) + switch (Common::g_TraversalClient->GetState()) { - case TraversalClient::State::Connecting: + case Common::TraversalClient::State::Connecting: m_hostcode_label->setText(tr("Connecting")); m_hostcode_action_button->setEnabled(false); m_hostcode_action_button->setText(tr("...")); break; - case TraversalClient::State::Connected: + case Common::TraversalClient::State::Connected: { if (m_room_box->currentIndex() == 0) { // Display Room ID. - const auto host_id = g_TraversalClient->GetHostID(); + const auto host_id = Common::g_TraversalClient->GetHostID(); m_hostcode_label->setText( QString::fromStdString(std::string(host_id.begin(), host_id.end()))); } else { // Externally mapped IP and port are known when using the traversal server. - m_hostcode_label->setText(InetAddressToString(g_TraversalClient->GetExternalAddress())); + m_hostcode_label->setText( + InetAddressToString(Common::g_TraversalClient->GetExternalAddress())); } m_hostcode_action_button->setEnabled(true); @@ -733,7 +734,7 @@ void NetPlayDialog::UpdateGUI() m_is_copy_button_retry = false; break; } - case TraversalClient::State::Failure: + case Common::TraversalClient::State::Failure: m_hostcode_label->setText(tr("Error")); m_hostcode_action_button->setText(tr("Retry")); m_hostcode_action_button->setEnabled(true); @@ -981,35 +982,35 @@ void NetPlayDialog::OnConnectionError(const std::string& message) }); } -void NetPlayDialog::OnTraversalError(TraversalClient::FailureReason error) +void NetPlayDialog::OnTraversalError(Common::TraversalClient::FailureReason error) { QueueOnObject(this, [this, error] { switch (error) { - case TraversalClient::FailureReason::BadHost: + case Common::TraversalClient::FailureReason::BadHost: ModalMessageBox::critical(this, tr("Traversal Error"), tr("Couldn't look up central server")); QDialog::reject(); break; - case TraversalClient::FailureReason::VersionTooOld: + case Common::TraversalClient::FailureReason::VersionTooOld: ModalMessageBox::critical(this, tr("Traversal Error"), tr("Dolphin is too old for traversal server")); QDialog::reject(); break; - case TraversalClient::FailureReason::ServerForgotAboutUs: - case TraversalClient::FailureReason::SocketSendError: - case TraversalClient::FailureReason::ResendTimeout: + case Common::TraversalClient::FailureReason::ServerForgotAboutUs: + case Common::TraversalClient::FailureReason::SocketSendError: + case Common::TraversalClient::FailureReason::ResendTimeout: UpdateGUI(); break; } }); } -void NetPlayDialog::OnTraversalStateChanged(TraversalClient::State state) +void NetPlayDialog::OnTraversalStateChanged(Common::TraversalClient::State state) { switch (state) { - case TraversalClient::State::Connected: - case TraversalClient::State::Failure: + case Common::TraversalClient::State::Connected: + case Common::TraversalClient::State::Failure: UpdateDiscordPresence(); break; default: diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h index 17079b0ba6..84f9ff0fbe 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h @@ -67,8 +67,8 @@ public: void OnDesync(u32 frame, const std::string& player) override; void OnConnectionLost() override; void OnConnectionError(const std::string& message) override; - void OnTraversalError(TraversalClient::FailureReason error) override; - void OnTraversalStateChanged(TraversalClient::State state) override; + void OnTraversalError(Common::TraversalClient::FailureReason error) override; + void OnTraversalStateChanged(Common::TraversalClient::State state) override; void OnGameStartAborted() override; void OnGolferChanged(bool is_golfer, const std::string& golfer_name) override; From 30e7ab94fa8d4177a8516a926dad5a7e663a1a51 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 24 Apr 2023 08:29:12 -0400 Subject: [PATCH 14/93] Common/TraversalProto: Move interface into Common namespace Gets the types out of the global namespace. --- Source/Core/Common/TraversalProto.h | 3 + Source/Core/Common/TraversalServer.cpp | 95 ++++++++++--------- Source/Core/Core/NetPlayClient.cpp | 10 +- Source/Core/Core/NetPlayClient.h | 2 +- Source/Core/Core/NetPlayServer.h | 2 +- .../Core/DolphinQt/NetPlay/NetPlayDialog.cpp | 2 +- 6 files changed, 61 insertions(+), 53 deletions(-) diff --git a/Source/Core/Common/TraversalProto.h b/Source/Core/Common/TraversalProto.h index fc7404048a..1946d7b9a9 100644 --- a/Source/Core/Common/TraversalProto.h +++ b/Source/Core/Common/TraversalProto.h @@ -6,6 +6,8 @@ #include #include "Common/CommonTypes.h" +namespace Common +{ constexpr size_t NETPLAY_CODE_SIZE = 8; using TraversalHostId = std::array; using TraversalRequestId = u64; @@ -92,3 +94,4 @@ struct TraversalPacket }; }; #pragma pack(pop) +} // namespace Common diff --git a/Source/Core/Common/TraversalServer.cpp b/Source/Core/Common/TraversalServer.cpp index e23c7676bd..b9b05519fa 100644 --- a/Source/Core/Common/TraversalServer.cpp +++ b/Source/Core/Common/TraversalServer.cpp @@ -31,8 +31,8 @@ static u64 currentTime; struct OutgoingPacketInfo { - TraversalPacket packet; - TraversalRequestId misc; + Common::TraversalPacket packet; + Common::TraversalRequestId misc; sockaddr_in6 dest; int tries; u64 sendTime; @@ -104,9 +104,9 @@ V* EvictSet(std::unordered_map>& map, const K& key) namespace std { template <> -struct hash +struct hash { - size_t operator()(const TraversalHostId& id) const + size_t operator()(const Common::TraversalHostId& id) const noexcept { auto p = (u32*)id.data(); return p[0] ^ ((p[1] << 13) | (p[1] >> 19)); @@ -114,11 +114,15 @@ struct hash }; } // namespace std -static int sock; -static std::unordered_map outgoingPackets; -static std::unordered_map> connectedClients; +using ConnectedClients = + std::unordered_map>; +using OutgoingPackets = std::unordered_map; -static TraversalInetAddress MakeInetAddress(const sockaddr_in6& addr) +static int sock; +static OutgoingPackets outgoingPackets; +static ConnectedClients connectedClients; + +static Common::TraversalInetAddress MakeInetAddress(const sockaddr_in6& addr) { if (addr.sin6_family != AF_INET6) { @@ -126,7 +130,7 @@ static TraversalInetAddress MakeInetAddress(const sockaddr_in6& addr) exit(1); } u32* words = (u32*)addr.sin6_addr.s6_addr; - TraversalInetAddress result = {0}; + Common::TraversalInetAddress result = {}; if (words[0] == 0 && words[1] == 0 && words[2] == 0xffff0000) { result.isIPV6 = false; @@ -141,7 +145,7 @@ static TraversalInetAddress MakeInetAddress(const sockaddr_in6& addr) return result; } -static sockaddr_in6 MakeSinAddr(const TraversalInetAddress& addr) +static sockaddr_in6 MakeSinAddr(const Common::TraversalInetAddress& addr) { sockaddr_in6 result; #ifdef SIN6_LEN @@ -166,7 +170,7 @@ static sockaddr_in6 MakeSinAddr(const TraversalInetAddress& addr) return result; } -static void GetRandomHostId(TraversalHostId* hostId) +static void GetRandomHostId(Common::TraversalHostId* hostId) { char buf[9]; const u32 num = Common::Random::GenerateValue(); @@ -185,7 +189,7 @@ static const char* SenderName(sockaddr_in6* addr) static void TrySend(const void* buffer, size_t size, sockaddr_in6* addr) { #if DEBUG - const auto* packet = static_cast(buffer); + const auto* packet = static_cast(buffer); printf("-> %d %llu %s\n", static_cast(packet->type), static_cast(packet->requestId), SenderName(addr)); #endif @@ -195,16 +199,17 @@ static void TrySend(const void* buffer, size_t size, sockaddr_in6* addr) } } -static TraversalPacket* AllocPacket(const sockaddr_in6& dest, TraversalRequestId misc = 0) +static Common::TraversalPacket* AllocPacket(const sockaddr_in6& dest, + Common::TraversalRequestId misc = 0) { - TraversalRequestId requestId; + Common::TraversalRequestId requestId{}; Common::Random::Generate(&requestId, sizeof(requestId)); OutgoingPacketInfo* info = &outgoingPackets[requestId]; info->dest = dest; info->misc = misc; info->tries = 0; info->sendTime = currentTime; - TraversalPacket* result = &info->packet; + Common::TraversalPacket* result = &info->packet; memset(result, 0, sizeof(*result)); result->requestId = requestId; return result; @@ -219,7 +224,7 @@ static void SendPacket(OutgoingPacketInfo* info) static void ResendPackets() { - std::vector> todoFailures; + std::vector> todoFailures; todoFailures.clear(); for (auto it = outgoingPackets.begin(); it != outgoingPackets.end();) { @@ -228,7 +233,7 @@ static void ResendPackets() { if (info->tries >= NUMBER_OF_TRIES) { - if (info->packet.type == TraversalPacketType::PleaseSendPacket) + if (info->packet.type == Common::TraversalPacketType::PleaseSendPacket) { todoFailures.push_back(std::make_pair(info->packet.pleaseSendPacket.address, info->misc)); } @@ -245,14 +250,14 @@ static void ResendPackets() for (const auto& p : todoFailures) { - TraversalPacket* fail = AllocPacket(MakeSinAddr(p.first)); - fail->type = TraversalPacketType::ConnectFailed; + Common::TraversalPacket* fail = AllocPacket(MakeSinAddr(p.first)); + fail->type = Common::TraversalPacketType::ConnectFailed; fail->connectFailed.requestId = p.second; - fail->connectFailed.reason = TraversalConnectFailedReason::ClientDidntRespond; + fail->connectFailed.reason = Common::TraversalConnectFailedReason::ClientDidntRespond; } } -static void HandlePacket(TraversalPacket* packet, sockaddr_in6* addr) +static void HandlePacket(Common::TraversalPacket* packet, sockaddr_in6* addr) { #if DEBUG printf("<- %d %llu %s\n", static_cast(packet->type), @@ -261,7 +266,7 @@ static void HandlePacket(TraversalPacket* packet, sockaddr_in6* addr) bool packetOk = true; switch (packet->type) { - case TraversalPacketType::Ack: + case Common::TraversalPacketType::Ack: { auto it = outgoingPackets.find(packet->requestId); if (it == outgoingPackets.end()) @@ -269,42 +274,42 @@ static void HandlePacket(TraversalPacket* packet, sockaddr_in6* addr) OutgoingPacketInfo* info = &it->second; - if (info->packet.type == TraversalPacketType::PleaseSendPacket) + if (info->packet.type == Common::TraversalPacketType::PleaseSendPacket) { - TraversalPacket* ready = AllocPacket(MakeSinAddr(info->packet.pleaseSendPacket.address)); + auto* ready = AllocPacket(MakeSinAddr(info->packet.pleaseSendPacket.address)); if (packet->ack.ok) { - ready->type = TraversalPacketType::ConnectReady; + ready->type = Common::TraversalPacketType::ConnectReady; ready->connectReady.requestId = info->misc; ready->connectReady.address = MakeInetAddress(info->dest); } else { - ready->type = TraversalPacketType::ConnectFailed; + ready->type = Common::TraversalPacketType::ConnectFailed; ready->connectFailed.requestId = info->misc; - ready->connectFailed.reason = TraversalConnectFailedReason::ClientFailure; + ready->connectFailed.reason = Common::TraversalConnectFailedReason::ClientFailure; } } outgoingPackets.erase(it); break; } - case TraversalPacketType::Ping: + case Common::TraversalPacketType::Ping: { auto r = EvictFind(connectedClients, packet->ping.hostId, true); packetOk = r.found; break; } - case TraversalPacketType::HelloFromClient: + case Common::TraversalPacketType::HelloFromClient: { - u8 ok = packet->helloFromClient.protoVersion <= TraversalProtoVersion; - TraversalPacket* reply = AllocPacket(*addr); - reply->type = TraversalPacketType::HelloFromServer; + u8 ok = packet->helloFromClient.protoVersion <= Common::TraversalProtoVersion; + Common::TraversalPacket* reply = AllocPacket(*addr); + reply->type = Common::TraversalPacketType::HelloFromServer; reply->helloFromServer.ok = ok; if (ok) { - TraversalHostId hostId; - TraversalInetAddress* iaddr; + Common::TraversalHostId hostId{}; + Common::TraversalInetAddress* iaddr{}; // not that there is any significant change of // duplication, but... GetRandomHostId(&hostId); @@ -325,21 +330,21 @@ static void HandlePacket(TraversalPacket* packet, sockaddr_in6* addr) } break; } - case TraversalPacketType::ConnectPlease: + case Common::TraversalPacketType::ConnectPlease: { - TraversalHostId& hostId = packet->connectPlease.hostId; + Common::TraversalHostId& hostId = packet->connectPlease.hostId; auto r = EvictFind(connectedClients, hostId); if (!r.found) { - TraversalPacket* reply = AllocPacket(*addr); - reply->type = TraversalPacketType::ConnectFailed; + Common::TraversalPacket* reply = AllocPacket(*addr); + reply->type = Common::TraversalPacketType::ConnectFailed; reply->connectFailed.requestId = packet->requestId; - reply->connectFailed.reason = TraversalConnectFailedReason::NoSuchClient; + reply->connectFailed.reason = Common::TraversalConnectFailedReason::NoSuchClient; } else { - TraversalPacket* please = AllocPacket(MakeSinAddr(*r.value), packet->requestId); - please->type = TraversalPacketType::PleaseSendPacket; + Common::TraversalPacket* please = AllocPacket(MakeSinAddr(*r.value), packet->requestId); + please->type = Common::TraversalPacketType::PleaseSendPacket; please->pleaseSendPacket.address = MakeInetAddress(*addr); } break; @@ -349,10 +354,10 @@ static void HandlePacket(TraversalPacket* packet, sockaddr_in6* addr) SenderName(addr)); break; } - if (packet->type != TraversalPacketType::Ack) + if (packet->type != Common::TraversalPacketType::Ack) { - TraversalPacket ack = {}; - ack.type = TraversalPacketType::Ack; + Common::TraversalPacket ack = {}; + ack.type = Common::TraversalPacketType::Ack; ack.requestId = packet->requestId; ack.ack.ok = packetOk; TrySend(&ack, sizeof(ack), addr); @@ -411,7 +416,7 @@ int main() { sockaddr_in6 raddr; socklen_t addrLen = sizeof(raddr); - TraversalPacket packet; + Common::TraversalPacket packet{}; // note: switch to recvmmsg (yes, mmsg) if this becomes // expensive rv = recvfrom(sock, &packet, sizeof(packet), 0, (sockaddr*)&raddr, &addrLen); diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 15f6e9e3ed..ff78728c80 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -179,7 +179,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay } else { - if (address.size() > NETPLAY_CODE_SIZE) + if (address.size() > Common::NETPLAY_CODE_SIZE) { m_dialog->OnConnectionError( _trans("The host code is too long.\nPlease recheck that you have the correct code.")); @@ -1967,19 +1967,19 @@ void NetPlayClient::OnConnectReady(ENetAddress addr) } // called from ---NETPLAY--- thread -void NetPlayClient::OnConnectFailed(TraversalConnectFailedReason reason) +void NetPlayClient::OnConnectFailed(Common::TraversalConnectFailedReason reason) { m_connecting = false; m_connection_state = ConnectionState::Failure; switch (reason) { - case TraversalConnectFailedReason::ClientDidntRespond: + case Common::TraversalConnectFailedReason::ClientDidntRespond: PanicAlertFmtT("Traversal server timed out connecting to the host"); break; - case TraversalConnectFailedReason::ClientFailure: + case Common::TraversalConnectFailedReason::ClientFailure: PanicAlertFmtT("Server rejected traversal attempt"); break; - case TraversalConnectFailedReason::NoSuchClient: + case Common::TraversalConnectFailedReason::NoSuchClient: PanicAlertFmtT("Invalid host"); break; default: diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index abff9c15b1..aba54b12dd 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -147,7 +147,7 @@ public: void OnTraversalStateChanged() override; void OnConnectReady(ENetAddress addr) override; - void OnConnectFailed(TraversalConnectFailedReason reason) override; + void OnConnectFailed(Common::TraversalConnectFailedReason reason) override; bool IsFirstInGamePad(int ingame_pad) const; int NumLocalPads() const; diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index d962205a5d..0498ff12fc 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -143,7 +143,7 @@ private: void OnTraversalStateChanged() override; void OnConnectReady(ENetAddress) override {} - void OnConnectFailed(TraversalConnectFailedReason) override {} + void OnConnectFailed(Common::TraversalConnectFailedReason) override {} void UpdatePadMapping(); void UpdateGBAConfig(); void UpdateWiimoteMapping(); diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp index 2809be1d73..c5edb9c0d9 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp @@ -65,7 +65,7 @@ namespace { -QString InetAddressToString(const TraversalInetAddress& addr) +QString InetAddressToString(const Common::TraversalInetAddress& addr) { QString ip; From d991cbaf3c098044323e0330cb66dd76138f8d43 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 24 Apr 2023 09:05:49 -0400 Subject: [PATCH 15/93] Common: Move CodeTrace.cpp/.h into Core This interface relies on Core details and shouldn't be in Common to begin with, since it's not a general utility. --- Source/Core/Common/CMakeLists.txt | 2 -- Source/Core/Core/CMakeLists.txt | 2 ++ Source/Core/{Common/Debug => Core/Debugger}/CodeTrace.cpp | 2 +- Source/Core/{Common/Debug => Core/Debugger}/CodeTrace.h | 0 Source/Core/DolphinLib.props | 4 ++-- Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp | 2 +- Source/Core/DolphinQt/Debugger/CodeViewWidget.h | 2 +- Source/Core/DolphinQt/Debugger/RegisterWidget.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) rename Source/Core/{Common/Debug => Core/Debugger}/CodeTrace.cpp (99%) rename Source/Core/{Common/Debug => Core/Debugger}/CodeTrace.h (100%) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 6d9636363d..9c642e7ec5 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -31,8 +31,6 @@ add_library(common Crypto/ec.h Crypto/SHA1.cpp Crypto/SHA1.h - Debug/CodeTrace.cpp - Debug/CodeTrace.h Debug/MemoryPatches.cpp Debug/MemoryPatches.h Debug/Threads.h diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index fcba3cba14..cbf3cf5cd7 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -59,6 +59,8 @@ add_library(core Core.h CoreTiming.cpp CoreTiming.h + Debugger/CodeTrace.cpp + Debugger/CodeTrace.h Debugger/Debugger_SymbolMap.cpp Debugger/Debugger_SymbolMap.h Debugger/Dump.cpp diff --git a/Source/Core/Common/Debug/CodeTrace.cpp b/Source/Core/Core/Debugger/CodeTrace.cpp similarity index 99% rename from Source/Core/Common/Debug/CodeTrace.cpp rename to Source/Core/Core/Debugger/CodeTrace.cpp index 88ff656a92..1329b82c7c 100644 --- a/Source/Core/Common/Debug/CodeTrace.cpp +++ b/Source/Core/Core/Debugger/CodeTrace.cpp @@ -1,7 +1,7 @@ // Copyright 2022 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "Common/Debug/CodeTrace.h" +#include "Core/Debugger/CodeTrace.h" #include #include diff --git a/Source/Core/Common/Debug/CodeTrace.h b/Source/Core/Core/Debugger/CodeTrace.h similarity index 100% rename from Source/Core/Common/Debug/CodeTrace.h rename to Source/Core/Core/Debugger/CodeTrace.h diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index 8a463f5a5e..ded5f4664b 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -36,7 +36,6 @@ - @@ -191,6 +190,7 @@ + @@ -749,7 +749,6 @@ - @@ -825,6 +824,7 @@ + diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index 312cc1f190..edac049a96 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -24,10 +24,10 @@ #include #include "Common/Assert.h" -#include "Common/Debug/CodeTrace.h" #include "Common/GekkoDisassembler.h" #include "Common/StringUtil.h" #include "Core/Core.h" +#include "Core/Debugger/CodeTrace.h" #include "Core/Debugger/PPCDebugInterface.h" #include "Core/PowerPC/MMU.h" #include "Core/PowerPC/PPCAnalyst.h" diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h index 2812d84a92..142a56d7a3 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.h @@ -8,7 +8,7 @@ #include #include "Common/CommonTypes.h" -#include "Common/Debug/CodeTrace.h" +#include "Core/Debugger/CodeTrace.h" class QKeyEvent; class QMouseEvent; diff --git a/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp b/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp index b41fffb39a..324d680dbb 100644 --- a/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp @@ -12,8 +12,8 @@ #include #include -#include "Common/Debug/CodeTrace.h" #include "Core/Core.h" +#include "Core/Debugger/CodeTrace.h" #include "Core/HW/ProcessorInterface.h" #include "Core/PowerPC/PowerPC.h" #include "Core/System.h" From 15a0860f1591f749bdbd2cc71a2470908cd4dcb7 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 23 Apr 2023 19:38:11 +0200 Subject: [PATCH 16/93] IOS: Leverage Kernel/EmulationKernel difference for passing System to most IOS devices. --- Source/Core/Core/IOS/DI/DI.cpp | 39 +++++---- Source/Core/Core/IOS/DI/DI.h | 4 +- Source/Core/Core/IOS/Device.cpp | 41 ++++----- Source/Core/Core/IOS/Device.h | 45 +++++++--- Source/Core/Core/IOS/DolphinDevice.cpp | 42 ++++----- Source/Core/Core/IOS/DolphinDevice.h | 4 +- Source/Core/Core/IOS/ES/ES.cpp | 2 +- Source/Core/Core/IOS/IOS.cpp | 68 +++++++-------- Source/Core/Core/IOS/IOS.h | 48 +++++----- Source/Core/Core/IOS/Network/IP/Top.cpp | 87 ++++++++++--------- Source/Core/Core/IOS/Network/IP/Top.h | 4 +- .../Core/Core/IOS/Network/KD/NetKDRequest.cpp | 16 ++-- .../Core/Core/IOS/Network/KD/NetKDRequest.h | 4 +- Source/Core/Core/IOS/Network/KD/NetKDTime.cpp | 14 ++- Source/Core/Core/IOS/Network/KD/NetKDTime.h | 4 +- Source/Core/Core/IOS/Network/NCD/Manage.cpp | 6 +- Source/Core/Core/IOS/Network/NCD/Manage.h | 4 +- Source/Core/Core/IOS/Network/SSL.cpp | 16 ++-- Source/Core/Core/IOS/Network/SSL.h | 4 +- Source/Core/Core/IOS/Network/Socket.cpp | 8 +- Source/Core/Core/IOS/Network/WD/Command.cpp | 19 ++-- Source/Core/Core/IOS/Network/WD/Command.h | 4 +- Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp | 29 ++++--- Source/Core/Core/IOS/SDIO/SDIOSlot0.h | 4 +- Source/Core/Core/IOS/STM/STM.cpp | 18 ++-- Source/Core/Core/IOS/STM/STM.h | 8 +- Source/Core/Core/IOS/USB/Bluetooth/BTBase.h | 4 +- Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp | 43 ++++----- Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h | 8 +- Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp | 31 ++++--- Source/Core/Core/IOS/USB/Bluetooth/BTReal.h | 2 +- Source/Core/Core/IOS/USB/Common.cpp | 6 +- Source/Core/Core/IOS/USB/Common.h | 6 +- .../Core/Core/IOS/USB/Emulated/Skylander.cpp | 6 +- Source/Core/Core/IOS/USB/Emulated/Skylander.h | 4 +- Source/Core/Core/IOS/USB/Host.cpp | 9 +- Source/Core/Core/IOS/USB/Host.h | 4 +- Source/Core/Core/IOS/USB/LibusbDevice.cpp | 4 +- Source/Core/Core/IOS/USB/LibusbDevice.h | 4 +- Source/Core/Core/IOS/USB/OH0/OH0.cpp | 41 +++++---- Source/Core/Core/IOS/USB/OH0/OH0.h | 2 +- Source/Core/Core/IOS/USB/OH0/OH0Device.cpp | 7 +- Source/Core/Core/IOS/USB/OH0/OH0Device.h | 4 +- Source/Core/Core/IOS/USB/USBV0.cpp | 16 ++-- Source/Core/Core/IOS/USB/USBV0.h | 8 +- Source/Core/Core/IOS/USB/USBV4.cpp | 16 ++-- Source/Core/Core/IOS/USB/USBV4.h | 6 +- Source/Core/Core/IOS/USB/USBV5.cpp | 37 ++++---- Source/Core/Core/IOS/USB/USBV5.h | 8 +- Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp | 35 +++++--- Source/Core/Core/IOS/USB/USB_HID/HIDv4.h | 2 +- Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp | 17 ++-- Source/Core/Core/IOS/USB/USB_KBD.cpp | 5 +- Source/Core/Core/IOS/USB/USB_KBD.h | 4 +- Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp | 19 ++-- Source/Core/Core/IOS/WFS/WFSI.cpp | 15 ++-- Source/Core/Core/IOS/WFS/WFSI.h | 4 +- Source/Core/Core/IOS/WFS/WFSSRV.cpp | 11 +-- Source/Core/Core/IOS/WFS/WFSSRV.h | 4 +- 59 files changed, 505 insertions(+), 429 deletions(-) diff --git a/Source/Core/Core/IOS/DI/DI.cpp b/Source/Core/Core/IOS/DI/DI.cpp index 40f818cef6..dd695d0586 100644 --- a/Source/Core/Core/IOS/DI/DI.cpp +++ b/Source/Core/Core/IOS/DI/DI.cpp @@ -41,7 +41,8 @@ namespace IOS::HLE { CoreTiming::EventType* DIDevice::s_finish_executing_di_command; -DIDevice::DIDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name) +DIDevice::DIDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { } @@ -70,7 +71,7 @@ std::optional DIDevice::IOCtl(const IOCtlRequest& request) // asynchronously. The rest are also treated as async to match this. Only one command can be // executed at a time, so commands are queued until DVDInterface is ready to handle them. - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8 command = memory.Read_U8(request.buffer_in); if (request.request != command) @@ -105,12 +106,13 @@ void DIDevice::ProcessQueuedIOCtl() m_executing_command = {m_commands_to_execute.front()}; m_commands_to_execute.pop_front(); - IOCtlRequest request{m_executing_command->m_request_address}; + auto& system = GetSystem(); + IOCtlRequest request{system, m_executing_command->m_request_address}; auto finished = StartIOCtl(request); if (finished) { - Core::System::GetInstance().GetCoreTiming().ScheduleEvent( - IPC_OVERHEAD_TICKS, s_finish_executing_di_command, static_cast(finished.value())); + system.GetCoreTiming().ScheduleEvent(IPC_OVERHEAD_TICKS, s_finish_executing_di_command, + static_cast(finished.value())); return; } } @@ -124,7 +126,7 @@ std::optional DIDevice::WriteIfFits(const IOCtlRequest& requ } else { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.Write_U32(value, request.buffer_out); return DIResult::Success; @@ -150,7 +152,7 @@ std::optional DIDevice::StartIOCtl(const IOCtlRequest& reque return DIResult::SecurityError; } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); auto* mmio = memory.GetMMIOMapping(); @@ -561,7 +563,7 @@ std::optional DIDevice::StartDMATransfer(u32 command_length, return DIResult::BadArgument; } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto* mmio = system.GetMemory().GetMMIOMapping(); mmio->Write(ADDRESS_DIMAR, request.buffer_out); m_last_length = command_length; @@ -585,7 +587,8 @@ std::optional DIDevice::StartImmediateTransfer(const IOCtlRe m_executing_command->m_copy_diimmbuf = write_to_buf; - Core::System::GetInstance().GetDVDInterface().ExecuteCommand(DVD::ReplyType::IOS); + auto& system = GetSystem(); + system.GetDVDInterface().ExecuteCommand(DVD::ReplyType::IOS); // Reply will be posted when done by FinishIOCtl. return {}; } @@ -649,15 +652,15 @@ void DIDevice::FinishDICommand(DIResult result) return; } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); auto* mmio = memory.GetMMIOMapping(); - IOCtlRequest request{m_executing_command->m_request_address}; + IOCtlRequest request{system, m_executing_command->m_request_address}; if (m_executing_command->m_copy_diimmbuf) memory.Write_U32(mmio->Read(ADDRESS_DIIMMBUF), request.buffer_out); - m_ios.EnqueueIPCReply(request, static_cast(result)); + GetEmulationKernel().EnqueueIPCReply(request, static_cast(result)); m_executing_command.reset(); @@ -683,7 +686,7 @@ std::optional DIDevice::IOCtlV(const IOCtlVRequest& request) return IPCReply{static_cast(DIResult::BadArgument)}; } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8 command = memory.Read_U8(request.in_vectors[0].address); @@ -742,17 +745,17 @@ std::optional DIDevice::IOCtlV(const IOCtlVRequest& request) case DIIoctl::DVDLowGetNoDiscOpenPartitionParams: ERROR_LOG_FMT(IOS_DI, "DVDLowGetNoDiscOpenPartitionParams - dummied out"); DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_DIFFERENT_PARTITION_COMMAND); - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_DI); break; case DIIoctl::DVDLowNoDiscOpenPartition: ERROR_LOG_FMT(IOS_DI, "DVDLowNoDiscOpenPartition - dummied out"); DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_DIFFERENT_PARTITION_COMMAND); - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_DI); break; case DIIoctl::DVDLowGetNoDiscBufferSizes: ERROR_LOG_FMT(IOS_DI, "DVDLowGetNoDiscBufferSizes - dummied out"); DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_DIFFERENT_PARTITION_COMMAND); - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_DI); break; case DIIoctl::DVDLowOpenPartitionWithTmdAndTicket: ERROR_LOG_FMT(IOS_DI, "DVDLowOpenPartitionWithTmdAndTicket - not implemented"); @@ -764,7 +767,7 @@ std::optional DIDevice::IOCtlV(const IOCtlVRequest& request) break; default: ERROR_LOG_FMT(IOS_DI, "Unknown ioctlv {:#04x}", request.request); - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_DI); } return IPCReply{static_cast(return_value)}; } @@ -804,7 +807,7 @@ void DIDevice::ResetDIRegisters() { // Clear transfer complete and error interrupts (normally r/z, but here we just directly write // zero) - auto& di = Core::System::GetInstance().GetDVDInterface(); + auto& di = GetSystem().GetDVDInterface(); di.ClearInterrupt(DVD::DIInterruptType::TCINT); di.ClearInterrupt(DVD::DIInterruptType::DEINT); // Enable transfer complete and error interrupts, and disable cover interrupt diff --git a/Source/Core/Core/IOS/DI/DI.h b/Source/Core/Core/IOS/DI/DI.h index 9b8acb37b9..117e603768 100644 --- a/Source/Core/Core/IOS/DI/DI.h +++ b/Source/Core/Core/IOS/DI/DI.h @@ -35,10 +35,10 @@ void Init(); namespace IOS::HLE { -class DIDevice : public Device +class DIDevice : public EmulationDevice { public: - DIDevice(Kernel& ios, const std::string& device_name); + DIDevice(EmulationKernel& ios, const std::string& device_name); static void InterruptFromDVDInterface(DVD::DIInterruptType interrupt_type); static DiscIO::Partition GetCurrentPartition(); diff --git a/Source/Core/Core/IOS/Device.cpp b/Source/Core/Core/IOS/Device.cpp index 1a44e84129..920b53bccc 100644 --- a/Source/Core/Core/IOS/Device.cpp +++ b/Source/Core/Core/IOS/Device.cpp @@ -16,17 +16,15 @@ namespace IOS::HLE { -Request::Request(const u32 address_) : address(address_) +Request::Request(Core::System& system, const u32 address_) : address(address_) { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); command = static_cast(memory.Read_U32(address)); fd = memory.Read_U32(address + 8); } -OpenRequest::OpenRequest(const u32 address_) : Request(address_) +OpenRequest::OpenRequest(Core::System& system, const u32 address_) : Request(system, address_) { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); path = memory.GetString(memory.Read_U32(address + 0xc)); flags = static_cast(memory.Read_U32(address + 0x10)); @@ -38,25 +36,23 @@ OpenRequest::OpenRequest(const u32 address_) : Request(address_) } } -ReadWriteRequest::ReadWriteRequest(const u32 address_) : Request(address_) +ReadWriteRequest::ReadWriteRequest(Core::System& system, const u32 address_) + : Request(system, address_) { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); buffer = memory.Read_U32(address + 0xc); size = memory.Read_U32(address + 0x10); } -SeekRequest::SeekRequest(const u32 address_) : Request(address_) +SeekRequest::SeekRequest(Core::System& system, const u32 address_) : Request(system, address_) { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); offset = memory.Read_U32(address + 0xc); mode = static_cast(memory.Read_U32(address + 0x10)); } -IOCtlRequest::IOCtlRequest(const u32 address_) : Request(address_) +IOCtlRequest::IOCtlRequest(Core::System& system, const u32 address_) : Request(system, address_) { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); request = memory.Read_U32(address + 0x0c); buffer_in = memory.Read_U32(address + 0x10); @@ -65,9 +61,8 @@ IOCtlRequest::IOCtlRequest(const u32 address_) : Request(address_) buffer_out_size = memory.Read_U32(address + 0x1c); } -IOCtlVRequest::IOCtlVRequest(const u32 address_) : Request(address_) +IOCtlVRequest::IOCtlVRequest(Core::System& system, const u32 address_) : Request(system, address_) { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); request = memory.Read_U32(address + 0x0c); const u32 in_number = memory.Read_U32(address + 0x10); @@ -114,10 +109,9 @@ void IOCtlRequest::Log(std::string_view device_name, Common::Log::LogType type, device_name, fd, request, buffer_in_size, buffer_out_size); } -void IOCtlRequest::Dump(const std::string& description, Common::Log::LogType type, - Common::Log::LogLevel level) const +void IOCtlRequest::Dump(Core::System& system, const std::string& description, + Common::Log::LogType type, Common::Log::LogLevel level) const { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); Log("===== " + description, type, level); @@ -127,16 +121,15 @@ void IOCtlRequest::Dump(const std::string& description, Common::Log::LogType typ HexDump(memory.GetPointer(buffer_out), buffer_out_size)); } -void IOCtlRequest::DumpUnknown(const std::string& description, Common::Log::LogType type, - Common::Log::LogLevel level) const +void IOCtlRequest::DumpUnknown(Core::System& system, const std::string& description, + Common::Log::LogType type, Common::Log::LogLevel level) const { - Dump("Unknown IOCtl - " + description, type, level); + Dump(system, "Unknown IOCtl - " + description, type, level); } -void IOCtlVRequest::Dump(std::string_view description, Common::Log::LogType type, - Common::Log::LogLevel level) const +void IOCtlVRequest::Dump(Core::System& system, std::string_view description, + Common::Log::LogType type, Common::Log::LogLevel level) const { - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); GENERIC_LOG_FMT(type, level, "===== {} (fd {}) - IOCtlV {:#x} ({} in, {} io)", description, fd, @@ -154,10 +147,10 @@ void IOCtlVRequest::Dump(std::string_view description, Common::Log::LogType type GENERIC_LOG_FMT(type, level, "io[{}] (size={:#x})", i++, vector.size); } -void IOCtlVRequest::DumpUnknown(const std::string& description, Common::Log::LogType type, - Common::Log::LogLevel level) const +void IOCtlVRequest::DumpUnknown(Core::System& system, const std::string& description, + Common::Log::LogType type, Common::Log::LogLevel level) const { - Dump("Unknown IOCtlV - " + description, type, level); + Dump(system, "Unknown IOCtlV - " + description, type, level); } Device::Device(Kernel& ios, const std::string& device_name, const DeviceType type) diff --git a/Source/Core/Core/IOS/Device.h b/Source/Core/Core/IOS/Device.h index d45351e76d..651d78ae60 100644 --- a/Source/Core/Core/IOS/Device.h +++ b/Source/Core/Core/IOS/Device.h @@ -13,6 +13,11 @@ #include "Common/Logging/Log.h" #include "Core/IOS/IOS.h" +namespace Core +{ +class System; +} + namespace IOS::HLE { enum ReturnCode : s32 @@ -77,7 +82,7 @@ struct Request u32 address = 0; IPCCommandType command = IPC_CMD_OPEN; u32 fd = 0; - explicit Request(u32 address); + Request(Core::System& system, u32 address); virtual ~Request() = default; }; @@ -97,14 +102,14 @@ struct OpenRequest final : Request // but they are set after they reach IOS and are dispatched to the appropriate module. u32 uid = 0; u16 gid = 0; - explicit OpenRequest(u32 address); + OpenRequest(Core::System& system, u32 address); }; struct ReadWriteRequest final : Request { u32 buffer = 0; u32 size = 0; - explicit ReadWriteRequest(u32 address); + ReadWriteRequest(Core::System& system, u32 address); }; enum SeekMode : s32 @@ -118,7 +123,7 @@ struct SeekRequest final : Request { u32 offset = 0; SeekMode mode = IOS_SEEK_SET; - explicit SeekRequest(u32 address); + SeekRequest(Core::System& system, u32 address); }; struct IOCtlRequest final : Request @@ -129,12 +134,13 @@ struct IOCtlRequest final : Request // Contrary to the name, the output buffer can also be used for input. u32 buffer_out = 0; u32 buffer_out_size = 0; - explicit IOCtlRequest(u32 address); + IOCtlRequest(Core::System& system, u32 address); void Log(std::string_view description, Common::Log::LogType type = Common::Log::LogType::IOS, Common::Log::LogLevel level = Common::Log::LogLevel::LINFO) const; - void Dump(const std::string& description, Common::Log::LogType type = Common::Log::LogType::IOS, + void Dump(Core::System& system, const std::string& description, + Common::Log::LogType type = Common::Log::LogType::IOS, Common::Log::LogLevel level = Common::Log::LogLevel::LINFO) const; - void DumpUnknown(const std::string& description, + void DumpUnknown(Core::System& system, const std::string& description, Common::Log::LogType type = Common::Log::LogType::IOS, Common::Log::LogLevel level = Common::Log::LogLevel::LERROR) const; }; @@ -159,11 +165,12 @@ struct IOCtlVRequest final : Request /// Returns the specified vector or nullptr if the index is out of bounds. const IOVector* GetVector(size_t index) const; - explicit IOCtlVRequest(u32 address); + IOCtlVRequest(Core::System& system, u32 address); bool HasNumberOfValidVectors(size_t in_count, size_t io_count) const; - void Dump(std::string_view description, Common::Log::LogType type = Common::Log::LogType::IOS, + void Dump(Core::System& system, std::string_view description, + Common::Log::LogType type = Common::Log::LogType::IOS, Common::Log::LogLevel level = Common::Log::LogLevel::LINFO) const; - void DumpUnknown(const std::string& description, + void DumpUnknown(Core::System& system, const std::string& description, Common::Log::LogType type = Common::Log::LogType::IOS, Common::Log::LogLevel level = Common::Log::LogLevel::LERROR) const; }; @@ -214,4 +221,22 @@ protected: private: std::optional Unsupported(const Request& request); }; + +// Helper class for Devices that we know are only ever instantiated under an EmulationKernel. +// Deriving a Device from this allows it to access EmulationKernel-only features without runtime +// overhead, since it will know that the m_ios instance is an EmulationKernel. +class EmulationDevice : public Device +{ +public: + EmulationDevice(EmulationKernel& ios, const std::string& device_name, + DeviceType type = DeviceType::Static) + : Device(ios, device_name, type) + { + } + +protected: + EmulationKernel& GetEmulationKernel() const { return static_cast(m_ios); } + + Core::System& GetSystem() const { return GetEmulationKernel().GetSystem(); } +}; } // namespace IOS::HLE diff --git a/Source/Core/Core/IOS/DolphinDevice.cpp b/Source/Core/Core/IOS/DolphinDevice.cpp index 32ee9f60ac..147313065d 100644 --- a/Source/Core/Core/IOS/DolphinDevice.cpp +++ b/Source/Core/Core/IOS/DolphinDevice.cpp @@ -40,7 +40,7 @@ enum }; -IPCReply GetVersion(const IOCtlVRequest& request) +IPCReply GetVersion(Core::System& system, const IOCtlVRequest& request) { if (!request.HasNumberOfValidVectors(0, 1)) { @@ -49,7 +49,6 @@ IPCReply GetVersion(const IOCtlVRequest& request) const auto length = std::min(size_t(request.io_vectors[0].size), Common::GetScmDescStr().size()); - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); memory.Memset(request.io_vectors[0].address, 0, request.io_vectors[0].size); memory.CopyToEmu(request.io_vectors[0].address, Common::GetScmDescStr().data(), length); @@ -57,7 +56,7 @@ IPCReply GetVersion(const IOCtlVRequest& request) return IPCReply(IPC_SUCCESS); } -IPCReply GetCPUSpeed(const IOCtlVRequest& request) +IPCReply GetCPUSpeed(Core::System& system, const IOCtlVRequest& request) { if (!request.HasNumberOfValidVectors(0, 1)) { @@ -74,14 +73,13 @@ IPCReply GetCPUSpeed(const IOCtlVRequest& request) const u32 core_clock = u32(float(SystemTimers::GetTicksPerSecond()) * oc); - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); memory.Write_U32(core_clock, request.io_vectors[0].address); return IPCReply(IPC_SUCCESS); } -IPCReply GetSpeedLimit(const IOCtlVRequest& request) +IPCReply GetSpeedLimit(Core::System& system, const IOCtlVRequest& request) { // get current speed limit if (!request.HasNumberOfValidVectors(0, 1)) @@ -96,14 +94,13 @@ IPCReply GetSpeedLimit(const IOCtlVRequest& request) const u32 speed_percent = Config::Get(Config::MAIN_EMULATION_SPEED) * 100; - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); memory.Write_U32(speed_percent, request.io_vectors[0].address); return IPCReply(IPC_SUCCESS); } -IPCReply SetSpeedLimit(const IOCtlVRequest& request) +IPCReply SetSpeedLimit(Core::System& system, const IOCtlVRequest& request) { // set current speed limit if (!request.HasNumberOfValidVectors(1, 0)) @@ -116,7 +113,6 @@ IPCReply SetSpeedLimit(const IOCtlVRequest& request) return IPCReply(IPC_EINVAL); } - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); const float speed = float(memory.Read_U32(request.in_vectors[0].address)) / 100.0f; Config::SetCurrent(Config::MAIN_EMULATION_SPEED, speed); @@ -124,7 +120,7 @@ IPCReply SetSpeedLimit(const IOCtlVRequest& request) return IPCReply(IPC_SUCCESS); } -IPCReply GetRealProductCode(const IOCtlVRequest& request) +IPCReply GetRealProductCode(Core::System& system, const IOCtlVRequest& request) { if (!request.HasNumberOfValidVectors(0, 1)) { @@ -150,14 +146,13 @@ IPCReply GetRealProductCode(const IOCtlVRequest& request) if (length == 0) return IPCReply(IPC_ENOENT); - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); memory.Memset(request.io_vectors[0].address, 0, request.io_vectors[0].size); memory.CopyToEmu(request.io_vectors[0].address, code.c_str(), length); return IPCReply(IPC_SUCCESS); } -IPCReply SetDiscordClient(const IOCtlVRequest& request) +IPCReply SetDiscordClient(Core::System& system, const IOCtlVRequest& request) { if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE)) return IPCReply(IPC_EACCES); @@ -165,7 +160,6 @@ IPCReply SetDiscordClient(const IOCtlVRequest& request) if (!request.HasNumberOfValidVectors(1, 0)) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); std::string new_client_id = memory.GetString(request.in_vectors[0].address, request.in_vectors[0].size); @@ -175,7 +169,7 @@ IPCReply SetDiscordClient(const IOCtlVRequest& request) return IPCReply(IPC_SUCCESS); } -IPCReply SetDiscordPresence(const IOCtlVRequest& request) +IPCReply SetDiscordPresence(Core::System& system, const IOCtlVRequest& request) { if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE)) return IPCReply(IPC_EACCES); @@ -183,7 +177,6 @@ IPCReply SetDiscordPresence(const IOCtlVRequest& request) if (!request.HasNumberOfValidVectors(10, 0)) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); std::string details = memory.GetString(request.in_vectors[0].address, request.in_vectors[0].size); @@ -242,7 +235,7 @@ IPCReply DolphinDevice::GetElapsedTime(const IOCtlVRequest& request) const // have issues. const u32 milliseconds = static_cast(m_timer.ElapsedMs()); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.Write_U32(milliseconds, request.io_vectors[0].address); @@ -261,7 +254,7 @@ IPCReply DolphinDevice::GetSystemTime(const IOCtlVRequest& request) const return IPCReply(IPC_EINVAL); } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // Write Unix timestamp in milliseconds to memory address @@ -272,7 +265,8 @@ IPCReply DolphinDevice::GetSystemTime(const IOCtlVRequest& request) const return IPCReply(IPC_SUCCESS); } -DolphinDevice::DolphinDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name) +DolphinDevice::DolphinDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { m_timer.Start(); } @@ -287,19 +281,19 @@ std::optional DolphinDevice::IOCtlV(const IOCtlVRequest& request) case IOCTL_DOLPHIN_GET_ELAPSED_TIME: return GetElapsedTime(request); case IOCTL_DOLPHIN_GET_VERSION: - return GetVersion(request); + return GetVersion(GetSystem(), request); case IOCTL_DOLPHIN_GET_SPEED_LIMIT: - return GetSpeedLimit(request); + return GetSpeedLimit(GetSystem(), request); case IOCTL_DOLPHIN_SET_SPEED_LIMIT: - return SetSpeedLimit(request); + return SetSpeedLimit(GetSystem(), request); case IOCTL_DOLPHIN_GET_CPU_SPEED: - return GetCPUSpeed(request); + return GetCPUSpeed(GetSystem(), request); case IOCTL_DOLPHIN_GET_REAL_PRODUCTCODE: - return GetRealProductCode(request); + return GetRealProductCode(GetSystem(), request); case IOCTL_DOLPHIN_DISCORD_SET_CLIENT: - return SetDiscordClient(request); + return SetDiscordClient(GetSystem(), request); case IOCTL_DOLPHIN_DISCORD_SET_PRESENCE: - return SetDiscordPresence(request); + return SetDiscordPresence(GetSystem(), request); case IOCTL_DOLPHIN_DISCORD_RESET: return ResetDiscord(request); case IOCTL_DOLPHIN_GET_SYSTEM_TIME: diff --git a/Source/Core/Core/IOS/DolphinDevice.h b/Source/Core/Core/IOS/DolphinDevice.h index 133f7dd673..e01e45134e 100644 --- a/Source/Core/Core/IOS/DolphinDevice.h +++ b/Source/Core/Core/IOS/DolphinDevice.h @@ -8,10 +8,10 @@ namespace IOS::HLE { -class DolphinDevice final : public Device +class DolphinDevice final : public EmulationDevice { public: - DolphinDevice(Kernel& ios, const std::string& device_name); + DolphinDevice(EmulationKernel& ios, const std::string& device_name); std::optional IOCtlV(const IOCtlVRequest& request) override; private: diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index 238b38152f..9cdc76b7ab 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -702,7 +702,7 @@ std::optional ESDevice::IOCtlV(const IOCtlVRequest& request) case IOCTL_ES_UNKNOWN_42: PanicAlertFmt("IOS-ES: Unimplemented ioctlv {:#x} ({} in vectors, {} io vectors)", request.request, request.in_vectors.size(), request.io_vectors.size()); - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_ES, + request.DumpUnknown(Core::System::GetInstance(), GetDeviceName(), Common::Log::LogType::IOS_ES, Common::Log::LogLevel::LERROR); return IPCReply(IPC_EINVAL); diff --git a/Source/Core/Core/IOS/IOS.cpp b/Source/Core/Core/IOS/IOS.cpp index 3e404a76cc..fe4b20e93c 100644 --- a/Source/Core/Core/IOS/IOS.cpp +++ b/Source/Core/Core/IOS/IOS.cpp @@ -319,7 +319,8 @@ Kernel::Kernel(u64 title_id) : m_title_id(title_id) { } -EmulationKernel::EmulationKernel(u64 title_id) : Kernel(title_id) +EmulationKernel::EmulationKernel(Core::System& system, u64 title_id) + : Kernel(title_id), m_system(system) { INFO_LOG_FMT(IOS, "Starting IOS {:016x}", title_id); @@ -364,7 +365,7 @@ std::shared_ptr Kernel::GetES() return std::static_pointer_cast(m_device_map.at("/dev/es")); } -std::shared_ptr Kernel::GetSocketManager() +std::shared_ptr EmulationKernel::GetSocketManager() { return m_socket_manager; } @@ -462,11 +463,11 @@ private: std::vector m_bytes; }; -static void FinishIOSBoot(u64 ios_title_id) +static void FinishIOSBoot(Core::System& system, u64 ios_title_id) { // Shut down the active IOS first before switching to the new one. s_ios.reset(); - s_ios = std::make_unique(ios_title_id); + s_ios = std::make_unique(system, ios_title_id); } static constexpr SystemTimers::TimeBaseTick GetIOSBootTicks(u32 version) @@ -515,7 +516,7 @@ bool Kernel::BootIOS(Core::System& system, const u64 ios_title_id, HangPPC hang_ } else { - FinishIOSBoot(ios_title_id); + FinishIOSBoot(system, ios_title_id); } return true; @@ -546,7 +547,7 @@ void Kernel::AddCoreDevices() AddDevice(std::make_unique(*this, "/dev/es")); } -void Kernel::AddStaticDevices() +void EmulationKernel::AddStaticDevices() { std::lock_guard lock(m_device_map_mutex); @@ -623,7 +624,7 @@ void Kernel::AddStaticDevices() } } -s32 Kernel::GetFreeDeviceID() +s32 EmulationKernel::GetFreeDeviceID() { for (u32 i = 0; i < IPC_MAX_FDS; i++) { @@ -649,7 +650,7 @@ std::shared_ptr EmulationKernel::GetDeviceByName(std::string_view device } // Returns the FD for the newly opened device (on success) or an error code. -std::optional Kernel::OpenDevice(OpenRequest& request) +std::optional EmulationKernel::OpenDevice(OpenRequest& request) { const s32 new_fd = GetFreeDeviceID(); INFO_LOG_FMT(IOS, "Opening {} (mode {}, fd {})", request.path, static_cast(request.flags), @@ -691,14 +692,14 @@ std::optional Kernel::OpenDevice(OpenRequest& request) return result; } -std::optional Kernel::HandleIPCCommand(const Request& request) +std::optional EmulationKernel::HandleIPCCommand(const Request& request) { if (request.command < IPC_CMD_OPEN || request.command > IPC_CMD_IOCTLV) return IPCReply{IPC_EINVAL, 978_tbticks}; if (request.command == IPC_CMD_OPEN) { - OpenRequest open_request{request.address}; + OpenRequest open_request{GetSystem(), request.address}; return OpenDevice(open_request); } @@ -716,19 +717,19 @@ std::optional Kernel::HandleIPCCommand(const Request& request) ret = device->Close(request.fd); break; case IPC_CMD_READ: - ret = device->Read(ReadWriteRequest{request.address}); + ret = device->Read(ReadWriteRequest{GetSystem(), request.address}); break; case IPC_CMD_WRITE: - ret = device->Write(ReadWriteRequest{request.address}); + ret = device->Write(ReadWriteRequest{GetSystem(), request.address}); break; case IPC_CMD_SEEK: - ret = device->Seek(SeekRequest{request.address}); + ret = device->Seek(SeekRequest{GetSystem(), request.address}); break; case IPC_CMD_IOCTL: - ret = device->IOCtl(IOCtlRequest{request.address}); + ret = device->IOCtl(IOCtlRequest{GetSystem(), request.address}); break; case IPC_CMD_IOCTLV: - ret = device->IOCtlV(IOCtlVRequest{request.address}); + ret = device->IOCtlV(IOCtlVRequest{GetSystem(), request.address}); break; default: ASSERT_MSG(IOS, false, "Unexpected command: {:#x}", static_cast(request.command)); @@ -747,17 +748,16 @@ std::optional Kernel::HandleIPCCommand(const Request& request) return ret; } -void Kernel::ExecuteIPCCommand(const u32 address) +void EmulationKernel::ExecuteIPCCommand(const u32 address) { - Request request{address}; + Request request{GetSystem(), address}; std::optional result = HandleIPCCommand(request); if (!result) return; // Ensure replies happen in order - auto& system = Core::System::GetInstance(); - auto& core_timing = system.GetCoreTiming(); + auto& core_timing = GetSystem().GetCoreTiming(); const s64 ticks_until_last_reply = m_last_reply_time - core_timing.GetTicks(); if (ticks_until_last_reply > 0) result->reply_delay_ticks += ticks_until_last_reply; @@ -767,20 +767,20 @@ void Kernel::ExecuteIPCCommand(const u32 address) } // Happens AS SOON AS IPC gets a new pointer! -void Kernel::EnqueueIPCRequest(u32 address) +void EmulationKernel::EnqueueIPCRequest(u32 address) { // Based on hardware tests, IOS takes between 5µs and 10µs to acknowledge an IPC request. // Console 1: 456 TB ticks before ACK // Console 2: 658 TB ticks before ACK - Core::System::GetInstance().GetCoreTiming().ScheduleEvent(500_tbticks, s_event_enqueue, - address | ENQUEUE_REQUEST_FLAG); + GetSystem().GetCoreTiming().ScheduleEvent(500_tbticks, s_event_enqueue, + address | ENQUEUE_REQUEST_FLAG); } // Called to send a reply to an IOS syscall -void Kernel::EnqueueIPCReply(const Request& request, const s32 return_value, s64 cycles_in_future, - CoreTiming::FromThread from) +void EmulationKernel::EnqueueIPCReply(const Request& request, const s32 return_value, + s64 cycles_in_future, CoreTiming::FromThread from) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.Write_U32(static_cast(return_value), request.address + 4); // IOS writes back the command that was responded to in the FD field. @@ -790,7 +790,7 @@ void Kernel::EnqueueIPCReply(const Request& request, const s32 return_value, s64 system.GetCoreTiming().ScheduleEvent(cycles_in_future, s_event_enqueue, request.address, from); } -void Kernel::HandleIPCEvent(u64 userdata) +void EmulationKernel::HandleIPCEvent(u64 userdata) { if (userdata & ENQUEUE_REQUEST_FLAG) m_request_queue.push_back(static_cast(userdata)); @@ -800,7 +800,7 @@ void Kernel::HandleIPCEvent(u64 userdata) UpdateIPC(); } -void Kernel::UpdateIPC() +void EmulationKernel::UpdateIPC() { if (m_ipc_paused || !IsReady()) return; @@ -824,7 +824,7 @@ void Kernel::UpdateIPC() } } -void Kernel::UpdateDevices() +void EmulationKernel::UpdateDevices() { // Check if a hardware device must be updated for (const auto& entry : m_device_map) @@ -836,7 +836,7 @@ void Kernel::UpdateDevices() } } -void Kernel::UpdateWantDeterminism(const bool new_want_determinism) +void EmulationKernel::UpdateWantDeterminism(const bool new_want_determinism) { if (m_socket_manager) m_socket_manager->UpdateWantDeterminism(new_want_determinism); @@ -844,7 +844,7 @@ void Kernel::UpdateWantDeterminism(const bool new_want_determinism) device.second->UpdateWantDeterminism(new_want_determinism); } -void Kernel::DoState(PointerWrap& p) +void EmulationKernel::DoState(PointerWrap& p) { p.Do(m_request_queue); p.Do(m_reply_queue); @@ -954,15 +954,15 @@ void Init() s_event_finish_ppc_bootstrap = core_timing.RegisterEvent("IOSFinishPPCBootstrap", FinishPPCBootstrap); - s_event_finish_ios_boot = - core_timing.RegisterEvent("IOSFinishIOSBoot", [](Core::System& system_, u64 ios_title_id, - s64) { FinishIOSBoot(ios_title_id); }); + s_event_finish_ios_boot = core_timing.RegisterEvent( + "IOSFinishIOSBoot", + [](Core::System& system_, u64 ios_title_id, s64) { FinishIOSBoot(system_, ios_title_id); }); DIDevice::s_finish_executing_di_command = core_timing.RegisterEvent("FinishDICommand", DIDevice::FinishDICommandCallback); // Start with IOS80 to simulate part of the Wii boot process. - s_ios = std::make_unique(Titles::SYSTEM_MENU_IOS); + s_ios = std::make_unique(system, Titles::SYSTEM_MENU_IOS); // On a Wii, boot2 launches the system menu IOS, which then launches the system menu // (which bootstraps the PPC). Bootstrapping the PPC results in memory values being set up. // This means that the constants in the 0x3100 region are always set up by the time diff --git a/Source/Core/Core/IOS/IOS.h b/Source/Core/Core/IOS/IOS.h index 878bb56ccc..b985a33028 100644 --- a/Source/Core/Core/IOS/IOS.h +++ b/Source/Core/Core/IOS/IOS.h @@ -119,25 +119,12 @@ public: explicit Kernel(IOSC::ConsoleType console_type = IOSC::ConsoleType::Retail); virtual ~Kernel(); - void DoState(PointerWrap& p); - void HandleIPCEvent(u64 userdata); - void UpdateIPC(); - void UpdateDevices(); - void UpdateWantDeterminism(bool new_want_determinism); - // These are *always* part of the IOS kernel and always available. // They are also the only available resource managers even before loading any module. std::shared_ptr GetFS(); std::shared_ptr GetFSDevice(); std::shared_ptr GetES(); - // This is only available on an EmulationKernel if the IOS features require it. - std::shared_ptr GetSocketManager(); - - void EnqueueIPCRequest(u32 address); - void EnqueueIPCReply(const Request& request, s32 return_value, s64 cycles_in_future = 0, - CoreTiming::FromThread from = CoreTiming::FromThread::CPU); - void SetUidForPPC(u32 uid); u32 GetUidForPPC() const; void SetGidForPPC(u16 gid); @@ -154,15 +141,9 @@ public: protected: explicit Kernel(u64 title_id); - void ExecuteIPCCommand(u32 address); - std::optional HandleIPCCommand(const Request& request); - void AddDevice(std::unique_ptr device); void AddCoreDevices(); - void AddStaticDevices(); std::shared_ptr GetDeviceByName(std::string_view device_name); - s32 GetFreeDeviceID(); - std::optional OpenDevice(OpenRequest& request); bool m_is_responsible_for_nand_root = false; u64 m_title_id = 0; @@ -187,15 +168,40 @@ protected: }; // HLE for an IOS tied to emulation: base kernel which may have additional modules loaded. -class EmulationKernel : public Kernel +class EmulationKernel final : public Kernel { public: - explicit EmulationKernel(u64 ios_title_id); + EmulationKernel(Core::System& system, u64 ios_title_id); ~EmulationKernel(); // Get a resource manager by name. // This only works for devices which are part of the device map. std::shared_ptr GetDeviceByName(std::string_view device_name); + + void DoState(PointerWrap& p); + void UpdateDevices(); + void UpdateWantDeterminism(bool new_want_determinism); + + std::shared_ptr GetSocketManager(); + + void HandleIPCEvent(u64 userdata); + void UpdateIPC(); + + void EnqueueIPCRequest(u32 address); + void EnqueueIPCReply(const Request& request, s32 return_value, s64 cycles_in_future = 0, + CoreTiming::FromThread from = CoreTiming::FromThread::CPU); + + Core::System& GetSystem() const { return m_system; } + +private: + Core::System& m_system; + + void ExecuteIPCCommand(u32 address); + std::optional HandleIPCCommand(const Request& request); + + void AddStaticDevices(); + s32 GetFreeDeviceID(); + std::optional OpenDevice(OpenRequest& request); }; // Used for controlling and accessing an IOS instance that is tied to emulation. diff --git a/Source/Core/Core/IOS/Network/IP/Top.cpp b/Source/Core/Core/IOS/Network/IP/Top.cpp index 261b6db9b7..7da4ddfdf9 100644 --- a/Source/Core/Core/IOS/Network/IP/Top.cpp +++ b/Source/Core/Core/IOS/Network/IP/Top.cpp @@ -62,8 +62,8 @@ enum SOResultCode : s32 SO_ERROR_HOST_NOT_FOUND = -305, }; -NetIPTopDevice::NetIPTopDevice(Kernel& ios, const std::string& device_name) - : Device(ios, device_name) +NetIPTopDevice::NetIPTopDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { m_work_queue.Reset("Network Worker", [this](AsyncTask task) { const IPCReply reply = task.handler(); @@ -330,7 +330,7 @@ std::optional NetIPTopDevice::IOCtl(const IOCtlRequest& request) case IOCTL_SO_ICMPCANCEL: return HandleICMPCancelRequest(request); default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_NET); + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_NET); break; } @@ -352,7 +352,7 @@ std::optional NetIPTopDevice::IOCtlV(const IOCtlVRequest& request) case IOCTLV_SO_ICMPPING: return HandleICMPPingRequest(request); default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_NET); + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_NET); break; } @@ -366,11 +366,11 @@ void NetIPTopDevice::Update() while (!m_async_replies.empty()) { const auto& reply = m_async_replies.front(); - GetIOS()->EnqueueIPCReply(reply.request, reply.return_value); + GetEmulationKernel().EnqueueIPCReply(reply.request, reply.return_value); m_async_replies.pop(); } } - m_ios.GetSocketManager()->Update(); + GetEmulationKernel().GetSocketManager()->Update(); } IPCReply NetIPTopDevice::HandleInitInterfaceRequest(const IOCtlRequest& request) @@ -381,14 +381,14 @@ IPCReply NetIPTopDevice::HandleInitInterfaceRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleSocketRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 af = memory.Read_U32(request.buffer_in); const u32 type = memory.Read_U32(request.buffer_in + 4); const u32 prot = memory.Read_U32(request.buffer_in + 8); - const s32 return_value = m_ios.GetSocketManager()->NewSocket(af, type, prot); + const s32 return_value = GetEmulationKernel().GetSocketManager()->NewSocket(af, type, prot); INFO_LOG_FMT(IOS_NET, "IOCTL_SO_SOCKET " "Socket: {:08x} ({},{},{}), BufferIn: ({:08x}, {}), BufferOut: ({:08x}, {})", @@ -400,23 +400,24 @@ IPCReply NetIPTopDevice::HandleSocketRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleICMPSocketRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 pf = memory.Read_U32(request.buffer_in); - const s32 return_value = m_ios.GetSocketManager()->NewSocket(pf, SOCK_RAW, IPPROTO_ICMP); + const s32 return_value = + GetEmulationKernel().GetSocketManager()->NewSocket(pf, SOCK_RAW, IPPROTO_ICMP); INFO_LOG_FMT(IOS_NET, "IOCTL_SO_ICMPSOCKET({:x}) {}", pf, return_value); return IPCReply(return_value); } IPCReply NetIPTopDevice::HandleCloseRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 fd = memory.Read_U32(request.buffer_in); - const s32 return_value = m_ios.GetSocketManager()->DeleteSocket(fd); + const s32 return_value = GetEmulationKernel().GetSocketManager()->DeleteSocket(fd); const char* const close_fn = request.request == IOCTL_SO_ICMPCLOSE ? "IOCTL_SO_ICMPCLOSE" : "IOCTL_SO_CLOSE"; @@ -427,11 +428,12 @@ IPCReply NetIPTopDevice::HandleCloseRequest(const IOCtlRequest& request) std::optional NetIPTopDevice::HandleDoSockRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 fd = memory.Read_U32(request.buffer_in); - m_ios.GetSocketManager()->DoSock(fd, request, static_cast(request.request)); + GetEmulationKernel().GetSocketManager()->DoSock(fd, request, + static_cast(request.request)); return std::nullopt; } @@ -444,12 +446,12 @@ IPCReply NetIPTopDevice::HandleShutdownRequest(const IOCtlRequest& request) return IPCReply(-SO_EINVAL); } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 fd = memory.Read_U32(request.buffer_in); const u32 how = memory.Read_U32(request.buffer_in + 4); - const s32 return_value = m_ios.GetSocketManager()->ShutdownSocket(fd, how); + const s32 return_value = GetEmulationKernel().GetSocketManager()->ShutdownSocket(fd, how); INFO_LOG_FMT(IOS_NET, "IOCTL_SO_SHUTDOWN(fd={}, how={}) = {}", fd, how, return_value); return IPCReply(return_value); @@ -457,12 +459,12 @@ IPCReply NetIPTopDevice::HandleShutdownRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleListenRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); u32 fd = memory.Read_U32(request.buffer_in); u32 BACKLOG = memory.Read_U32(request.buffer_in + 0x04); - auto socket_manager = m_ios.GetSocketManager(); + auto socket_manager = GetEmulationKernel().GetSocketManager(); u32 ret = listen(socket_manager->GetHostSocket(fd), BACKLOG); request.Log(GetDeviceName(), Common::Log::LogType::IOS_WC24); @@ -471,7 +473,7 @@ IPCReply NetIPTopDevice::HandleListenRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleGetSockOptRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); u32 fd = memory.Read_U32(request.buffer_out); @@ -487,7 +489,7 @@ IPCReply NetIPTopDevice::HandleGetSockOptRequest(const IOCtlRequest& request) u8 optval[20]; u32 optlen = 4; - auto socket_manager = m_ios.GetSocketManager(); + auto socket_manager = GetEmulationKernel().GetSocketManager(); int ret = getsockopt(socket_manager->GetHostSocket(fd), nat_level, nat_optname, (char*)&optval, (socklen_t*)&optlen); const s32 return_value = socket_manager->GetNetErrorCode(ret, "SO_GETSOCKOPT", false); @@ -508,7 +510,7 @@ IPCReply NetIPTopDevice::HandleGetSockOptRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleSetSockOptRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 fd = memory.Read_U32(request.buffer_in); @@ -539,7 +541,7 @@ IPCReply NetIPTopDevice::HandleSetSockOptRequest(const IOCtlRequest& request) const int nat_level = MapWiiSockOptLevelToNative(level); const int nat_optname = MapWiiSockOptNameToNative(optname); - auto socket_manager = m_ios.GetSocketManager(); + auto socket_manager = GetEmulationKernel().GetSocketManager(); const int ret = setsockopt(socket_manager->GetHostSocket(fd), nat_level, nat_optname, reinterpret_cast(optval), optlen); return IPCReply(socket_manager->GetNetErrorCode(ret, "SO_SETSOCKOPT", false)); @@ -547,7 +549,7 @@ IPCReply NetIPTopDevice::HandleSetSockOptRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleGetSockNameRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); u32 fd = memory.Read_U32(request.buffer_in); @@ -556,7 +558,8 @@ IPCReply NetIPTopDevice::HandleGetSockNameRequest(const IOCtlRequest& request) sockaddr sa; socklen_t sa_len = sizeof(sa); - const int ret = getsockname(m_ios.GetSocketManager()->GetHostSocket(fd), &sa, &sa_len); + const int ret = + getsockname(GetEmulationKernel().GetSocketManager()->GetHostSocket(fd), &sa, &sa_len); if (request.buffer_out_size < 2 + sizeof(sa.sa_data)) WARN_LOG_FMT(IOS_NET, "IOCTL_SO_GETSOCKNAME output buffer is too small. Truncating"); @@ -576,14 +579,15 @@ IPCReply NetIPTopDevice::HandleGetSockNameRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleGetPeerNameRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); u32 fd = memory.Read_U32(request.buffer_in); sockaddr sa; socklen_t sa_len = sizeof(sa); - const int ret = getpeername(m_ios.GetSocketManager()->GetHostSocket(fd), &sa, &sa_len); + const int ret = + getpeername(GetEmulationKernel().GetSocketManager()->GetHostSocket(fd), &sa, &sa_len); if (request.buffer_out_size < 2 + sizeof(sa.sa_data)) WARN_LOG_FMT(IOS_NET, "IOCTL_SO_GETPEERNAME output buffer is too small. Truncating"); @@ -613,7 +617,7 @@ IPCReply NetIPTopDevice::HandleGetHostIDRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleInetAToNRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const std::string hostname = memory.GetString(request.buffer_in); @@ -645,7 +649,7 @@ IPCReply NetIPTopDevice::HandleInetAToNRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleInetPToNRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const std::string address = memory.GetString(request.buffer_in); @@ -655,7 +659,7 @@ IPCReply NetIPTopDevice::HandleInetPToNRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleInetNToPRequest(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // u32 af = memory.Read_U32(BufferIn); @@ -674,12 +678,12 @@ IPCReply NetIPTopDevice::HandleInetNToPRequest(const IOCtlRequest& request) std::optional NetIPTopDevice::HandlePollRequest(const IOCtlRequest& request) { - auto sm = m_ios.GetSocketManager(); + auto sm = GetEmulationKernel().GetSocketManager(); if (!request.buffer_in || !request.buffer_out) return IPCReply(-SO_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // Negative timeout indicates wait forever @@ -726,7 +730,7 @@ IPCReply NetIPTopDevice::HandleGetHostByNameRequest(const IOCtlRequest& request) return IPCReply(-1); } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const std::string hostname = memory.GetString(request.buffer_in); @@ -814,7 +818,7 @@ IPCReply NetIPTopDevice::HandleICMPCancelRequest(const IOCtlRequest& request) IPCReply NetIPTopDevice::HandleGetInterfaceOptRequest(const IOCtlVRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 param = memory.Read_U32(request.in_vectors[0].address); @@ -1007,27 +1011,27 @@ IPCReply NetIPTopDevice::HandleGetInterfaceOptRequest(const IOCtlVRequest& reque std::optional NetIPTopDevice::HandleSendToRequest(const IOCtlVRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); u32 fd = memory.Read_U32(request.in_vectors[1].address); - m_ios.GetSocketManager()->DoSock(fd, request, IOCTLV_SO_SENDTO); + GetEmulationKernel().GetSocketManager()->DoSock(fd, request, IOCTLV_SO_SENDTO); return std::nullopt; } std::optional NetIPTopDevice::HandleRecvFromRequest(const IOCtlVRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); u32 fd = memory.Read_U32(request.in_vectors[0].address); - m_ios.GetSocketManager()->DoSock(fd, request, IOCTLV_SO_RECVFROM); + GetEmulationKernel().GetSocketManager()->DoSock(fd, request, IOCTLV_SO_RECVFROM); return std::nullopt; } IPCReply NetIPTopDevice::HandleGetAddressInfoRequest(const IOCtlVRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); addrinfo hints; @@ -1113,7 +1117,8 @@ IPCReply NetIPTopDevice::HandleGetAddressInfoRequest(const IOCtlVRequest& reques ret = SO_ERROR_HOST_NOT_FOUND; } - request.Dump(GetDeviceName(), Common::Log::LogType::IOS_NET, Common::Log::LogLevel::LINFO); + request.Dump(system, GetDeviceName(), Common::Log::LogType::IOS_NET, + Common::Log::LogLevel::LINFO); return IPCReply(ret); } @@ -1127,7 +1132,7 @@ IPCReply NetIPTopDevice::HandleICMPPingRequest(const IOCtlVRequest& request) u32 ip; } ip_info; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 fd = memory.Read_U32(request.in_vectors[0].address); @@ -1176,7 +1181,7 @@ IPCReply NetIPTopDevice::HandleICMPPingRequest(const IOCtlVRequest& request) icmp_length = 22; } - auto socket_manager = m_ios.GetSocketManager(); + auto socket_manager = GetEmulationKernel().GetSocketManager(); int ret = icmp_echo_req(socket_manager->GetHostSocket(fd), &addr, data, icmp_length); if (ret == icmp_length) { diff --git a/Source/Core/Core/IOS/Network/IP/Top.h b/Source/Core/Core/IOS/Network/IP/Top.h index cc41180860..812cffad5d 100644 --- a/Source/Core/Core/IOS/Network/IP/Top.h +++ b/Source/Core/Core/IOS/Network/IP/Top.h @@ -63,10 +63,10 @@ enum NET_IOCTL IOCTL_SO_ICMPCLOSE }; -class NetIPTopDevice : public Device +class NetIPTopDevice : public EmulationDevice { public: - NetIPTopDevice(Kernel& ios, const std::string& device_name); + NetIPTopDevice(EmulationKernel& ios, const std::string& device_name); void DoState(PointerWrap& p) override; std::optional IOCtl(const IOCtlRequest& request) override; diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp index fd7988cf44..aa99a5a177 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp @@ -147,8 +147,8 @@ s32 NWC24MakeUserID(u64* nwc24_id, u32 hollywood_id, u16 id_ctr, HardwareModel h } } // Anonymous namespace -NetKDRequestDevice::NetKDRequestDevice(Kernel& ios, const std::string& device_name) - : Device(ios, device_name), config{ios.GetFS()}, m_dl_list{ios.GetFS()} +NetKDRequestDevice::NetKDRequestDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name), config{ios.GetFS()}, m_dl_list{ios.GetFS()} { m_work_queue.Reset("WiiConnect24 Worker", [this](AsyncTask task) { const IPCReply reply = task.handler(); @@ -161,7 +161,7 @@ NetKDRequestDevice::NetKDRequestDevice(Kernel& ios, const std::string& device_na NetKDRequestDevice::~NetKDRequestDevice() { - auto socket_manager = m_ios.GetSocketManager(); + auto socket_manager = GetEmulationKernel().GetSocketManager(); if (socket_manager) socket_manager->Clean(); } @@ -173,7 +173,7 @@ void NetKDRequestDevice::Update() while (!m_async_replies.empty()) { const auto& reply = m_async_replies.front(); - GetIOS()->EnqueueIPCReply(reply.request, reply.return_value); + GetEmulationKernel().EnqueueIPCReply(reply.request, reply.return_value); m_async_replies.pop(); } } @@ -236,7 +236,7 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index, IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& request) { m_dl_list.ReadDlList(); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 flags = memory.Read_U32(request.buffer_in); // Nintendo converts the entry ID between a u32 and u16 @@ -321,7 +321,7 @@ std::optional NetKDRequestDevice::IOCtl(const IOCtlRequest& request) IOCTL_NWC24_REQUEST_SHUTDOWN = 0x28, }; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); s32 return_value = 0; switch (request.request) @@ -350,7 +350,7 @@ std::optional NetKDRequestDevice::IOCtl(const IOCtlRequest& request) case IOCTL_NWC24_CLEANUP_SOCKET: INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_CLEANUP_SOCKET"); - m_ios.GetSocketManager()->Clean(); + GetEmulationKernel().GetSocketManager()->Clean(); break; case IOCTL_NWC24_LOCK_SOCKET: // WiiMenu @@ -454,7 +454,7 @@ std::optional NetKDRequestDevice::IOCtl(const IOCtlRequest& request) // SOGetInterfaceOpt(0xfffe,0xc001); // DHCP lease time remaining? // SOGetInterfaceOpt(0xfffe,0x1003); // Error // Call /dev/net/ip/top 0x1b (SOCleanup), it closes all sockets - m_ios.GetSocketManager()->Clean(); + GetEmulationKernel().GetSocketManager()->Clean(); return_value = IPC_SUCCESS; break; } diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.h b/Source/Core/Core/IOS/Network/KD/NetKDRequest.h index aae52a11f5..7e0a986a10 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.h +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.h @@ -21,10 +21,10 @@ constexpr const char DL_CNT_PATH[] = "/" WII_WC24CONF_DIR "/dlcnt.bin"; // KD is the IOS module responsible for implementing WiiConnect24 functionality. // It can perform HTTPS downloads, send and receive mail via SMTP, and execute a // JavaScript-like language while the Wii is in standby mode. -class NetKDRequestDevice : public Device +class NetKDRequestDevice : public EmulationDevice { public: - NetKDRequestDevice(Kernel& ios, const std::string& device_name); + NetKDRequestDevice(EmulationKernel& ios, const std::string& device_name); IPCReply HandleNWC24DownloadNowEx(const IOCtlRequest& request); NWC24::ErrorCode KDDownload(const u16 entry_index, const std::optional subtask_id); ~NetKDRequestDevice() override; diff --git a/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp b/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp index b6a5c735ba..e267dadf17 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp @@ -12,8 +12,8 @@ namespace IOS::HLE { -NetKDTimeDevice::NetKDTimeDevice(Kernel& ios, const std::string& device_name) - : Device(ios, device_name) +NetKDTimeDevice::NetKDTimeDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { } @@ -35,7 +35,7 @@ std::optional NetKDTimeDevice::IOCtl(const IOCtlRequest& request) // TODO Writes stuff to /shared2/nwc24/misc.bin u32 update_misc = 0; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); switch (request.request) @@ -78,7 +78,7 @@ std::optional NetKDTimeDevice::IOCtl(const IOCtlRequest& request) break; default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WC24); + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_WC24); break; } @@ -91,8 +91,7 @@ u64 NetKDTimeDevice::GetAdjustedUTC() const { using namespace ExpansionInterface; - const time_t current_time = - CEXIIPL::GetEmulatedTime(Core::System::GetInstance(), CEXIIPL::UNIX_EPOCH); + const time_t current_time = CEXIIPL::GetEmulatedTime(GetSystem(), CEXIIPL::UNIX_EPOCH); tm* const gm_time = gmtime(¤t_time); const u32 emulated_time = mktime(gm_time); return u64(s64(emulated_time) + utcdiff); @@ -102,8 +101,7 @@ void NetKDTimeDevice::SetAdjustedUTC(u64 wii_utc) { using namespace ExpansionInterface; - const time_t current_time = - CEXIIPL::GetEmulatedTime(Core::System::GetInstance(), CEXIIPL::UNIX_EPOCH); + const time_t current_time = CEXIIPL::GetEmulatedTime(GetSystem(), CEXIIPL::UNIX_EPOCH); tm* const gm_time = gmtime(¤t_time); const u32 emulated_time = mktime(gm_time); utcdiff = s64(emulated_time - wii_utc); diff --git a/Source/Core/Core/IOS/Network/KD/NetKDTime.h b/Source/Core/Core/IOS/Network/KD/NetKDTime.h index 55c071ddaf..025594c921 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDTime.h +++ b/Source/Core/Core/IOS/Network/KD/NetKDTime.h @@ -10,10 +10,10 @@ namespace IOS::HLE { -class NetKDTimeDevice : public Device +class NetKDTimeDevice : public EmulationDevice { public: - NetKDTimeDevice(Kernel& ios, const std::string& device_name); + NetKDTimeDevice(EmulationKernel& ios, const std::string& device_name); ~NetKDTimeDevice() override; std::optional IOCtl(const IOCtlRequest& request) override; diff --git a/Source/Core/Core/IOS/Network/NCD/Manage.cpp b/Source/Core/Core/IOS/Network/NCD/Manage.cpp index a7db57b3b8..4b04e2d5bc 100644 --- a/Source/Core/Core/IOS/Network/NCD/Manage.cpp +++ b/Source/Core/Core/IOS/Network/NCD/Manage.cpp @@ -15,8 +15,8 @@ namespace IOS::HLE { -NetNCDManageDevice::NetNCDManageDevice(Kernel& ios, const std::string& device_name) - : Device(ios, device_name) +NetNCDManageDevice::NetNCDManageDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { config.ReadConfig(ios.GetFS().get()); } @@ -33,7 +33,7 @@ std::optional NetNCDManageDevice::IOCtlV(const IOCtlVRequest& request) u32 common_result = 0; u32 common_vector = 0; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); switch (request.request) diff --git a/Source/Core/Core/IOS/Network/NCD/Manage.h b/Source/Core/Core/IOS/Network/NCD/Manage.h index a16c3c4f62..e19500bb42 100644 --- a/Source/Core/Core/IOS/Network/NCD/Manage.h +++ b/Source/Core/Core/IOS/Network/NCD/Manage.h @@ -12,10 +12,10 @@ namespace IOS::HLE { // Interface for reading and changing network configuration (probably some other stuff as well) -class NetNCDManageDevice : public Device +class NetNCDManageDevice : public EmulationDevice { public: - NetNCDManageDevice(Kernel& ios, const std::string& device_name); + NetNCDManageDevice(EmulationKernel& ios, const std::string& device_name); std::optional IOCtlV(const IOCtlVRequest& request) override; diff --git a/Source/Core/Core/IOS/Network/SSL.cpp b/Source/Core/Core/IOS/Network/SSL.cpp index bbd182347a..1ec262305d 100644 --- a/Source/Core/Core/IOS/Network/SSL.cpp +++ b/Source/Core/Core/IOS/Network/SSL.cpp @@ -88,7 +88,8 @@ int SSLRecv(void* ctx, unsigned char* buf, size_t len) } } // namespace -NetSSLDevice::NetSSLDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name) +NetSSLDevice::NetSSLDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { for (WII_SSL& ssl : _SSL) { @@ -496,7 +497,7 @@ std::optional NetSSLDevice::IOCtlV(const IOCtlVRequest& request) WII_SSL* ssl = &_SSL[sslID]; mbedtls_ssl_setup(&ssl->ctx, &ssl->config); ssl->sockfd = memory.Read_U32(BufferOut2); - ssl->hostfd = m_ios.GetSocketManager()->GetHostSocket(ssl->sockfd); + ssl->hostfd = GetEmulationKernel().GetSocketManager()->GetHostSocket(ssl->sockfd); INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_CONNECT socket = {}", ssl->sockfd); mbedtls_ssl_set_bio(&ssl->ctx, ssl, SSLSendWithoutSNI, SSLRecv, nullptr); WriteReturnValue(SSL_OK, BufferIn); @@ -519,7 +520,8 @@ std::optional NetSSLDevice::IOCtlV(const IOCtlVRequest& request) int sslID = memory.Read_U32(BufferOut) - 1; if (IsSSLIDValid(sslID)) { - m_ios.GetSocketManager()->DoSock(_SSL[sslID].sockfd, request, IOCTLV_NET_SSL_DOHANDSHAKE); + GetEmulationKernel().GetSocketManager()->DoSock(_SSL[sslID].sockfd, request, + IOCTLV_NET_SSL_DOHANDSHAKE); return std::nullopt; } else @@ -533,7 +535,8 @@ std::optional NetSSLDevice::IOCtlV(const IOCtlVRequest& request) const int sslID = memory.Read_U32(BufferOut) - 1; if (IsSSLIDValid(sslID)) { - m_ios.GetSocketManager()->DoSock(_SSL[sslID].sockfd, request, IOCTLV_NET_SSL_WRITE); + GetEmulationKernel().GetSocketManager()->DoSock(_SSL[sslID].sockfd, request, + IOCTLV_NET_SSL_WRITE); return std::nullopt; } else @@ -556,7 +559,8 @@ std::optional NetSSLDevice::IOCtlV(const IOCtlVRequest& request) int sslID = memory.Read_U32(BufferOut) - 1; if (IsSSLIDValid(sslID)) { - m_ios.GetSocketManager()->DoSock(_SSL[sslID].sockfd, request, IOCTLV_NET_SSL_READ); + GetEmulationKernel().GetSocketManager()->DoSock(_SSL[sslID].sockfd, request, + IOCTLV_NET_SSL_READ); return std::nullopt; } else @@ -615,7 +619,7 @@ std::optional NetSSLDevice::IOCtlV(const IOCtlVRequest& request) break; } default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_SSL); + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_SSL); } // SSL return codes are written to BufferIn diff --git a/Source/Core/Core/IOS/Network/SSL.h b/Source/Core/Core/IOS/Network/SSL.h index 98cb2adf3b..980361c901 100644 --- a/Source/Core/Core/IOS/Network/SSL.h +++ b/Source/Core/Core/IOS/Network/SSL.h @@ -79,10 +79,10 @@ struct WII_SSL bool active = false; }; -class NetSSLDevice : public Device +class NetSSLDevice : public EmulationDevice { public: - NetSSLDevice(Kernel& ios, const std::string& device_name); + NetSSLDevice(EmulationKernel& ios, const std::string& device_name); virtual ~NetSSLDevice(); diff --git a/Source/Core/Core/IOS/Network/Socket.cpp b/Source/Core/Core/IOS/Network/Socket.cpp index 9e1b45097e..56d300526e 100644 --- a/Source/Core/Core/IOS/Network/Socket.cpp +++ b/Source/Core/Core/IOS/Network/Socket.cpp @@ -260,7 +260,7 @@ void WiiSocket::Update(bool read, bool write, bool except) IPCCommandType ct = it->request.command; if (!it->is_ssl && ct == IPC_CMD_IOCTL) { - IOCtlRequest ioctl{it->request.address}; + IOCtlRequest ioctl{system, it->request.address}; switch (it->net_type) { case IOCTL_SO_FCNTL: @@ -351,7 +351,7 @@ void WiiSocket::Update(bool read, bool write, bool except) } else if (ct == IPC_CMD_IOCTLV) { - IOCtlVRequest ioctlv{it->request.address}; + IOCtlVRequest ioctlv{system, it->request.address}; u32 BufferIn = 0, BufferIn2 = 0; u32 BufferInSize = 0, BufferInSize2 = 0; u32 BufferOut = 0, BufferOut2 = 0; @@ -1042,8 +1042,8 @@ void WiiSockMan::UpdatePollCommands() pending_polls.erase( std::remove_if( pending_polls.begin(), pending_polls.end(), - [&memory, this](PollCommand& pcmd) { - const auto request = Request(pcmd.request_addr); + [&system, &memory, this](PollCommand& pcmd) { + const auto request = Request(system, pcmd.request_addr); auto& pfds = pcmd.wii_fds; int ret = 0; diff --git a/Source/Core/Core/IOS/Network/WD/Command.cpp b/Source/Core/Core/IOS/Network/WD/Command.cpp index faa99e0035..5489f310ed 100644 --- a/Source/Core/Core/IOS/Network/WD/Command.cpp +++ b/Source/Core/Core/IOS/Network/WD/Command.cpp @@ -61,8 +61,8 @@ NetWDCommandDevice::Status NetWDCommandDevice::GetTargetStatusForMode(WD::Mode m } } -NetWDCommandDevice::NetWDCommandDevice(Kernel& ios, const std::string& device_name) - : Device(ios, device_name) +NetWDCommandDevice::NetWDCommandDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { // TODO: use the MPCH setting in setting.txt to determine this value. m_nitro_enabled_channels = LegalNitroChannelMask; @@ -87,6 +87,8 @@ void NetWDCommandDevice::Update() void NetWDCommandDevice::ProcessRecvRequests() { + auto& system = GetSystem(); + // Because we currently do not actually emulate the wireless driver, we have no frames // and no notification data that could be used to reply to requests. // Therefore, requests are left pending to simulate the situation where there is nothing to send. @@ -117,7 +119,7 @@ void NetWDCommandDevice::ProcessRecvRequests() } INFO_LOG_FMT(IOS_NET, "Processed request {:08x} (result {:08x})", request, result); - m_ios.EnqueueIPCReply(Request{request}, result); + GetEmulationKernel().EnqueueIPCReply(Request{system, request}, result); queue.pop_front(); } }; @@ -234,7 +236,7 @@ IPCReply NetWDCommandDevice::SetLinkState(const IOCtlVRequest& request) if (!vector || vector->address == 0) return IPCReply(u32(ResultCode::IllegalParameter)); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 state = memory.Read_U32(vector->address); INFO_LOG_FMT(IOS_NET, "WD_SetLinkState called (state={}, mode={})", state, m_mode); @@ -282,7 +284,7 @@ IPCReply NetWDCommandDevice::Disassociate(const IOCtlVRequest& request) if (!vector || vector->address == 0) return IPCReply(u32(ResultCode::IllegalParameter)); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); Common::MACAddress mac; @@ -315,7 +317,7 @@ IPCReply NetWDCommandDevice::GetInfo(const IOCtlVRequest& request) const if (!vector || vector->address == 0) return IPCReply(u32(ResultCode::IllegalParameter)); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.CopyToEmu(vector->address, &m_info, sizeof(m_info)); return IPCReply(IPC_SUCCESS); @@ -342,7 +344,7 @@ std::optional NetWDCommandDevice::IOCtlV(const IOCtlVRequest& request) // XXX - unused // ScanInfo *scan = (ScanInfo *)memory.GetPointer(request.in_vectors.at(0).m_Address); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); u16* results = (u16*)memory.GetPointer(request.io_vectors.at(0).address); // first u16 indicates number of BSSInfo following @@ -388,7 +390,8 @@ std::optional NetWDCommandDevice::IOCtlV(const IOCtlVRequest& request) case IOCTLV_WD_CHANGE_VTSF: default: DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_WD_UNIMPLEMENTED_IOCTL); - request.Dump(GetDeviceName(), Common::Log::LogType::IOS_NET, Common::Log::LogLevel::LWARNING); + request.Dump(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_NET, + Common::Log::LogLevel::LWARNING); } return IPCReply(IPC_SUCCESS); diff --git a/Source/Core/Core/IOS/Network/WD/Command.h b/Source/Core/Core/IOS/Network/WD/Command.h index fba54b8693..96ac5f4170 100644 --- a/Source/Core/Core/IOS/Network/WD/Command.h +++ b/Source/Core/Core/IOS/Network/WD/Command.h @@ -39,7 +39,7 @@ constexpr bool IsValidMode(Mode mode) namespace IOS::HLE { -class NetWDCommandDevice : public Device +class NetWDCommandDevice : public EmulationDevice { public: enum class ResultCode : u32 @@ -50,7 +50,7 @@ public: DriverError = 0x80008003, }; - NetWDCommandDevice(Kernel& ios, const std::string& device_name); + NetWDCommandDevice(EmulationKernel& ios, const std::string& device_name); std::optional Open(const OpenRequest& request) override; std::optional Close(u32 fd) override; diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp index 178e1e8933..55ee8e771b 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp @@ -25,8 +25,9 @@ namespace IOS::HLE { -SDIOSlot0Device::SDIOSlot0Device(Kernel& ios, const std::string& device_name) - : Device(ios, device_name), m_sdhc_supported(HasFeature(ios.GetVersion(), Feature::SDv2)) +SDIOSlot0Device::SDIOSlot0Device(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name), + m_sdhc_supported(HasFeature(ios.GetVersion(), Feature::SDv2)) { if (!Config::Get(Config::MAIN_ALLOW_SD_WRITES)) INFO_LOG_FMT(IOS_SD, "Writes to SD card disabled by user"); @@ -83,7 +84,7 @@ void SDIOSlot0Device::EventNotify() else INFO_LOG_FMT(IOS_SD, "Notifying PPC of SD card removal"); - m_ios.EnqueueIPCReply(m_event->request, m_event->type); + GetEmulationKernel().EnqueueIPCReply(m_event->request, m_event->type); m_event.reset(); } } @@ -129,7 +130,7 @@ std::optional SDIOSlot0Device::Close(u32 fd) std::optional SDIOSlot0Device::IOCtl(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.Memset(request.buffer_out, 0, request.buffer_out_size); @@ -190,7 +191,7 @@ s32 SDIOSlot0Device::ExecuteCommand(const Request& request, u32 buffer_in, u32 b u32 pad0; } req; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); req.command = memory.Read_U32(buffer_in + 0); @@ -345,7 +346,7 @@ s32 SDIOSlot0Device::ExecuteCommand(const Request& request, u32 buffer_in, u32 b // release returns 0 // unknown sd int // technically we do it out of order, oh well - m_ios.EnqueueIPCReply(m_event->request, EVENT_INVALID); + GetEmulationKernel().EnqueueIPCReply(m_event->request, EVENT_INVALID); m_event.reset(); break; } @@ -360,7 +361,7 @@ s32 SDIOSlot0Device::ExecuteCommand(const Request& request, u32 buffer_in, u32 b IPCReply SDIOSlot0Device::WriteHCRegister(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 reg = memory.Read_U32(request.buffer_in); @@ -395,7 +396,7 @@ IPCReply SDIOSlot0Device::WriteHCRegister(const IOCtlRequest& request) IPCReply SDIOSlot0Device::ReadHCRegister(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 reg = memory.Read_U32(request.buffer_in); @@ -418,7 +419,7 @@ IPCReply SDIOSlot0Device::ResetCard(const IOCtlRequest& request) { INFO_LOG_FMT(IOS_SD, "IOCTL_RESETCARD"); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // Returns 16bit RCA and 16bit 0s (meaning success) @@ -431,7 +432,7 @@ IPCReply SDIOSlot0Device::SetClk(const IOCtlRequest& request) { INFO_LOG_FMT(IOS_SD, "IOCTL_SETCLK"); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // libogc only sets it to 1 and makes sure the return isn't negative... @@ -445,7 +446,7 @@ IPCReply SDIOSlot0Device::SetClk(const IOCtlRequest& request) std::optional SDIOSlot0Device::SendCommand(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); INFO_LOG_FMT(IOS_SD, "IOCTL_SENDCMD {:x} IPC:{:08x}", memory.Read_U32(request.buffer_in), @@ -497,7 +498,7 @@ IPCReply SDIOSlot0Device::GetStatus(const IOCtlRequest& request) (status & CARD_INSERTED) ? "inserted" : "not present", (status & CARD_INITIALIZED) ? " and initialized" : ""); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.Write_U32(status, request.buffer_out); return IPCReply(IPC_SUCCESS); @@ -505,7 +506,7 @@ IPCReply SDIOSlot0Device::GetStatus(const IOCtlRequest& request) IPCReply SDIOSlot0Device::GetOCRegister(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u32 ocr = GetOCRegister(); @@ -517,7 +518,7 @@ IPCReply SDIOSlot0Device::GetOCRegister(const IOCtlRequest& request) IPCReply SDIOSlot0Device::SendCommand(const IOCtlVRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); DEBUG_LOG_FMT(IOS_SD, "IOCTLV_SENDCMD {:#010x}", memory.Read_U32(request.in_vectors[0].address)); diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.h b/Source/Core/Core/IOS/SDIO/SDIOSlot0.h index fcdabd372e..c096539e70 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.h +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.h @@ -18,10 +18,10 @@ class PointerWrap; namespace IOS::HLE { // The front SD slot -class SDIOSlot0Device : public Device +class SDIOSlot0Device : public EmulationDevice { public: - SDIOSlot0Device(Kernel& ios, const std::string& device_name); + SDIOSlot0Device(EmulationKernel& ios, const std::string& device_name); ~SDIOSlot0Device() override; void DoState(PointerWrap& p) override; diff --git a/Source/Core/Core/IOS/STM/STM.cpp b/Source/Core/Core/IOS/STM/STM.cpp index 3deffc5600..0b0e1bbbda 100644 --- a/Source/Core/Core/IOS/STM/STM.cpp +++ b/Source/Core/Core/IOS/STM/STM.cpp @@ -18,7 +18,7 @@ static std::unique_ptr s_event_hook_request; std::optional STMImmediateDevice::IOCtl(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); s32 return_value = IPC_SUCCESS; @@ -37,7 +37,7 @@ std::optional STMImmediateDevice::IOCtl(const IOCtlRequest& request) break; } memory.Write_U32(0, s_event_hook_request->buffer_out); - m_ios.EnqueueIPCReply(*s_event_hook_request, IPC_SUCCESS); + GetEmulationKernel().EnqueueIPCReply(*s_event_hook_request, IPC_SUCCESS); s_event_hook_request.reset(); break; @@ -59,7 +59,7 @@ std::optional STMImmediateDevice::IOCtl(const IOCtlRequest& request) break; default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_STM); + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_STM); } return IPCReply(return_value); @@ -79,7 +79,7 @@ std::optional STMEventHookDevice::IOCtl(const IOCtlRequest& request) return IPCReply(IPC_EEXIST); // IOCTL_STM_EVENTHOOK waits until the reset button or power button is pressed. - s_event_hook_request = std::make_unique(request.address); + s_event_hook_request = std::make_unique(GetSystem(), request.address); return std::nullopt; } @@ -89,9 +89,13 @@ void STMEventHookDevice::DoState(PointerWrap& p) u32 address = s_event_hook_request ? s_event_hook_request->address : 0; p.Do(address); if (address != 0) - s_event_hook_request = std::make_unique(address); + { + s_event_hook_request = std::make_unique(GetSystem(), address); + } else + { s_event_hook_request.reset(); + } } bool STMEventHookDevice::HasHookInstalled() const @@ -105,10 +109,10 @@ void STMEventHookDevice::TriggerEvent(const u32 event) const if (!m_is_active || !s_event_hook_request) return; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.Write_U32(event, s_event_hook_request->buffer_out); - m_ios.EnqueueIPCReply(*s_event_hook_request, IPC_SUCCESS); + GetEmulationKernel().EnqueueIPCReply(*s_event_hook_request, IPC_SUCCESS); s_event_hook_request.reset(); } diff --git a/Source/Core/Core/IOS/STM/STM.h b/Source/Core/Core/IOS/STM/STM.h index 41ae19dcd2..e5eb750cd8 100644 --- a/Source/Core/Core/IOS/STM/STM.h +++ b/Source/Core/Core/IOS/STM/STM.h @@ -38,18 +38,18 @@ enum }; // The /dev/stm/immediate -class STMImmediateDevice final : public Device +class STMImmediateDevice final : public EmulationDevice { public: - using Device::Device; + using EmulationDevice::EmulationDevice; std::optional IOCtl(const IOCtlRequest& request) override; }; // The /dev/stm/eventhook -class STMEventHookDevice final : public Device +class STMEventHookDevice final : public EmulationDevice { public: - using Device::Device; + using EmulationDevice::EmulationDevice; ~STMEventHookDevice() override; std::optional IOCtl(const IOCtlRequest& request) override; void DoState(PointerWrap& p) override; diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTBase.h b/Source/Core/Core/IOS/USB/Bluetooth/BTBase.h index bdcaf9235d..44cc011290 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTBase.h +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTBase.h @@ -18,10 +18,10 @@ namespace IOS::HLE void BackUpBTInfoSection(const SysConf* sysconf); void RestoreBTInfoSection(SysConf* sysconf); -class BluetoothBaseDevice : public Device +class BluetoothBaseDevice : public EmulationDevice { public: - using Device::Device; + using EmulationDevice::EmulationDevice; virtual void UpdateSyncButtonState(bool is_held) {} virtual void TriggerSyncButtonPressedEvent() {} virtual void TriggerSyncButtonHeldEvent() {} diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp index 856a0d5486..3100e6d38e 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp @@ -36,7 +36,7 @@ SQueuedEvent::SQueuedEvent(u32 size_, u16 handle) : size(size_), connection_hand PanicAlertFmt("SQueuedEvent: The size is too large."); } -BluetoothEmuDevice::BluetoothEmuDevice(Kernel& ios, const std::string& device_name) +BluetoothEmuDevice::BluetoothEmuDevice(EmulationKernel& ios, const std::string& device_name) : BluetoothBaseDevice(ios, device_name) { SysConf sysconf{ios.GetFS()}; @@ -81,13 +81,13 @@ BluetoothEmuDevice::BluetoothEmuDevice(Kernel& ios, const std::string& device_na BluetoothEmuDevice::~BluetoothEmuDevice() = default; template -static void DoStateForMessage(Kernel& ios, PointerWrap& p, std::unique_ptr& message) +static void DoStateForMessage(EmulationKernel& ios, PointerWrap& p, std::unique_ptr& message) { u32 request_address = (message != nullptr) ? message->ios_request.address : 0; p.Do(request_address); if (request_address != 0) { - IOCtlVRequest request{request_address}; + IOCtlVRequest request{ios.GetSystem(), request_address}; message = std::make_unique(ios, request); } } @@ -105,8 +105,8 @@ void BluetoothEmuDevice::DoState(PointerWrap& p) Device::DoState(p); p.Do(m_controller_bd); - DoStateForMessage(m_ios, p, m_hci_endpoint); - DoStateForMessage(m_ios, p, m_acl_endpoint); + DoStateForMessage(GetEmulationKernel(), p, m_hci_endpoint); + DoStateForMessage(GetEmulationKernel(), p, m_acl_endpoint); p.Do(m_last_ticks); p.DoArray(m_packet_count); p.Do(m_scan_enable); @@ -152,19 +152,19 @@ std::optional BluetoothEmuDevice::IOCtlV(const IOCtlVRequest& request) case USB::IOCTLV_USBV0_CTRLMSG: // HCI command is received from the stack { // Replies are generated inside - ExecuteHCICommandMessage(USB::V0CtrlMessage(m_ios, request)); + ExecuteHCICommandMessage(USB::V0CtrlMessage(GetEmulationKernel(), request)); send_reply = false; break; } case USB::IOCTLV_USBV0_BLKMSG: { - const USB::V0BulkMessage ctrl{m_ios, request}; + const USB::V0BulkMessage ctrl{GetEmulationKernel(), request}; switch (ctrl.endpoint) { case ACL_DATA_OUT: // ACL data is received from the stack { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // This is the ACL datapath from CPU to Wii Remote @@ -181,7 +181,7 @@ std::optional BluetoothEmuDevice::IOCtlV(const IOCtlVRequest& request) } case ACL_DATA_IN: // We are given an ACL buffer to fill { - m_acl_endpoint = std::make_unique(m_ios, request); + m_acl_endpoint = std::make_unique(GetEmulationKernel(), request); DEBUG_LOG_FMT(IOS_WIIMOTE, "ACL_DATA_IN: {:#010x}", request.address); send_reply = false; break; @@ -194,10 +194,10 @@ std::optional BluetoothEmuDevice::IOCtlV(const IOCtlVRequest& request) case USB::IOCTLV_USBV0_INTRMSG: { - const USB::V0IntrMessage ctrl{m_ios, request}; + const USB::V0IntrMessage ctrl{GetEmulationKernel(), request}; if (ctrl.endpoint == HCI_EVENT) // We are given a HCI buffer to fill { - m_hci_endpoint = std::make_unique(m_ios, request); + m_hci_endpoint = std::make_unique(GetEmulationKernel(), request); DEBUG_LOG_FMT(IOS_WIIMOTE, "HCI_EVENT: {:#010x}", request.address); send_reply = false; } @@ -209,7 +209,7 @@ std::optional BluetoothEmuDevice::IOCtlV(const IOCtlVRequest& request) } default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WIIMOTE); + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_WIIMOTE); } if (!send_reply) @@ -247,7 +247,7 @@ void BluetoothEmuDevice::SendACLPacket(const bdaddr_t& source, const u8* data, u DEBUG_LOG_FMT(IOS_WIIMOTE, "ACL endpoint valid, sending packet to {:08x}", m_acl_endpoint->ios_request.address); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); hci_acldata_hdr_t* header = @@ -258,7 +258,8 @@ void BluetoothEmuDevice::SendACLPacket(const bdaddr_t& source, const u8* data, u // Write the packet to the buffer memcpy(reinterpret_cast(header) + sizeof(hci_acldata_hdr_t), data, header->length); - m_ios.EnqueueIPCReply(m_acl_endpoint->ios_request, sizeof(hci_acldata_hdr_t) + size); + GetEmulationKernel().EnqueueIPCReply(m_acl_endpoint->ios_request, + sizeof(hci_acldata_hdr_t) + size); m_acl_endpoint.reset(); } else @@ -287,7 +288,7 @@ void BluetoothEmuDevice::AddEventToQueue(const SQueuedEvent& event) m_hci_endpoint->FillBuffer(event.buffer, event.size); // Send a reply to indicate HCI buffer is filled - m_ios.EnqueueIPCReply(m_hci_endpoint->ios_request, event.size); + GetEmulationKernel().EnqueueIPCReply(m_hci_endpoint->ios_request, event.size); m_hci_endpoint.reset(); } else // push new one, pop oldest @@ -304,7 +305,7 @@ void BluetoothEmuDevice::AddEventToQueue(const SQueuedEvent& event) m_hci_endpoint->FillBuffer(queued_event.buffer, queued_event.size); // Send a reply to indicate HCI buffer is filled - m_ios.EnqueueIPCReply(m_hci_endpoint->ios_request, queued_event.size); + GetEmulationKernel().EnqueueIPCReply(m_hci_endpoint->ios_request, queued_event.size); m_hci_endpoint.reset(); m_event_queue.pop_front(); } @@ -330,7 +331,7 @@ void BluetoothEmuDevice::Update() m_hci_endpoint->FillBuffer(event.buffer, event.size); // Send a reply to indicate HCI buffer is filled - m_ios.EnqueueIPCReply(m_hci_endpoint->ios_request, event.size); + GetEmulationKernel().EnqueueIPCReply(m_hci_endpoint->ios_request, event.size); m_hci_endpoint.reset(); m_event_queue.pop_front(); } @@ -346,7 +347,7 @@ void BluetoothEmuDevice::Update() wiimote->Update(); const u64 interval = SystemTimers::GetTicksPerSecond() / Wiimote::UPDATE_FREQ; - const u64 now = Core::System::GetInstance().GetCoreTiming().GetTicks(); + const u64 now = GetSystem().GetCoreTiming().GetTicks(); if (now - m_last_ticks > interval) { @@ -427,7 +428,7 @@ void BluetoothEmuDevice::ACLPool::WriteToEndpoint(const USB::V0BulkMessage& endp DEBUG_LOG_FMT(IOS_WIIMOTE, "ACL packet being written from queue to {:08x}", endpoint.ios_request.address); - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); hci_acldata_hdr_t* header = (hci_acldata_hdr_t*)memory.GetPointer(endpoint.data_address); @@ -966,7 +967,7 @@ bool BluetoothEmuDevice::SendEventConPacketTypeChange(u16 connection_handle, u16 // This is called from the USB::IOCTLV_USBV0_CTRLMSG Ioctlv void BluetoothEmuDevice::ExecuteHCICommandMessage(const USB::V0CtrlMessage& ctrl_message) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8* input = memory.GetPointer(ctrl_message.data_address + 3); @@ -1149,7 +1150,7 @@ void BluetoothEmuDevice::ExecuteHCICommandMessage(const USB::V0CtrlMessage& ctrl } // HCI command is finished, send a reply to command - m_ios.EnqueueIPCReply(ctrl_message.ios_request, ctrl_message.length); + GetEmulationKernel().EnqueueIPCReply(ctrl_message.ios_request, ctrl_message.length); } // diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h index 038ed2f5e2..d41cd4f95d 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.h @@ -39,7 +39,7 @@ struct SQueuedEvent class BluetoothEmuDevice final : public BluetoothBaseDevice { public: - BluetoothEmuDevice(Kernel& ios, const std::string& device_name); + BluetoothEmuDevice(EmulationKernel& ios, const std::string& device_name); virtual ~BluetoothEmuDevice(); @@ -74,7 +74,7 @@ private: class ACLPool { public: - explicit ACLPool(Kernel& ios) : m_ios(ios), m_queue() {} + explicit ACLPool(EmulationKernel& ios) : m_ios(ios), m_queue() {} void Store(const u8* data, const u16 size, const u16 conn_handle); void WriteToEndpoint(const USB::V0BulkMessage& endpoint); @@ -91,9 +91,9 @@ private: u16 conn_handle; }; - Kernel& m_ios; + EmulationKernel& m_ios; std::deque m_queue; - } m_acl_pool{m_ios}; + } m_acl_pool{GetEmulationKernel()}; u32 m_packet_count[MAX_BBMOTES] = {}; u64 m_last_ticks = 0; diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index 72f591c7f5..b4dac1a680 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -60,7 +60,7 @@ static bool IsBluetoothDevice(const libusb_interface_descriptor& descriptor) descriptor.bInterfaceProtocol == PROTOCOL_BLUETOOTH; } -BluetoothRealDevice::BluetoothRealDevice(Kernel& ios, const std::string& device_name) +BluetoothRealDevice::BluetoothRealDevice(EmulationKernel& ios, const std::string& device_name) : BluetoothBaseDevice(ios, device_name) { LoadLinkKeys(); @@ -214,11 +214,11 @@ std::optional BluetoothRealDevice::IOCtlV(const IOCtlVRequest& request // HCI commands to the Bluetooth adapter case USB::IOCTLV_USBV0_CTRLMSG: { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); std::lock_guard lk(m_transfers_mutex); - auto cmd = std::make_unique(m_ios, request); + auto cmd = std::make_unique(GetEmulationKernel(), request); const u16 opcode = Common::swap16(memory.Read_U16(cmd->data_address)); if (opcode == HCI_CMD_READ_BUFFER_SIZE) { @@ -263,7 +263,7 @@ std::optional BluetoothRealDevice::IOCtlV(const IOCtlVRequest& request case USB::IOCTLV_USBV0_INTRMSG: { std::lock_guard lk(m_transfers_mutex); - auto cmd = std::make_unique(m_ios, request); + auto cmd = std::make_unique(GetEmulationKernel(), request); if (request.request == USB::IOCTLV_USBV0_INTRMSG) { if (m_sync_button_state == SyncButtonState::Pressed) @@ -347,8 +347,9 @@ void BluetoothRealDevice::DoState(PointerWrap& p) // On load, discard any pending transfer to make sure the emulated software is not stuck // waiting for the previous request to complete. This is usually not an issue as long as // the Bluetooth state is the same (same Wii Remote connections). + auto& system = GetSystem(); for (const auto& address_to_discard : addresses_to_discard) - m_ios.EnqueueIPCReply(Request{address_to_discard}, 0); + GetEmulationKernel().EnqueueIPCReply(Request{system, address_to_discard}, 0); // Prevent the callbacks from replying to a request that has already been discarded. m_current_transfers.clear(); @@ -494,7 +495,7 @@ bool BluetoothRealDevice::SendHCIStoreLinkKeyCommand() void BluetoothRealDevice::FakeVendorCommandReply(USB::V0IntrMessage& ctrl) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); SHCIEventCommand hci_event; @@ -504,7 +505,7 @@ void BluetoothRealDevice::FakeVendorCommandReply(USB::V0IntrMessage& ctrl) hci_event.PacketIndicator = 0x01; hci_event.Opcode = m_fake_vendor_command_reply_opcode; memory.CopyToEmu(ctrl.data_address, &hci_event, sizeof(hci_event)); - m_ios.EnqueueIPCReply(ctrl.ios_request, static_cast(sizeof(hci_event))); + GetEmulationKernel().EnqueueIPCReply(ctrl.ios_request, static_cast(sizeof(hci_event))); } // Due to how the widcomm stack which Nintendo uses is coded, we must never @@ -514,7 +515,7 @@ void BluetoothRealDevice::FakeVendorCommandReply(USB::V0IntrMessage& ctrl) // (including Wiimote disconnects and "event mismatch" warning messages). void BluetoothRealDevice::FakeReadBufferSizeReply(USB::V0IntrMessage& ctrl) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); SHCIEventCommand hci_event; @@ -532,13 +533,14 @@ void BluetoothRealDevice::FakeReadBufferSizeReply(USB::V0IntrMessage& ctrl) reply.max_sco_size = SCO_PKT_SIZE; reply.num_sco_pkts = SCO_PKT_NUM; memory.CopyToEmu(ctrl.data_address + sizeof(hci_event), &reply, sizeof(reply)); - m_ios.EnqueueIPCReply(ctrl.ios_request, static_cast(sizeof(hci_event) + sizeof(reply))); + GetEmulationKernel().EnqueueIPCReply(ctrl.ios_request, + static_cast(sizeof(hci_event) + sizeof(reply))); } void BluetoothRealDevice::FakeSyncButtonEvent(USB::V0IntrMessage& ctrl, const u8* payload, const u8 size) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); hci_event_hdr_t hci_event; @@ -547,7 +549,8 @@ void BluetoothRealDevice::FakeSyncButtonEvent(USB::V0IntrMessage& ctrl, const u8 hci_event.length = size; memory.CopyToEmu(ctrl.data_address, &hci_event, sizeof(hci_event)); memory.CopyToEmu(ctrl.data_address + sizeof(hci_event), payload, size); - m_ios.EnqueueIPCReply(ctrl.ios_request, static_cast(sizeof(hci_event) + size)); + GetEmulationKernel().EnqueueIPCReply(ctrl.ios_request, + static_cast(sizeof(hci_event) + size)); } // When the red sync button is pressed, a HCI event is generated: @@ -694,7 +697,8 @@ void BluetoothRealDevice::HandleCtrlTransfer(libusb_transfer* tr) } const auto& command = m_current_transfers.at(tr).command; command->FillBuffer(libusb_control_transfer_get_data(tr), tr->actual_length); - m_ios.EnqueueIPCReply(command->ios_request, tr->actual_length, 0, CoreTiming::FromThread::ANY); + GetEmulationKernel().EnqueueIPCReply(command->ios_request, tr->actual_length, 0, + CoreTiming::FromThread::ANY); m_current_transfers.erase(tr); } @@ -743,7 +747,8 @@ void BluetoothRealDevice::HandleBulkOrIntrTransfer(libusb_transfer* tr) const auto& command = m_current_transfers.at(tr).command; command->FillBuffer(tr->buffer, tr->actual_length); - m_ios.EnqueueIPCReply(command->ios_request, tr->actual_length, 0, CoreTiming::FromThread::ANY); + GetEmulationKernel().EnqueueIPCReply(command->ios_request, tr->actual_length, 0, + CoreTiming::FromThread::ANY); m_current_transfers.erase(tr); } } // namespace IOS::HLE diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.h b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.h index 9b5c36635b..a1bd605f6f 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.h +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.h @@ -42,7 +42,7 @@ using linkkey_t = std::array; class BluetoothRealDevice final : public BluetoothBaseDevice { public: - BluetoothRealDevice(Kernel& ios, const std::string& device_name); + BluetoothRealDevice(EmulationKernel& ios, const std::string& device_name); ~BluetoothRealDevice() override; std::optional Open(const OpenRequest& request) override; diff --git a/Source/Core/Core/IOS/USB/Common.cpp b/Source/Core/Core/IOS/USB/Common.cpp index fda8e37129..9819ec71dd 100644 --- a/Source/Core/Core/IOS/USB/Common.cpp +++ b/Source/Core/Core/IOS/USB/Common.cpp @@ -19,7 +19,7 @@ std::unique_ptr TransferCommand::MakeBuffer(const size_t size) const { ASSERT_MSG(IOS_USB, data_address != 0, "Invalid data_address"); auto buffer = std::make_unique(size); - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); memory.CopyFromEmu(buffer.get(), data_address, size); return buffer; @@ -28,7 +28,7 @@ std::unique_ptr TransferCommand::MakeBuffer(const size_t size) const void TransferCommand::FillBuffer(const u8* src, const size_t size) const { ASSERT_MSG(IOS_USB, size == 0 || data_address != 0, "Invalid data_address"); - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); memory.CopyToEmu(data_address, src, size); } @@ -47,7 +47,7 @@ void TransferCommand::ScheduleTransferCompletion(s32 return_value, u32 expected_ void IsoMessage::SetPacketReturnValue(const size_t packet_num, const u16 return_value) const { - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); memory.Write_U16(return_value, static_cast(packet_sizes_addr + packet_num * sizeof(u16))); } diff --git a/Source/Core/Core/IOS/USB/Common.h b/Source/Core/Core/IOS/USB/Common.h index edf9a724e1..1c5fd07670 100644 --- a/Source/Core/Core/IOS/USB/Common.h +++ b/Source/Core/Core/IOS/USB/Common.h @@ -101,7 +101,7 @@ struct TransferCommand Request ios_request; u32 data_address = 0; - TransferCommand(Kernel& ios, const Request& ios_request_, u32 data_address_) + TransferCommand(EmulationKernel& ios, const Request& ios_request_, u32 data_address_) : ios_request(ios_request_), data_address(data_address_), m_ios(ios) { } @@ -113,8 +113,8 @@ struct TransferCommand std::unique_ptr MakeBuffer(size_t size) const; void FillBuffer(const u8* src, size_t size) const; -private: - Kernel& m_ios; +protected: + EmulationKernel& m_ios; }; struct CtrlMessage : TransferCommand diff --git a/Source/Core/Core/IOS/USB/Emulated/Skylander.cpp b/Source/Core/Core/IOS/USB/Emulated/Skylander.cpp index 5138fb0f66..55a59d0bf4 100644 --- a/Source/Core/Core/IOS/USB/Emulated/Skylander.cpp +++ b/Source/Core/Core/IOS/USB/Emulated/Skylander.cpp @@ -471,7 +471,7 @@ const std::map, const char*> list_skylande {{3503, 0x0000}, "Kaos Trophy"}, }; -SkylanderUSB::SkylanderUSB(Kernel& ios, const std::string& device_name) : m_ios(ios) +SkylanderUSB::SkylanderUSB(EmulationKernel& ios, const std::string& device_name) : m_ios(ios) { m_vid = 0x1430; m_pid = 0x150; @@ -600,7 +600,7 @@ int SkylanderUSB::SubmitTransfer(std::unique_ptr cmd) else { // Skylander Portal Requests - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); u8* buf = memory.GetPointerForRange(cmd->data_address, cmd->length); if (cmd->length == 0 || buf == nullptr) @@ -892,7 +892,7 @@ int SkylanderUSB::SubmitTransfer(std::unique_ptr cmd) DEBUG_LOG_FMT(IOS_USB, "[{:04x}:{:04x} {}] Interrupt: length={} endpoint={}", m_vid, m_pid, m_active_interface, cmd->length, cmd->endpoint); - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); u8* buf = memory.GetPointerForRange(cmd->data_address, cmd->length); if (cmd->length == 0 || buf == nullptr) diff --git a/Source/Core/Core/IOS/USB/Emulated/Skylander.h b/Source/Core/Core/IOS/USB/Emulated/Skylander.h index 81d6e19799..f46f7c2625 100644 --- a/Source/Core/Core/IOS/USB/Emulated/Skylander.h +++ b/Source/Core/Core/IOS/USB/Emulated/Skylander.h @@ -23,7 +23,7 @@ extern const std::map, const char*> list_s class SkylanderUSB final : public Device { public: - SkylanderUSB(Kernel& ios, const std::string& device_name); + SkylanderUSB(EmulationKernel& ios, const std::string& device_name); ~SkylanderUSB(); DeviceDescriptor GetDeviceDescriptor() const override; std::vector GetConfigurations() const override; @@ -43,7 +43,7 @@ public: s32 expected_count, u64 expected_time_us); private: - Kernel& m_ios; + EmulationKernel& m_ios; u16 m_vid = 0; u16 m_pid = 0; u8 m_active_interface = 0; diff --git a/Source/Core/Core/IOS/USB/Host.cpp b/Source/Core/Core/IOS/USB/Host.cpp index 8870f730b0..a8a5182254 100644 --- a/Source/Core/Core/IOS/USB/Host.cpp +++ b/Source/Core/Core/IOS/USB/Host.cpp @@ -29,7 +29,8 @@ namespace IOS::HLE { -USBHost::USBHost(Kernel& ios, const std::string& device_name) : Device(ios, device_name) +USBHost::USBHost(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { } @@ -137,7 +138,8 @@ bool USBHost::AddNewDevices(std::set& new_devices, DeviceChangeHooks& hooks if (whitelist.count({descriptor.idVendor, descriptor.idProduct}) == 0) return true; - auto usb_device = std::make_unique(m_ios, device, descriptor); + auto usb_device = + std::make_unique(GetEmulationKernel(), device, descriptor); if (!ShouldAddDevice(*usb_device)) return true; @@ -190,7 +192,8 @@ void USBHost::AddEmulatedDevices(std::set& new_devices, DeviceChangeHooks& { if (Config::Get(Config::MAIN_EMULATE_SKYLANDER_PORTAL) && !NetPlay::IsNetPlayRunning()) { - auto skylanderportal = std::make_unique(m_ios, "Skylander Portal"); + auto skylanderportal = + std::make_unique(GetEmulationKernel(), "Skylander Portal"); if (ShouldAddDevice(*skylanderportal)) { const u64 skyid = skylanderportal->GetId(); diff --git a/Source/Core/Core/IOS/USB/Host.h b/Source/Core/Core/IOS/USB/Host.h index 8e146df9d1..70de628df0 100644 --- a/Source/Core/Core/IOS/USB/Host.h +++ b/Source/Core/Core/IOS/USB/Host.h @@ -26,10 +26,10 @@ class PointerWrap; namespace IOS::HLE { // Common base class for USB host devices (such as /dev/usb/oh0 and /dev/usb/ven). -class USBHost : public Device +class USBHost : public EmulationDevice { public: - USBHost(Kernel& ios, const std::string& device_name); + USBHost(EmulationKernel& ios, const std::string& device_name); virtual ~USBHost(); std::optional Open(const OpenRequest& request) override; diff --git a/Source/Core/Core/IOS/USB/LibusbDevice.cpp b/Source/Core/Core/IOS/USB/LibusbDevice.cpp index 9e305b9179..1e8188de9b 100644 --- a/Source/Core/Core/IOS/USB/LibusbDevice.cpp +++ b/Source/Core/Core/IOS/USB/LibusbDevice.cpp @@ -25,7 +25,7 @@ namespace IOS::HLE::USB { -LibusbDevice::LibusbDevice(Kernel& ios, libusb_device* device, +LibusbDevice::LibusbDevice(EmulationKernel& ios, libusb_device* device, const libusb_device_descriptor& descriptor) : m_ios(ios), m_device(device) { @@ -249,7 +249,7 @@ int LibusbDevice::SubmitTransfer(std::unique_ptr cmd) libusb_fill_control_setup(buffer.get(), cmd->request_type, cmd->request, cmd->value, cmd->index, cmd->length); - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); memory.CopyFromEmu(buffer.get() + LIBUSB_CONTROL_SETUP_SIZE, cmd->data_address, cmd->length); diff --git a/Source/Core/Core/IOS/USB/LibusbDevice.h b/Source/Core/Core/IOS/USB/LibusbDevice.h index 2e87b6ceb5..11d940e75b 100644 --- a/Source/Core/Core/IOS/USB/LibusbDevice.h +++ b/Source/Core/Core/IOS/USB/LibusbDevice.h @@ -26,7 +26,7 @@ namespace IOS::HLE::USB class LibusbDevice final : public Device { public: - LibusbDevice(Kernel& ios, libusb_device* device, + LibusbDevice(EmulationKernel& ios, libusb_device* device, const libusb_device_descriptor& device_descriptor); ~LibusbDevice(); DeviceDescriptor GetDeviceDescriptor() const override; @@ -46,7 +46,7 @@ public: int SubmitTransfer(std::unique_ptr message) override; private: - Kernel& m_ios; + EmulationKernel& m_ios; std::vector m_config_descriptors; u16 m_vid = 0; diff --git a/Source/Core/Core/IOS/USB/OH0/OH0.cpp b/Source/Core/Core/IOS/USB/OH0/OH0.cpp index 5e8cf831d6..3685c9d8f5 100644 --- a/Source/Core/Core/IOS/USB/OH0/OH0.cpp +++ b/Source/Core/Core/IOS/USB/OH0/OH0.cpp @@ -22,7 +22,7 @@ namespace IOS::HLE { -OH0::OH0(Kernel& ios, const std::string& device_name) : USBHost(ios, device_name) +OH0::OH0(EmulationKernel& ios, const std::string& device_name) : USBHost(ios, device_name) { } @@ -93,7 +93,7 @@ IPCReply OH0::CancelInsertionHook(const IOCtlRequest& request) if (!request.buffer_in || request.buffer_in_size != 4) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // IOS assigns random IDs, but ours are simply the VID + PID (see RegisterInsertionHookWithID) @@ -108,7 +108,7 @@ IPCReply OH0::GetDeviceList(const IOCtlVRequest& request) const if (!request.HasNumberOfValidVectors(2, 2)) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8 max_entries_count = memory.Read_U8(request.in_vectors[0].address); @@ -140,12 +140,13 @@ IPCReply OH0::GetRhDesca(const IOCtlRequest& request) const if (!request.buffer_out || request.buffer_out_size != 4) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // Based on a hardware test, this ioctl seems to return a constant value memory.Write_U32(0x02000302, request.buffer_out); - request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LWARNING); + request.Dump(system, GetDeviceName(), Common::Log::LogType::IOS_USB, + Common::Log::LogLevel::LWARNING); return IPCReply(IPC_SUCCESS); } @@ -155,7 +156,8 @@ IPCReply OH0::GetRhPortStatus(const IOCtlVRequest& request) const return IPCReply(IPC_EINVAL); ERROR_LOG_FMT(IOS_USB, "Unimplemented IOCtlV: IOCTLV_USBV0_GETRHPORTSTATUS"); - request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LERROR); + request.Dump(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB, + Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } @@ -165,7 +167,8 @@ IPCReply OH0::SetRhPortStatus(const IOCtlVRequest& request) return IPCReply(IPC_EINVAL); ERROR_LOG_FMT(IOS_USB, "Unimplemented IOCtlV: IOCTLV_USBV0_SETRHPORTSTATUS"); - request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LERROR); + request.Dump(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB, + Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } @@ -184,7 +187,7 @@ std::optional OH0::RegisterInsertionHook(const IOCtlVRequest& request) if (!request.HasNumberOfValidVectors(2, 0)) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u16 vid = memory.Read_U16(request.in_vectors[0].address); @@ -203,7 +206,7 @@ std::optional OH0::RegisterInsertionHookWithID(const IOCtlVRequest& re if (!request.HasNumberOfValidVectors(3, 1)) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); std::lock_guard lock{m_hooks_mutex}; @@ -224,7 +227,8 @@ std::optional OH0::RegisterClassChangeHook(const IOCtlVRequest& reques if (!request.HasNumberOfValidVectors(1, 0)) return IPCReply(IPC_EINVAL); WARN_LOG_FMT(IOS_USB, "Unimplemented IOCtlV: USB::IOCTLV_USBV0_DEVICECLASSCHANGE (no reply)"); - request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LWARNING); + request.Dump(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB, + Common::Log::LogLevel::LWARNING); return std::nullopt; } @@ -251,7 +255,8 @@ void OH0::TriggerHook(std::map& hooks, T value, const ReturnCode return_ const auto hook = hooks.find(value); if (hook == hooks.end()) return; - m_ios.EnqueueIPCReply(Request{hook->second}, return_value, 0, CoreTiming::FromThread::ANY); + GetEmulationKernel().EnqueueIPCReply(Request{GetSystem(), hook->second}, return_value, 0, + CoreTiming::FromThread::ANY); hooks.erase(hook); } @@ -323,7 +328,7 @@ std::optional OH0::DeviceIOCtlV(const u64 device_id, const IOCtlVReque return HandleTransfer(device, request.request, [&, this]() { return SubmitTransfer(*device, request); }); case USB::IOCTLV_USBV0_UNKNOWN_32: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB); + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB); return IPCReply(IPC_SUCCESS); default: return IPCReply(IPC_EINVAL); @@ -332,7 +337,7 @@ std::optional OH0::DeviceIOCtlV(const u64 device_id, const IOCtlVReque s32 OH0::SubmitTransfer(USB::Device& device, const IOCtlVRequest& ioctlv) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); switch (ioctlv.request) @@ -341,7 +346,8 @@ s32 OH0::SubmitTransfer(USB::Device& device, const IOCtlVRequest& ioctlv) if (!ioctlv.HasNumberOfValidVectors(6, 1) || Common::swap16(memory.Read_U16(ioctlv.in_vectors[4].address)) != ioctlv.io_vectors[0].size) return IPC_EINVAL; - return device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), ioctlv)); case USB::IOCTLV_USBV0_BLKMSG: case USB::IOCTLV_USBV0_LBLKMSG: @@ -349,18 +355,19 @@ s32 OH0::SubmitTransfer(USB::Device& device, const IOCtlVRequest& ioctlv) memory.Read_U16(ioctlv.in_vectors[1].address) != ioctlv.io_vectors[0].size) return IPC_EINVAL; return device.SubmitTransfer(std::make_unique( - m_ios, ioctlv, ioctlv.request == USB::IOCTLV_USBV0_LBLKMSG)); + GetEmulationKernel(), ioctlv, ioctlv.request == USB::IOCTLV_USBV0_LBLKMSG)); case USB::IOCTLV_USBV0_INTRMSG: if (!ioctlv.HasNumberOfValidVectors(2, 1) || memory.Read_U16(ioctlv.in_vectors[1].address) != ioctlv.io_vectors[0].size) return IPC_EINVAL; - return device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), ioctlv)); case USB::IOCTLV_USBV0_ISOMSG: if (!ioctlv.HasNumberOfValidVectors(3, 2)) return IPC_EINVAL; - return device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return device.SubmitTransfer(std::make_unique(GetEmulationKernel(), ioctlv)); default: return IPC_EINVAL; diff --git a/Source/Core/Core/IOS/USB/OH0/OH0.h b/Source/Core/Core/IOS/USB/OH0/OH0.h index 11f46a3a5b..daf0772397 100644 --- a/Source/Core/Core/IOS/USB/OH0/OH0.h +++ b/Source/Core/Core/IOS/USB/OH0/OH0.h @@ -33,7 +33,7 @@ struct DeviceInfo class OH0 final : public USBHost { public: - OH0(Kernel& ios, const std::string& device_name); + OH0(EmulationKernel& ios, const std::string& device_name); ~OH0() override; std::optional Open(const OpenRequest& request) override; diff --git a/Source/Core/Core/IOS/USB/OH0/OH0Device.cpp b/Source/Core/Core/IOS/USB/OH0/OH0Device.cpp index 398f7490c0..5d6dba445e 100644 --- a/Source/Core/Core/IOS/USB/OH0/OH0Device.cpp +++ b/Source/Core/Core/IOS/USB/OH0/OH0Device.cpp @@ -35,7 +35,8 @@ static void GetVidPidFromDevicePath(const std::string& device_path, u16& vid, u1 ss >> pid; } -OH0Device::OH0Device(Kernel& ios, const std::string& name) : Device(ios, name, DeviceType::OH0) +OH0Device::OH0Device(EmulationKernel& ios, const std::string& name) + : EmulationDevice(ios, name, DeviceType::OH0) { if (!name.empty()) GetVidPidFromDevicePath(name, m_vid, m_pid); @@ -43,7 +44,7 @@ OH0Device::OH0Device(Kernel& ios, const std::string& name) : Device(ios, name, D void OH0Device::DoState(PointerWrap& p) { - m_oh0 = std::static_pointer_cast(GetIOS()->GetDeviceByName("/dev/usb/oh0")); + m_oh0 = std::static_pointer_cast(GetEmulationKernel().GetDeviceByName("/dev/usb/oh0")); Device::DoState(p); p.Do(m_vid); p.Do(m_pid); @@ -55,7 +56,7 @@ std::optional OH0Device::Open(const OpenRequest& request) if (m_vid == 0 && m_pid == 0) return IPCReply(IPC_ENOENT); - m_oh0 = std::static_pointer_cast(GetIOS()->GetDeviceByName("/dev/usb/oh0")); + m_oh0 = std::static_pointer_cast(GetEmulationKernel().GetDeviceByName("/dev/usb/oh0")); ReturnCode return_code; std::tie(return_code, m_device_id) = m_oh0->DeviceOpen(m_vid, m_pid); diff --git a/Source/Core/Core/IOS/USB/OH0/OH0Device.h b/Source/Core/Core/IOS/USB/OH0/OH0Device.h index 918cb4aa96..2658cca5eb 100644 --- a/Source/Core/Core/IOS/USB/OH0/OH0Device.h +++ b/Source/Core/Core/IOS/USB/OH0/OH0Device.h @@ -14,10 +14,10 @@ class PointerWrap; namespace IOS::HLE { class OH0; -class OH0Device final : public Device +class OH0Device final : public EmulationDevice { public: - OH0Device(Kernel& ios, const std::string& device_name); + OH0Device(EmulationKernel& ios, const std::string& device_name); std::optional Open(const OpenRequest& request) override; std::optional Close(u32 fd) override; diff --git a/Source/Core/Core/IOS/USB/USBV0.cpp b/Source/Core/Core/IOS/USB/USBV0.cpp index 3fcba31a4d..24fd182843 100644 --- a/Source/Core/Core/IOS/USB/USBV0.cpp +++ b/Source/Core/Core/IOS/USB/USBV0.cpp @@ -13,10 +13,10 @@ namespace IOS::HLE::USB { -V0CtrlMessage::V0CtrlMessage(Kernel& ios, const IOCtlVRequest& ioctlv) +V0CtrlMessage::V0CtrlMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv) : CtrlMessage(ios, ioctlv, ioctlv.io_vectors[0].address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); request_type = memory.Read_U8(ioctlv.in_vectors[0].address); request = memory.Read_U8(ioctlv.in_vectors[1].address); @@ -25,10 +25,10 @@ V0CtrlMessage::V0CtrlMessage(Kernel& ios, const IOCtlVRequest& ioctlv) length = Common::swap16(memory.Read_U16(ioctlv.in_vectors[4].address)); } -V0BulkMessage::V0BulkMessage(Kernel& ios, const IOCtlVRequest& ioctlv, bool long_length) +V0BulkMessage::V0BulkMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv, bool long_length) : BulkMessage(ios, ioctlv, ioctlv.io_vectors[0].address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); endpoint = memory.Read_U8(ioctlv.in_vectors[0].address); if (long_length) @@ -37,19 +37,19 @@ V0BulkMessage::V0BulkMessage(Kernel& ios, const IOCtlVRequest& ioctlv, bool long length = memory.Read_U16(ioctlv.in_vectors[1].address); } -V0IntrMessage::V0IntrMessage(Kernel& ios, const IOCtlVRequest& ioctlv) +V0IntrMessage::V0IntrMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv) : IntrMessage(ios, ioctlv, ioctlv.io_vectors[0].address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); endpoint = memory.Read_U8(ioctlv.in_vectors[0].address); length = memory.Read_U16(ioctlv.in_vectors[1].address); } -V0IsoMessage::V0IsoMessage(Kernel& ios, const IOCtlVRequest& ioctlv) +V0IsoMessage::V0IsoMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv) : IsoMessage(ios, ioctlv, ioctlv.io_vectors[1].address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); endpoint = memory.Read_U8(ioctlv.in_vectors[0].address); length = memory.Read_U16(ioctlv.in_vectors[1].address); diff --git a/Source/Core/Core/IOS/USB/USBV0.h b/Source/Core/Core/IOS/USB/USBV0.h index 2a80e168af..089969a74e 100644 --- a/Source/Core/Core/IOS/USB/USBV0.h +++ b/Source/Core/Core/IOS/USB/USBV0.h @@ -38,22 +38,22 @@ enum V0Requests struct V0CtrlMessage final : CtrlMessage { - V0CtrlMessage(Kernel& ios, const IOCtlVRequest& ioctlv); + V0CtrlMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv); }; struct V0BulkMessage final : BulkMessage { - V0BulkMessage(Kernel& ios, const IOCtlVRequest& ioctlv, bool long_length = false); + V0BulkMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv, bool long_length = false); }; struct V0IntrMessage final : IntrMessage { - V0IntrMessage(Kernel& ios, const IOCtlVRequest& ioctlv); + V0IntrMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv); }; struct V0IsoMessage final : IsoMessage { - V0IsoMessage(Kernel& ios, const IOCtlVRequest& ioctlv); + V0IsoMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv); }; } // namespace USB } // namespace IOS::HLE diff --git a/Source/Core/Core/IOS/USB/USBV4.cpp b/Source/Core/Core/IOS/USB/USBV4.cpp index 973f15f739..26514f412c 100644 --- a/Source/Core/Core/IOS/USB/USBV4.cpp +++ b/Source/Core/Core/IOS/USB/USBV4.cpp @@ -46,9 +46,10 @@ struct HIDRequest }; #pragma pack(pop) -V4CtrlMessage::V4CtrlMessage(Kernel& ios, const IOCtlRequest& ioctl) : CtrlMessage(ios, ioctl, 0) +V4CtrlMessage::V4CtrlMessage(EmulationKernel& ios, const IOCtlRequest& ioctl) + : CtrlMessage(ios, ioctl, 0) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); HIDRequest hid_request; @@ -64,10 +65,10 @@ V4CtrlMessage::V4CtrlMessage(Kernel& ios, const IOCtlRequest& ioctl) : CtrlMessa // Since this is just a standard control request, but with additional requirements // (US for the language and replacing non-ASCII characters with '?'), // we can simply submit it as a usual control request. -V4GetUSStringMessage::V4GetUSStringMessage(Kernel& ios, const IOCtlRequest& ioctl) +V4GetUSStringMessage::V4GetUSStringMessage(EmulationKernel& ios, const IOCtlRequest& ioctl) : CtrlMessage(ios, ioctl, 0) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); HIDRequest hid_request; @@ -82,7 +83,7 @@ V4GetUSStringMessage::V4GetUSStringMessage(Kernel& ios, const IOCtlRequest& ioct void V4GetUSStringMessage::OnTransferComplete(s32 return_value) const { - auto& system = Core::System::GetInstance(); + auto& system = m_ios.GetSystem(); auto& memory = system.GetMemory(); std::string message = memory.GetString(data_address); @@ -91,9 +92,10 @@ void V4GetUSStringMessage::OnTransferComplete(s32 return_value) const TransferCommand::OnTransferComplete(return_value); } -V4IntrMessage::V4IntrMessage(Kernel& ios, const IOCtlRequest& ioctl) : IntrMessage(ios, ioctl, 0) +V4IntrMessage::V4IntrMessage(EmulationKernel& ios, const IOCtlRequest& ioctl) + : IntrMessage(ios, ioctl, 0) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); HIDRequest hid_request; diff --git a/Source/Core/Core/IOS/USB/USBV4.h b/Source/Core/Core/IOS/USB/USBV4.h index 7002f81f64..896abc098f 100644 --- a/Source/Core/Core/IOS/USB/USBV4.h +++ b/Source/Core/Core/IOS/USB/USBV4.h @@ -29,18 +29,18 @@ enum V4Requests struct V4CtrlMessage final : CtrlMessage { - V4CtrlMessage(Kernel& ios, const IOCtlRequest& ioctl); + V4CtrlMessage(EmulationKernel& ios, const IOCtlRequest& ioctl); }; struct V4GetUSStringMessage final : CtrlMessage { - V4GetUSStringMessage(Kernel& ios, const IOCtlRequest& ioctl); + V4GetUSStringMessage(EmulationKernel& ios, const IOCtlRequest& ioctl); void OnTransferComplete(s32 return_value) const override; }; struct V4IntrMessage final : IntrMessage { - V4IntrMessage(Kernel& ios, const IOCtlRequest& ioctl); + V4IntrMessage(EmulationKernel& ios, const IOCtlRequest& ioctl); }; } // namespace USB } // namespace IOS::HLE diff --git a/Source/Core/Core/IOS/USB/USBV5.cpp b/Source/Core/Core/IOS/USB/USBV5.cpp index 1aeaa49d63..ee07fe7da6 100644 --- a/Source/Core/Core/IOS/USB/USBV5.cpp +++ b/Source/Core/Core/IOS/USB/USBV5.cpp @@ -19,10 +19,10 @@ namespace IOS::HLE { namespace USB { -V5CtrlMessage::V5CtrlMessage(Kernel& ios, const IOCtlVRequest& ioctlv) +V5CtrlMessage::V5CtrlMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv) : CtrlMessage(ios, ioctlv, ioctlv.GetVector(1)->address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); request_type = memory.Read_U8(ioctlv.in_vectors[0].address + 8); request = memory.Read_U8(ioctlv.in_vectors[0].address + 9); @@ -31,28 +31,28 @@ V5CtrlMessage::V5CtrlMessage(Kernel& ios, const IOCtlVRequest& ioctlv) length = static_cast(ioctlv.GetVector(1)->size); } -V5BulkMessage::V5BulkMessage(Kernel& ios, const IOCtlVRequest& ioctlv) +V5BulkMessage::V5BulkMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv) : BulkMessage(ios, ioctlv, ioctlv.GetVector(1)->address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); length = ioctlv.GetVector(1)->size; endpoint = memory.Read_U8(ioctlv.in_vectors[0].address + 18); } -V5IntrMessage::V5IntrMessage(Kernel& ios, const IOCtlVRequest& ioctlv) +V5IntrMessage::V5IntrMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv) : IntrMessage(ios, ioctlv, ioctlv.GetVector(1)->address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); length = ioctlv.GetVector(1)->size; endpoint = memory.Read_U8(ioctlv.in_vectors[0].address + 14); } -V5IsoMessage::V5IsoMessage(Kernel& ios, const IOCtlVRequest& ioctlv) +V5IsoMessage::V5IsoMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv) : IsoMessage(ios, ioctlv, ioctlv.GetVector(2)->address) { - auto& system = Core::System::GetInstance(); + auto& system = ios.GetSystem(); auto& memory = system.GetMemory(); num_packets = memory.Read_U8(ioctlv.in_vectors[0].address + 16); endpoint = memory.Read_U8(ioctlv.in_vectors[0].address + 17); @@ -98,9 +98,13 @@ void USBV5ResourceManager::DoState(PointerWrap& p) u32 hook_address = m_devicechange_hook_request ? m_devicechange_hook_request->address : 0; p.Do(hook_address); if (hook_address != 0) - m_devicechange_hook_request = std::make_unique(hook_address); + { + m_devicechange_hook_request = std::make_unique(GetSystem(), hook_address); + } else + { m_devicechange_hook_request.reset(); + } p.Do(m_usbv5_devices); USBHost::DoState(p); @@ -108,7 +112,7 @@ void USBV5ResourceManager::DoState(PointerWrap& p) USBV5ResourceManager::USBV5Device* USBV5ResourceManager::GetUSBV5Device(u32 in_buffer) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8 index = memory.Read_U8(in_buffer + offsetof(DeviceID, index)); const u16 number = memory.Read_U16(in_buffer + offsetof(DeviceID, number)); @@ -129,7 +133,7 @@ std::optional USBV5ResourceManager::GetDeviceChange(const IOCtlRequest return IPCReply(IPC_EINVAL); std::lock_guard lk{m_devicechange_hook_address_mutex}; - m_devicechange_hook_request = std::make_unique(request.address); + m_devicechange_hook_request = std::make_unique(GetSystem(), request.address); // If there are pending changes, the reply is sent immediately (instead of on device // insertion/removal). if (m_has_pending_changes) @@ -146,7 +150,7 @@ IPCReply USBV5ResourceManager::SetAlternateSetting(USBV5Device& device, const IO if (!host_device->AttachAndChangeInterface(device.interface_number)) return IPCReply(-1); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8 alt_setting = memory.Read_U8(request.buffer_in + 2 * sizeof(s32)); @@ -165,7 +169,7 @@ IPCReply USBV5ResourceManager::Shutdown(const IOCtlRequest& request) std::lock_guard lk{m_devicechange_hook_address_mutex}; if (m_devicechange_hook_request) { - m_ios.EnqueueIPCReply(*m_devicechange_hook_request, IPC_SUCCESS); + GetEmulationKernel().EnqueueIPCReply(*m_devicechange_hook_request, IPC_SUCCESS); m_devicechange_hook_request.reset(); } return IPCReply(IPC_SUCCESS); @@ -173,7 +177,7 @@ IPCReply USBV5ResourceManager::Shutdown(const IOCtlRequest& request) IPCReply USBV5ResourceManager::SuspendResume(USBV5Device& device, const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const auto host_device = GetDeviceById(device.host_id); @@ -248,7 +252,7 @@ void USBV5ResourceManager::TriggerDeviceChangeReply() return; } - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); std::lock_guard lock{m_usbv5_devices_mutex}; @@ -288,7 +292,8 @@ void USBV5ResourceManager::TriggerDeviceChangeReply() ++num_devices; } - m_ios.EnqueueIPCReply(*m_devicechange_hook_request, num_devices, 0, CoreTiming::FromThread::ANY); + GetEmulationKernel().EnqueueIPCReply(*m_devicechange_hook_request, num_devices, 0, + CoreTiming::FromThread::ANY); m_devicechange_hook_request.reset(); INFO_LOG_FMT(IOS_USB, "{} USBv5 device(s), including interfaces", num_devices); } diff --git a/Source/Core/Core/IOS/USB/USBV5.h b/Source/Core/Core/IOS/USB/USBV5.h index 733e90c1ab..8c722ff723 100644 --- a/Source/Core/Core/IOS/USB/USBV5.h +++ b/Source/Core/Core/IOS/USB/USBV5.h @@ -43,22 +43,22 @@ enum V5Requests struct V5CtrlMessage final : CtrlMessage { - V5CtrlMessage(Kernel& ios, const IOCtlVRequest& ioctlv); + V5CtrlMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv); }; struct V5BulkMessage final : BulkMessage { - V5BulkMessage(Kernel& ios, const IOCtlVRequest& ioctlv); + V5BulkMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv); }; struct V5IntrMessage final : IntrMessage { - V5IntrMessage(Kernel& ios, const IOCtlVRequest& ioctlv); + V5IntrMessage(EmulationKernel& ios, const IOCtlVRequest& ioctlv); }; struct V5IsoMessage final : IsoMessage { - V5IsoMessage(Kernel& ios, const IOCtlVRequest& cmd_buffer); + V5IsoMessage(EmulationKernel& ios, const IOCtlVRequest& cmd_buffer); }; } // namespace USB diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp index 610194ddfd..fd8faaa3a6 100644 --- a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp @@ -22,7 +22,8 @@ namespace IOS::HLE { -USB_HIDv4::USB_HIDv4(Kernel& ios, const std::string& device_name) : USBHost(ios, device_name) +USB_HIDv4::USB_HIDv4(EmulationKernel& ios, const std::string& device_name) + : USBHost(ios, device_name) { } @@ -33,7 +34,7 @@ USB_HIDv4::~USB_HIDv4() std::optional USB_HIDv4::IOCtl(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB); @@ -64,7 +65,7 @@ std::optional USB_HIDv4::IOCtl(const IOCtlRequest& request) [&, this]() { return SubmitTransfer(*device, request); }); } default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB); + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB); return IPCReply(IPC_SUCCESS); } } @@ -74,7 +75,7 @@ IPCReply USB_HIDv4::CancelInterrupt(const IOCtlRequest& request) if (request.buffer_in == 0 || request.buffer_in_size != 8) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); auto device = GetDeviceByIOSID(memory.Read_U32(request.buffer_in)); @@ -90,7 +91,7 @@ std::optional USB_HIDv4::GetDeviceChange(const IOCtlRequest& request) if (request.buffer_out == 0 || request.buffer_out_size != 0x600) return IPCReply(IPC_EINVAL); - m_devicechange_hook_request = std::make_unique(request.address); + m_devicechange_hook_request = std::make_unique(GetSystem(), request.address); // On the first call, the reply is sent immediately (instead of on device insertion/removal) if (m_devicechange_first_call) { @@ -105,10 +106,10 @@ IPCReply USB_HIDv4::Shutdown(const IOCtlRequest& request) std::lock_guard lk{m_devicechange_hook_address_mutex}; if (m_devicechange_hook_request != nullptr) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.Write_U32(0xffffffff, m_devicechange_hook_request->buffer_out); - m_ios.EnqueueIPCReply(*m_devicechange_hook_request, -1); + GetEmulationKernel().EnqueueIPCReply(*m_devicechange_hook_request, -1); m_devicechange_hook_request.reset(); } return IPCReply(IPC_SUCCESS); @@ -119,12 +120,15 @@ s32 USB_HIDv4::SubmitTransfer(USB::Device& device, const IOCtlRequest& request) switch (request.request) { case USB::IOCTL_USBV4_CTRLMSG: - return device.SubmitTransfer(std::make_unique(m_ios, request)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), request)); case USB::IOCTL_USBV4_GET_US_STRING: - return device.SubmitTransfer(std::make_unique(m_ios, request)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), request)); case USB::IOCTL_USBV4_INTRMSG_IN: case USB::IOCTL_USBV4_INTRMSG_OUT: - return device.SubmitTransfer(std::make_unique(m_ios, request)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), request)); default: return IPC_EINVAL; } @@ -136,9 +140,13 @@ void USB_HIDv4::DoState(PointerWrap& p) u32 hook_address = m_devicechange_hook_request ? m_devicechange_hook_request->address : 0; p.Do(hook_address); if (hook_address != 0) - m_devicechange_hook_request = std::make_unique(hook_address); + { + m_devicechange_hook_request = std::make_unique(GetSystem(), hook_address); + } else + { m_devicechange_hook_request.reset(); + } p.Do(m_ios_ids); p.Do(m_device_ids); @@ -191,7 +199,7 @@ void USB_HIDv4::TriggerDeviceChangeReply() if (!m_devicechange_hook_request) return; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); { @@ -213,7 +221,8 @@ void USB_HIDv4::TriggerDeviceChangeReply() memory.Write_U32(0xffffffff, dest + offset); } - m_ios.EnqueueIPCReply(*m_devicechange_hook_request, IPC_SUCCESS, 0, CoreTiming::FromThread::ANY); + GetEmulationKernel().EnqueueIPCReply(*m_devicechange_hook_request, IPC_SUCCESS, 0, + CoreTiming::FromThread::ANY); m_devicechange_hook_request.reset(); } diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.h b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.h index 9b356a10df..3fdd02fbab 100644 --- a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.h +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.h @@ -20,7 +20,7 @@ namespace IOS::HLE class USB_HIDv4 final : public USBHost { public: - USB_HIDv4(Kernel& ios, const std::string& device_name); + USB_HIDv4(EmulationKernel& ios, const std::string& device_name); ~USB_HIDv4() override; std::optional IOCtl(const IOCtlRequest& request) override; diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp index 1987ec78d5..1fa3b58686 100644 --- a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp @@ -25,7 +25,7 @@ USB_HIDv5::~USB_HIDv5() std::optional USB_HIDv5::IOCtl(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB); @@ -50,7 +50,7 @@ std::optional USB_HIDv5::IOCtl(const IOCtlRequest& request) return HandleDeviceIOCtl(request, [&](USBV5Device& device) { return CancelEndpoint(device, request); }); default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB, + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } @@ -58,7 +58,6 @@ std::optional USB_HIDv5::IOCtl(const IOCtlRequest& request) std::optional USB_HIDv5::IOCtlV(const IOCtlVRequest& request) { - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB); switch (request.request) { // TODO: HIDv5 seems to be able to queue transfers depending on the transfer length (unlike VEN). @@ -82,6 +81,7 @@ std::optional USB_HIDv5::IOCtlV(const IOCtlVRequest& request) [&, this]() { return SubmitTransfer(*device, *host_device, request); }); } default: + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB); return IPCReply(IPC_EINVAL); } } @@ -92,12 +92,13 @@ s32 USB_HIDv5::SubmitTransfer(USBV5Device& device, USB::Device& host_device, switch (ioctlv.request) { case USB::IOCTLV_USBV5_CTRLMSG: - return host_device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return host_device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), ioctlv)); case USB::IOCTLV_USBV5_INTRMSG: { - auto message = std::make_unique(m_ios, ioctlv); + auto message = std::make_unique(GetEmulationKernel(), ioctlv); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); // Unlike VEN, the endpoint is determined by the value at 8-12. @@ -118,7 +119,7 @@ s32 USB_HIDv5::SubmitTransfer(USBV5Device& device, USB::Device& host_device, IPCReply USB_HIDv5::CancelEndpoint(USBV5Device& device, const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8 value = memory.Read_U8(request.buffer_in + 8); @@ -148,7 +149,7 @@ IPCReply USB_HIDv5::GetDeviceInfo(USBV5Device& device, const IOCtlRequest& reque if (request.buffer_out == 0 || request.buffer_out_size != 0x60) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const std::shared_ptr host_device = GetDeviceById(device.host_id); diff --git a/Source/Core/Core/IOS/USB/USB_KBD.cpp b/Source/Core/Core/IOS/USB/USB_KBD.cpp index 5dcdb109c0..badfbac4b7 100644 --- a/Source/Core/Core/IOS/USB/USB_KBD.cpp +++ b/Source/Core/Core/IOS/USB/USB_KBD.cpp @@ -184,7 +184,8 @@ USB_KBD::MessageData::MessageData(MessageType type, u8 modifiers_, PressedKeyDat // TODO: support in netplay/movies. -USB_KBD::USB_KBD(Kernel& ios, const std::string& device_name) : Device(ios, device_name) +USB_KBD::USB_KBD(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { } @@ -214,7 +215,7 @@ std::optional USB_KBD::IOCtl(const IOCtlRequest& request) if (Config::Get(Config::MAIN_WII_KEYBOARD) && !Core::WantsDeterminism() && ControlReference::GetInputGate() && !m_message_queue.empty()) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); memory.CopyToEmu(request.buffer_out, &m_message_queue.front(), sizeof(MessageData)); m_message_queue.pop(); diff --git a/Source/Core/Core/IOS/USB/USB_KBD.h b/Source/Core/Core/IOS/USB/USB_KBD.h index fe6265b023..ea928b1236 100644 --- a/Source/Core/Core/IOS/USB/USB_KBD.h +++ b/Source/Core/Core/IOS/USB/USB_KBD.h @@ -14,10 +14,10 @@ namespace IOS::HLE { -class USB_KBD : public Device +class USB_KBD : public EmulationDevice { public: - USB_KBD(Kernel& ios, const std::string& device_name); + USB_KBD(EmulationKernel& ios, const std::string& device_name); std::optional Open(const OpenRequest& request) override; std::optional Write(const ReadWriteRequest& request) override; diff --git a/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp b/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp index 53d7c3248c..eec7df9392 100644 --- a/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp +++ b/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp @@ -25,7 +25,7 @@ USB_VEN::~USB_VEN() std::optional USB_VEN::IOCtl(const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB); @@ -53,7 +53,7 @@ std::optional USB_VEN::IOCtl(const IOCtlRequest& request) return HandleDeviceIOCtl(request, [&](USBV5Device& device) { return CancelEndpoint(device, request); }); default: - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB, + request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } @@ -100,13 +100,16 @@ s32 USB_VEN::SubmitTransfer(USB::Device& device, const IOCtlVRequest& ioctlv) switch (ioctlv.request) { case USB::IOCTLV_USBV5_CTRLMSG: - return device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), ioctlv)); case USB::IOCTLV_USBV5_INTRMSG: - return device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), ioctlv)); case USB::IOCTLV_USBV5_BULKMSG: - return device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return device.SubmitTransfer( + std::make_unique(GetEmulationKernel(), ioctlv)); case USB::IOCTLV_USBV5_ISOMSG: - return device.SubmitTransfer(std::make_unique(m_ios, ioctlv)); + return device.SubmitTransfer(std::make_unique(GetEmulationKernel(), ioctlv)); default: return IPC_EINVAL; } @@ -114,7 +117,7 @@ s32 USB_VEN::SubmitTransfer(USB::Device& device, const IOCtlVRequest& ioctlv) IPCReply USB_VEN::CancelEndpoint(USBV5Device& device, const IOCtlRequest& request) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const u8 endpoint = memory.Read_U8(request.buffer_in + 8); @@ -129,7 +132,7 @@ IPCReply USB_VEN::GetDeviceInfo(USBV5Device& device, const IOCtlRequest& request if (request.buffer_out == 0 || request.buffer_out_size != 0xc0) return IPCReply(IPC_EINVAL); - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); const std::shared_ptr host_device = GetDeviceById(device.host_id); diff --git a/Source/Core/Core/IOS/WFS/WFSI.cpp b/Source/Core/Core/IOS/WFS/WFSI.cpp index 833052ce55..253b472142 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.cpp +++ b/Source/Core/Core/IOS/WFS/WFSI.cpp @@ -94,7 +94,8 @@ void ARCUnpacker::Extract(const WriteCallback& callback) } } -WFSIDevice::WFSIDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name) +WFSIDevice::WFSIDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { } @@ -128,7 +129,7 @@ std::optional WFSIDevice::IOCtl(const IOCtlRequest& request) { s32 return_error_code = IPC_SUCCESS; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); switch (request.request) @@ -351,7 +352,7 @@ std::optional WFSIDevice::IOCtl(const IOCtlRequest& request) return_error_code = -3; if (homedir_path_len > 0x1FD) break; - auto device = GetIOS()->GetDeviceByName("/dev/usb/wfssrv"); + auto device = GetEmulationKernel().GetDeviceByName("/dev/usb/wfssrv"); if (!device) break; std::static_pointer_cast(device)->SetHomeDir(homedir_path); @@ -384,14 +385,14 @@ std::optional WFSIDevice::IOCtl(const IOCtlRequest& request) { INFO_LOG_FMT(IOS_WFS, "IOCTL_WFSI_INIT"); u64 tid; - if (GetIOS()->GetES()->GetTitleId(&tid) < 0) + if (GetEmulationKernel().GetES()->GetTitleId(&tid) < 0) { ERROR_LOG_FMT(IOS_WFS, "IOCTL_WFSI_INIT: Could not get title id."); return_error_code = IPC_EINVAL; break; } - const ES::TMDReader tmd = GetIOS()->GetES()->FindInstalledTMD(tid); + const ES::TMDReader tmd = GetEmulationKernel().GetES()->FindInstalledTMD(tid); SetCurrentTitleIdAndGroupId(tmd.GetTitleId(), tmd.GetGroupId()); break; } @@ -543,7 +544,7 @@ std::optional WFSIDevice::IOCtl(const IOCtlRequest& request) // TODO(wfs): Should be returning an error. However until we have // everything properly stubbed it's easier to simulate the methods // succeeding. - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WFS, + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_WFS, Common::Log::LogLevel::LWARNING); memory.Memset(request.buffer_out, 0, request.buffer_out_size); break; @@ -564,7 +565,7 @@ u32 WFSIDevice::GetTmd(u16 group_id, u32 title_id, u64 subtitle_id, u32 address, } if (address) { - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); fp.ReadBytes(memory.GetPointer(address), fp.GetSize()); } diff --git a/Source/Core/Core/IOS/WFS/WFSI.h b/Source/Core/Core/IOS/WFS/WFSI.h index d1c2fdd919..3abfa5bd9b 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.h +++ b/Source/Core/Core/IOS/WFS/WFSI.h @@ -31,10 +31,10 @@ private: std::vector m_whole_file; }; -class WFSIDevice : public Device +class WFSIDevice : public EmulationDevice { public: - WFSIDevice(Kernel& ios, const std::string& device_name); + WFSIDevice(EmulationKernel& ios, const std::string& device_name); std::optional IOCtl(const IOCtlRequest& request) override; diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.cpp b/Source/Core/Core/IOS/WFS/WFSSRV.cpp index 41f75b803d..db1a716581 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.cpp +++ b/Source/Core/Core/IOS/WFS/WFSSRV.cpp @@ -25,7 +25,8 @@ std::string NativePath(const std::string& wfs_path) } } // namespace WFS -WFSSRVDevice::WFSSRVDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name) +WFSSRVDevice::WFSSRVDevice(EmulationKernel& ios, const std::string& device_name) + : EmulationDevice(ios, device_name) { m_device_name = "msc01"; } @@ -34,7 +35,7 @@ std::optional WFSSRVDevice::IOCtl(const IOCtlRequest& request) { int return_error_code = IPC_SUCCESS; - auto& system = Core::System::GetInstance(); + auto& system = GetSystem(); auto& memory = system.GetMemory(); switch (request.request) @@ -57,11 +58,11 @@ std::optional WFSSRVDevice::IOCtl(const IOCtlRequest& request) // Close all hanging attach/detach ioctls with an appropriate error code. for (auto address : m_hanging) { - IOCtlRequest hanging_request{address}; + IOCtlRequest hanging_request{system, address}; memory.Write_U32(0x80000000, hanging_request.buffer_out); memory.Write_U32(0, hanging_request.buffer_out + 4); memory.Write_U32(0, hanging_request.buffer_out + 8); - m_ios.EnqueueIPCReply(hanging_request, 0); + GetEmulationKernel().EnqueueIPCReply(hanging_request, 0); } break; @@ -355,7 +356,7 @@ std::optional WFSSRVDevice::IOCtl(const IOCtlRequest& request) default: // TODO(wfs): Should be returning -3. However until we have everything // properly stubbed it's easier to simulate the methods succeeding. - request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WFS, + request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_WFS, Common::Log::LogLevel::LWARNING); memory.Memset(request.buffer_out, 0, request.buffer_out_size); break; diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.h b/Source/Core/Core/IOS/WFS/WFSSRV.h index cfc6dcc2df..a5c585fede 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.h +++ b/Source/Core/Core/IOS/WFS/WFSSRV.h @@ -28,10 +28,10 @@ enum WFS_FILE_IS_OPENED = -10032, // Cannot perform operation on an opened file. }; -class WFSSRVDevice : public Device +class WFSSRVDevice : public EmulationDevice { public: - WFSSRVDevice(Kernel& ios, const std::string& device_name); + WFSSRVDevice(EmulationKernel& ios, const std::string& device_name); std::optional IOCtl(const IOCtlRequest& request) override; From c9bbb12c2e96e5efc042ddd445df70513ffe485e Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Tue, 25 Apr 2023 01:22:05 -0400 Subject: [PATCH 17/93] Fix build of iconv code on OpenBSD --- Source/Core/Common/StringUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 113d7b781a..af81e2b84b 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -547,7 +547,7 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v while (src_bytes != 0) { size_t const iconv_result = -#if defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__NetBSD__) iconv(conv_desc, reinterpret_cast(&src_buffer), &src_bytes, &dst_buffer, &dst_bytes); #else From 97157eaf5cf51b05a268abb8755254b809487e49 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 19 Apr 2023 09:25:59 -0700 Subject: [PATCH 18/93] DolphinQt: use new style of addAction API --- Source/Core/DolphinQt/MenuBar.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/Core/DolphinQt/MenuBar.cpp b/Source/Core/DolphinQt/MenuBar.cpp index 07391cb65b..917935ec50 100644 --- a/Source/Core/DolphinQt/MenuBar.cpp +++ b/Source/Core/DolphinQt/MenuBar.cpp @@ -191,7 +191,11 @@ void MenuBar::OnDebugModeToggled(bool enabled) void MenuBar::AddFileMenu() { QMenu* file_menu = addMenu(tr("&File")); +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + m_open_action = file_menu->addAction(tr("&Open..."), QKeySequence::Open, this, &MenuBar::Open); +#else m_open_action = file_menu->addAction(tr("&Open..."), this, &MenuBar::Open, QKeySequence::Open); +#endif file_menu->addSeparator(); @@ -501,14 +505,23 @@ void MenuBar::AddViewMenu() connect(&Settings::Instance(), &Settings::GameListRefreshStarted, purge_action, [purge_action] { purge_action->setEnabled(true); }); view_menu->addSeparator(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + view_menu->addAction(tr("Search"), QKeySequence::Find, this, &MenuBar::ShowSearch); +#else view_menu->addAction(tr("Search"), this, &MenuBar::ShowSearch, QKeySequence::Find); +#endif } void MenuBar::AddOptionsMenu() { QMenu* options_menu = addMenu(tr("&Options")); +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + options_menu->addAction(tr("Co&nfiguration"), QKeySequence::Preferences, this, + &MenuBar::Configure); +#else options_menu->addAction(tr("Co&nfiguration"), this, &MenuBar::Configure, QKeySequence::Preferences); +#endif options_menu->addSeparator(); options_menu->addAction(tr("&Graphics Settings"), this, &MenuBar::ConfigureGraphics); options_menu->addAction(tr("&Audio Settings"), this, &MenuBar::ConfigureAudio); From ce9413e5494b7025a2f73f54f7438a756fcecf82 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 19 Apr 2023 12:05:24 -0700 Subject: [PATCH 19/93] cmake: drop qt5 --- Source/Core/DolphinQt/CMakeLists.txt | 49 ++++++++-------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 1ef8c0cb64..8b3f72f580 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -13,16 +13,10 @@ endif() set(CMAKE_AUTOMOC ON) -# For some reason the method in Qt6 documentation is not working (at least on ubuntu jammy) -# When Qt5 and Qt6 are given in same NAMES entry, only Qt5 is ever found. -find_package(QT NAMES Qt6 COMPONENTS Core Gui Widgets) -if(NOT QT_DIR) - find_package(QT NAMES Qt5 COMPONENTS Core Gui Widgets) -endif() -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets) -message(STATUS "Found Qt version ${QT_VERSION}") +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) +message(STATUS "Found Qt version ${Qt6_VERSION}") -set_property(TARGET Qt${QT_VERSION_MAJOR}::Core PROPERTY INTERFACE_COMPILE_FEATURES "") +set_property(TARGET Qt6::Core PROPERTY INTERFACE_COMPILE_FEATURES "") add_executable(dolphin-emu AboutDialog.cpp @@ -374,13 +368,13 @@ PRIVATE target_include_directories(dolphin-emu PRIVATE ${CMAKE_CURRENT_BINARY_DIR} - ${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS} + ${Qt6Gui_PRIVATE_INCLUDE_DIRS} ) target_link_libraries(dolphin-emu PRIVATE core - Qt${QT_VERSION_MAJOR}::Widgets + Qt6::Widgets uicommon imgui implot @@ -408,14 +402,9 @@ if (MSVC) # Qt 6.3.0 headers use std::aligned_storage instead of alignas target_compile_definitions(dolphin-emu PRIVATE _SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING) - if ("${QT_VERSION_MAJOR}" GREATER_EQUAL 6) - # Qt6 requires RTTI - remove_cxx_flag_from_target(dolphin-emu "/GR-") - target_compile_options(dolphin-emu PRIVATE "/GR") - else() - # Add precompiled header - target_link_libraries(audiocommon PRIVATE use_pch) - endif() + # Qt6 requires RTTI + remove_cxx_flag_from_target(dolphin-emu "/GR-") + target_compile_options(dolphin-emu PRIVATE "/GR") endif() if(WIN32) @@ -448,17 +437,10 @@ if(WIN32) ) # Delegate to Qt's official deployment binary on Windows to copy over the necessary Qt-specific libraries, etc. - get_target_property(MOC_EXECUTABLE_LOCATION Qt${QT_VERSION_MAJOR}::moc IMPORTED_LOCATION) + get_target_property(MOC_EXECUTABLE_LOCATION Qt6::moc IMPORTED_LOCATION) get_filename_component(QT_BINARY_DIRECTORY "${MOC_EXECUTABLE_LOCATION}" DIRECTORY) find_program(WINDEPLOYQT_EXE windeployqt HINTS "${QT_BINARY_DIRECTORY}") - if ("${QT_VERSION_MAJOR}" LESS 6) - set(NO_ANGLE_PARAM "--no-angle") - else() - # parameter no longer exists in Qt6 - set(NO_ANGLE_PARAM "") - endif() - # Note: We set the PATH for the duration of this command so that the # deployment application is able to locate the Qt libraries to copy. # if the necessary paths aren't already set beforehand. @@ -481,7 +463,6 @@ if(WIN32) --no-translations --no-compiler-runtime --no-system-d3d-compiler - "${NO_ANGLE_PARAM}" --no-opengl-sw "$" ) @@ -560,18 +541,16 @@ if(APPLE) target_sources(dolphin-emu PRIVATE "${CMAKE_SOURCE_DIR}/Data/Dolphin.icns") set_source_files_properties("${CMAKE_SOURCE_DIR}/Data/Dolphin.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - # Plugins have to be manually included with Qt 6 - if (QT_VERSION_MAJOR EQUAL 6) - find_package(Qt6QMacStylePlugin REQUIRED PATHS ${Qt6Widgets_DIR}) - find_package(Qt6QCocoaIntegrationPlugin REQUIRED PATHS ${Qt6Gui_DIR}) - endif() + # Manually include plugins + find_package(Qt6QMacStylePlugin REQUIRED PATHS ${Qt6Widgets_DIR}) + find_package(Qt6QCocoaIntegrationPlugin REQUIRED PATHS ${Qt6Gui_DIR}) # Copy Qt plugins into the bundle - get_target_property(qtcocoa_location Qt${QT_VERSION_MAJOR}::QCocoaIntegrationPlugin LOCATION) + get_target_property(qtcocoa_location Qt6::QCocoaIntegrationPlugin LOCATION) target_sources(dolphin-emu PRIVATE "${qtcocoa_location}") set_source_files_properties("${qtcocoa_location}" PROPERTIES MACOSX_PACKAGE_LOCATION MacOS/platforms) - get_target_property(qtmacstyle_location Qt${QT_VERSION_MAJOR}::QMacStylePlugin LOCATION) + get_target_property(qtmacstyle_location Qt6::QMacStylePlugin LOCATION) target_sources(dolphin-emu PRIVATE "${qtmacstyle_location}") set_source_files_properties("${qtmacstyle_location}" PROPERTIES MACOSX_PACKAGE_LOCATION MacOS/styles) From 258cf0ff289edb7960cf78b35417fa9c5fa4ecf7 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 19 Apr 2023 12:48:20 -0700 Subject: [PATCH 20/93] DolphinQt: assume QT_VERSION_CHECK >= 6.0.0 --- .../Config/ToolTipControls/BalloonTip.cpp | 14 +------------- .../Config/ToolTipControls/ToolTipWidget.h | 4 ---- .../Core/DolphinQt/Debugger/MemoryViewWidget.cpp | 4 ---- Source/Core/DolphinQt/GBAWidget.cpp | 7 +------ 4 files changed, 2 insertions(+), 27 deletions(-) diff --git a/Source/Core/DolphinQt/Config/ToolTipControls/BalloonTip.cpp b/Source/Core/DolphinQt/Config/ToolTipControls/BalloonTip.cpp index 7f5516bbd2..ccec65c374 100644 --- a/Source/Core/DolphinQt/Config/ToolTipControls/BalloonTip.cpp +++ b/Source/Core/DolphinQt/Config/ToolTipControls/BalloonTip.cpp @@ -16,12 +16,7 @@ #include #include -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) #include -#else -#include -#include -#endif #if defined(__APPLE__) #include @@ -105,11 +100,7 @@ BalloonTip::BalloonTip(PrivateTag, const QIcon& icon, QString title, QString mes message_label->setTextFormat(Qt::RichText); message_label->setAlignment(Qt::AlignTop | Qt::AlignLeft); -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - const int limit = QApplication::desktop()->availableGeometry(message_label).width() / 3; -#else const int limit = message_label->screen()->availableGeometry().width() / 3; -#endif message_label->setMaximumWidth(limit); message_label->setSizePolicy(QSizePolicy::Policy::MinimumExpanding, QSizePolicy::Policy::MinimumExpanding); @@ -136,14 +127,11 @@ void BalloonTip::UpdateBoundsAndRedraw(const QPoint& pos, ShowArrow show_arrow) { m_show_arrow = show_arrow == ShowArrow::Yes; -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - const QRect screen_rect = QApplication::desktop()->screenGeometry(pos); -#else QScreen* screen = QGuiApplication::screenAt(pos); if (!screen) screen = QGuiApplication::primaryScreen(); const QRect screen_rect = screen->geometry(); -#endif + QSize sh = sizeHint(); // The look should resemble the default tooltip style set in Settings::SetCurrentUserStyle() const int border = 1; diff --git a/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h b/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h index 6e3658e8bb..1f7c574345 100644 --- a/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h +++ b/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h @@ -22,11 +22,7 @@ public: void SetDescription(QString description) { m_description = std::move(description); } private: -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - void enterEvent(QEvent* event) override -#else void enterEvent(QEnterEvent* event) override -#endif { if (m_timer_id) return; diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp index 41b406536b..80a4cdd7f4 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp @@ -212,11 +212,7 @@ void MemoryViewWidget::UpdateFont() // BoundingRect is too unpredictable, a custom one would be needed for each view type. Different // fonts have wildly different spacing between two characters and horizontalAdvance includes // spacing. -#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) m_font_width = fm.horizontalAdvance(QLatin1Char('0')); -#else - m_font_width = fm.width(QLatin1Char('0')); -#endif m_table->setFont(Settings::Instance().GetDebugFont()); CreateTable(); diff --git a/Source/Core/DolphinQt/GBAWidget.cpp b/Source/Core/DolphinQt/GBAWidget.cpp index eb868440e5..6805321df5 100644 --- a/Source/Core/DolphinQt/GBAWidget.cpp +++ b/Source/Core/DolphinQt/GBAWidget.cpp @@ -514,12 +514,7 @@ void GBAWidget::mouseMoveEvent(QMouseEvent* event) { if (!m_moving) return; - auto event_pos = -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - event->globalPosition().toPoint(); -#else - event->globalPos(); -#endif + auto event_pos = event->globalPosition().toPoint(); move(event_pos - m_move_pos - (geometry().topLeft() - pos())); } From b20cc6b67e30373597edd761102dca4b8f31d391 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 19 Apr 2023 09:24:24 -0700 Subject: [PATCH 21/93] DolphinQt: dont set dpi awareness in manifest Qt already does this itself programmatically. Setting in the manifest interferes with Qt's internal handling of dpi awareness. --- Source/Core/DolphinQt/DolphinQt.manifest | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/DolphinQt/DolphinQt.manifest b/Source/Core/DolphinQt/DolphinQt.manifest index 211b0bb068..f6e81b516f 100644 --- a/Source/Core/DolphinQt/DolphinQt.manifest +++ b/Source/Core/DolphinQt/DolphinQt.manifest @@ -2,7 +2,6 @@ - true true From b00e898affc7dd81baecacbd421a0855964b3f75 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 19 Apr 2023 09:40:12 -0700 Subject: [PATCH 22/93] DolphinQt: fix handling of Qt-specific cmdline args QApplication should parse and remove and args it recognizes before dolphin starts inspecting the args. This allows using e.g. -style