Compare commits

..

44 Commits

Author SHA1 Message Date
yuzubot
d789f0f99c Android 194 2024-01-16 01:00:38 +00:00
yuzubot
f3f1b70728 Merge yuzu-emu#12644 2024-01-16 01:00:38 +00:00
yuzubot
fca2beb76d Merge yuzu-emu#12579 2024-01-16 01:00:38 +00:00
liamwhite
c683ec2bcb Merge pull request #12681 from t895/stick-toggles
android: Fix overlay toggle ordering
2024-01-15 13:52:53 -05:00
liamwhite
2e4e33156e Merge pull request #12680 from t895/format-mainline
ci: Remove format step from mainline builds
2024-01-15 13:52:48 -05:00
liamwhite
04f4eeaca2 Merge pull request #12677 from GPUCode/whyy-modders
core: Support multiple modules per patcher
2024-01-15 13:52:38 -05:00
liamwhite
2e4b32204c Merge pull request #12665 from german77/proof
service: acc: Only save profiles when profiles have changed
2024-01-15 13:52:33 -05:00
Charles Lombardo
34db13486a Merge pull request #12659 from liamwhite/audio-memory
audio: fetch process object from handle table
2024-01-15 13:52:01 -05:00
Charles Lombardo
c6c6bb4041 Merge pull request #12652 from liamwhite/huge-pile-of-spirv-spaghetti
shader_recompiler: emulate 8-bit and 16-bit storage writes with cas loop
2024-01-15 13:51:36 -05:00
Charles Lombardo
a2ffb419c9 Merge pull request #12612 from liamwhite/fs-pid
fsp-srv: use program registry for SetCurrentProcess
2024-01-15 13:51:14 -05:00
Charles Lombardo
0127cec371 Merge pull request #12611 from liamwhite/resource-management-is-hard
kernel: fix resource management issues
2024-01-15 13:50:58 -05:00
Charles Lombardo
db3a6075f5 Merge pull request #12610 from liamwhite/reply-and-dont-receive
server_manager: respond to session close correctly
2024-01-15 13:50:43 -05:00
t895
8876a15227 android: Fix overlay toggle ordering 2024-01-15 12:41:49 -05:00
t895
954eb40237 ci: Remove format step from mainline builds 2024-01-15 10:30:57 -05:00
GPUCode
d4acdac168 core: Support multiple modules per patcher 2024-01-15 00:46:05 +02:00
liamwhite
817c7c445d Merge pull request #12667 from t895/version-info
android: Show version name instead of build hash in about fragment
2024-01-13 20:23:12 -05:00
liamwhite
da714a362b Merge pull request #12666 from t895/ktlint-yuzu-verify
android: Move ktlintCheck to yuzu-verify
2024-01-13 20:23:02 -05:00
t895
7b3941e5d4 android: Show version name instead of git hash in the about fragment 2024-01-13 18:12:19 -05:00
t895
15d8a40529 android: Clean up git commands in build.gradle 2024-01-13 18:06:33 -05:00
t895
cdeaca73c4 android: Move ktlintCheck to yuzu-verify 2024-01-13 17:41:01 -05:00
german77
bee22540a1 service: acc: Only save profiles when profiles have changed 2024-01-13 14:28:29 -06:00
Liam
76880b84f9 loader: fix homebrew nro registration 2024-01-13 13:48:56 -05:00
Liam
2f0b57ca13 kernel: optimize page free on shutdown 2024-01-12 19:19:07 -05:00
Liam
f90a022d3a kernel: fix debugger and process list lifetime 2024-01-12 18:31:33 -05:00
Liam
f2fed21c11 kernel: fix page leak on process termination 2024-01-12 18:31:33 -05:00
Liam
d940974789 audio: fetch process object from handle table 2024-01-12 10:03:16 -05:00
liamwhite
f7a3c135e2 Merge pull request #12605 from german77/abstract
service: hid: Create abstracted pad structure
2024-01-12 10:02:13 -05:00
liamwhite
fcb0dff67c Merge pull request #12642 from t895/adapter-refactor
android: Refactor list adapters
2024-01-12 10:01:54 -05:00
german77
b5dac5f525 service: hid: Create abstracted pad structure 2024-01-11 19:35:04 -06:00
Charles Lombardo
a4d90a9a64 Merge pull request #12653 from liamwhite/once-more
ci: fix file mode check in format script
2024-01-11 19:58:41 -05:00
Liam
84787a2ada ci: fix file mode check in format script 2024-01-11 18:57:07 -05:00
Liam
2a0d707ce1 shader_recompiler: emulate 8-bit and 16-bit storage writes with cas loop 2024-01-11 16:50:59 -05:00
Liam
aae9eea532 fsp-srv: use program registry for SetCurrentProcess 2024-01-11 11:28:52 -05:00
t895
d3ba6b334b android: Fix added driver path
While this didn't break anything, the extra separator was unnecessary
2024-01-10 23:14:04 -05:00
t895
dac8c4ce4d android: Add button to use global driver value 2024-01-10 23:14:04 -05:00
t895
9e974d4c7e android: Reload driver data on importing user data 2024-01-10 23:14:04 -05:00
t895
6bfc3c530c android: Rework driver fragment
Applies settings upon selection and uses a new Driver model to represent the information in-view. Also switches from an async diff list to a plain one.
2024-01-10 23:14:04 -05:00
t895
93239f191a android: Refactor DriverAdapter to use AbstractSingleSelectionList 2024-01-10 23:14:04 -05:00
t895
b17db2b462 android: Create generic single selection list adapter 2024-01-10 23:14:04 -05:00
t895
9130366a58 android: Refactor recycler view adapters to use AbstractListAdapter 2024-01-10 23:14:04 -05:00
t895
ad0066a6b6 android: Create generic list adapter for basic lists
Simplifies basic setup for lists
2024-01-10 23:14:04 -05:00
t895
78c323c4eb android: Refactor async diff adapters to use AbstractDiffAdapter 2024-01-10 23:14:04 -05:00
t895
51ad2d10de android: Create generic adapter and viewholder
Eliminates repeated code associated with every async differ list
2024-01-10 23:14:04 -05:00
Liam
200b371d13 server_manager: respond to session close correctly 2024-01-07 21:33:24 -05:00
88 changed files with 3813 additions and 347 deletions

View File

@@ -25,10 +25,13 @@ for f in $FILES_TO_LINT; do
"$CLANG_FORMAT" -i "$f"
done
DIFF=$(git diff)
DIFF=$(git -c core.fileMode=false diff)
if [ ! -z "$DIFF" ]; then
echo "!!! Not compliant to coding style, here is the fix:"
echo "$DIFF"
exit 1
fi
cd src/android
./gradlew ktlintCheck

View File

@@ -8,17 +8,7 @@ variables:
DisplayVersion: $[counter(variables['DisplayPrefix'], 1)]
stages:
- stage: format
displayName: 'format'
jobs:
- job: format
displayName: 'clang'
pool:
vmImage: ubuntu-latest
steps:
- template: ./templates/format-check.yml
- stage: build
dependsOn: format
displayName: 'build'
jobs:
- job: build

View File

@@ -13,13 +13,15 @@ jobs:
format:
name: 'verify format'
runs-on: ubuntu-latest
container:
image: yuzuemu/build-environments:linux-clang-format
options: -u 1001
steps:
- uses: actions/checkout@v3
with:
submodules: false
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: 'Verify Formatting'
run: bash -ex ./.ci/scripts/format/script.sh
build:

View File

@@ -1,10 +1,7 @@
| Pull Request | Commit | Title | Author | Merged? |
|----|----|----|----|----|
| [12579](https://github.com/yuzu-emu/yuzu-android//pull/12579) | [`66ae60a9e`](https://github.com/yuzu-emu/yuzu-android//pull/12579/files) | Core: Implement Device Mapping & GPU SMMU | [FernandoS27](https://github.com/FernandoS27/) | Yes |
| [12610](https://github.com/yuzu-emu/yuzu-android//pull/12610) | [`200b371d1`](https://github.com/yuzu-emu/yuzu-android//pull/12610/files) | server_manager: respond to session close correctly | [liamwhite](https://github.com/liamwhite/) | Yes |
| [12611](https://github.com/yuzu-emu/yuzu-android//pull/12611) | [`642a29923`](https://github.com/yuzu-emu/yuzu-android//pull/12611/files) | kernel: fix resource management issues | [liamwhite](https://github.com/liamwhite/) | Yes |
| [12612](https://github.com/yuzu-emu/yuzu-android//pull/12612) | [`417df3b6e`](https://github.com/yuzu-emu/yuzu-android//pull/12612/files) | fsp-srv: use program registry for SetCurrentProcess | [liamwhite](https://github.com/liamwhite/) | Yes |
| [12642](https://github.com/yuzu-emu/yuzu-android//pull/12642) | [`4037afea1`](https://github.com/yuzu-emu/yuzu-android//pull/12642/files) | android: Refactor list adapters | [t895](https://github.com/t895/) | Yes |
| [12644](https://github.com/yuzu-emu/yuzu-android//pull/12644) | [`2044a289f`](https://github.com/yuzu-emu/yuzu-android//pull/12644/files) | shader_recompiler: fix Offset operand usage for non-OpImage*Gather | [liamwhite](https://github.com/liamwhite/) | Yes |
End of merge log. You can find the original README.md below the break.

View File

@@ -188,8 +188,15 @@ tasks.create<Delete>("ktlintReset") {
delete(File(buildDir.path + File.separator + "intermediates/ktLint"))
}
val showFormatHelp = {
logger.lifecycle(
"If this check fails, please try running \"gradlew ktlintFormat\" for automatic " +
"codestyle fixes"
)
}
tasks.getByPath("ktlintKotlinScriptCheck").doFirst { showFormatHelp.invoke() }
tasks.getByPath("ktlintMainSourceSetCheck").doFirst { showFormatHelp.invoke() }
tasks.getByPath("loadKtlintReporters").dependsOn("ktlintReset")
tasks.getByPath("preBuild").dependsOn("ktlintCheck")
ktlint {
version.set("0.47.1")
@@ -228,71 +235,33 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
}
fun getGitVersion(): String {
var versionName = "0.0"
try {
versionName = ProcessBuilder("git", "describe", "--always", "--long")
fun runGitCommand(command: List<String>): String {
return try {
ProcessBuilder(command)
.directory(project.rootDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start().inputStream.bufferedReader().use { it.readText() }
.trim()
} catch (e: Exception) {
logger.error("Cannot find git")
""
}
}
fun getGitVersion(): String {
val versionName = if (System.getenv("GITHUB_ACTIONS") != null) {
val gitTag = System.getenv("GIT_TAG_NAME") ?: ""
gitTag
} else {
runGitCommand(listOf("git", "describe", "--always", "--long"))
.replace(Regex("(-0)?-[^-]+$"), "")
} catch (e: Exception) {
logger.error("Cannot find git, defaulting to dummy version number")
}
if (System.getenv("GITHUB_ACTIONS") != null) {
val gitTag = System.getenv("GIT_TAG_NAME")
versionName = gitTag ?: versionName
}
return versionName
return versionName.ifEmpty { "0.0" }
}
fun getGitHash(): String {
try {
val processBuilder = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
processBuilder.directory(project.rootDir)
val process = processBuilder.start()
val inputStream = process.inputStream
val errorStream = process.errorStream
process.waitFor()
fun getGitHash(): String =
runGitCommand(listOf("git", "rev-parse", "--short", "HEAD")).ifEmpty { "dummy-hash" }
return if (process.exitValue() == 0) {
inputStream.bufferedReader()
.use { it.readText().trim() } // return the value of gitHash
} else {
val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
logger.error("Error running git command: $errorMessage")
"dummy-hash" // return a dummy hash value in case of an error
}
} catch (e: Exception) {
logger.error("$e: Cannot find git, defaulting to dummy build hash")
return "dummy-hash" // return a dummy hash value in case of an error
}
}
fun getBranch(): String {
try {
val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD")
processBuilder.directory(project.rootDir)
val process = processBuilder.start()
val inputStream = process.inputStream
val errorStream = process.errorStream
process.waitFor()
return if (process.exitValue() == 0) {
inputStream.bufferedReader()
.use { it.readText().trim() } // return the value of gitHash
} else {
val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
logger.error("Error running git command: $errorMessage")
"dummy-hash" // return a dummy hash value in case of an error
}
} catch (e: Exception) {
logger.error("$e: Cannot find git, defaulting to dummy build hash")
return "dummy-hash" // return a dummy hash value in case of an error
}
}
fun getBranch(): String =
runGitCommand(listOf("git", "rev-parse", "--abbrev-ref", "HEAD")).ifEmpty { "dummy-hash" }

View File

@@ -76,8 +76,8 @@ class AboutFragment : Fragment() {
binding.root.findNavController().navigate(R.id.action_aboutFragment_to_licensesFragment)
}
binding.textBuildHash.text = BuildConfig.GIT_HASH
binding.buttonBuildHash.setOnClickListener {
binding.textVersionName.text = BuildConfig.VERSION_NAME
binding.textVersionName.setOnClickListener {
val clipBoard =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH)

View File

@@ -410,8 +410,8 @@ void EmulationSession::OnGamepadConnectEvent([[maybe_unused]] int index) {
jauto handheld = m_system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
if (controller->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::Handheld) {
handheld->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
handheld->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
handheld->Disconnect();
}
}

View File

@@ -147,7 +147,7 @@
android:layout_marginHorizontal="20dp" />
<LinearLayout
android:id="@+id/button_build_hash"
android:id="@+id/button_version_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
@@ -164,7 +164,7 @@
android:textAlignment="viewStart" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_build_hash"
android:id="@+id/text_version_name"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -148,7 +148,7 @@
android:layout_marginHorizontal="20dp" />
<LinearLayout
android:id="@+id/button_build_hash"
android:id="@+id/button_version_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="16dp"
@@ -165,7 +165,7 @@
android:text="@string/build" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_build_hash"
android:id="@+id/text_version_name"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -228,10 +228,10 @@
<item>R</item>
<item>ZL</item>
<item>ZR</item>
<item>@string/gamepad_left_stick</item>
<item>@string/gamepad_right_stick</item>
<item>L3</item>
<item>R3</item>
<item>@string/gamepad_left_stick</item>
<item>@string/gamepad_right_stick</item>
<item>@string/gamepad_d_pad</item>
</string-array>

View File

@@ -11,6 +11,8 @@
#include "core/guest_memory.h"
#include "core/memory.h"
#include "core/hle/kernel/k_process.h"
namespace AudioCore {
using namespace std::literals;
@@ -26,7 +28,7 @@ DeviceSession::~DeviceSession() {
}
Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_format_,
u16 channel_count_, size_t session_id_, u32 handle_,
u16 channel_count_, size_t session_id_, Kernel::KProcess* handle_,
u64 applet_resource_user_id_, Sink::StreamType type_) {
if (stream) {
Finalize();
@@ -37,6 +39,7 @@ Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_for
channel_count = channel_count_;
session_id = session_id_;
handle = handle_;
handle->Open();
applet_resource_user_id = applet_resource_user_id_;
if (type == Sink::StreamType::In) {
@@ -55,6 +58,11 @@ void DeviceSession::Finalize() {
sink->CloseStream(stream);
stream = nullptr;
}
if (handle) {
handle->Close();
handle = nullptr;
}
}
void DeviceSession::Start() {
@@ -92,7 +100,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) {
stream->AppendBuffer(new_buffer, tmp_samples);
} else {
Core::Memory::CpuGuestMemory<s16, Core::Memory::GuestMemoryFlags::UnsafeRead> samples(
system.ApplicationMemory(), buffer.samples, buffer.size / sizeof(s16));
handle->GetMemory(), buffer.samples, buffer.size / sizeof(s16));
stream->AppendBuffer(new_buffer, samples);
}
}
@@ -101,7 +109,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) {
void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const {
if (type == Sink::StreamType::In) {
auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))};
system.ApplicationMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size);
handle->GetMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size);
}
}

View File

@@ -20,6 +20,10 @@ struct EventType;
} // namespace Timing
} // namespace Core
namespace Kernel {
class KProcess;
} // namespace Kernel
namespace AudioCore {
namespace Sink {
@@ -44,13 +48,13 @@ public:
* @param sample_format - Sample format for this device's output.
* @param channel_count - Number of channels for this device (2 or 6).
* @param session_id - This session's id.
* @param handle - Handle for this device session (unused).
* @param handle - Process handle for this device session.
* @param applet_resource_user_id - Applet resource user id for this device session (unused).
* @param type - Type of this stream (Render, In, Out).
* @return Result code for this call.
*/
Result Initialize(std::string_view name, SampleFormat sample_format, u16 channel_count,
size_t session_id, u32 handle, u64 applet_resource_user_id,
size_t session_id, Kernel::KProcess* handle, u64 applet_resource_user_id,
Sink::StreamType type);
/**
@@ -137,8 +141,8 @@ private:
u16 channel_count{};
/// Session id of this device session
size_t session_id{};
/// Handle of this device session
u32 handle{};
/// Process handle of device memory owner
Kernel::KProcess* handle{};
/// Applet resource user id of this device session
u64 applet_resource_user_id{};
/// Total number of samples played by this device session

View File

@@ -57,7 +57,7 @@ Result System::IsConfigValid(const std::string_view device_name,
}
Result System::Initialize(std::string device_name, const AudioInParameter& in_params,
const u32 handle_, const u64 applet_resource_user_id_) {
Kernel::KProcess* handle_, const u64 applet_resource_user_id_) {
auto result{IsConfigValid(device_name, in_params)};
if (result.IsError()) {
return result;

View File

@@ -19,7 +19,8 @@ class System;
namespace Kernel {
class KEvent;
}
class KProcess;
} // namespace Kernel
namespace AudioCore::AudioIn {
@@ -93,12 +94,12 @@ public:
*
* @param device_name - The name of the requested input device.
* @param in_params - Input parameters, see AudioInParameter.
* @param handle - Unused.
* @param handle - Process handle.
* @param applet_resource_user_id - Unused.
* @return Result code.
*/
Result Initialize(std::string device_name, const AudioInParameter& in_params, u32 handle,
u64 applet_resource_user_id);
Result Initialize(std::string device_name, const AudioInParameter& in_params,
Kernel::KProcess* handle, u64 applet_resource_user_id);
/**
* Start this system.
@@ -244,8 +245,8 @@ public:
private:
/// Core system
Core::System& system;
/// (Unused)
u32 handle{};
/// Process handle
Kernel::KProcess* handle{};
/// (Unused)
u64 applet_resource_user_id{};
/// Buffer event, signalled when a buffer is ready

View File

@@ -48,8 +48,8 @@ Result System::IsConfigValid(std::string_view device_name,
return Service::Audio::ResultInvalidChannelCount;
}
Result System::Initialize(std::string device_name, const AudioOutParameter& in_params, u32 handle_,
u64 applet_resource_user_id_) {
Result System::Initialize(std::string device_name, const AudioOutParameter& in_params,
Kernel::KProcess* handle_, u64 applet_resource_user_id_) {
auto result = IsConfigValid(device_name, in_params);
if (result.IsError()) {
return result;

View File

@@ -19,7 +19,8 @@ class System;
namespace Kernel {
class KEvent;
}
class KProcess;
} // namespace Kernel
namespace AudioCore::AudioOut {
@@ -84,12 +85,12 @@ public:
*
* @param device_name - The name of the requested output device.
* @param in_params - Input parameters, see AudioOutParameter.
* @param handle - Unused.
* @param handle - Process handle.
* @param applet_resource_user_id - Unused.
* @return Result code.
*/
Result Initialize(std::string device_name, const AudioOutParameter& in_params, u32 handle,
u64 applet_resource_user_id);
Result Initialize(std::string device_name, const AudioOutParameter& in_params,
Kernel::KProcess* handle, u64 applet_resource_user_id);
/**
* Start this system.
@@ -228,8 +229,8 @@ public:
private:
/// Core system
Core::System& system;
/// (Unused)
u32 handle{};
/// Process handle
Kernel::KProcess* handle{};
/// (Unused)
u64 applet_resource_user_id{};
/// Buffer event, signalled when a buffer is ready

View File

@@ -22,14 +22,10 @@ using NativeExecutionParameters = Kernel::KThread::NativeExecutionParameters;
constexpr size_t MaxRelativeBranch = 128_MiB;
constexpr u32 ModuleCodeIndex = 0x24 / sizeof(u32);
Patcher::Patcher() : c(m_patch_instructions) {}
Patcher::~Patcher() = default;
void Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
const Kernel::CodeSet::Segment& code) {
// Branch to the first instruction of the module.
this->BranchToModule(0);
Patcher::Patcher() : c(m_patch_instructions) {
// The first word of the patch section is always a branch to the first instruction of the
// module.
c.dw(0);
// Write save context helper function.
c.l(m_save_context);
@@ -38,6 +34,25 @@ void Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
// Write load context helper function.
c.l(m_load_context);
WriteLoadContext();
}
Patcher::~Patcher() = default;
bool Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
const Kernel::CodeSet::Segment& code) {
// If we have patched modules but cannot reach the new module, then it needs its own patcher.
const size_t image_size = program_image.size();
if (total_program_size + image_size > MaxRelativeBranch && total_program_size > 0) {
return false;
}
// Add a new module patch to our list
modules.emplace_back();
curr_patch = &modules.back();
// The first word of the patch section is always a branch to the first instruction of the
// module.
curr_patch->m_branch_to_module_relocations.push_back({0, 0});
// Retrieve text segment data.
const auto text = std::span{program_image}.subspan(code.offset, code.size);
@@ -94,16 +109,17 @@ void Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
}
if (auto exclusive = Exclusive{inst}; exclusive.Verify()) {
m_exclusives.push_back(i);
curr_patch->m_exclusives.push_back(i);
}
}
// Determine patching mode for the final relocation step
const size_t image_size = program_image.size();
total_program_size += image_size;
this->mode = image_size > MaxRelativeBranch ? PatchMode::PreText : PatchMode::PostData;
return true;
}
void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
bool Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
const Kernel::CodeSet::Segment& code,
Kernel::PhysicalMemory& program_image,
EntryTrampolines* out_trampolines) {
@@ -120,7 +136,7 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
if (mode == PatchMode::PreText) {
rc.B(rel.patch_offset - patch_size - rel.module_offset);
} else {
rc.B(image_size - rel.module_offset + rel.patch_offset);
rc.B(total_program_size - rel.module_offset + rel.patch_offset);
}
};
@@ -129,7 +145,7 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
if (mode == PatchMode::PreText) {
rc.B(patch_size - rel.patch_offset + rel.module_offset);
} else {
rc.B(rel.module_offset - image_size - rel.patch_offset);
rc.B(rel.module_offset - total_program_size - rel.patch_offset);
}
};
@@ -137,7 +153,7 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
if (mode == PatchMode::PreText) {
return GetInteger(load_base) + patch_offset;
} else {
return GetInteger(load_base) + image_size + patch_offset;
return GetInteger(load_base) + total_program_size + patch_offset;
}
};
@@ -150,39 +166,50 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
};
// We are now ready to relocate!
for (const Relocation& rel : m_branch_to_patch_relocations) {
auto& patch = modules[m_relocate_module_index++];
for (const Relocation& rel : patch.m_branch_to_patch_relocations) {
ApplyBranchToPatchRelocation(text_words.data() + rel.module_offset / sizeof(u32), rel);
}
for (const Relocation& rel : m_branch_to_module_relocations) {
for (const Relocation& rel : patch.m_branch_to_module_relocations) {
ApplyBranchToModuleRelocation(m_patch_instructions.data() + rel.patch_offset / sizeof(u32),
rel);
}
// Rewrite PC constants and record post trampolines
for (const Relocation& rel : m_write_module_pc_relocations) {
for (const Relocation& rel : patch.m_write_module_pc_relocations) {
oaknut::CodeGenerator rc{m_patch_instructions.data() + rel.patch_offset / sizeof(u32)};
rc.dx(RebasePc(rel.module_offset));
}
for (const Trampoline& rel : m_trampolines) {
for (const Trampoline& rel : patch.m_trampolines) {
out_trampolines->insert({RebasePc(rel.module_offset), RebasePatch(rel.patch_offset)});
}
// Cortex-A57 seems to treat all exclusives as ordered, but newer processors do not.
// Convert to ordered to preserve this assumption.
for (const ModuleTextAddress i : m_exclusives) {
for (const ModuleTextAddress i : patch.m_exclusives) {
auto exclusive = Exclusive{text_words[i]};
text_words[i] = exclusive.AsOrdered();
}
// Copy to program image
if (this->mode == PatchMode::PreText) {
std::memcpy(program_image.data(), m_patch_instructions.data(),
m_patch_instructions.size() * sizeof(u32));
} else {
program_image.resize(image_size + patch_size);
std::memcpy(program_image.data() + image_size, m_patch_instructions.data(),
m_patch_instructions.size() * sizeof(u32));
// Remove the patched module size from the total. This is done so total_program_size
// always represents the distance from the currently patched module to the patch section.
total_program_size -= image_size;
// Only copy to the program image of the last module
if (m_relocate_module_index == modules.size()) {
if (this->mode == PatchMode::PreText) {
ASSERT(image_size == total_program_size);
std::memcpy(program_image.data(), m_patch_instructions.data(),
m_patch_instructions.size() * sizeof(u32));
} else {
program_image.resize(image_size + patch_size);
std::memcpy(program_image.data() + image_size, m_patch_instructions.data(),
m_patch_instructions.size() * sizeof(u32));
}
return true;
}
return false;
}
size_t Patcher::GetSectionSize() const noexcept {
@@ -322,7 +349,7 @@ void Patcher::WriteSvcTrampoline(ModuleDestLabel module_dest, u32 svc_id) {
// Write the post-SVC trampoline address, which will jump back to the guest after restoring its
// state.
m_trampolines.push_back({c.offset(), module_dest});
curr_patch->m_trampolines.push_back({c.offset(), module_dest});
// Host called this location. Save the return address so we can
// unwind the stack properly when jumping back.

View File

@@ -31,9 +31,9 @@ public:
explicit Patcher();
~Patcher();
void PatchText(const Kernel::PhysicalMemory& program_image,
bool PatchText(const Kernel::PhysicalMemory& program_image,
const Kernel::CodeSet::Segment& code);
void RelocateAndCopy(Common::ProcessAddress load_base, const Kernel::CodeSet::Segment& code,
bool RelocateAndCopy(Common::ProcessAddress load_base, const Kernel::CodeSet::Segment& code,
Kernel::PhysicalMemory& program_image, EntryTrampolines* out_trampolines);
size_t GetSectionSize() const noexcept;
@@ -61,16 +61,16 @@ private:
private:
void BranchToPatch(uintptr_t module_dest) {
m_branch_to_patch_relocations.push_back({c.offset(), module_dest});
curr_patch->m_branch_to_patch_relocations.push_back({c.offset(), module_dest});
}
void BranchToModule(uintptr_t module_dest) {
m_branch_to_module_relocations.push_back({c.offset(), module_dest});
curr_patch->m_branch_to_module_relocations.push_back({c.offset(), module_dest});
c.dw(0);
}
void WriteModulePc(uintptr_t module_dest) {
m_write_module_pc_relocations.push_back({c.offset(), module_dest});
curr_patch->m_write_module_pc_relocations.push_back({c.offset(), module_dest});
c.dx(0);
}
@@ -84,15 +84,22 @@ private:
uintptr_t module_offset; ///< Offset in bytes from the start of the text section.
};
struct ModulePatch {
std::vector<Trampoline> m_trampolines;
std::vector<Relocation> m_branch_to_patch_relocations{};
std::vector<Relocation> m_branch_to_module_relocations{};
std::vector<Relocation> m_write_module_pc_relocations{};
std::vector<ModuleTextAddress> m_exclusives{};
};
oaknut::VectorCodeGenerator c;
std::vector<Trampoline> m_trampolines;
std::vector<Relocation> m_branch_to_patch_relocations{};
std::vector<Relocation> m_branch_to_module_relocations{};
std::vector<Relocation> m_write_module_pc_relocations{};
std::vector<ModuleTextAddress> m_exclusives{};
oaknut::Label m_save_context{};
oaknut::Label m_load_context{};
PatchMode mode{PatchMode::None};
size_t total_program_size{};
size_t m_relocate_module_index{};
std::vector<ModulePatch> modules;
ModulePatch* curr_patch;
};
} // namespace Core::NCE

View File

@@ -47,7 +47,7 @@ void DefaultControllerApplet::ReconfigureControllers(ReconfigureCallback callbac
// Connect controllers based on the following priority list from highest to lowest priority:
// Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
if (parameters.allow_pro_controller) {
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
controller->Connect(true);
} else if (parameters.allow_dual_joycons) {
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconDual);

View File

@@ -28,14 +28,14 @@ Result KMemoryBlockManager::Initialize(KProcessAddress st, KProcessAddress nd,
}
void KMemoryBlockManager::Finalize(KMemoryBlockSlabManager* slab_manager,
HostUnmapCallback&& host_unmap_callback) {
BlockCallback&& block_callback) {
// Erase every block until we have none left.
auto it = m_memory_block_tree.begin();
while (it != m_memory_block_tree.end()) {
KMemoryBlock* block = std::addressof(*it);
it = m_memory_block_tree.erase(it);
block_callback(block->GetAddress(), block->GetSize());
slab_manager->Free(block);
host_unmap_callback(block->GetAddress(), block->GetSize());
}
ASSERT(m_memory_block_tree.empty());

View File

@@ -85,11 +85,11 @@ public:
public:
KMemoryBlockManager();
using HostUnmapCallback = std::function<void(Common::ProcessAddress, u64)>;
using BlockCallback = std::function<void(Common::ProcessAddress, u64)>;
Result Initialize(KProcessAddress st, KProcessAddress nd,
KMemoryBlockSlabManager* slab_manager);
void Finalize(KMemoryBlockSlabManager* slab_manager, HostUnmapCallback&& host_unmap_callback);
void Finalize(KMemoryBlockSlabManager* slab_manager, BlockCallback&& block_callback);
iterator end() {
return m_memory_block_tree.end();

View File

@@ -435,69 +435,14 @@ Result KPageTableBase::FinalizeProcess() {
// Only process tables should be finalized.
ASSERT(!this->IsKernel());
// HLE processes don't have memory mapped.
R_SUCCEED_IF(m_impl == nullptr);
// NOTE: Here Nintendo calls an unknown OnFinalize function.
// this->OnFinalize();
// NOTE: Here Nintendo calls a second unknown OnFinalize function.
// this->OnFinalize2();
// Get implementation objects.
auto& impl = this->GetImpl();
auto& mm = m_kernel.MemoryManager();
// Traverse, freeing all pages.
{
// Get the address space size.
const size_t as_size = this->GetAddressSpaceSize();
// Begin the traversal.
TraversalContext context;
TraversalEntry cur_entry = {
.phys_addr = 0,
.block_size = 0,
};
bool cur_valid = false;
TraversalEntry next_entry;
bool next_valid;
size_t tot_size = 0;
next_valid = impl.BeginTraversal(std::addressof(next_entry), std::addressof(context),
this->GetAddressSpaceStart());
// Iterate over entries.
while (true) {
if ((!next_valid && !cur_valid) ||
(next_valid && cur_valid &&
next_entry.phys_addr == cur_entry.phys_addr + cur_entry.block_size)) {
cur_entry.block_size += next_entry.block_size;
} else {
if (cur_valid && IsHeapPhysicalAddressForFinalize(cur_entry.phys_addr)) {
mm.Close(cur_entry.phys_addr, cur_entry.block_size / PageSize);
}
// Update tracking variables.
tot_size += cur_entry.block_size;
cur_entry = next_entry;
cur_valid = next_valid;
}
if (cur_entry.block_size + tot_size >= as_size) {
break;
}
next_valid =
impl.ContinueTraversal(std::addressof(next_entry), std::addressof(context));
}
// Handle the last block.
if (cur_valid && IsHeapPhysicalAddressForFinalize(cur_entry.phys_addr)) {
mm.Close(cur_entry.phys_addr, cur_entry.block_size / PageSize);
}
}
// NOTE: Here Nintendo does a page table walk to discover heap pages to free.
// We will use the block manager finalization below to free them.
R_SUCCEED();
}
@@ -505,14 +450,24 @@ Result KPageTableBase::FinalizeProcess() {
void KPageTableBase::Finalize() {
this->FinalizeProcess();
auto HostUnmapCallback = [&](KProcessAddress addr, u64 size) {
auto BlockCallback = [&](KProcessAddress addr, u64 size) {
if (m_impl->fastmem_arena) {
m_system.DeviceMemory().buffer.Unmap(GetInteger(addr), size, false);
}
// Get physical pages.
KPageGroup pg(m_kernel, m_block_info_manager);
this->MakePageGroup(pg, addr, size / PageSize);
// Free the pages.
pg.CloseAndReset();
};
// Finalize memory blocks.
m_memory_block_manager.Finalize(m_memory_block_slab_manager, std::move(HostUnmapCallback));
{
KScopedLightLock lk(m_general_lock);
m_memory_block_manager.Finalize(m_memory_block_slab_manager, std::move(BlockCallback));
}
// Free any unsafe mapped memory.
if (m_mapped_unsafe_physical_memory) {

View File

@@ -1239,10 +1239,10 @@ void KProcess::LoadModule(CodeSet code_set, KProcessAddress base_addr) {
ReprotectSegment(code_set.DataSegment(), Svc::MemoryPermission::ReadWrite);
#ifdef HAS_NCE
if (this->IsApplication() && Settings::IsNceEnabled()) {
const auto& patch = code_set.PatchSegment();
if (this->IsApplication() && Settings::IsNceEnabled() && patch.size != 0) {
auto& buffer = m_kernel.System().DeviceMemory().buffer;
const auto& code = code_set.CodeSegment();
const auto& patch = code_set.PatchSegment();
buffer.Protect(GetInteger(base_addr + code.addr), code.size,
Common::MemoryPermission::Read | Common::MemoryPermission::Execute);
buffer.Protect(GetInteger(base_addr + patch.addr), patch.size,

View File

@@ -112,7 +112,14 @@ struct KernelCore::Impl {
old_process->Close();
}
process_list.clear();
{
std::scoped_lock lk{process_list_lock};
for (auto* const process : process_list) {
process->Terminate();
process->Close();
}
process_list.clear();
}
next_object_id = 0;
next_kernel_process_id = KProcess::InitialProcessIdMin;

View File

@@ -61,9 +61,7 @@ ProfileManager::ProfileManager() {
OpenUser(*GetUser(current));
}
ProfileManager::~ProfileManager() {
WriteUserSaveFile();
}
ProfileManager::~ProfileManager() = default;
/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the
/// internal management of the users profiles
@@ -113,6 +111,8 @@ Result ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& username)
return ERROR_USER_ALREADY_EXISTS;
}
is_save_needed = true;
return AddUser({
.user_uuid = uuid,
.username = username,
@@ -326,6 +326,9 @@ bool ProfileManager::RemoveUser(UUID uuid) {
profiles[*index] = ProfileInfo{};
std::stable_partition(profiles.begin(), profiles.end(),
[](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); });
is_save_needed = true;
return true;
}
@@ -340,6 +343,8 @@ bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
profile.username = profile_new.username;
profile.creation_time = profile_new.timestamp;
is_save_needed = true;
return true;
}
@@ -348,6 +353,7 @@ bool ProfileManager::SetProfileBaseAndData(Common::UUID uuid, const ProfileBase&
const auto index = GetUserIndex(uuid);
if (index.has_value() && SetProfileBase(uuid, profile_new)) {
profiles[*index].data = data_new;
is_save_needed = true;
return true;
}
@@ -391,6 +397,10 @@ void ProfileManager::ParseUserSaveFile() {
}
void ProfileManager::WriteUserSaveFile() {
if (!is_save_needed) {
return;
}
ProfileDataRaw raw{};
for (std::size_t i = 0; i < MAX_USERS; ++i) {
@@ -423,7 +433,10 @@ void ProfileManager::WriteUserSaveFile() {
if (!save.IsOpen() || !save.SetSize(sizeof(ProfileDataRaw)) || !save.WriteObject(raw)) {
LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data "
"made in current session will be saved.");
return;
}
is_save_needed = false;
}
}; // namespace Service::Account

View File

@@ -103,6 +103,7 @@ private:
std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
bool RemoveProfileAtIndex(std::size_t index);
bool is_save_needed{};
std::array<ProfileInfo, MAX_USERS> profiles{};
std::array<ProfileInfo, MAX_USERS> stored_opened_profiles{};
std::size_t user_count{};

View File

@@ -18,11 +18,11 @@ using namespace AudioCore::AudioIn;
class IAudioIn final : public ServiceFramework<IAudioIn> {
public:
explicit IAudioIn(Core::System& system_, Manager& manager, size_t session_id,
const std::string& device_name, const AudioInParameter& in_params, u32 handle,
u64 applet_resource_user_id)
const std::string& device_name, const AudioInParameter& in_params,
Kernel::KProcess* handle, u64 applet_resource_user_id)
: ServiceFramework{system_, "IAudioIn"},
service_context{system_, "IAudioIn"}, event{service_context.CreateEvent("AudioInEvent")},
impl{std::make_shared<In>(system_, manager, event, session_id)} {
process{handle}, impl{std::make_shared<In>(system_, manager, event, session_id)} {
// clang-format off
static const FunctionInfo functions[] = {
{0, &IAudioIn::GetAudioInState, "GetAudioInState"},
@@ -45,6 +45,8 @@ public:
RegisterHandlers(functions);
process->Open();
if (impl->GetSystem()
.Initialize(device_name, in_params, handle, applet_resource_user_id)
.IsError()) {
@@ -55,6 +57,7 @@ public:
~IAudioIn() override {
impl->Free();
service_context.CloseEvent(event);
process->Close();
}
[[nodiscard]] std::shared_ptr<In> GetImpl() {
@@ -196,6 +199,7 @@ private:
KernelHelpers::ServiceContext service_context;
Kernel::KEvent* event;
Kernel::KProcess* process;
std::shared_ptr<AudioCore::AudioIn::In> impl;
Common::ScratchBuffer<u64> released_buffer;
};
@@ -267,6 +271,14 @@ void AudInU::OpenAudioIn(HLERequestContext& ctx) {
auto device_name = Common::StringFromBuffer(device_name_data);
auto handle{ctx.GetCopyHandle(0)};
auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(handle)};
if (process.IsNull()) {
LOG_ERROR(Service_Audio, "Failed to get process handle");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
return;
}
std::scoped_lock l{impl->mutex};
auto link{impl->LinkToManager()};
if (link.IsError()) {
@@ -287,8 +299,9 @@ void AudInU::OpenAudioIn(HLERequestContext& ctx) {
LOG_DEBUG(Service_Audio, "Opening new AudioIn, sessionid={}, free sessions={}", new_session_id,
impl->num_free_sessions);
auto audio_in = std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name,
in_params, handle, applet_resource_user_id);
auto audio_in =
std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, in_params,
process.GetPointerUnsafe(), applet_resource_user_id);
impl->sessions[new_session_id] = audio_in->GetImpl();
impl->applet_resource_user_ids[new_session_id] = applet_resource_user_id;
@@ -318,6 +331,14 @@ void AudInU::OpenAudioInProtocolSpecified(HLERequestContext& ctx) {
auto device_name = Common::StringFromBuffer(device_name_data);
auto handle{ctx.GetCopyHandle(0)};
auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(handle)};
if (process.IsNull()) {
LOG_ERROR(Service_Audio, "Failed to get process handle");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
return;
}
std::scoped_lock l{impl->mutex};
auto link{impl->LinkToManager()};
if (link.IsError()) {
@@ -338,8 +359,9 @@ void AudInU::OpenAudioInProtocolSpecified(HLERequestContext& ctx) {
LOG_DEBUG(Service_Audio, "Opening new AudioIn, sessionid={}, free sessions={}", new_session_id,
impl->num_free_sessions);
auto audio_in = std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name,
in_params, handle, applet_resource_user_id);
auto audio_in =
std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, in_params,
process.GetPointerUnsafe(), applet_resource_user_id);
impl->sessions[new_session_id] = audio_in->GetImpl();
impl->applet_resource_user_ids[new_session_id] = applet_resource_user_id;

View File

@@ -26,9 +26,10 @@ class IAudioOut final : public ServiceFramework<IAudioOut> {
public:
explicit IAudioOut(Core::System& system_, AudioCore::AudioOut::Manager& manager,
size_t session_id, const std::string& device_name,
const AudioOutParameter& in_params, u32 handle, u64 applet_resource_user_id)
const AudioOutParameter& in_params, Kernel::KProcess* handle,
u64 applet_resource_user_id)
: ServiceFramework{system_, "IAudioOut"}, service_context{system_, "IAudioOut"},
event{service_context.CreateEvent("AudioOutEvent")},
event{service_context.CreateEvent("AudioOutEvent")}, process{handle},
impl{std::make_shared<AudioCore::AudioOut::Out>(system_, manager, event, session_id)} {
// clang-format off
@@ -50,11 +51,14 @@ public:
};
// clang-format on
RegisterHandlers(functions);
process->Open();
}
~IAudioOut() override {
impl->Free();
service_context.CloseEvent(event);
process->Close();
}
[[nodiscard]] std::shared_ptr<AudioCore::AudioOut::Out> GetImpl() {
@@ -206,6 +210,7 @@ private:
KernelHelpers::ServiceContext service_context;
Kernel::KEvent* event;
Kernel::KProcess* process;
std::shared_ptr<AudioCore::AudioOut::Out> impl;
Common::ScratchBuffer<u64> released_buffer;
};
@@ -257,6 +262,14 @@ void AudOutU::OpenAudioOut(HLERequestContext& ctx) {
auto device_name = Common::StringFromBuffer(device_name_data);
auto handle{ctx.GetCopyHandle(0)};
auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(handle)};
if (process.IsNull()) {
LOG_ERROR(Service_Audio, "Failed to get process handle");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
return;
}
auto link{impl->LinkToManager()};
if (link.IsError()) {
LOG_ERROR(Service_Audio, "Failed to link Audio Out to Audio Manager");
@@ -276,10 +289,11 @@ void AudOutU::OpenAudioOut(HLERequestContext& ctx) {
LOG_DEBUG(Service_Audio, "Opening new AudioOut, sessionid={}, free sessions={}", new_session_id,
impl->num_free_sessions);
auto audio_out = std::make_shared<IAudioOut>(system, *impl, new_session_id, device_name,
in_params, handle, applet_resource_user_id);
result = audio_out->GetImpl()->GetSystem().Initialize(device_name, in_params, handle,
applet_resource_user_id);
auto audio_out =
std::make_shared<IAudioOut>(system, *impl, new_session_id, device_name, in_params,
process.GetPointerUnsafe(), applet_resource_user_id);
result = audio_out->GetImpl()->GetSystem().Initialize(
device_name, in_params, process.GetPointerUnsafe(), applet_resource_user_id);
if (result.IsError()) {
LOG_ERROR(Service_Audio, "Failed to initialize the AudioOut System!");
IPC::ResponseBuilder rb{ctx, 2};

View File

@@ -40,7 +40,7 @@ Result SaveDataController::CreateSaveData(FileSys::VirtualDir* out_save_data,
FileSys::SaveDataSpaceId space,
const FileSys::SaveDataAttribute& attribute) {
LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", space,
save_struct.DebugInfo());
attribute.DebugInfo());
auto save_data = factory->Create(space, attribute);
if (save_data == nullptr) {

View File

@@ -1498,7 +1498,7 @@ void IHidServer::GetVibrationDeviceInfo(HLERequestContext& ctx) {
bool check_device_index = false;
switch (vibration_device_handle.npad_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::Handheld:
case Core::HID::NpadStyleIndex::JoyconDual:
case Core::HID::NpadStyleIndex::JoyconLeft:

View File

@@ -19,8 +19,54 @@
#include "core/arm/nce/patcher.h"
#endif
#ifndef HAS_NCE
namespace Core::NCE {
class Patcher {};
} // namespace Core::NCE
#endif
namespace Loader {
struct PatchCollection {
explicit PatchCollection(bool is_application_) : is_application{is_application_} {
module_patcher_indices.fill(-1);
patchers.emplace_back();
}
std::vector<Core::NCE::Patcher>* GetPatchers() {
if (is_application && Settings::IsNceEnabled()) {
return &patchers;
}
return nullptr;
}
size_t GetTotalPatchSize() const {
size_t total_size{};
#ifdef HAS_NCE
for (auto& patcher : patchers) {
total_size += patcher.GetSectionSize();
}
#endif
return total_size;
}
void SaveIndex(size_t module) {
module_patcher_indices[module] = static_cast<s32>(patchers.size() - 1);
}
s32 GetIndex(size_t module) const {
return module_patcher_indices[module];
}
s32 GetLastIndex() const {
return static_cast<s32>(patchers.size()) - 1;
}
bool is_application;
std::vector<Core::NCE::Patcher> patchers;
std::array<s32, 13> module_patcher_indices{};
};
AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys::VirtualFile file_,
bool override_update_)
: AppLoader(std::move(file_)), override_update(override_update_), is_hbl(false) {
@@ -142,18 +188,7 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
std::size_t code_size{};
// Define an nce patch context for each potential module.
#ifdef HAS_NCE
std::array<Core::NCE::Patcher, 13> module_patchers;
#endif
const auto GetPatcher = [&](size_t i) -> Core::NCE::Patcher* {
#ifdef HAS_NCE
if (is_application && Settings::IsNceEnabled()) {
return &module_patchers[i];
}
#endif
return nullptr;
};
PatchCollection patch_ctx{is_application};
// Use the NSO module loader to figure out the code layout
for (size_t i = 0; i < static_modules.size(); i++) {
@@ -164,13 +199,14 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
}
const bool should_pass_arguments = std::strcmp(module, "rtld") == 0;
const auto tentative_next_load_addr =
AppLoader_NSO::LoadModule(process, system, *module_file, code_size,
should_pass_arguments, false, {}, GetPatcher(i));
const auto tentative_next_load_addr = AppLoader_NSO::LoadModule(
process, system, *module_file, code_size, should_pass_arguments, false, {},
patch_ctx.GetPatchers(), patch_ctx.GetLastIndex());
if (!tentative_next_load_addr) {
return {ResultStatus::ErrorLoadingNSO, {}};
}
patch_ctx.SaveIndex(i);
code_size = *tentative_next_load_addr;
}
@@ -184,6 +220,9 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
return 0;
}();
// Add patch size to the total module size
code_size += patch_ctx.GetTotalPatchSize();
// Setup the process code layout
if (process.LoadFromMetadata(metadata, code_size, fastmem_base, is_hbl).IsError()) {
return {ResultStatus::ErrorUnableToParseKernelMetadata, {}};
@@ -204,9 +243,9 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
const VAddr load_addr{next_load_addr};
const bool should_pass_arguments = std::strcmp(module, "rtld") == 0;
const auto tentative_next_load_addr =
AppLoader_NSO::LoadModule(process, system, *module_file, load_addr,
should_pass_arguments, true, pm, GetPatcher(i));
const auto tentative_next_load_addr = AppLoader_NSO::LoadModule(
process, system, *module_file, load_addr, should_pass_arguments, true, pm,
patch_ctx.GetPatchers(), patch_ctx.GetIndex(i));
if (!tentative_next_load_addr) {
return {ResultStatus::ErrorLoadingNSO, {}};
}

View File

@@ -275,12 +275,12 @@ AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::KProcess& process, Core::S
return {ResultStatus::ErrorLoadingNRO, {}};
}
if (romfs != nullptr) {
system.GetFileSystemController().RegisterProcess(
process.GetProcessId(), {},
std::make_unique<FileSys::RomFSFactory>(*this, system.GetContentProvider(),
system.GetFileSystemController()));
}
u64 program_id{};
ReadProgramId(program_id);
system.GetFileSystemController().RegisterProcess(
process.GetProcessId(), program_id,
std::make_unique<FileSys::RomFSFactory>(*this, system.GetContentProvider(),
system.GetFileSystemController()));
is_loaded = true;
return {ResultStatus::Success, LoadParameters{Kernel::KThread::DefaultThreadPriority,

View File

@@ -77,7 +77,8 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core::
const FileSys::VfsFile& nso_file, VAddr load_base,
bool should_pass_arguments, bool load_into_process,
std::optional<FileSys::PatchManager> pm,
Core::NCE::Patcher* patch) {
std::vector<Core::NCE::Patcher>* patches,
s32 patch_index) {
if (nso_file.GetSize() < sizeof(NSOHeader)) {
return std::nullopt;
}
@@ -94,8 +95,11 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core::
// Allocate some space at the beginning if we are patching in PreText mode.
const size_t module_start = [&]() -> size_t {
#ifdef HAS_NCE
if (patch && patch->GetPatchMode() == Core::NCE::PatchMode::PreText) {
return patch->GetSectionSize();
if (patches && load_into_process) {
auto* patch = &patches->operator[](patch_index);
if (patch->GetPatchMode() == Core::NCE::PatchMode::PreText) {
return patch->GetSectionSize();
}
}
#endif
return 0;
@@ -160,27 +164,24 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core::
#ifdef HAS_NCE
// If we are computing the process code layout and using nce backend, patch.
const auto& code = codeset.CodeSegment();
if (patch && patch->GetPatchMode() == Core::NCE::PatchMode::None) {
auto* patch = patches ? &patches->operator[](patch_index) : nullptr;
if (patch && !load_into_process) {
// Patch SVCs and MRS calls in the guest code
patch->PatchText(program_image, code);
// Add patch section size to the module size.
image_size += static_cast<u32>(patch->GetSectionSize());
while (!patch->PatchText(program_image, code)) {
patch = &patches->emplace_back();
}
} else if (patch) {
// Relocate code patch and copy to the program_image.
patch->RelocateAndCopy(load_base, code, program_image, &process.GetPostHandlers());
// Update patch section.
auto& patch_segment = codeset.PatchSegment();
patch_segment.addr =
patch->GetPatchMode() == Core::NCE::PatchMode::PreText ? 0 : image_size;
patch_segment.size = static_cast<u32>(patch->GetSectionSize());
// Add patch section size to the module size. In PreText mode image_size
// already contains the patch segment as part of module_start.
if (patch->GetPatchMode() == Core::NCE::PatchMode::PostData) {
image_size += patch_segment.size;
if (patch->RelocateAndCopy(load_base, code, program_image, &process.GetPostHandlers())) {
// Update patch section.
auto& patch_segment = codeset.PatchSegment();
patch_segment.addr =
patch->GetPatchMode() == Core::NCE::PatchMode::PreText ? 0 : image_size;
patch_segment.size = static_cast<u32>(patch->GetSectionSize());
}
// Refresh image_size to take account the patch section if it was added by RelocateAndCopy
image_size = static_cast<u32>(program_image.size());
}
#endif

View File

@@ -93,7 +93,8 @@ public:
const FileSys::VfsFile& nso_file, VAddr load_base,
bool should_pass_arguments, bool load_into_process,
std::optional<FileSys::PatchManager> pm = {},
Core::NCE::Patcher* patch = nullptr);
std::vector<Core::NCE::Patcher>* patches = nullptr,
s32 patch_index = -1);
LoadResult Load(Kernel::KProcess& process, Core::System& system) override;

View File

@@ -36,6 +36,30 @@ add_library(hid_core STATIC
irsensor/processor_base.h
irsensor/tera_plugin_processor.cpp
irsensor/tera_plugin_processor.h
resources/abstracted_pad/abstract_battery_handler.cpp
resources/abstracted_pad/abstract_battery_handler.h
resources/abstracted_pad/abstract_button_handler.cpp
resources/abstracted_pad/abstract_button_handler.h
resources/abstracted_pad/abstract_ir_sensor_handler.cpp
resources/abstracted_pad/abstract_ir_sensor_handler.h
resources/abstracted_pad/abstract_led_handler.cpp
resources/abstracted_pad/abstract_led_handler.h
resources/abstracted_pad/abstract_mcu_handler.cpp
resources/abstracted_pad/abstract_mcu_handler.h
resources/abstracted_pad/abstract_nfc_handler.cpp
resources/abstracted_pad/abstract_nfc_handler.h
resources/abstracted_pad/abstract_pad.cpp
resources/abstracted_pad/abstract_pad.h
resources/abstracted_pad/abstract_pad_holder.cpp
resources/abstracted_pad/abstract_pad_holder.h
resources/abstracted_pad/abstract_palma_handler.cpp
resources/abstracted_pad/abstract_palma_handler.h
resources/abstracted_pad/abstract_properties_handler.cpp
resources/abstracted_pad/abstract_properties_handler.h
resources/abstracted_pad/abstract_sixaxis_handler.cpp
resources/abstracted_pad/abstract_sixaxis_handler.h
resources/abstracted_pad/abstract_vibration_handler.cpp
resources/abstracted_pad/abstract_vibration_handler.h
resources/debug_pad/debug_pad.cpp
resources/debug_pad/debug_pad.h
resources/debug_pad/debug_pad_types.h
@@ -56,6 +80,8 @@ add_library(hid_core STATIC
resources/npad/npad_resource.cpp
resources/npad/npad_resource.h
resources/npad/npad_types.h
resources/npad/npad_vibration.cpp
resources/npad/npad_vibration.h
resources/palma/palma.cpp
resources/palma/palma.h
resources/six_axis/console_six_axis.cpp
@@ -78,6 +104,14 @@ add_library(hid_core STATIC
resources/touch_screen/touch_types.h
resources/unique_pad/unique_pad.cpp
resources/unique_pad/unique_pad.h
resources/vibration/gc_vibration_device.h
resources/vibration/gc_vibration_device.cpp
resources/vibration/n64_vibration_device.h
resources/vibration/n64_vibration_device.cpp
resources/vibration/vibration_base.h
resources/vibration/vibration_base.cpp
resources/vibration/vibration_device.h
resources/vibration/vibration_device.cpp
resources/applet_resource.cpp
resources/applet_resource.h
resources/controller_base.cpp

View File

@@ -27,7 +27,7 @@ EmulatedController::~EmulatedController() = default;
NpadStyleIndex EmulatedController::MapSettingsTypeToNPad(Settings::ControllerType type) {
switch (type) {
case Settings::ControllerType::ProController:
return NpadStyleIndex::ProController;
return NpadStyleIndex::Fullkey;
case Settings::ControllerType::DualJoyconDetached:
return NpadStyleIndex::JoyconDual;
case Settings::ControllerType::LeftJoycon:
@@ -49,13 +49,13 @@ NpadStyleIndex EmulatedController::MapSettingsTypeToNPad(Settings::ControllerTyp
case Settings::ControllerType::SegaGenesis:
return NpadStyleIndex::SegaGenesis;
default:
return NpadStyleIndex::ProController;
return NpadStyleIndex::Fullkey;
}
}
Settings::ControllerType EmulatedController::MapNPadToSettingsType(NpadStyleIndex type) {
switch (type) {
case NpadStyleIndex::ProController:
case NpadStyleIndex::Fullkey:
return Settings::ControllerType::ProController;
case NpadStyleIndex::JoyconDual:
return Settings::ControllerType::DualJoyconDetached;
@@ -106,7 +106,7 @@ void EmulatedController::ReloadFromSettings() {
SetNpadStyleIndex(MapSettingsTypeToNPad(player.controller_type));
original_npad_type = npad_type;
} else {
SetNpadStyleIndex(NpadStyleIndex::ProController);
SetNpadStyleIndex(NpadStyleIndex::Fullkey);
original_npad_type = npad_type;
}
@@ -1073,7 +1073,7 @@ void EmulatedController::SetColors(const Common::Input::CallbackStatus& callback
.body = GetNpadColor(controller.color_values[index].body),
.button = GetNpadColor(controller.color_values[index].buttons),
};
if (npad_type == NpadStyleIndex::ProController) {
if (npad_type == NpadStyleIndex::Fullkey) {
controller.colors_state.left = {
.body = GetNpadColor(controller.color_values[index].left_grip),
.button = GetNpadColor(controller.color_values[index].buttons),
@@ -1356,7 +1356,7 @@ bool EmulatedController::HasNfc() const {
switch (npad_type) {
case NpadStyleIndex::JoyconRight:
case NpadStyleIndex::JoyconDual:
case NpadStyleIndex::ProController:
case NpadStyleIndex::Fullkey:
case NpadStyleIndex::Handheld:
break;
default:
@@ -1548,7 +1548,7 @@ void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles)
// Fallback Fullkey controllers to Pro controllers
if (IsControllerFullkey() && supported_style_tag.fullkey) {
LOG_WARNING(Service_HID, "Reconnecting controller type {} as Pro controller", npad_type);
SetNpadStyleIndex(NpadStyleIndex::ProController);
SetNpadStyleIndex(NpadStyleIndex::Fullkey);
Connect();
return;
}
@@ -1556,13 +1556,13 @@ void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles)
// Fallback Dual joycon controllers to Pro controllers
if (npad_type == NpadStyleIndex::JoyconDual && supported_style_tag.fullkey) {
LOG_WARNING(Service_HID, "Reconnecting controller type {} as Pro controller", npad_type);
SetNpadStyleIndex(NpadStyleIndex::ProController);
SetNpadStyleIndex(NpadStyleIndex::Fullkey);
Connect();
return;
}
// Fallback Pro controllers to Dual joycon
if (npad_type == NpadStyleIndex::ProController && supported_style_tag.joycon_dual) {
if (npad_type == NpadStyleIndex::Fullkey && supported_style_tag.joycon_dual) {
LOG_WARNING(Service_HID, "Reconnecting controller type {} as Dual Joycons", npad_type);
SetNpadStyleIndex(NpadStyleIndex::JoyconDual);
Connect();
@@ -1577,7 +1577,7 @@ bool EmulatedController::IsControllerFullkey(bool use_temporary_value) const {
std::scoped_lock lock{mutex};
const auto type = is_configuring && use_temporary_value ? tmp_npad_type : npad_type;
switch (type) {
case NpadStyleIndex::ProController:
case NpadStyleIndex::Fullkey:
case NpadStyleIndex::GameCube:
case NpadStyleIndex::NES:
case NpadStyleIndex::SNES:
@@ -1593,7 +1593,7 @@ bool EmulatedController::IsControllerSupported(bool use_temporary_value) const {
std::scoped_lock lock{mutex};
const auto type = is_configuring && use_temporary_value ? tmp_npad_type : npad_type;
switch (type) {
case NpadStyleIndex::ProController:
case NpadStyleIndex::Fullkey:
return supported_style_tag.fullkey.As<bool>();
case NpadStyleIndex::Handheld:
return supported_style_tag.handheld.As<bool>();

View File

@@ -220,6 +220,7 @@ enum class NpadIdType : u32 {
};
enum class NpadInterfaceType : u8 {
None = 0,
Bluetooth = 1,
Rail = 2,
Usb = 3,
@@ -229,7 +230,7 @@ enum class NpadInterfaceType : u8 {
// This is nn::hid::NpadStyleIndex
enum class NpadStyleIndex : u8 {
None = 0,
ProController = 3,
Fullkey = 3,
Handheld = 4,
HandheldNES = 4,
JoyconDual = 5,

View File

@@ -42,7 +42,7 @@ constexpr Result IsSixaxisHandleValid(const Core::HID::SixAxisSensorHandle& hand
constexpr Result IsVibrationHandleValid(const Core::HID::VibrationDeviceHandle& handle) {
switch (handle.npad_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::Handheld:
case Core::HID::NpadStyleIndex::JoyconDual:
case Core::HID::NpadStyleIndex::JoyconLeft:

View File

@@ -0,0 +1,197 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/core_timing.h"
#include "hid_core/hid_result.h"
#include "hid_core/hid_util.h"
#include "hid_core/resources/abstracted_pad/abstract_battery_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
NpadAbstractBatteryHandler::NpadAbstractBatteryHandler() {}
NpadAbstractBatteryHandler::~NpadAbstractBatteryHandler() = default;
void NpadAbstractBatteryHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractBatteryHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
applet_resource_holder = applet_resource;
}
void NpadAbstractBatteryHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
Result NpadAbstractBatteryHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractBatteryHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
Result NpadAbstractBatteryHandler::UpdateBatteryState(u64 aruid) {
const auto npad_index = NpadIdTypeToIndex(properties_handler->GetNpadId());
AruidData* aruid_data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (aruid_data == nullptr) {
return ResultSuccess;
}
auto& npad_internal_state =
aruid_data->shared_memory_format->npad.npad_entry[npad_index].internal_state;
auto& system_properties = npad_internal_state.system_properties;
system_properties.is_charging_joy_dual.Assign(dual_battery.is_charging);
system_properties.is_powered_joy_dual.Assign(dual_battery.is_powered);
system_properties.is_charging_joy_left.Assign(left_battery.is_charging);
system_properties.is_powered_joy_left.Assign(left_battery.is_powered);
system_properties.is_charging_joy_right.Assign(right_battery.is_charging);
system_properties.is_powered_joy_right.Assign(right_battery.is_powered);
npad_internal_state.battery_level_dual = dual_battery.battery_level;
npad_internal_state.battery_level_left = left_battery.battery_level;
npad_internal_state.battery_level_right = right_battery.battery_level;
return ResultSuccess;
}
void NpadAbstractBatteryHandler::UpdateBatteryState() {
if (ref_counter == 0) {
return;
}
has_new_battery_data = GetNewBatteryState();
}
bool NpadAbstractBatteryHandler::GetNewBatteryState() {
bool has_changed = false;
Core::HID::NpadPowerInfo new_dual_battery_state{};
Core::HID::NpadPowerInfo new_left_battery_state{};
Core::HID::NpadPowerInfo new_right_battery_state{};
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
const auto power_info = abstract_pad->power_info;
if (power_info.battery_level > Core::HID::NpadBatteryLevel::Full) {
// Abort
continue;
}
const auto style = abstract_pad->assignment_style;
if (style.is_external_assigned || style.is_handheld_assigned) {
new_dual_battery_state = power_info;
}
if (style.is_external_left_assigned || style.is_handheld_left_assigned) {
new_left_battery_state = power_info;
}
if (style.is_external_right_assigned || style.is_handheld_right_assigned) {
new_right_battery_state = power_info;
}
if (abstract_pad->internal_flags.is_battery_low_ovln_required) {
if (abstract_pad->interface_type == Core::HID::NpadInterfaceType::Rail) {
// TODO
}
abstract_pad->internal_flags.is_battery_low_ovln_required.Assign(false);
}
}
if (dual_battery.battery_level != new_dual_battery_state.battery_level ||
dual_battery.is_charging != new_dual_battery_state.is_charging ||
dual_battery.is_powered != new_dual_battery_state.is_powered) {
has_changed = true;
dual_battery = new_dual_battery_state;
}
if (left_battery.battery_level != new_left_battery_state.battery_level ||
left_battery.is_charging != new_left_battery_state.is_charging ||
left_battery.is_powered != new_left_battery_state.is_powered) {
has_changed = true;
left_battery = new_left_battery_state;
}
if (right_battery.battery_level != new_right_battery_state.battery_level ||
right_battery.is_charging != new_right_battery_state.is_charging ||
right_battery.is_powered != new_right_battery_state.is_powered) {
has_changed = true;
right_battery = new_right_battery_state;
}
return has_changed;
}
void NpadAbstractBatteryHandler::UpdateCoreBatteryState() {
if (ref_counter == 0) {
return;
}
if (!has_new_battery_data) {
return;
}
UpdateBatteryState(0);
}
void NpadAbstractBatteryHandler::InitializeBatteryState(u64 aruid) {
UpdateBatteryState(aruid);
}
bool NpadAbstractBatteryHandler::HasBattery() const {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
for (std::size_t i = 0; i < count; i++) {
const auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
return abstract_pad->disabled_feature_set.has_fullkey_battery ||
abstract_pad->disabled_feature_set.has_left_right_joy_battery;
}
return false;
}
void NpadAbstractBatteryHandler::HasLeftRightBattery(bool& has_left, bool& has_right) const {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
has_left = false;
has_right = false;
for (std::size_t i = 0; i < count; i++) {
const auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (!abstract_pad->disabled_feature_set.has_fullkey_battery &&
!abstract_pad->disabled_feature_set.has_left_right_joy_battery) {
continue;
}
has_left = abstract_pad->assignment_style.is_external_left_assigned ||
abstract_pad->assignment_style.is_handheld_left_assigned;
has_right = abstract_pad->assignment_style.is_external_right_assigned ||
abstract_pad->assignment_style.is_handheld_right_assigned;
}
}
} // namespace Service::HID

View File

@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Service::HID {
struct AppletResourceHolder;
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
/// Handles Npad request from HID interfaces
class NpadAbstractBatteryHandler final {
public:
explicit NpadAbstractBatteryHandler();
~NpadAbstractBatteryHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetAppletResource(AppletResourceHolder* applet_resource);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
Result IncrementRefCounter();
Result DecrementRefCounter();
Result UpdateBatteryState(u64 aruid);
void UpdateBatteryState();
bool GetNewBatteryState();
void UpdateCoreBatteryState();
void InitializeBatteryState(u64 aruid);
bool HasBattery() const;
void HasLeftRightBattery(bool& has_left, bool& has_right) const;
private:
AppletResourceHolder* applet_resource_holder{nullptr};
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
s32 ref_counter{};
Core::HID::NpadPowerInfo dual_battery{};
Core::HID::NpadPowerInfo left_battery{};
Core::HID::NpadPowerInfo right_battery{};
bool has_new_battery_data{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,199 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/hid_util.h"
#include "hid_core/resources/abstracted_pad/abstract_button_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_resource.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
NpadAbstractButtonHandler::NpadAbstractButtonHandler() {}
NpadAbstractButtonHandler::~NpadAbstractButtonHandler() = default;
void NpadAbstractButtonHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractButtonHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
applet_resource_holder = applet_resource;
}
void NpadAbstractButtonHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
Result NpadAbstractButtonHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractButtonHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
Result NpadAbstractButtonHandler::UpdateAllButtonWithHomeProtection(u64 aruid) {
const Core::HID::NpadIdType npad_id = properties_handler->GetNpadId();
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return ResultSuccess;
}
auto& npad_entry = data->shared_memory_format->npad.npad_entry[NpadIdTypeToIndex(npad_id)];
UpdateButtonLifo(npad_entry, aruid);
bool is_home_button_protection_enabled{};
const auto result = applet_resource_holder->shared_npad_resource->GetHomeProtectionEnabled(
is_home_button_protection_enabled, aruid, npad_id);
if (result.IsError()) {
return ResultSuccess;
}
npad_entry.internal_state.button_properties.is_home_button_protection_enabled.Assign(
is_home_button_protection_enabled);
return ResultSuccess;
}
void NpadAbstractButtonHandler::UpdateAllButtonLifo() {
Core::HID::NpadIdType npad_id = properties_handler->GetNpadId();
for (std::size_t i = 0; i < AruidIndexMax; i++) {
auto* data = applet_resource_holder->applet_resource->GetAruidDataByIndex(i);
auto& npad_entry = data->shared_memory_format->npad.npad_entry[NpadIdTypeToIndex(npad_id)];
UpdateButtonLifo(npad_entry, data->aruid);
}
}
void NpadAbstractButtonHandler::UpdateCoreBatteryState() {
Core::HID::NpadIdType npad_id = properties_handler->GetNpadId();
for (std::size_t i = 0; i < AruidIndexMax; i++) {
auto* data = applet_resource_holder->applet_resource->GetAruidDataByIndex(i);
auto& npad_entry = data->shared_memory_format->npad.npad_entry[NpadIdTypeToIndex(npad_id)];
UpdateButtonLifo(npad_entry, data->aruid);
}
}
void NpadAbstractButtonHandler::UpdateButtonState(u64 aruid) {
Core::HID::NpadIdType npad_id = properties_handler->GetNpadId();
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
auto& npad_entry = data->shared_memory_format->npad.npad_entry[NpadIdTypeToIndex(npad_id)];
UpdateButtonLifo(npad_entry, aruid);
}
Result NpadAbstractButtonHandler::SetHomeProtection(bool is_enabled, u64 aruid) {
const Core::HID::NpadIdType npad_id = properties_handler->GetNpadId();
auto result = applet_resource_holder->shared_npad_resource->SetHomeProtectionEnabled(
aruid, npad_id, is_enabled);
if (result.IsError()) {
return result;
}
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return ResultSuccess;
}
bool is_home_protection_enabled{};
result = applet_resource_holder->shared_npad_resource->GetHomeProtectionEnabled(
is_home_protection_enabled, aruid, npad_id);
if (result.IsError()) {
return ResultSuccess;
}
auto& npad_entry = data->shared_memory_format->npad.npad_entry[NpadIdTypeToIndex(npad_id)];
npad_entry.internal_state.button_properties.is_home_button_protection_enabled.Assign(
is_home_protection_enabled);
return ResultSuccess;
}
bool NpadAbstractButtonHandler::IsButtonPressedOnConsoleMode() {
return is_button_pressed_on_console_mode;
}
void NpadAbstractButtonHandler::EnableCenterClamp() {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
abstract_pad->internal_flags.use_center_clamp.Assign(true);
}
}
void NpadAbstractButtonHandler::UpdateButtonLifo(NpadSharedMemoryEntry& shared_memory, u64 aruid) {
auto* npad_resource = applet_resource_holder->shared_npad_resource;
Core::HID::NpadStyleTag style_tag = {properties_handler->GetStyleSet(aruid)};
style_tag.system_ext.Assign(npad_resource->GetActiveData()->GetNpadSystemExtState());
UpdateNpadFullkeyLifo(style_tag, 0, aruid, shared_memory);
UpdateHandheldLifo(style_tag, 1, aruid, shared_memory);
UpdateJoyconDualLifo(style_tag, 2, aruid, shared_memory);
UpdateJoyconLeftLifo(style_tag, 3, aruid, shared_memory);
UpdateJoyconRightLifo(style_tag, 4, aruid, shared_memory);
UpdatePalmaLifo(style_tag, 5, aruid, shared_memory);
UpdateSystemExtLifo(style_tag, 6, aruid, shared_memory);
}
void NpadAbstractButtonHandler::UpdateNpadFullkeyLifo(Core::HID::NpadStyleTag style_tag,
int style_index, u64 aruid,
NpadSharedMemoryEntry& shared_memory) {
// TODO
}
void NpadAbstractButtonHandler::UpdateHandheldLifo(Core::HID::NpadStyleTag style_tag,
int style_index, u64 aruid,
NpadSharedMemoryEntry& shared_memory) {
// TODO
}
void NpadAbstractButtonHandler::UpdateJoyconDualLifo(Core::HID::NpadStyleTag style_tag,
int style_index, u64 aruid,
NpadSharedMemoryEntry& shared_memory) {
// TODO
}
void NpadAbstractButtonHandler::UpdateJoyconLeftLifo(Core::HID::NpadStyleTag style_tag,
int style_index, u64 aruid,
NpadSharedMemoryEntry& shared_memory) {
// TODO
}
void NpadAbstractButtonHandler::UpdateJoyconRightLifo(Core::HID::NpadStyleTag style_tag,
int style_index, u64 aruid,
NpadSharedMemoryEntry& shared_memory) {
// TODO
}
void NpadAbstractButtonHandler::UpdateSystemExtLifo(Core::HID::NpadStyleTag style_tag,
int style_index, u64 aruid,
NpadSharedMemoryEntry& shared_memory) {
// TODO
}
void NpadAbstractButtonHandler::UpdatePalmaLifo(Core::HID::NpadStyleTag style_tag, int style_index,
u64 aruid, NpadSharedMemoryEntry& shared_memory) {
// TODO
}
} // namespace Service::HID

View File

@@ -0,0 +1,75 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Service::HID {
struct NpadSharedMemoryEntry;
struct AppletResourceHolder;
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
/// Handles Npad request from HID interfaces
class NpadAbstractButtonHandler final {
public:
explicit NpadAbstractButtonHandler();
~NpadAbstractButtonHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetAppletResource(AppletResourceHolder* applet_resource);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
Result IncrementRefCounter();
Result DecrementRefCounter();
Result UpdateAllButtonWithHomeProtection(u64 aruid);
void UpdateAllButtonLifo();
void UpdateCoreBatteryState();
void UpdateButtonState(u64 aruid);
Result SetHomeProtection(bool is_enabled, u64 aruid);
bool IsButtonPressedOnConsoleMode();
void EnableCenterClamp();
void UpdateButtonLifo(NpadSharedMemoryEntry& shared_memory, u64 aruid);
void UpdateNpadFullkeyLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
NpadSharedMemoryEntry& shared_memory);
void UpdateHandheldLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
NpadSharedMemoryEntry& shared_memory);
void UpdateJoyconDualLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
NpadSharedMemoryEntry& shared_memory);
void UpdateJoyconLeftLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
NpadSharedMemoryEntry& shared_memory);
void UpdateJoyconRightLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
NpadSharedMemoryEntry& shared_memory);
void UpdateSystemExtLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
NpadSharedMemoryEntry& shared_memory);
void UpdatePalmaLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
NpadSharedMemoryEntry& shared_memory);
private:
struct GcTrigger {
float left;
float right;
};
AppletResourceHolder* applet_resource_holder{nullptr};
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
s32 ref_counter{};
bool is_button_pressed_on_console_mode{};
u64 gc_sampling_number{};
GcTrigger gc_trigger_state{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,126 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
#include "hid_core/hid_result.h"
#include "hid_core/resources/abstracted_pad/abstract_ir_sensor_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
NpadAbstractIrSensorHandler::NpadAbstractIrSensorHandler() {}
NpadAbstractIrSensorHandler::~NpadAbstractIrSensorHandler() = default;
void NpadAbstractIrSensorHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractIrSensorHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
Result NpadAbstractIrSensorHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractIrSensorHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
void NpadAbstractIrSensorHandler::UpdateIrSensorState() {
const auto previous_state = sensor_state;
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
if (count == 0) {
sensor_state = NpadIrSensorState::Disabled;
if (sensor_state == previous_state) {
return;
}
ir_sensor_event->Signal();
return;
}
bool is_found{};
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (!abstract_pad->disabled_feature_set.has_bluetooth_address) {
continue;
}
is_found = true;
xcd_handle = abstract_pad->xcd_handle;
}
if (is_found) {
if (sensor_state == NpadIrSensorState::Active) {
return;
}
sensor_state = NpadIrSensorState::Available;
if (sensor_state == previous_state) {
return;
}
ir_sensor_event->Signal();
return;
}
sensor_state = NpadIrSensorState::Unavailable;
if (sensor_state == previous_state) {
return;
}
ir_sensor_event->Signal();
return;
}
Result NpadAbstractIrSensorHandler::ActivateIrSensor(bool is_enabled) {
if (sensor_state == NpadIrSensorState::Unavailable) {
return ResultIrSensorIsNotReady;
}
if (is_enabled && sensor_state == NpadIrSensorState::Available) {
sensor_state = NpadIrSensorState::Active;
} else {
if (is_enabled) {
return ResultSuccess;
}
if (sensor_state != NpadIrSensorState::Active) {
return ResultSuccess;
}
sensor_state = NpadIrSensorState::Available;
}
ir_sensor_event->Signal();
return ResultSuccess;
}
Result NpadAbstractIrSensorHandler::GetIrSensorEventHandle(Kernel::KReadableEvent** out_event) {
*out_event = &ir_sensor_event->GetReadableEvent();
return ResultSuccess;
}
Result NpadAbstractIrSensorHandler::GetXcdHandleForNpadWithIrSensor(u64& handle) const {
if (sensor_state < NpadIrSensorState::Available) {
return ResultIrSensorIsNotReady;
}
handle = xcd_handle;
return ResultSuccess;
}
NpadIrSensorState NpadAbstractIrSensorHandler::GetSensorState() const {
return sensor_state;
}
} // namespace Service::HID

View File

@@ -0,0 +1,56 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Kernel {
class KEvent;
class KReadableEvent;
} // namespace Kernel
enum class NpadIrSensorState : u32 {
Disabled,
Unavailable,
Available,
Active,
};
namespace Service::HID {
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
/// Handles Npad request from HID interfaces
class NpadAbstractIrSensorHandler final {
public:
explicit NpadAbstractIrSensorHandler();
~NpadAbstractIrSensorHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
Result IncrementRefCounter();
Result DecrementRefCounter();
void UpdateIrSensorState();
Result ActivateIrSensor(bool param_2);
Result GetIrSensorEventHandle(Kernel::KReadableEvent** out_event);
Result GetXcdHandleForNpadWithIrSensor(u64& handle) const;
NpadIrSensorState GetSensorState() const;
private:
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
s32 ref_counter{};
Kernel::KEvent* ir_sensor_event{nullptr};
u64 xcd_handle{};
NpadIrSensorState sensor_state{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,123 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/core_timing.h"
#include "hid_core/hid_result.h"
#include "hid_core/hid_util.h"
#include "hid_core/resources/abstracted_pad/abstract_led_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
NpadAbstractLedHandler::NpadAbstractLedHandler() {}
NpadAbstractLedHandler::~NpadAbstractLedHandler() = default;
void NpadAbstractLedHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractLedHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
applet_resource_holder = applet_resource;
}
void NpadAbstractLedHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
Result NpadAbstractLedHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractLedHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
void NpadAbstractLedHandler::SetNpadLedHandlerLedPattern() {
const auto npad_id = properties_handler->GetNpadId();
switch (npad_id) {
case Core::HID::NpadIdType::Player1:
left_pattern = Core::HID::LedPattern{1, 0, 0, 0};
break;
case Core::HID::NpadIdType::Player2:
left_pattern = Core::HID::LedPattern{1, 1, 0, 0};
break;
case Core::HID::NpadIdType::Player3:
left_pattern = Core::HID::LedPattern{1, 1, 1, 0};
break;
case Core::HID::NpadIdType::Player4:
left_pattern = Core::HID::LedPattern{1, 1, 1, 1};
break;
case Core::HID::NpadIdType::Player5:
left_pattern = Core::HID::LedPattern{1, 0, 0, 1};
break;
case Core::HID::NpadIdType::Player6:
left_pattern = Core::HID::LedPattern{1, 0, 1, 0};
break;
case Core::HID::NpadIdType::Player7:
left_pattern = Core::HID::LedPattern{1, 0, 1, 1};
break;
case Core::HID::NpadIdType::Player8:
left_pattern = Core::HID::LedPattern{0, 1, 1, 0};
break;
case Core::HID::NpadIdType::Other:
case Core::HID::NpadIdType::Handheld:
left_pattern = Core::HID::LedPattern{0, 0, 0, 0};
break;
default:
ASSERT_MSG(false, "Invalid npad id type");
break;
}
switch (npad_id) {
case Core::HID::NpadIdType::Player1:
right_pattern = Core::HID::LedPattern{0, 0, 0, 1};
break;
case Core::HID::NpadIdType::Player2:
right_pattern = Core::HID::LedPattern{0, 1, 1, 1};
break;
case Core::HID::NpadIdType::Player3:
right_pattern = Core::HID::LedPattern{0, 1, 1, 1};
break;
case Core::HID::NpadIdType::Player4:
right_pattern = Core::HID::LedPattern{1, 1, 1, 1};
break;
case Core::HID::NpadIdType::Player5:
right_pattern = Core::HID::LedPattern{1, 0, 0, 1};
break;
case Core::HID::NpadIdType::Player6:
right_pattern = Core::HID::LedPattern{0, 1, 0, 1};
break;
case Core::HID::NpadIdType::Player7:
right_pattern = Core::HID::LedPattern{1, 1, 0, 1};
break;
case Core::HID::NpadIdType::Player8:
right_pattern = Core::HID::LedPattern{0, 1, 1, 0};
break;
case Core::HID::NpadIdType::Other:
case Core::HID::NpadIdType::Handheld:
right_pattern = Core::HID::LedPattern{0, 0, 0, 0};
break;
default:
ASSERT_MSG(false, "Invalid npad id type");
break;
}
}
void NpadAbstractLedHandler::SetLedBlinkingDevice(Core::HID::LedPattern pattern) {
led_blinking = pattern;
}
} // namespace Service::HID

View File

@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Service::HID {
struct AppletResourceHolder;
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
/// Handles Npad request from HID interfaces
class NpadAbstractLedHandler final {
public:
explicit NpadAbstractLedHandler();
~NpadAbstractLedHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetAppletResource(AppletResourceHolder* applet_resource);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
Result IncrementRefCounter();
Result DecrementRefCounter();
void SetNpadLedHandlerLedPattern();
void SetLedBlinkingDevice(Core::HID::LedPattern pattern);
private:
AppletResourceHolder* applet_resource_holder{nullptr};
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
s32 ref_counter{};
Core::HID::LedPattern led_blinking{0, 0, 0, 0};
Core::HID::LedPattern left_pattern{0, 0, 0, 0};
Core::HID::LedPattern right_pattern{0, 0, 0, 0};
u64 led_interval{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,108 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/abstracted_pad/abstract_mcu_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
NpadAbstractMcuHandler::NpadAbstractMcuHandler() {}
NpadAbstractMcuHandler::~NpadAbstractMcuHandler() = default;
void NpadAbstractMcuHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractMcuHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
Result NpadAbstractMcuHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractMcuHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
void NpadAbstractMcuHandler::UpdateMcuState() {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = properties_handler->GetAbstractedPads(abstract_pads);
if (count == 0) {
mcu_holder = {};
return;
}
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (!abstract_pad->disabled_feature_set.has_left_joy_rail_bus) {
if (!abstract_pad->disabled_feature_set.has_left_joy_six_axis_sensor &&
!abstract_pad->disabled_feature_set.has_right_joy_six_axis_sensor) {
continue;
}
if (mcu_holder[1].state != NpadMcuState::Active) {
mcu_holder[1].state = NpadMcuState::Available;
}
mcu_holder[1].abstracted_pad = abstract_pad;
continue;
}
if (mcu_holder[0].state != NpadMcuState::Active) {
mcu_holder[0].state = NpadMcuState::Available;
}
mcu_holder[0].abstracted_pad = abstract_pad;
}
}
Result NpadAbstractMcuHandler::GetAbstractedPad(IAbstractedPad** data, u32 mcu_index) {
if (mcu_holder[mcu_index].state == NpadMcuState::None ||
mcu_holder[mcu_index].abstracted_pad == nullptr) {
return ResultMcuIsNotReady;
}
*data = mcu_holder[mcu_index].abstracted_pad;
return ResultSuccess;
}
NpadMcuState NpadAbstractMcuHandler::GetMcuState(u32 mcu_index) {
return mcu_holder[mcu_index].state;
}
Result NpadAbstractMcuHandler::SetMcuState(bool is_enabled, u32 mcu_index) {
NpadMcuState& state = mcu_holder[mcu_index].state;
if (state == NpadMcuState::None) {
return ResultMcuIsNotReady;
}
if ((is_enabled) && (state == NpadMcuState::Available)) {
state = NpadMcuState::Active;
return ResultSuccess;
}
if (is_enabled) {
return ResultSuccess;
}
if (state != NpadMcuState::Active) {
return ResultSuccess;
}
state = NpadMcuState::Available;
return ResultSuccess;
}
} // namespace Service::HID

View File

@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Service::HID {
struct IAbstractedPad;
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
enum class NpadMcuState : u32 {
None,
Available,
Active,
};
struct NpadMcuHolder {
NpadMcuState state;
INSERT_PADDING_BYTES(0x4);
IAbstractedPad* abstracted_pad;
};
static_assert(sizeof(NpadMcuHolder) == 0x10, "NpadMcuHolder is an invalid size");
/// Handles Npad request from HID interfaces
class NpadAbstractMcuHandler final {
public:
explicit NpadAbstractMcuHandler();
~NpadAbstractMcuHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
Result IncrementRefCounter();
Result DecrementRefCounter();
void UpdateMcuState();
Result GetAbstractedPad(IAbstractedPad** data, u32 mcu_index);
NpadMcuState GetMcuState(u32 mcu_index);
Result SetMcuState(bool is_enabled, u32 mcu_index);
private:
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
s32 ref_counter{};
std::array<NpadMcuHolder, 2> mcu_holder{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,140 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
#include "hid_core/hid_result.h"
#include "hid_core/resources/abstracted_pad/abstract_nfc_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
NpadAbstractNfcHandler::NpadAbstractNfcHandler() {}
NpadAbstractNfcHandler::~NpadAbstractNfcHandler() = default;
void NpadAbstractNfcHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractNfcHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
Result NpadAbstractNfcHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractNfcHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
void NpadAbstractNfcHandler::UpdateNfcState() {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = properties_handler->GetAbstractedPads(abstract_pads);
if (count == 0) {
if (sensor_state == NpadNfcState::Active) {
nfc_activate_event->Signal();
}
if (sensor_state == NpadNfcState::Unavailable) {
return;
}
sensor_state = NpadNfcState::Unavailable;
input_event->Signal();
return;
}
bool is_found{};
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (!abstract_pad->disabled_feature_set.has_nfc) {
continue;
}
is_found = true;
xcd_handle = 0;
}
if (is_found) {
if (sensor_state == NpadNfcState::Active) {
return;
}
if (sensor_state == NpadNfcState::Available) {
return;
}
sensor_state = NpadNfcState::Available;
input_event->Signal();
return;
}
if (sensor_state == NpadNfcState::Active) {
nfc_activate_event->Signal();
}
if (sensor_state == NpadNfcState::Unavailable) {
return;
}
sensor_state = NpadNfcState::Unavailable;
input_event->Signal();
return;
}
bool NpadAbstractNfcHandler::HasNfcSensor() {
return sensor_state != NpadNfcState::Unavailable;
}
bool NpadAbstractNfcHandler::IsNfcActivated() {
return sensor_state == NpadNfcState::Active;
}
Result NpadAbstractNfcHandler::GetAcquireNfcActivateEventHandle(
Kernel::KReadableEvent** out_event) {
*out_event = &nfc_activate_event->GetReadableEvent();
return ResultSuccess;
}
void NpadAbstractNfcHandler::SetInputEvent(Kernel::KEvent* event) {
input_event = event;
}
Result NpadAbstractNfcHandler::ActivateNfc(bool is_enabled) {
if (sensor_state == NpadNfcState::Active) {
return ResultNfcIsNotReady;
}
NpadNfcState new_state = NpadNfcState::Available;
if (is_enabled) {
new_state = NpadNfcState::Active;
}
if (sensor_state != new_state) {
sensor_state = new_state;
nfc_activate_event->Signal();
}
return ResultSuccess;
}
Result NpadAbstractNfcHandler::GetXcdHandleWithNfc(u64& out_xcd_handle) const {
if (sensor_state == NpadNfcState::Unavailable) {
return ResultNfcIsNotReady;
}
if (xcd_handle == 0) {
return ResultNfcXcdHandleIsNotInitialized;
}
out_xcd_handle = xcd_handle;
return ResultSuccess;
}
} // namespace Service::HID

View File

@@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Kernel {
class KReadableEvent;
}
enum class NpadNfcState : u32 {
Unavailable,
Available,
Active,
};
namespace Service::HID {
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
/// Handles Npad request from HID interfaces
class NpadAbstractNfcHandler final {
public:
explicit NpadAbstractNfcHandler();
~NpadAbstractNfcHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
Result IncrementRefCounter();
Result DecrementRefCounter();
void UpdateNfcState();
bool HasNfcSensor();
bool IsNfcActivated();
Result GetAcquireNfcActivateEventHandle(Kernel::KReadableEvent** out_event);
void SetInputEvent(Kernel::KEvent* event);
Result ActivateNfc(bool is_enabled);
Result GetXcdHandleWithNfc(u64& out_xcd_handle) const;
private:
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
s32 ref_counter{};
Kernel::KEvent* nfc_activate_event{nullptr};
Kernel::KEvent* input_event{nullptr};
u64 xcd_handle{};
NpadNfcState sensor_state{NpadNfcState::Unavailable};
};
} // namespace Service::HID

View File

@@ -0,0 +1,294 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/abstracted_pad/abstract_pad.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
AbstractPad::AbstractPad() {}
AbstractPad::~AbstractPad() = default;
void AbstractPad::SetExternals(AppletResourceHolder* applet_resource,
CaptureButtonResource* capture_button_resource,
HomeButtonResource* home_button_resource,
SixAxisResource* sixaxis_resource, PalmaResource* palma_resource,
VibrationHandler* vibration) {
applet_resource_holder = applet_resource;
properties_handler.SetAppletResource(applet_resource_holder);
properties_handler.SetAbstractPadHolder(&abstract_pad_holder);
led_handler.SetAppletResource(applet_resource_holder);
led_handler.SetAbstractPadHolder(&abstract_pad_holder);
led_handler.SetPropertiesHandler(&properties_handler);
ir_sensor_handler.SetAbstractPadHolder(&abstract_pad_holder);
ir_sensor_handler.SetPropertiesHandler(&properties_handler);
nfc_handler.SetAbstractPadHolder(&abstract_pad_holder);
nfc_handler.SetPropertiesHandler(&properties_handler);
mcu_handler.SetAbstractPadHolder(&abstract_pad_holder);
mcu_handler.SetPropertiesHandler(&properties_handler);
std::array<NpadVibrationDevice*, 2> vibration_devices{&vibration_left, &vibration_right};
vibration_handler.SetAppletResource(applet_resource_holder);
vibration_handler.SetAbstractPadHolder(&abstract_pad_holder);
vibration_handler.SetPropertiesHandler(&properties_handler);
vibration_handler.SetN64Vibration(&vibration_n64);
vibration_handler.SetVibration(vibration_devices);
vibration_handler.SetGcVibration(&vibration_gc);
sixaxis_handler.SetAppletResource(applet_resource_holder);
sixaxis_handler.SetAbstractPadHolder(&abstract_pad_holder);
sixaxis_handler.SetPropertiesHandler(&properties_handler);
sixaxis_handler.SetSixaxisResource(sixaxis_resource);
button_handler.SetAppletResource(applet_resource_holder);
button_handler.SetAbstractPadHolder(&abstract_pad_holder);
button_handler.SetPropertiesHandler(&properties_handler);
battery_handler.SetAppletResource(applet_resource_holder);
battery_handler.SetAbstractPadHolder(&abstract_pad_holder);
battery_handler.SetPropertiesHandler(&properties_handler);
palma_handler.SetAbstractPadHolder(&abstract_pad_holder);
palma_handler.SetPropertiesHandler(&properties_handler);
palma_handler.SetPalmaResource(palma_resource);
}
void AbstractPad::SetNpadId(Core::HID::NpadIdType npad_id) {
properties_handler.SetNpadId(npad_id);
}
Result AbstractPad::Activate() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
if (ref_counter != 0) {
ref_counter++;
return ResultSuccess;
}
std::size_t stage = 0;
Result result = ResultSuccess;
if (result.IsSuccess()) {
stage++;
result = properties_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = led_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = ir_sensor_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = mcu_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = nfc_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = vibration_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = sixaxis_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = button_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = battery_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
stage++;
result = palma_handler.IncrementRefCounter();
}
if (result.IsSuccess()) {
ref_counter++;
return result;
}
if (stage > 9) {
battery_handler.DecrementRefCounter();
}
if (stage > 8) {
button_handler.DecrementRefCounter();
}
if (stage > 7) {
sixaxis_handler.DecrementRefCounter();
}
if (stage > 6) {
vibration_handler.DecrementRefCounter();
}
if (stage > 5) {
nfc_handler.DecrementRefCounter();
}
if (stage > 4) {
mcu_handler.DecrementRefCounter();
}
if (stage > 3) {
ir_sensor_handler.DecrementRefCounter();
}
if (stage > 2) {
led_handler.DecrementRefCounter();
}
if (stage > 1) {
properties_handler.DecrementRefCounter();
}
return result;
}
Result AbstractPad::Deactivate() {
if (ref_counter == 0) {
return ResultNpadResourceNotInitialized;
}
ref_counter--;
battery_handler.DecrementRefCounter();
button_handler.DecrementRefCounter();
sixaxis_handler.DecrementRefCounter();
vibration_handler.DecrementRefCounter();
nfc_handler.DecrementRefCounter();
ir_sensor_handler.DecrementRefCounter();
mcu_handler.DecrementRefCounter();
led_handler.DecrementRefCounter();
properties_handler.DecrementRefCounter();
palma_handler.DecrementRefCounter();
return ResultSuccess;
}
Result AbstractPad::ActivateNpad(u64 aruid) {
Result result = ResultSuccess;
if (result.IsSuccess()) {
result = properties_handler.ActivateNpadUnknown0x88(aruid);
}
if (result.IsSuccess()) {
result = sixaxis_handler.UpdateSixAxisState2(aruid);
}
if (result.IsSuccess()) {
result = battery_handler.UpdateBatteryState(aruid);
}
return result;
}
NpadAbstractedPadHolder* AbstractPad::GetAbstractedPadHolder() {
return &abstract_pad_holder;
}
NpadAbstractPropertiesHandler* AbstractPad::GetAbstractPropertiesHandler() {
return &properties_handler;
}
NpadAbstractLedHandler* AbstractPad::GetAbstractLedHandler() {
return &led_handler;
}
NpadAbstractIrSensorHandler* AbstractPad::GetAbstractIrSensorHandler() {
return &ir_sensor_handler;
}
NpadAbstractMcuHandler* AbstractPad::GetAbstractMcuHandler() {
return &mcu_handler;
}
NpadAbstractNfcHandler* AbstractPad::GetAbstractNfcHandler() {
return &nfc_handler;
}
NpadAbstractVibrationHandler* AbstractPad::GetAbstractVibrationHandler() {
return &vibration_handler;
}
NpadAbstractSixAxisHandler* AbstractPad::GetAbstractSixAxisHandler() {
return &sixaxis_handler;
}
NpadAbstractButtonHandler* AbstractPad::GetAbstractButtonHandler() {
return &button_handler;
}
NpadAbstractBatteryHandler* AbstractPad::GetAbstractBatteryHandler() {
return &battery_handler;
}
NpadN64VibrationDevice* AbstractPad::GetN64VibrationDevice() {
return &vibration_n64;
}
NpadVibrationDevice* AbstractPad::GetVibrationDevice(Core::HID::DeviceIndex device_index) {
if (device_index == Core::HID::DeviceIndex::Right) {
return &vibration_right;
}
return &vibration_left;
}
void AbstractPad::GetLeftRightVibrationDevice(std::vector<NpadVibrationDevice*> list) {
list.emplace_back(&vibration_left);
list.emplace_back(&vibration_right);
}
NpadGcVibrationDevice* AbstractPad::GetGCVibrationDevice() {
return &vibration_gc;
}
Core::HID::NpadIdType AbstractPad::GetLastActiveNpad() {
return properties_handler.GetNpadId();
}
void AbstractPad::UpdateInterfaceType() {
if (interface_type != properties_handler.GetInterfaceType()) {
Update();
}
battery_handler.UpdateBatteryState();
}
void AbstractPad::Update() {
properties_handler.UpdateDeviceType();
led_handler.SetNpadLedHandlerLedPattern();
vibration_handler.UpdateVibrationState();
sixaxis_handler.UpdateSixAxisState();
nfc_handler.UpdateNfcState();
ir_sensor_handler.UpdateIrSensorState();
mcu_handler.UpdateMcuState();
palma_handler.UpdatePalmaState();
battery_handler.UpdateBatteryState();
button_handler.EnableCenterClamp();
interface_type = properties_handler.GetInterfaceType();
std::scoped_lock lock{*applet_resource_holder->shared_mutex};
properties_handler.UpdateAllDeviceProperties();
battery_handler.UpdateCoreBatteryState();
button_handler.UpdateCoreBatteryState();
}
void AbstractPad::UpdatePadState() {
button_handler.UpdateAllButtonLifo();
sixaxis_handler.UpdateSixAxisState();
battery_handler.UpdateCoreBatteryState();
}
void AbstractPad::EnableAppletToGetInput(u64 aruid) {
button_handler.UpdateButtonState(aruid);
sixaxis_handler.UpdateSixAxisState(aruid);
battery_handler.UpdateBatteryState(aruid);
}
} // namespace Service::HID

View File

@@ -0,0 +1,123 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <array>
#include <mutex>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/abstracted_pad/abstract_battery_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_button_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_ir_sensor_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_led_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_mcu_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_nfc_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_palma_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_sixaxis_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_vibration_handler.h"
#include "hid_core/resources/vibration/gc_vibration_device.h"
#include "hid_core/resources/vibration/n64_vibration_device.h"
#include "hid_core/resources/vibration/vibration_device.h"
namespace Service::HID {
class AppletResource;
class SixAxisResource;
class PalmaResource;
class NPadResource;
class AbstractPad;
class NpadLastActiveHandler;
class NpadIrNfcHandler;
class UniquePads;
class NpadPalmaHandler;
class FirmwareResource;
class NpadVibration;
class NpadHighestBattery;
class NpadGcVibration;
class CaptureButtonResource;
class HomeButtonResource;
class VibrationHandler;
struct HandheldConfig;
/// Handles Npad request from HID interfaces
class AbstractPad final {
public:
explicit AbstractPad();
~AbstractPad();
void SetExternals(AppletResourceHolder* applet_resource,
CaptureButtonResource* capture_button_resource,
HomeButtonResource* home_button_resource, SixAxisResource* sixaxis_resource,
PalmaResource* palma_resource, VibrationHandler* vibration);
void SetNpadId(Core::HID::NpadIdType npad_id);
Result Activate();
Result Deactivate();
Result ActivateNpad(u64 aruid);
NpadAbstractedPadHolder* GetAbstractedPadHolder();
NpadAbstractPropertiesHandler* GetAbstractPropertiesHandler();
NpadAbstractLedHandler* GetAbstractLedHandler();
NpadAbstractIrSensorHandler* GetAbstractIrSensorHandler();
NpadAbstractMcuHandler* GetAbstractMcuHandler();
NpadAbstractNfcHandler* GetAbstractNfcHandler();
NpadAbstractVibrationHandler* GetAbstractVibrationHandler();
NpadAbstractSixAxisHandler* GetAbstractSixAxisHandler();
NpadAbstractButtonHandler* GetAbstractButtonHandler();
NpadAbstractBatteryHandler* GetAbstractBatteryHandler();
NpadN64VibrationDevice* GetN64VibrationDevice();
NpadVibrationDevice* GetVibrationDevice(Core::HID::DeviceIndex device_index);
void GetLeftRightVibrationDevice(std::vector<NpadVibrationDevice*> list);
NpadGcVibrationDevice* GetGCVibrationDevice();
Core::HID::NpadIdType GetLastActiveNpad();
void UpdateInterfaceType();
void Update();
void UpdatePadState();
void EnableAppletToGetInput(u64 aruid);
private:
AppletResourceHolder* applet_resource_holder{nullptr};
NpadAbstractedPadHolder abstract_pad_holder{};
NpadAbstractPropertiesHandler properties_handler{};
NpadAbstractLedHandler led_handler{};
NpadAbstractIrSensorHandler ir_sensor_handler{};
NpadAbstractNfcHandler nfc_handler{};
NpadAbstractMcuHandler mcu_handler{};
NpadAbstractVibrationHandler vibration_handler{};
NpadAbstractSixAxisHandler sixaxis_handler{};
NpadAbstractButtonHandler button_handler{};
NpadAbstractBatteryHandler battery_handler{};
NpadAbstractPalmaHandler palma_handler{};
NpadN64VibrationDevice vibration_n64{};
NpadVibrationDevice vibration_left{};
NpadVibrationDevice vibration_right{};
NpadGcVibrationDevice vibration_gc{};
// SixAxisConfigHolder fullkey_config;
// SixAxisConfigHolder handheld_config;
// SixAxisConfigHolder dual_left_config;
// SixAxisConfigHolder dual_right_config;
// SixAxisConfigHolder left_config;
// SixAxisConfigHolder right_config;
s32 ref_counter{};
Core::HID::NpadInterfaceType interface_type{Core::HID::NpadInterfaceType::None};
};
using FullAbstractPad = std::array<AbstractPad, MaxSupportedNpadIdTypes>;
} // namespace Service::HID

View File

@@ -0,0 +1,99 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
Result NpadAbstractedPadHolder::RegisterAbstractPad(IAbstractedPad* abstracted_pad) {
if (list_size >= assignment_list.size()) {
return ResultNpadIsNotProController;
}
for (std::size_t i = 0; i < list_size; i++) {
if (assignment_list[i].device_type == abstracted_pad->device_type) {
return ResultNpadIsNotProController;
}
}
assignment_list[list_size] = {
.abstracted_pad = abstracted_pad,
.device_type = abstracted_pad->device_type,
.interface_type = abstracted_pad->interface_type,
.controller_id = abstracted_pad->controller_id,
};
list_size++;
return ResultSuccess;
}
void NpadAbstractedPadHolder::RemoveAbstractPadByControllerId(u64 controller_id) {
if (list_size == 0) {
return;
}
if (controller_id == 0) {
return;
}
for (std::size_t i = 0; i < list_size; i++) {
if (assignment_list[i].controller_id != controller_id) {
continue;
}
for (std::size_t e = i + 1; e < list_size; e++) {
assignment_list[e - 1] = assignment_list[e];
}
list_size--;
return;
}
}
void NpadAbstractedPadHolder::DetachAbstractedPad() {
while (list_size > 0) {
for (std::size_t i = 1; i < list_size; i++) {
assignment_list[i - 1] = assignment_list[i];
}
list_size--;
}
}
u64 NpadAbstractedPadHolder::RemoveAbstractPadByAssignmentStyle(
Service::HID::AssignmentStyle assignment_style) {
for (std::size_t i = 0; i < list_size; i++) {
if ((assignment_style.raw & assignment_list[i].abstracted_pad->assignment_style.raw) == 0) {
continue;
}
for (std::size_t e = i + 1; e < list_size; e++) {
assignment_list[e - 1] = assignment_list[e];
}
list_size--;
return list_size;
}
return list_size;
}
u32 NpadAbstractedPadHolder::GetAbstractedPads(std::span<IAbstractedPad*> list) const {
u32 num_elements = std::min(static_cast<u32>(list.size()), list_size);
for (std::size_t i = 0; i < num_elements; i++) {
list[i] = assignment_list[i].abstracted_pad;
}
return num_elements;
}
void NpadAbstractedPadHolder::SetAssignmentMode(const NpadJoyAssignmentMode& mode) {
assignment_mode = mode;
}
NpadJoyAssignmentMode NpadAbstractedPadHolder::GetAssignmentMode() const {
return assignment_mode;
}
std::size_t NpadAbstractedPadHolder::GetStyleIndexList(
std::span<Core::HID::NpadStyleIndex> list) const {
for (std::size_t i = 0; i < list_size; i++) {
list[i] = assignment_list[i].device_type;
}
return list_size;
}
} // namespace Service::HID

View File

@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <array>
#include <mutex>
#include <span>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
struct IAbstractedPad;
struct AbstractAssignmentHolder {
IAbstractedPad* abstracted_pad;
Core::HID::NpadStyleIndex device_type;
Core::HID::NpadInterfaceType interface_type;
INSERT_PADDING_BYTES(0x6);
u64 controller_id;
};
static_assert(sizeof(AbstractAssignmentHolder) == 0x18,
"AbstractAssignmentHolder is an invalid size");
/// This is nn::hid::server::NpadAbstractedPadHolder
class NpadAbstractedPadHolder final {
public:
Result RegisterAbstractPad(IAbstractedPad* abstracted_pad);
void RemoveAbstractPadByControllerId(u64 controller_id);
void DetachAbstractedPad();
u64 RemoveAbstractPadByAssignmentStyle(Service::HID::AssignmentStyle assignment_style);
u32 GetAbstractedPads(std::span<IAbstractedPad*> list) const;
void SetAssignmentMode(const NpadJoyAssignmentMode& mode);
NpadJoyAssignmentMode GetAssignmentMode() const;
std::size_t GetStyleIndexList(std::span<Core::HID::NpadStyleIndex> list) const;
private:
std::array<AbstractAssignmentHolder, 5> assignment_list{};
u32 list_size{};
NpadJoyAssignmentMode assignment_mode{NpadJoyAssignmentMode::Dual};
};
} // namespace Service::HID

View File

@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/abstracted_pad/abstract_palma_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
namespace Service::HID {
NpadAbstractPalmaHandler::NpadAbstractPalmaHandler() {}
NpadAbstractPalmaHandler::~NpadAbstractPalmaHandler() = default;
void NpadAbstractPalmaHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractPalmaHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
return;
}
void NpadAbstractPalmaHandler::SetPalmaResource(PalmaResource* resource) {
palma_resource = resource;
}
Result NpadAbstractPalmaHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractPalmaHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
void NpadAbstractPalmaHandler::UpdatePalmaState() {
// TODO
}
} // namespace Service::HID

View File

@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Service::HID {
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
class PalmaResource;
class NpadAbstractPalmaHandler final {
public:
explicit NpadAbstractPalmaHandler();
~NpadAbstractPalmaHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
void SetPalmaResource(PalmaResource* resource);
Result IncrementRefCounter();
Result DecrementRefCounter();
void UpdatePalmaState();
private:
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
PalmaResource* palma_resource{nullptr};
s32 ref_counter{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,322 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_util.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_resource.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
NpadAbstractPropertiesHandler::NpadAbstractPropertiesHandler() {}
NpadAbstractPropertiesHandler::~NpadAbstractPropertiesHandler() = default;
void NpadAbstractPropertiesHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
return;
}
void NpadAbstractPropertiesHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
applet_resource_holder = applet_resource;
return;
}
void NpadAbstractPropertiesHandler::SetNpadId(Core::HID::NpadIdType npad_id) {
if (!IsNpadIdValid(npad_id)) {
ASSERT_MSG(false, "Invalid npad id");
}
npad_id_type = npad_id;
}
Core::HID::NpadIdType NpadAbstractPropertiesHandler::GetNpadId() const {
return npad_id_type;
}
Result NpadAbstractPropertiesHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
if (ref_counter != 0) {
ref_counter++;
return ResultSuccess;
}
const auto npad_index = NpadIdTypeToIndex(npad_id_type);
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid_index);
auto& internal_state =
data->shared_memory_format->npad.npad_entry[npad_index].internal_state;
if (!data->flag.is_assigned) {
continue;
}
internal_state.fullkey_lifo.buffer_count = 0;
internal_state.handheld_lifo.buffer_count = 0;
internal_state.joy_dual_lifo.buffer_count = 0;
internal_state.joy_left_lifo.buffer_count = 0;
internal_state.joy_right_lifo.buffer_count = 0;
internal_state.palma_lifo.buffer_count = 0;
internal_state.system_ext_lifo.buffer_count = 0;
internal_state.gc_trigger_lifo.buffer_count = 0;
internal_state.sixaxis_fullkey_lifo.lifo.buffer_count = 0;
internal_state.sixaxis_handheld_lifo.lifo.buffer_count = 0;
internal_state.sixaxis_dual_left_lifo.lifo.buffer_count = 0;
internal_state.sixaxis_dual_right_lifo.lifo.buffer_count = 0;
internal_state.sixaxis_left_lifo.lifo.buffer_count = 0;
internal_state.sixaxis_right_lifo.lifo.buffer_count = 0;
internal_state.style_tag = {Core::HID::NpadStyleSet::None};
internal_state.assignment_mode = NpadJoyAssignmentMode::Dual;
internal_state.joycon_color = {};
internal_state.fullkey_color = {};
internal_state.system_properties.raw = 0;
internal_state.button_properties.raw = 0;
internal_state.device_type.raw = 0;
internal_state.battery_level_dual = Core::HID::NpadBatteryLevel::Empty;
internal_state.battery_level_left = Core::HID::NpadBatteryLevel::Empty;
internal_state.battery_level_right = Core::HID::NpadBatteryLevel::Empty;
internal_state.applet_footer_type = AppletFooterUiType::None;
internal_state.applet_footer_attributes = {};
internal_state.lark_type_l_and_main = {};
internal_state.lark_type_r = {};
internal_state.sixaxis_fullkey_properties.is_newly_assigned.Assign(true);
internal_state.sixaxis_handheld_properties.is_newly_assigned.Assign(true);
internal_state.sixaxis_dual_left_properties.is_newly_assigned.Assign(true);
internal_state.sixaxis_dual_right_properties.is_newly_assigned.Assign(true);
internal_state.sixaxis_left_properties.is_newly_assigned.Assign(true);
internal_state.sixaxis_right_properties.is_newly_assigned.Assign(true);
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractPropertiesHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
Result NpadAbstractPropertiesHandler::ActivateNpadUnknown0x88(u64 aruid) {
const auto npad_index = NpadIdTypeToIndex(npad_id_type);
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid_index);
if (!data->flag.is_assigned || data->aruid != aruid) {
continue;
}
UpdateDeviceProperties(aruid, data->shared_memory_format->npad.npad_entry[npad_index]);
return ResultSuccess;
}
return ResultSuccess;
}
void NpadAbstractPropertiesHandler::UpdateDeviceType() {
// TODO
}
void NpadAbstractPropertiesHandler::UpdateDeviceColor() {
// TODO
}
void NpadAbstractPropertiesHandler::UpdateFooterAttributes() {
// TODO
}
void NpadAbstractPropertiesHandler::UpdateAllDeviceProperties() {
const auto npad_index = NpadIdTypeToIndex(npad_id_type);
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid_index);
if (!data->flag.is_assigned) {
continue;
}
auto& npad_entry = data->shared_memory_format->npad.npad_entry[npad_index];
UpdateDeviceProperties(data->aruid, npad_entry);
}
}
Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetFullkeyInterfaceType() {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (abstract_pad->device_type != Core::HID::NpadStyleIndex::Fullkey) {
continue;
}
if (abstract_pad->interface_type >= Core::HID::NpadInterfaceType::Embedded) {
// Abort
continue;
}
return abstract_pad->interface_type;
}
return Core::HID::NpadInterfaceType::None;
}
Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetInterfaceType() {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (!abstract_pad->disabled_feature_set.has_identification_code) {
continue;
}
if (abstract_pad->interface_type >= Core::HID::NpadInterfaceType::Embedded) {
// Abort
continue;
}
return abstract_pad->interface_type;
}
return Core::HID::NpadInterfaceType::None;
}
Core::HID::NpadStyleSet NpadAbstractPropertiesHandler::GetStyleSet(u64 aruid) {
// TODO
return Core::HID::NpadStyleSet::None;
}
std::size_t NpadAbstractPropertiesHandler::GetAbstractedPadsWithStyleTag(
std::span<IAbstractedPad*> list, Core::HID::NpadStyleTag style) {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
if (count == 0) {
return count;
}
bool is_supported_style_set{};
const auto result = applet_resource_holder->shared_npad_resource->IsSupportedNpadStyleSet(
is_supported_style_set, applet_resource_holder->applet_resource->GetActiveAruid());
if (!is_supported_style_set || result.IsError()) {
for (std::size_t i = 0; i < count; i++) {
// TODO
}
return count;
}
std::size_t filtered_count{};
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
const bool is_enabled = true;
if (is_enabled) {
list[filtered_count] = abstract_pad;
filtered_count++;
}
}
return filtered_count;
}
std::size_t NpadAbstractPropertiesHandler::GetAbstractedPads(std::span<IAbstractedPad*> list) {
Core::HID::NpadStyleTag style{
GetStyleSet(applet_resource_holder->applet_resource->GetActiveAruid())};
return GetAbstractedPadsWithStyleTag(list, style);
}
AppletFooterUiType NpadAbstractPropertiesHandler::GetAppletFooterUiType() {
return applet_ui_type.footer;
}
AppletDetailedUiType NpadAbstractPropertiesHandler::GetAppletDetailedUiType() {
return applet_ui_type;
}
void NpadAbstractPropertiesHandler::UpdateDeviceProperties(u64 aruid,
NpadSharedMemoryEntry& internal_state) {
// TODO
}
Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetNpadInterfaceType() {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (abstract_pad->interface_type >= Core::HID::NpadInterfaceType::Embedded) {
// Abort
continue;
}
return abstract_pad->interface_type;
}
return Core::HID::NpadInterfaceType::None;
}
Result NpadAbstractPropertiesHandler::GetNpadFullKeyGripColor(
Core::HID::NpadColor& main_color, Core::HID::NpadColor& sub_color) const {
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
if (applet_ui_type.footer != AppletFooterUiType::SwitchProController) {
return ResultNpadIsNotProController;
}
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
return ResultSuccess;
}
return ResultNpadIsNotProController;
}
void NpadAbstractPropertiesHandler::GetNpadLeftRightInterfaceType(
Core::HID::NpadInterfaceType& out_left_interface,
Core::HID::NpadInterfaceType& out_right_interface) const {
out_left_interface = Core::HID::NpadInterfaceType::None;
out_right_interface = Core::HID::NpadInterfaceType::None;
std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
for (std::size_t i = 0; i < count; i++) {
auto* abstract_pad = abstract_pads[i];
if (!abstract_pad->internal_flags.is_connected) {
continue;
}
if (abstract_pad->assignment_style.is_external_left_assigned &&
abstract_pad->assignment_style.is_handheld_left_assigned) {
if (abstract_pad->interface_type > Core::HID::NpadInterfaceType::Embedded) {
// Abort
continue;
}
out_left_interface = abstract_pad->interface_type;
continue;
}
if (abstract_pad->assignment_style.is_external_right_assigned &&
abstract_pad->assignment_style.is_handheld_right_assigned) {
if (abstract_pad->interface_type > Core::HID::NpadInterfaceType::Embedded) {
// Abort
continue;
}
out_right_interface = abstract_pad->interface_type;
continue;
}
}
}
} // namespace Service::HID

View File

@@ -0,0 +1,86 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <span>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
#include "hid_core/resources/npad/npad_types.h"
namespace Service::HID {
struct NpadSharedMemoryEntry;
struct AppletResourceHolder;
class NpadAbstractedPadHolder;
struct ColorProperties {
ColorAttribute attribute;
Core::HID::NpadControllerColor color;
INSERT_PADDING_BYTES(0x4);
};
/// Handles Npad request from HID interfaces
class NpadAbstractPropertiesHandler final {
public:
explicit NpadAbstractPropertiesHandler();
~NpadAbstractPropertiesHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetAppletResource(AppletResourceHolder* applet_resource);
void SetNpadId(Core::HID::NpadIdType npad_id);
Core::HID::NpadIdType GetNpadId() const;
Result IncrementRefCounter();
Result DecrementRefCounter();
Result ActivateNpadUnknown0x88(u64 aruid);
void UpdateDeviceType();
void UpdateDeviceColor();
void UpdateFooterAttributes();
void UpdateAllDeviceProperties();
Core::HID::NpadInterfaceType GetFullkeyInterfaceType();
Core::HID::NpadInterfaceType GetInterfaceType();
Core::HID::NpadStyleSet GetStyleSet(u64 aruid);
std::size_t GetAbstractedPadsWithStyleTag(std::span<IAbstractedPad*> list,
Core::HID::NpadStyleTag style);
std::size_t GetAbstractedPads(std::span<IAbstractedPad*> list);
AppletFooterUiType GetAppletFooterUiType();
AppletDetailedUiType GetAppletDetailedUiType();
void UpdateDeviceProperties(u64 aruid, NpadSharedMemoryEntry& internal_state);
Core::HID::NpadInterfaceType GetNpadInterfaceType();
Result GetNpadFullKeyGripColor(Core::HID::NpadColor& main_color,
Core::HID::NpadColor& sub_color) const;
void GetNpadLeftRightInterfaceType(Core::HID::NpadInterfaceType& param_2,
Core::HID::NpadInterfaceType& param_3) const;
private:
AppletResourceHolder* applet_resource_holder{nullptr};
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
Core::HID::NpadIdType npad_id_type{Core::HID::NpadIdType::Invalid};
s32 ref_counter{};
Core::HID::DeviceIndex device_type{};
AppletDetailedUiType applet_ui_type{};
AppletFooterUiAttributes applet_ui_attributes{};
bool is_vertical{};
bool is_horizontal{};
bool use_plus{};
bool use_minus{};
bool has_directional_buttons{};
ColorProperties fullkey_color{};
ColorProperties left_color{};
ColorProperties right_color{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,154 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/hid_util.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_sixaxis_handler.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
NpadAbstractSixAxisHandler::NpadAbstractSixAxisHandler() {}
NpadAbstractSixAxisHandler::~NpadAbstractSixAxisHandler() = default;
void NpadAbstractSixAxisHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractSixAxisHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
applet_resource_holder = applet_resource;
}
void NpadAbstractSixAxisHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
void NpadAbstractSixAxisHandler::SetSixaxisResource(SixAxisResource* resource) {
six_axis_resource = resource;
}
Result NpadAbstractSixAxisHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractSixAxisHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
u64 NpadAbstractSixAxisHandler::IsFirmwareUpdateAvailable() {
// TODO
return false;
}
Result NpadAbstractSixAxisHandler::UpdateSixAxisState() {
Core::HID::NpadIdType npad_id = properties_handler->GetNpadId();
for (std::size_t i = 0; i < AruidIndexMax; i++) {
auto* data = applet_resource_holder->applet_resource->GetAruidDataByIndex(i);
if (data->flag.is_assigned) {
continue;
}
auto& npad_entry = data->shared_memory_format->npad.npad_entry[NpadIdTypeToIndex(npad_id)];
UpdateSixaxisInternalState(npad_entry, data->aruid,
data->flag.enable_six_axis_sensor.As<bool>());
}
return ResultSuccess;
}
Result NpadAbstractSixAxisHandler::UpdateSixAxisState(u64 aruid) {
Core::HID::NpadIdType npad_id = properties_handler->GetNpadId();
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return ResultSuccess;
}
auto& npad_entry = data->shared_memory_format->npad.npad_entry[NpadIdTypeToIndex(npad_id)];
UpdateSixaxisInternalState(npad_entry, data->aruid,
data->flag.enable_six_axis_sensor.As<bool>());
return ResultSuccess;
}
Result NpadAbstractSixAxisHandler::UpdateSixAxisState2(u64 aruid) {
const auto npad_index = NpadIdTypeToIndex(properties_handler->GetNpadId());
AruidData* aruid_data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (aruid_data == nullptr) {
return ResultSuccess;
}
auto& npad_internal_state = aruid_data->shared_memory_format->npad.npad_entry[npad_index];
UpdateSixaxisInternalState(npad_internal_state, aruid,
aruid_data->flag.enable_six_axis_sensor.As<bool>());
return ResultSuccess;
}
void NpadAbstractSixAxisHandler::UpdateSixaxisInternalState(NpadSharedMemoryEntry& npad_entry,
u64 aruid, bool is_sensor_enabled) {
const Core::HID::NpadStyleTag style_tag{properties_handler->GetStyleSet(aruid)};
if (!style_tag.palma) {
UpdateSixaxisFullkeyLifo(style_tag, npad_entry.internal_state.sixaxis_fullkey_lifo,
is_sensor_enabled);
} else {
UpdateSixAxisPalmaLifo(style_tag, npad_entry.internal_state.sixaxis_fullkey_lifo,
is_sensor_enabled);
}
UpdateSixaxisHandheldLifo(style_tag, npad_entry.internal_state.sixaxis_handheld_lifo,
is_sensor_enabled);
UpdateSixaxisDualLifo(style_tag, npad_entry.internal_state.sixaxis_dual_left_lifo,
is_sensor_enabled);
UpdateSixaxisDualLifo(style_tag, npad_entry.internal_state.sixaxis_dual_right_lifo,
is_sensor_enabled);
UpdateSixaxisLeftLifo(style_tag, npad_entry.internal_state.sixaxis_left_lifo,
is_sensor_enabled);
UpdateSixaxisRightLifo(style_tag, npad_entry.internal_state.sixaxis_right_lifo,
is_sensor_enabled);
// TODO: Set sixaxis properties
}
void NpadAbstractSixAxisHandler::UpdateSixaxisFullkeyLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo,
bool is_sensor_enabled) {
// TODO
}
void NpadAbstractSixAxisHandler::UpdateSixAxisPalmaLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo,
bool is_sensor_enabled) {
// TODO
}
void NpadAbstractSixAxisHandler::UpdateSixaxisHandheldLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo,
bool is_sensor_enabled) {
// TODO
}
void NpadAbstractSixAxisHandler::UpdateSixaxisDualLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo,
bool is_sensor_enabled) {
// TODO
}
void NpadAbstractSixAxisHandler::UpdateSixaxisLeftLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo,
bool is_sensor_enabled) {
// TODO
}
void NpadAbstractSixAxisHandler::UpdateSixaxisRightLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo,
bool is_sensor_enabled) {
// TODO
}
} // namespace Service::HID

View File

@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Service::HID {
class SixAxisResource;
struct AppletResourceHolder;
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
struct NpadSixAxisSensorLifo;
/// Handles Npad request from HID interfaces
class NpadAbstractSixAxisHandler final {
public:
explicit NpadAbstractSixAxisHandler();
~NpadAbstractSixAxisHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetAppletResource(AppletResourceHolder* applet_resource);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
void SetSixaxisResource(SixAxisResource* resource);
Result IncrementRefCounter();
Result DecrementRefCounter();
u64 IsFirmwareUpdateAvailable();
Result UpdateSixAxisState();
Result UpdateSixAxisState(u64 aruid);
Result UpdateSixAxisState2(u64 aruid);
private:
void UpdateSixaxisInternalState(NpadSharedMemoryEntry& npad_entry, u64 aruid,
bool is_sensor_enabled);
void UpdateSixaxisFullkeyLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo, bool is_sensor_enabled);
void UpdateSixAxisPalmaLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo, bool is_sensor_enabled);
void UpdateSixaxisHandheldLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo, bool is_sensor_enabled);
void UpdateSixaxisDualLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo, bool is_sensor_enabled);
void UpdateSixaxisLeftLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo, bool is_sensor_enabled);
void UpdateSixaxisRightLifo(Core::HID::NpadStyleTag style_tag,
NpadSixAxisSensorLifo& sensor_lifo, bool is_sensor_enabled);
AppletResourceHolder* applet_resource_holder{nullptr};
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
SixAxisResource* six_axis_resource{nullptr};
s32 ref_counter{};
};
} // namespace Service::HID

View File

@@ -0,0 +1,73 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/hid_util.h"
#include "hid_core/resources/abstracted_pad/abstract_pad_holder.h"
#include "hid_core/resources/abstracted_pad/abstract_properties_handler.h"
#include "hid_core/resources/abstracted_pad/abstract_vibration_handler.h"
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/npad/npad_vibration.h"
#include "hid_core/resources/vibration/gc_vibration_device.h"
#include "hid_core/resources/vibration/n64_vibration_device.h"
#include "hid_core/resources/vibration/vibration_device.h"
namespace Service::HID {
NpadAbstractVibrationHandler::NpadAbstractVibrationHandler() {}
NpadAbstractVibrationHandler::~NpadAbstractVibrationHandler() = default;
void NpadAbstractVibrationHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
abstract_pad_holder = holder;
}
void NpadAbstractVibrationHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
applet_resource_holder = applet_resource;
}
void NpadAbstractVibrationHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
properties_handler = handler;
}
void NpadAbstractVibrationHandler::SetN64Vibration(NpadN64VibrationDevice* n64_device) {
n64_vibration_device = n64_device;
}
void NpadAbstractVibrationHandler::SetVibration(std::span<NpadVibrationDevice*> device) {
for (std::size_t i = 0; i < device.size() && i < vibration_device.size(); i++) {
vibration_device[i] = device[i];
}
}
void NpadAbstractVibrationHandler::SetGcVibration(NpadGcVibrationDevice* gc_device) {
gc_vibration_device = gc_device;
}
Result NpadAbstractVibrationHandler::IncrementRefCounter() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultNpadHandlerOverflow;
}
ref_counter++;
return ResultSuccess;
}
Result NpadAbstractVibrationHandler::DecrementRefCounter() {
if (ref_counter == 0) {
return ResultNpadHandlerNotInitialized;
}
ref_counter--;
return ResultSuccess;
}
void NpadAbstractVibrationHandler::UpdateVibrationState() {
const bool is_handheld_hid_enabled =
applet_resource_holder->handheld_config->is_handheld_hid_enabled;
const bool is_force_handheld_style_vibration =
applet_resource_holder->handheld_config->is_force_handheld_style_vibration;
if (!is_handheld_hid_enabled && is_force_handheld_style_vibration) {
// TODO
}
}
} // namespace Service::HID

View File

@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <span>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
namespace Service::HID {
struct AppletResourceHolder;
class NpadAbstractedPadHolder;
class NpadAbstractPropertiesHandler;
class NpadGcVibrationDevice;
class NpadVibrationDevice;
class NpadN64VibrationDevice;
class NpadVibration;
/// Keeps track of battery levels and updates npad battery shared memory values
class NpadAbstractVibrationHandler final {
public:
explicit NpadAbstractVibrationHandler();
~NpadAbstractVibrationHandler();
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
void SetAppletResource(AppletResourceHolder* applet_resource);
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
void SetN64Vibration(NpadN64VibrationDevice* n64_device);
void SetVibration(std::span<NpadVibrationDevice*> device);
void SetGcVibration(NpadGcVibrationDevice* gc_device);
Result IncrementRefCounter();
Result DecrementRefCounter();
void UpdateVibrationState();
private:
AppletResourceHolder* applet_resource_holder{nullptr};
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
NpadAbstractPropertiesHandler* properties_handler{nullptr};
NpadN64VibrationDevice* n64_vibration_device{nullptr};
std::array<NpadVibrationDevice*, 2> vibration_device{};
NpadGcVibrationDevice* gc_vibration_device{nullptr};
NpadVibration* vibration_handler{nullptr};
s32 ref_counter{};
};
} // namespace Service::HID

View File

@@ -193,7 +193,7 @@ void NPad::InitNewlyAddedController(u64 aruid, Core::HID::NpadIdType npad_id) {
case Core::HID::NpadStyleIndex::None:
ASSERT(false);
break;
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
shared_memory->fullkey_color.attribute = ColorAttribute::Ok;
shared_memory->fullkey_color.fullkey = body_colors.fullkey;
shared_memory->battery_level_dual = battery_level.dual.battery_level;
@@ -491,7 +491,7 @@ void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
case Core::HID::NpadStyleIndex::None:
ASSERT(false);
break;
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::NES:
case Core::HID::NpadStyleIndex::SNES:
case Core::HID::NpadStyleIndex::N64:
@@ -1292,7 +1292,7 @@ Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties(
u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
auto& controller = GetControllerFromHandle(aruid, sixaxis_handle);
switch (sixaxis_handle.npad_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::Pokeball:
return controller.shared_memory->sixaxis_fullkey_properties;
case Core::HID::NpadStyleIndex::Handheld:
@@ -1315,7 +1315,7 @@ const Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties(
u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle) const {
const auto& controller = GetControllerFromHandle(aruid, sixaxis_handle);
switch (sixaxis_handle.npad_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::Pokeball:
return controller.shared_memory->sixaxis_fullkey_properties;
case Core::HID::NpadStyleIndex::Handheld:

View File

@@ -151,7 +151,7 @@ Core::HID::NpadStyleSet NPadData::GetSupportedNpadStyleSet() const {
bool NPadData::IsNpadStyleIndexSupported(Core::HID::NpadStyleIndex style_index) const {
Core::HID::NpadStyleTag style = {supported_npad_style_set};
switch (style_index) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
return style.fullkey.As<bool>();
case Core::HID::NpadStyleIndex::Handheld:
return style.handheld.As<bool>();

View File

@@ -252,4 +252,103 @@ enum class NpadLagerType : u32 {
U,
};
// nn::hidtypes::FeatureType
struct FeatureType {
union {
u64 raw{};
BitField<0, 1, u64> has_left_analog_stick;
BitField<1, 1, u64> has_right_analog_stick;
BitField<2, 1, u64> has_left_joy_six_axis_sensor;
BitField<3, 1, u64> has_right_joy_six_axis_sensor;
BitField<4, 1, u64> has_fullkey_joy_six_axis_sensor;
BitField<5, 1, u64> has_left_lra_vibration_device;
BitField<6, 1, u64> has_right_lra_vibration_device;
BitField<7, 1, u64> has_gc_vibration_device;
BitField<8, 1, u64> has_erm_vibration_device;
BitField<9, 1, u64> has_left_joy_rail_bus;
BitField<10, 1, u64> has_right_joy_rail_bus;
BitField<11, 1, u64> has_internal_bus;
BitField<12, 1, u64> is_palma;
BitField<13, 1, u64> has_nfc;
BitField<14, 1, u64> has_ir_sensor;
BitField<15, 1, u64> is_analog_stick_calibration_supported;
BitField<16, 1, u64> is_six_axis_Sensor_user_calibration_supported;
BitField<17, 1, u64> has_left_right_joy_battery;
BitField<18, 1, u64> has_fullkey_battery;
BitField<19, 1, u64> is_disconnect_controller_if_battery_none;
BitField<20, 1, u64> has_controller_color;
BitField<21, 1, u64> has_grip_color;
BitField<22, 1, u64> has_identification_code;
BitField<23, 1, u64> has_bluetooth_address;
BitField<24, 1, u64> has_mcu;
BitField<25, 1, u64> has_notification_led;
BitField<26, 1, u64> has_directional_buttons;
BitField<27, 1, u64> has_indicator_led;
BitField<28, 1, u64> is_button_config_embedded_supported;
BitField<29, 1, u64> is_button_config_full_supported;
BitField<30, 1, u64> is_button_config_left_supported;
BitField<31, 1, u64> is_button_config_right_supported;
BitField<32, 1, u64> is_usb_hid_device;
BitField<33, 1, u64> is_kuina_device;
BitField<34, 1, u64> is_direct_usb_to_bt_switching_device;
BitField<35, 1, u64> is_normalize_analog_stick_with_inner_cross;
};
};
static_assert(sizeof(FeatureType) == 8, "FeatureType is an invalid size");
// This is nn::hid::AssignmentStyle
struct AssignmentStyle {
union {
u32 raw{};
BitField<0, 1, u32> is_external_assigned;
BitField<1, 1, u32> is_external_left_assigned;
BitField<2, 1, u32> is_external_right_assigned;
BitField<3, 1, u32> is_handheld_assigned;
BitField<4, 1, u32> is_handheld_left_assigned;
BitField<5, 1, u32> is_handheld_right_assigned;
};
};
static_assert(sizeof(AssignmentStyle) == 4, "AssignmentStyle is an invalid size");
// This is nn::hid::server::IAbstractedPad::InternalFlags
struct InternalFlags {
union {
u32 raw{};
BitField<0, 1, u32> is_bound;
BitField<1, 1, u32> is_connected;
BitField<2, 1, u32> is_battery_low_ovln_required;
BitField<3, 1, u32> is_battery_low_ovln_delay_required;
BitField<4, 1, u32> is_sample_recieved;
BitField<5, 1, u32> is_virtual_input;
BitField<6, 1, u32> is_wired;
BitField<8, 1, u32> use_center_clamp;
BitField<9, 1, u32> has_virtual_six_axis_sensor_acceleration;
BitField<10, 1, u32> has_virtual_six_axis_sensor_angle;
BitField<11, 1, u32> is_debug_pad;
};
};
static_assert(sizeof(InternalFlags) == 4, "InternalFlags is an invalid size");
/// This is nn::hid::server::IAbstractedPad
struct IAbstractedPad {
InternalFlags internal_flags;
u64 controller_id;
u32 controller_number;
u64 low_battery_display_delay_time;
u64 low_battery_display_delay_interval;
FeatureType feature_set;
FeatureType disabled_feature_set;
AssignmentStyle assignment_style;
Core::HID::NpadStyleIndex device_type;
Core::HID::NpadInterfaceType interface_type;
Core::HID::NpadPowerInfo power_info;
u32 pad_state;
u32 button_mask;
u32 system_button_mask;
u8 indicator;
std::vector<f32> virtual_six_axis_sensor_acceleration;
std::vector<f32> virtual_six_axis_sensor_angle;
u64 xcd_handle;
u64 color;
};
} // namespace Service::HID

View File

@@ -0,0 +1,80 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/npad/npad_vibration.h"
namespace Service::HID {
NpadVibration::NpadVibration() {}
NpadVibration::~NpadVibration() = default;
Result NpadVibration::Activate() {
std::scoped_lock lock{mutex};
const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume();
// if (master_volume < 0.0f || master_volume > 1.0f) {
// return ResultVibrationStrenghtOutOfRange;
// }
volume = master_volume;
return ResultSuccess;
}
Result NpadVibration::Deactivate() {
return ResultSuccess;
}
Result NpadVibration::SetVibrationMasterVolume(f32 master_volume) {
std::scoped_lock lock{mutex};
if (master_volume < 0.0f && master_volume > 1.0f) {
return ResultVibrationStrenghtOutOfRange;
}
volume = master_volume;
// nn::settings::system::SetVibrationMasterVolume(master_volume);
return ResultSuccess;
}
Result NpadVibration::GetVibrationVolume(f32& out_volume) const {
std::scoped_lock lock{mutex};
out_volume = volume;
return ResultSuccess;
}
Result NpadVibration::GetVibrationMasterVolume(f32& out_volume) const {
std::scoped_lock lock{mutex};
const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume();
// if (master_volume < 0.0f || master_volume > 1.0f) {
// return ResultVibrationStrenghtOutOfRange;
// }
out_volume = master_volume;
return ResultSuccess;
}
Result NpadVibration::BeginPermitVibrationSession(u64 aruid) {
std::scoped_lock lock{mutex};
session_aruid = aruid;
volume = 1.0;
return ResultSuccess;
}
Result NpadVibration::EndPermitVibrationSession() {
std::scoped_lock lock{mutex};
const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume();
// if (master_volume < 0.0f || master_volume > 1.0f) {
// return ResultVibrationStrenghtOutOfRange;
// }
volume = master_volume;
session_aruid = 0;
return ResultSuccess;
}
} // namespace Service::HID

View File

@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <mutex>
#include "common/common_types.h"
#include "core/hle/result.h"
namespace Service::HID {
class NpadVibration final {
public:
explicit NpadVibration();
~NpadVibration();
Result Activate();
Result Deactivate();
Result SetVibrationMasterVolume(f32 master_volume);
Result GetVibrationVolume(f32& out_volume) const;
Result GetVibrationMasterVolume(f32& out_volume) const;
Result BeginPermitVibrationSession(u64 aruid);
Result EndPermitVibrationSession();
private:
f32 volume{};
u64 session_aruid{};
mutable std::mutex mutex;
};
} // namespace Service::HID

View File

@@ -114,7 +114,7 @@ void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
case Core::HID::NpadStyleIndex::None:
ASSERT(false);
break;
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
set_motion_state(sixaxis_fullkey_state, motion_state[0]);
break;
case Core::HID::NpadStyleIndex::Handheld:
@@ -345,7 +345,7 @@ SixAxis::SixaxisParameters& SixAxis::GetSixaxisState(
const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
auto& controller = GetControllerFromHandle(sixaxis_handle);
switch (sixaxis_handle.npad_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::Pokeball:
return controller.sixaxis_fullkey;
case Core::HID::NpadStyleIndex::Handheld:
@@ -368,7 +368,7 @@ const SixAxis::SixaxisParameters& SixAxis::GetSixaxisState(
const Core::HID::SixAxisSensorHandle& sixaxis_handle) const {
const auto& controller = GetControllerFromHandle(sixaxis_handle);
switch (sixaxis_handle.npad_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::Pokeball:
return controller.sixaxis_fullkey;
case Core::HID::NpadStyleIndex::Handheld:

View File

@@ -0,0 +1,106 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/npad/npad_vibration.h"
#include "hid_core/resources/vibration/gc_vibration_device.h"
namespace Service::HID {
NpadGcVibrationDevice::NpadGcVibrationDevice() {}
Result NpadGcVibrationDevice::IncrementRefCounter() {
if (ref_counter == 0 && is_mounted) {
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsSuccess()) {
// TODO: SendVibrationGcErmCommand
}
}
ref_counter++;
return ResultSuccess;
}
Result NpadGcVibrationDevice::DecrementRefCounter() {
if (ref_counter == 1 && !is_mounted) {
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsSuccess()) {
// TODO: SendVibrationGcErmCommand
}
}
if (ref_counter > 0) {
ref_counter--;
}
return ResultSuccess;
}
Result NpadGcVibrationDevice::SendVibrationGcErmCommand(Core::HID::VibrationGcErmCommand command) {
if (!is_mounted) {
return ResultSuccess;
}
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsError()) {
return result;
}
if (volume == 0.0) {
command = Core::HID::VibrationGcErmCommand::Stop;
} else {
if (command > Core::HID::VibrationGcErmCommand::StopHard) {
// Abort
return ResultSuccess;
}
}
// TODO: SendVibrationGcErmCommand
return ResultSuccess;
}
Result NpadGcVibrationDevice::GetActualVibrationGcErmCommand(
Core::HID::VibrationGcErmCommand& out_command) {
if (!is_mounted) {
out_command = Core::HID::VibrationGcErmCommand::Stop;
return ResultSuccess;
}
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsError()) {
return result;
}
if (volume == 0.0f) {
out_command = Core::HID::VibrationGcErmCommand::Stop;
return ResultSuccess;
}
// TODO: GetActualVibrationGcErmCommand
return ResultSuccess;
}
Result NpadGcVibrationDevice::SendVibrationNotificationPattern(
Core::HID::VibrationGcErmCommand command) {
if (!is_mounted) {
return ResultSuccess;
}
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsError()) {
return result;
}
if (volume <= 0.0f) {
command = Core::HID::VibrationGcErmCommand::Stop;
}
if (command > Core::HID::VibrationGcErmCommand::StopHard) {
// Abort
return ResultSuccess;
}
// TODO: SendVibrationNotificationPattern
return ResultSuccess;
}
} // namespace Service::HID

View File

@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <array>
#include <mutex>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/vibration/vibration_base.h"
namespace Service::HID {
class NpadVibration;
/// Handles Npad request from HID interfaces
class NpadGcVibrationDevice final : public NpadVibrationBase {
public:
explicit NpadGcVibrationDevice();
Result IncrementRefCounter() override;
Result DecrementRefCounter() override;
Result SendVibrationGcErmCommand(Core::HID::VibrationGcErmCommand command);
Result GetActualVibrationGcErmCommand(Core::HID::VibrationGcErmCommand& out_command);
Result SendVibrationNotificationPattern(Core::HID::VibrationGcErmCommand command);
};
} // namespace Service::HID

View File

@@ -0,0 +1,80 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/npad/npad_vibration.h"
#include "hid_core/resources/vibration/n64_vibration_device.h"
namespace Service::HID {
NpadN64VibrationDevice::NpadN64VibrationDevice() {}
Result NpadN64VibrationDevice::IncrementRefCounter() {
if (ref_counter == 0 && is_mounted) {
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsSuccess()) {
// TODO: SendVibrationInBool
}
}
ref_counter++;
return ResultSuccess;
}
Result NpadN64VibrationDevice::DecrementRefCounter() {
if (ref_counter == 1) {
if (!is_mounted) {
ref_counter = 0;
if (is_mounted != false) {
// TODO: SendVibrationInBool
}
return ResultSuccess;
}
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsSuccess()) {
// TODO
}
}
if (ref_counter > 0) {
ref_counter--;
}
return ResultSuccess;
}
Result NpadN64VibrationDevice::SendValueInBool(bool is_vibrating) {
if (ref_counter < 1) {
return ResultVibrationNotInitialized;
}
if (is_mounted) {
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsError()) {
return result;
}
// TODO: SendVibrationInBool
}
return ResultSuccess;
}
Result NpadN64VibrationDevice::SendVibrationNotificationPattern([[maybe_unused]] u32 pattern) {
if (!is_mounted) {
return ResultSuccess;
}
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsError()) {
return result;
}
if (volume <= 0.0) {
pattern = 0;
}
// TODO: SendVibrationNotificationPattern
return ResultSuccess;
}
} // namespace Service::HID

View File

@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <array>
#include <mutex>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/vibration/vibration_base.h"
namespace Service::HID {
class NpadVibration;
/// Handles Npad request from HID interfaces
class NpadN64VibrationDevice final : public NpadVibrationBase {
public:
explicit NpadN64VibrationDevice();
Result IncrementRefCounter() override;
Result DecrementRefCounter() override;
Result SendValueInBool(bool is_vibrating);
Result SendVibrationNotificationPattern(u32 pattern);
};
} // namespace Service::HID

View File

@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/npad/npad_vibration.h"
#include "hid_core/resources/vibration/vibration_base.h"
namespace Service::HID {
NpadVibrationBase::NpadVibrationBase() {}
Result NpadVibrationBase::IncrementRefCounter() {
ref_counter++;
return ResultSuccess;
}
Result NpadVibrationBase::DecrementRefCounter() {
if (ref_counter > 0) {
ref_counter--;
}
return ResultSuccess;
}
bool NpadVibrationBase::IsVibrationMounted() const {
return is_mounted;
}
} // namespace Service::HID

View File

@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "common/common_types.h"
#include "core/hle/result.h"
namespace Service::HID {
class NpadVibration;
/// Handles Npad request from HID interfaces
class NpadVibrationBase {
public:
explicit NpadVibrationBase();
virtual Result IncrementRefCounter();
virtual Result DecrementRefCounter();
bool IsVibrationMounted() const;
protected:
u64 xcd_handle{};
s32 ref_counter{};
bool is_mounted{};
NpadVibration* vibration_handler{nullptr};
};
} // namespace Service::HID

View File

@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "hid_core/hid_result.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/npad/npad_vibration.h"
#include "hid_core/resources/vibration/vibration_device.h"
namespace Service::HID {
NpadVibrationDevice::NpadVibrationDevice() {}
Result NpadVibrationDevice::IncrementRefCounter() {
ref_counter++;
return ResultSuccess;
}
Result NpadVibrationDevice::DecrementRefCounter() {
if (ref_counter > 0) {
ref_counter--;
}
return ResultSuccess;
}
Result NpadVibrationDevice::SendVibrationValue(const Core::HID::VibrationValue& value) {
if (ref_counter == 0) {
return ResultVibrationNotInitialized;
}
if (!is_mounted) {
return ResultSuccess;
}
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsError()) {
return result;
}
if (volume <= 0.0f) {
// TODO: SendVibrationValue
return ResultSuccess;
}
Core::HID::VibrationValue vibration_value = value;
vibration_value.high_amplitude *= volume;
vibration_value.low_amplitude *= volume;
// TODO: SendVibrationValue
return ResultSuccess;
}
Result NpadVibrationDevice::SendVibrationNotificationPattern([[maybe_unused]] u32 pattern) {
if (!is_mounted) {
return ResultSuccess;
}
f32 volume = 1.0f;
const auto result = vibration_handler->GetVibrationVolume(volume);
if (result.IsError()) {
return result;
}
if (volume <= 0.0) {
pattern = 0;
}
// return xcd_handle->SendVibrationNotificationPattern(pattern);
return ResultSuccess;
}
Result NpadVibrationDevice::GetActualVibrationValue(Core::HID::VibrationValue& out_value) {
if (ref_counter < 1) {
return ResultVibrationNotInitialized;
}
out_value = Core::HID::DEFAULT_VIBRATION_VALUE;
if (!is_mounted) {
return ResultSuccess;
}
// TODO: SendVibrationValue
return ResultSuccess;
}
} // namespace Service::HID

View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <array>
#include <mutex>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "hid_core/hid_types.h"
#include "hid_core/resources/npad/npad_types.h"
#include "hid_core/resources/vibration/vibration_base.h"
namespace Service::HID {
class NpadVibration;
/// Handles Npad request from HID interfaces
class NpadVibrationDevice final : public NpadVibrationBase {
public:
explicit NpadVibrationDevice();
Result IncrementRefCounter();
Result DecrementRefCounter();
Result SendVibrationValue(const Core::HID::VibrationValue& value);
Result SendVibrationNotificationPattern(u32 pattern);
Result GetActualVibrationValue(Core::HID::VibrationValue& out_value);
private:
u32 device_index{};
};
} // namespace Service::HID

View File

@@ -12,6 +12,11 @@ namespace Shader::Backend::SPIRV {
namespace {
class ImageOperands {
public:
[[maybe_unused]] static constexpr bool ImageSampleOffsetAllowed = false;
[[maybe_unused]] static constexpr bool ImageGatherOffsetAllowed = true;
[[maybe_unused]] static constexpr bool ImageFetchOffsetAllowed = false;
[[maybe_unused]] static constexpr bool ImageGradientOffsetAllowed = false;
explicit ImageOperands(EmitContext& ctx, bool has_bias, bool has_lod, bool has_lod_clamp,
Id lod, const IR::Value& offset) {
if (has_bias) {
@@ -22,7 +27,7 @@ public:
const Id lod_value{has_lod_clamp ? ctx.OpCompositeExtract(ctx.F32[1], lod, 0) : lod};
Add(spv::ImageOperandsMask::Lod, lod_value);
}
AddOffset(ctx, offset);
AddOffset(ctx, offset, ImageSampleOffsetAllowed);
if (has_lod_clamp) {
const Id lod_clamp{has_bias ? ctx.OpCompositeExtract(ctx.F32[1], lod, 1) : lod};
Add(spv::ImageOperandsMask::MinLod, lod_clamp);
@@ -55,20 +60,17 @@ public:
Add(spv::ImageOperandsMask::ConstOffsets, offsets);
}
explicit ImageOperands(Id offset, Id lod, Id ms) {
explicit ImageOperands(Id lod, Id ms) {
if (Sirit::ValidId(lod)) {
Add(spv::ImageOperandsMask::Lod, lod);
}
if (Sirit::ValidId(offset)) {
Add(spv::ImageOperandsMask::Offset, offset);
}
if (Sirit::ValidId(ms)) {
Add(spv::ImageOperandsMask::Sample, ms);
}
}
explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivatives,
u32 num_derivatives, Id offset, Id lod_clamp) {
u32 num_derivatives, const IR::Value& offset, Id lod_clamp) {
if (!Sirit::ValidId(derivatives)) {
throw LogicError("Derivatives must be present");
}
@@ -83,16 +85,14 @@ public:
const Id derivatives_Y{ctx.OpCompositeConstruct(
ctx.F32[num_derivatives], std::span{deriv_y_accum.data(), deriv_y_accum.size()})};
Add(spv::ImageOperandsMask::Grad, derivatives_X, derivatives_Y);
if (Sirit::ValidId(offset)) {
Add(spv::ImageOperandsMask::Offset, offset);
}
AddOffset(ctx, offset, ImageGradientOffsetAllowed);
if (has_lod_clamp) {
Add(spv::ImageOperandsMask::MinLod, lod_clamp);
}
}
explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivatives_1, Id derivatives_2,
Id offset, Id lod_clamp) {
const IR::Value& offset, Id lod_clamp) {
if (!Sirit::ValidId(derivatives_1) || !Sirit::ValidId(derivatives_2)) {
throw LogicError("Derivatives must be present");
}
@@ -111,9 +111,7 @@ public:
const Id derivatives_id2{ctx.OpCompositeConstruct(
ctx.F32[3], std::span{deriv_2_accum.data(), deriv_2_accum.size()})};
Add(spv::ImageOperandsMask::Grad, derivatives_id1, derivatives_id2);
if (Sirit::ValidId(offset)) {
Add(spv::ImageOperandsMask::Offset, offset);
}
AddOffset(ctx, offset, ImageGradientOffsetAllowed);
if (has_lod_clamp) {
Add(spv::ImageOperandsMask::MinLod, lod_clamp);
}
@@ -132,7 +130,7 @@ public:
}
private:
void AddOffset(EmitContext& ctx, const IR::Value& offset) {
void AddOffset(EmitContext& ctx, const IR::Value& offset, bool runtime_offset_allowed) {
if (offset.IsEmpty()) {
return;
}
@@ -165,7 +163,9 @@ private:
break;
}
}
Add(spv::ImageOperandsMask::Offset, ctx.Def(offset));
if (runtime_offset_allowed) {
Add(spv::ImageOperandsMask::Offset, ctx.Def(offset));
}
}
void Add(spv::ImageOperandsMask new_mask, Id value) {
@@ -311,6 +311,37 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info,
return coords;
}
}
void AddOffsetToCoordinates(EmitContext& ctx, const IR::TextureInstInfo& info, Id& coords,
Id offset) {
if (!Sirit::ValidId(offset)) {
return;
}
Id result_type{};
switch (info.type) {
case TextureType::Buffer:
case TextureType::Color1D:
case TextureType::ColorArray1D: {
result_type = ctx.U32[1];
break;
}
case TextureType::Color2D:
case TextureType::Color2DRect:
case TextureType::ColorArray2D: {
result_type = ctx.U32[2];
break;
}
case TextureType::Color3D: {
result_type = ctx.U32[3];
break;
}
case TextureType::ColorCube:
case TextureType::ColorArrayCube:
return;
}
coords = ctx.OpIAdd(result_type, coords, offset);
}
} // Anonymous namespace
Id EmitBindlessImageSampleImplicitLod(EmitContext&) {
@@ -496,6 +527,7 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset,
Id lod, Id ms) {
const auto info{inst->Flags<IR::TextureInstInfo>()};
AddOffsetToCoordinates(ctx, info, coords, offset);
if (info.type == TextureType::Buffer) {
lod = Id{};
}
@@ -503,7 +535,7 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c
// This image is multisampled, lod must be implicit
lod = Id{};
}
const ImageOperands operands(offset, lod, ms);
const ImageOperands operands(lod, ms);
return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4],
TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span());
}
@@ -548,13 +580,13 @@ Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, I
}
Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
Id derivatives, Id offset, Id lod_clamp) {
Id derivatives, const IR::Value& offset, Id lod_clamp) {
const auto info{inst->Flags<IR::TextureInstInfo>()};
const auto operands =
info.num_derivatives == 3
? ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, offset, {}, lod_clamp)
: ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, info.num_derivatives, offset,
lod_clamp);
const auto operands = info.num_derivatives == 3
? ImageOperands(ctx, info.has_lod_clamp != 0, derivatives,
ctx.Def(offset), {}, lod_clamp)
: ImageOperands(ctx, info.has_lod_clamp != 0, derivatives,
info.num_derivatives, offset, lod_clamp);
return Emit(&EmitContext::OpImageSparseSampleExplicitLod,
&EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4],
Texture(ctx, info, index), coords, operands.Mask(), operands.Span());

View File

@@ -543,7 +543,7 @@ Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& i
const IR::Value& skip_mips);
Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);
Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
Id derivatives, Id offset, Id lod_clamp);
Id derivatives, const IR::Value& offset, Id lod_clamp);
Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);
void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color);
Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index);

View File

@@ -65,6 +65,14 @@ void WriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value&
WriteStorage(ctx, binding, offset, value, ctx.storage_types.U32, sizeof(u32),
&StorageDefinitions::U32, index_offset);
}
void WriteStorageByCasLoop(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
Id value, Id bit_offset, Id bit_count) {
const Id pointer{StoragePointer(ctx, binding, offset, ctx.storage_types.U32, sizeof(u32),
&StorageDefinitions::U32)};
ctx.OpFunctionCall(ctx.TypeVoid(), ctx.write_storage_cas_loop_func, pointer, value, bit_offset,
bit_count);
}
} // Anonymous namespace
void EmitLoadGlobalU8(EmitContext&) {
@@ -219,26 +227,42 @@ Id EmitLoadStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Valu
void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
Id value) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.U8, value), ctx.storage_types.U8,
sizeof(u8), &StorageDefinitions::U8);
if (ctx.profile.support_int8) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.U8, value), ctx.storage_types.U8,
sizeof(u8), &StorageDefinitions::U8);
} else {
WriteStorageByCasLoop(ctx, binding, offset, value, ctx.BitOffset8(offset), ctx.Const(8u));
}
}
void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
Id value) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.S8, value), ctx.storage_types.S8,
sizeof(s8), &StorageDefinitions::S8);
if (ctx.profile.support_int8) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.S8, value), ctx.storage_types.S8,
sizeof(s8), &StorageDefinitions::S8);
} else {
WriteStorageByCasLoop(ctx, binding, offset, value, ctx.BitOffset8(offset), ctx.Const(8u));
}
}
void EmitWriteStorageU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
Id value) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.U16, value), ctx.storage_types.U16,
sizeof(u16), &StorageDefinitions::U16);
if (ctx.profile.support_int16) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.U16, value), ctx.storage_types.U16,
sizeof(u16), &StorageDefinitions::U16);
} else {
WriteStorageByCasLoop(ctx, binding, offset, value, ctx.BitOffset16(offset), ctx.Const(16u));
}
}
void EmitWriteStorageS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
Id value) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.S16, value), ctx.storage_types.S16,
sizeof(s16), &StorageDefinitions::S16);
if (ctx.profile.support_int16) {
WriteStorage(ctx, binding, offset, ctx.OpSConvert(ctx.S16, value), ctx.storage_types.S16,
sizeof(s16), &StorageDefinitions::S16);
} else {
WriteStorageByCasLoop(ctx, binding, offset, value, ctx.BitOffset16(offset), ctx.Const(16u));
}
}
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,

View File

@@ -480,6 +480,7 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf
DefineTextures(program.info, texture_binding, bindings.texture_scaling_index);
DefineImages(program.info, image_binding, bindings.image_scaling_index);
DefineAttributeMemAccess(program.info);
DefineWriteStorageCasLoopFunction(program.info);
DefineGlobalMemoryFunctions(program.info);
DefineRescalingInput(program.info);
DefineRenderArea(program.info);
@@ -877,6 +878,56 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
}
}
void EmitContext::DefineWriteStorageCasLoopFunction(const Info& info) {
if (profile.support_int8 && profile.support_int16) {
return;
}
if (!info.uses_int8 && !info.uses_int16) {
return;
}
AddCapability(spv::Capability::VariablePointersStorageBuffer);
const Id ptr_type{TypePointer(spv::StorageClass::StorageBuffer, U32[1])};
const Id func_type{TypeFunction(void_id, ptr_type, U32[1], U32[1], U32[1])};
const Id func{OpFunction(void_id, spv::FunctionControlMask::MaskNone, func_type)};
const Id pointer{OpFunctionParameter(ptr_type)};
const Id value{OpFunctionParameter(U32[1])};
const Id bit_offset{OpFunctionParameter(U32[1])};
const Id bit_count{OpFunctionParameter(U32[1])};
AddLabel();
const Id scope_device{Const(1u)};
const Id ordering_relaxed{u32_zero_value};
const Id body_label{OpLabel()};
const Id continue_label{OpLabel()};
const Id endloop_label{OpLabel()};
const Id beginloop_label{OpLabel()};
OpBranch(beginloop_label);
AddLabel(beginloop_label);
OpLoopMerge(endloop_label, continue_label, spv::LoopControlMask::MaskNone);
OpBranch(body_label);
AddLabel(body_label);
const Id expected_value{OpLoad(U32[1], pointer)};
const Id desired_value{OpBitFieldInsert(U32[1], expected_value, value, bit_offset, bit_count)};
const Id actual_value{OpAtomicCompareExchange(U32[1], pointer, scope_device, ordering_relaxed,
ordering_relaxed, desired_value, expected_value)};
const Id store_successful{OpIEqual(U1, expected_value, actual_value)};
OpBranchConditional(store_successful, endloop_label, continue_label);
AddLabel(endloop_label);
OpReturn();
AddLabel(continue_label);
OpBranch(beginloop_label);
OpFunctionEnd();
write_storage_cas_loop_func = func;
}
void EmitContext::DefineGlobalMemoryFunctions(const Info& info) {
if (!info.uses_global_memory || !profile.support_int64) {
return;

View File

@@ -325,6 +325,8 @@ public:
Id f32x2_min_cas{};
Id f32x2_max_cas{};
Id write_storage_cas_loop_func{};
Id load_global_func_u32{};
Id load_global_func_u32x2{};
Id load_global_func_u32x4{};
@@ -372,6 +374,7 @@ private:
void DefineTextures(const Info& info, u32& binding, u32& scaling_index);
void DefineImages(const Info& info, u32& binding, u32& scaling_index);
void DefineAttributeMemAccess(const Info& info);
void DefineWriteStorageCasLoopFunction(const Info& info);
void DefineGlobalMemoryFunctions(const Info& info);
void DefineRescalingInput(const Info& info);
void DefineRescalingInputPushConstant();

View File

@@ -41,7 +41,7 @@ void UpdateController(Core::HID::EmulatedController* controller,
bool IsControllerCompatible(Core::HID::NpadStyleIndex controller_type,
Core::Frontend::ControllerParameters parameters) {
switch (controller_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
return parameters.allow_pro_controller;
case Core::HID::NpadStyleIndex::JoyconDual:
return parameters.allow_dual_joycons;
@@ -462,7 +462,7 @@ void QtControllerSelectorDialog::SetEmulatedControllers(std::size_t player_index
};
if (npad_style_set.fullkey == 1) {
add_item(Core::HID::NpadStyleIndex::ProController, tr("Pro Controller"));
add_item(Core::HID::NpadStyleIndex::Fullkey, tr("Pro Controller"));
}
if (npad_style_set.joycon_dual == 1) {
@@ -519,7 +519,7 @@ Core::HID::NpadStyleIndex QtControllerSelectorDialog::GetControllerTypeFromIndex
[index](const auto& pair) { return pair.first == index; });
if (it == pairs.end()) {
return Core::HID::NpadStyleIndex::ProController;
return Core::HID::NpadStyleIndex::Fullkey;
}
return it->second;
@@ -549,7 +549,7 @@ void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index)
const QString stylesheet = [this, player_index] {
switch (GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex(),
player_index)) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::GameCube:
return QStringLiteral("image: url(:/controller/applet_pro_controller%0); ");
case Core::HID::NpadStyleIndex::JoyconDual:

View File

@@ -832,7 +832,7 @@ void QtSoftwareKeyboardDialog::SetControllerImage() {
}();
switch (controller_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::GameCube:
ui->icon_controller->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_pro%1.png);").arg(theme));

View File

@@ -1094,7 +1094,7 @@ void ConfigureInputPlayer::SetConnectableControllers() {
};
if (npad_style_set.fullkey == 1) {
add_item(Core::HID::NpadStyleIndex::ProController, tr("Pro Controller"));
add_item(Core::HID::NpadStyleIndex::Fullkey, tr("Pro Controller"));
}
if (npad_style_set.joycon_dual == 1) {
@@ -1149,7 +1149,7 @@ Core::HID::NpadStyleIndex ConfigureInputPlayer::GetControllerTypeFromIndex(int i
[index](const auto& pair) { return pair.first == index; });
if (it == index_controller_type_pairs.end()) {
return Core::HID::NpadStyleIndex::ProController;
return Core::HID::NpadStyleIndex::Fullkey;
}
return it->second;
@@ -1178,7 +1178,7 @@ void ConfigureInputPlayer::UpdateInputDevices() {
void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
layout = Core::HID::NpadStyleIndex::ProController;
layout = Core::HID::NpadStyleIndex::Fullkey;
}
// List of all the widgets that will be hidden by any of the following layouts that need
@@ -1206,7 +1206,7 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
std::vector<QWidget*> layout_hidden;
switch (layout) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::Handheld:
layout_hidden = {
ui->buttonShoulderButtonsSLSRLeft,
@@ -1254,7 +1254,7 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
void ConfigureInputPlayer::UpdateControllerEnabledButtons() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
layout = Core::HID::NpadStyleIndex::ProController;
layout = Core::HID::NpadStyleIndex::Fullkey;
}
// List of all the widgets that will be disabled by any of the following layouts that need
@@ -1271,7 +1271,7 @@ void ConfigureInputPlayer::UpdateControllerEnabledButtons() {
std::vector<QWidget*> layout_disable;
switch (layout) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::JoyconDual:
case Core::HID::NpadStyleIndex::Handheld:
case Core::HID::NpadStyleIndex::JoyconLeft:
@@ -1304,7 +1304,7 @@ void ConfigureInputPlayer::UpdateMotionButtons() {
// Show/hide the "Motion 1/2" groupboxes depending on the currently selected controller.
switch (GetControllerTypeFromIndex(ui->comboControllerType->currentIndex())) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::JoyconLeft:
case Core::HID::NpadStyleIndex::Handheld:
// Show "Motion 1" and hide "Motion 2".
@@ -1333,11 +1333,11 @@ void ConfigureInputPlayer::UpdateMotionButtons() {
void ConfigureInputPlayer::UpdateControllerButtonNames() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
layout = Core::HID::NpadStyleIndex::ProController;
layout = Core::HID::NpadStyleIndex::Fullkey;
}
switch (layout) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::JoyconDual:
case Core::HID::NpadStyleIndex::Handheld:
case Core::HID::NpadStyleIndex::JoyconLeft:

View File

@@ -244,7 +244,7 @@ void PlayerControlPreview::paintEvent(QPaintEvent* event) {
case Core::HID::NpadStyleIndex::GameCube:
DrawGCController(p, center);
break;
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
default:
DrawProController(p, center);
break;

View File

@@ -205,6 +205,7 @@ void ConfigureProfileManager::AddUser() {
const auto uuid = Common::UUID::MakeRandom();
profile_manager.CreateNewUser(uuid, username.toStdString());
profile_manager.WriteUserSaveFile();
item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)});
}
@@ -228,6 +229,7 @@ void ConfigureProfileManager::RenameUser() {
std::copy(username_std.begin(), username_std.end(), profile.username.begin());
profile_manager.SetProfileBase(*uuid, profile);
profile_manager.WriteUserSaveFile();
item_model->setItem(
user, 0,
@@ -256,6 +258,8 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
return;
}
profile_manager.WriteUserSaveFile();
item_model->removeRows(tree_view->currentIndex().row(), 1);
tree_view->clearSelection();

View File

@@ -3988,7 +3988,7 @@ void GMainWindow::OnToggleDockedMode() {
tr("Handheld controller can't be used on docked mode. Pro "
"controller will be selected."));
handheld->Disconnect();
player_1->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
player_1->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
player_1->Connect();
controller_dialog->refreshConfiguration();
}

View File

@@ -66,7 +66,7 @@ void ControllerNavigation::ControllerUpdateButton() {
}
switch (controller_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::JoyconDual:
case Core::HID::NpadStyleIndex::Handheld:
case Core::HID::NpadStyleIndex::GameCube:
@@ -116,7 +116,7 @@ void ControllerNavigation::ControllerUpdateStick() {
}
switch (controller_type) {
case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Fullkey:
case Core::HID::NpadStyleIndex::JoyconDual:
case Core::HID::NpadStyleIndex::Handheld:
case Core::HID::NpadStyleIndex::GameCube: