summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/android-merge.js49
-rw-r--r--.github/workflows/android-publish.yml4
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt17
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt28
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt3
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt5
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt3
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt12
-rw-r--r--src/android/app/src/main/jni/android_config.cpp6
-rw-r--r--src/android/app/src/main/jni/android_config.h1
-rw-r--r--src/android/app/src/main/jni/native.cpp6
-rw-r--r--src/android/app/src/main/res/values/arrays.xml12
-rw-r--r--src/android/app/src/main/res/values/strings.xml6
-rw-r--r--src/core/CMakeLists.txt92
-rw-r--r--src/core/core.cpp2
-rw-r--r--src/core/frontend/applets/controller.cpp6
-rw-r--r--src/core/hle/kernel/k_thread.cpp8
-rw-r--r--src/core/hle/service/am/am.cpp4
-rw-r--r--src/core/hle/service/am/applets/applet_cabinet.cpp2
-rw-r--r--src/core/hle/service/am/applets/applet_controller.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/npad.h197
-rw-r--r--src/core/hle/service/hid/errors.h39
-rw-r--r--src/core/hle/service/hid/hid.cpp5
-rw-r--r--src/core/hle/service/hid/hid_debug_server.cpp2
-rw-r--r--src/core/hle/service/hid/hid_server.cpp257
-rw-r--r--src/core/hle/service/hid/hid_system_server.cpp113
-rw-r--r--src/core/hle/service/hid/hid_system_server.h6
-rw-r--r--src/core/hle/service/hid/hidbus.cpp8
-rw-r--r--src/core/hle/service/hid/hidbus.h2
-rw-r--r--src/core/hle/service/hid/irs.cpp22
-rw-r--r--src/core/hle/service/hid/irs.h6
-rw-r--r--src/core/hle/service/nfc/common/device.cpp6
-rw-r--r--src/core/hle/service/nfc/common/device_manager.cpp4
-rw-r--r--src/core/hle/service/nfc/common/device_manager.h2
-rw-r--r--src/core/hle/service/nfc/nfc_interface.cpp2
-rw-r--r--src/core/hle/service/nfp/nfp_interface.cpp2
-rw-r--r--src/core/memory/cheat_engine.cpp4
-rw-r--r--src/frontend_common/config.cpp18
-rw-r--r--src/frontend_common/config.h16
-rw-r--r--src/hid_core/CMakeLists.txt126
-rw-r--r--src/hid_core/frontend/emulated_console.cpp (renamed from src/core/hid/emulated_console.cpp)4
-rw-r--r--src/hid_core/frontend/emulated_console.h (renamed from src/core/hid/emulated_console.h)4
-rw-r--r--src/hid_core/frontend/emulated_controller.cpp (renamed from src/core/hid/emulated_controller.cpp)6
-rw-r--r--src/hid_core/frontend/emulated_controller.h (renamed from src/core/hid/emulated_controller.h)6
-rw-r--r--src/hid_core/frontend/emulated_devices.cpp (renamed from src/core/hid/emulated_devices.cpp)4
-rw-r--r--src/hid_core/frontend/emulated_devices.h (renamed from src/core/hid/emulated_devices.h)2
-rw-r--r--src/hid_core/frontend/input_converter.cpp (renamed from src/core/hid/input_converter.cpp)2
-rw-r--r--src/hid_core/frontend/input_converter.h (renamed from src/core/hid/input_converter.h)0
-rw-r--r--src/hid_core/frontend/input_interpreter.cpp (renamed from src/core/hid/input_interpreter.cpp)8
-rw-r--r--src/hid_core/frontend/input_interpreter.h (renamed from src/core/hid/input_interpreter.h)0
-rw-r--r--src/hid_core/frontend/motion_input.cpp (renamed from src/core/hid/motion_input.cpp)2
-rw-r--r--src/hid_core/frontend/motion_input.h (renamed from src/core/hid/motion_input.h)0
-rw-r--r--src/hid_core/hid_core.cpp (renamed from src/core/hid/hid_core.cpp)10
-rw-r--r--src/hid_core/hid_core.h (renamed from src/core/hid/hid_core.h)2
-rw-r--r--src/hid_core/hid_result.h59
-rw-r--r--src/hid_core/hid_types.h (renamed from src/core/hid/hid_types.h)1
-rw-r--r--src/hid_core/hid_util.h (renamed from src/core/hle/service/hid/hid_util.h)12
-rw-r--r--src/hid_core/hidbus/hidbus_base.cpp (renamed from src/core/hle/service/hid/hidbus/hidbus_base.cpp)4
-rw-r--r--src/hid_core/hidbus/hidbus_base.h (renamed from src/core/hle/service/hid/hidbus/hidbus_base.h)0
-rw-r--r--src/hid_core/hidbus/ringcon.cpp (renamed from src/core/hle/service/hid/hidbus/ringcon.cpp)6
-rw-r--r--src/hid_core/hidbus/ringcon.h (renamed from src/core/hle/service/hid/hidbus/ringcon.h)2
-rw-r--r--src/hid_core/hidbus/starlink.cpp (renamed from src/core/hle/service/hid/hidbus/starlink.cpp)6
-rw-r--r--src/hid_core/hidbus/starlink.h (renamed from src/core/hle/service/hid/hidbus/starlink.h)2
-rw-r--r--src/hid_core/hidbus/stubbed.cpp (renamed from src/core/hle/service/hid/hidbus/stubbed.cpp)6
-rw-r--r--src/hid_core/hidbus/stubbed.h (renamed from src/core/hle/service/hid/hidbus/stubbed.h)2
-rw-r--r--src/hid_core/irsensor/clustering_processor.cpp (renamed from src/core/hle/service/hid/irsensor/clustering_processor.cpp)6
-rw-r--r--src/hid_core/irsensor/clustering_processor.h (renamed from src/core/hle/service/hid/irsensor/clustering_processor.h)6
-rw-r--r--src/hid_core/irsensor/image_transfer_processor.cpp (renamed from src/core/hle/service/hid/irsensor/image_transfer_processor.cpp)6
-rw-r--r--src/hid_core/irsensor/image_transfer_processor.h (renamed from src/core/hle/service/hid/irsensor/image_transfer_processor.h)4
-rw-r--r--src/hid_core/irsensor/ir_led_processor.cpp (renamed from src/core/hle/service/hid/irsensor/ir_led_processor.cpp)2
-rw-r--r--src/hid_core/irsensor/ir_led_processor.h (renamed from src/core/hle/service/hid/irsensor/ir_led_processor.h)4
-rw-r--r--src/hid_core/irsensor/irs_types.h (renamed from src/core/hid/irs_types.h)2
-rw-r--r--src/hid_core/irsensor/moment_processor.cpp (renamed from src/core/hle/service/hid/irsensor/moment_processor.cpp)6
-rw-r--r--src/hid_core/irsensor/moment_processor.h (renamed from src/core/hle/service/hid/irsensor/moment_processor.h)6
-rw-r--r--src/hid_core/irsensor/pointing_processor.cpp (renamed from src/core/hle/service/hid/irsensor/pointing_processor.cpp)2
-rw-r--r--src/hid_core/irsensor/pointing_processor.h (renamed from src/core/hle/service/hid/irsensor/pointing_processor.h)4
-rw-r--r--src/hid_core/irsensor/processor_base.cpp (renamed from src/core/hle/service/hid/irsensor/processor_base.cpp)2
-rw-r--r--src/hid_core/irsensor/processor_base.h (renamed from src/core/hle/service/hid/irsensor/processor_base.h)2
-rw-r--r--src/hid_core/irsensor/tera_plugin_processor.cpp (renamed from src/core/hle/service/hid/irsensor/tera_plugin_processor.cpp)2
-rw-r--r--src/hid_core/irsensor/tera_plugin_processor.h (renamed from src/core/hle/service/hid/irsensor/tera_plugin_processor.h)4
-rw-r--r--src/hid_core/precompiled_headers.h6
-rw-r--r--src/hid_core/resource_manager.cpp (renamed from src/core/hle/service/hid/resource_manager.cpp)81
-rw-r--r--src/hid_core/resource_manager.h (renamed from src/core/hle/service/hid/resource_manager.h)2
-rw-r--r--src/hid_core/resources/applet_resource.cpp (renamed from src/core/hle/service/hid/controllers/applet_resource.cpp)40
-rw-r--r--src/hid_core/resources/applet_resource.h (renamed from src/core/hle/service/hid/controllers/applet_resource.h)3
-rw-r--r--src/hid_core/resources/controller_base.cpp (renamed from src/core/hle/service/hid/controllers/controller_base.cpp)6
-rw-r--r--src/hid_core/resources/controller_base.h (renamed from src/core/hle/service/hid/controllers/controller_base.h)6
-rw-r--r--src/hid_core/resources/debug_pad/debug_pad.cpp (renamed from src/core/hle/service/hid/controllers/debug_pad.cpp)15
-rw-r--r--src/hid_core/resources/debug_pad/debug_pad.h (renamed from src/core/hle/service/hid/controllers/debug_pad.h)7
-rw-r--r--src/hid_core/resources/debug_pad/debug_pad_types.h (renamed from src/core/hle/service/hid/controllers/types/debug_pad_types.h)2
-rw-r--r--src/hid_core/resources/digitizer/digitizer.cpp (renamed from src/core/hle/service/hid/controllers/digitizer.cpp)9
-rw-r--r--src/hid_core/resources/digitizer/digitizer.h (renamed from src/core/hle/service/hid/controllers/digitizer.h)2
-rw-r--r--src/hid_core/resources/hid_firmware_settings.cpp (renamed from src/core/hle/service/hid/hid_firmware_settings.cpp)2
-rw-r--r--src/hid_core/resources/hid_firmware_settings.h (renamed from src/core/hle/service/hid/hid_firmware_settings.h)0
-rw-r--r--src/hid_core/resources/irs_ring_lifo.h (renamed from src/core/hle/service/hid/irs_ring_lifo.h)0
-rw-r--r--src/hid_core/resources/keyboard/keyboard.cpp (renamed from src/core/hle/service/hid/controllers/keyboard.cpp)13
-rw-r--r--src/hid_core/resources/keyboard/keyboard.h (renamed from src/core/hle/service/hid/controllers/keyboard.h)9
-rw-r--r--src/hid_core/resources/keyboard/keyboard_types.h (renamed from src/core/hle/service/hid/controllers/types/keyboard_types.h)2
-rw-r--r--src/hid_core/resources/mouse/debug_mouse.cpp (renamed from src/core/hle/service/hid/controllers/debug_mouse.cpp)13
-rw-r--r--src/hid_core/resources/mouse/debug_mouse.h (renamed from src/core/hle/service/hid/controllers/debug_mouse.h)6
-rw-r--r--src/hid_core/resources/mouse/mouse.cpp (renamed from src/core/hle/service/hid/controllers/mouse.cpp)13
-rw-r--r--src/hid_core/resources/mouse/mouse.h (renamed from src/core/hle/service/hid/controllers/mouse.h)6
-rw-r--r--src/hid_core/resources/mouse/mouse_types.h (renamed from src/core/hle/service/hid/controllers/types/mouse_types.h)0
-rw-r--r--src/hid_core/resources/npad/npad.cpp (renamed from src/core/hle/service/hid/controllers/npad.cpp)1002
-rw-r--r--src/hid_core/resources/npad/npad.h214
-rw-r--r--src/hid_core/resources/npad/npad_data.cpp228
-rw-r--r--src/hid_core/resources/npad/npad_data.h88
-rw-r--r--src/hid_core/resources/npad/npad_resource.cpp687
-rw-r--r--src/hid_core/resources/npad/npad_resource.h132
-rw-r--r--src/hid_core/resources/npad/npad_types.h (renamed from src/core/hle/service/hid/controllers/types/npad_types.h)5
-rw-r--r--src/hid_core/resources/palma/palma.cpp (renamed from src/core/hle/service/hid/controllers/palma.cpp)7
-rw-r--r--src/hid_core/resources/palma/palma.h (renamed from src/core/hle/service/hid/controllers/palma.h)5
-rw-r--r--src/hid_core/resources/ring_lifo.h (renamed from src/core/hle/service/hid/ring_lifo.h)0
-rw-r--r--src/hid_core/resources/shared_memory_format.h (renamed from src/core/hle/service/hid/controllers/types/shared_memory_format.h)16
-rw-r--r--src/hid_core/resources/shared_memory_holder.cpp (renamed from src/core/hle/service/hid/controllers/shared_memory_holder.cpp)8
-rw-r--r--src/hid_core/resources/shared_memory_holder.h (renamed from src/core/hle/service/hid/controllers/shared_memory_holder.h)0
-rw-r--r--src/hid_core/resources/six_axis/console_six_axis.cpp (renamed from src/core/hle/service/hid/controllers/console_six_axis.cpp)11
-rw-r--r--src/hid_core/resources/six_axis/console_six_axis.h (renamed from src/core/hle/service/hid/controllers/console_six_axis.h)2
-rw-r--r--src/hid_core/resources/six_axis/seven_six_axis.cpp (renamed from src/core/hle/service/hid/controllers/seven_six_axis.cpp)8
-rw-r--r--src/hid_core/resources/six_axis/seven_six_axis.h (renamed from src/core/hle/service/hid/controllers/seven_six_axis.h)4
-rw-r--r--src/hid_core/resources/six_axis/six_axis.cpp (renamed from src/core/hle/service/hid/controllers/six_axis.cpp)17
-rw-r--r--src/hid_core/resources/six_axis/six_axis.h (renamed from src/core/hle/service/hid/controllers/six_axis.h)6
-rw-r--r--src/hid_core/resources/system_buttons/capture_button.cpp (renamed from src/core/hle/service/hid/controllers/capture_button.cpp)9
-rw-r--r--src/hid_core/resources/system_buttons/capture_button.h (renamed from src/core/hle/service/hid/controllers/capture_button.h)2
-rw-r--r--src/hid_core/resources/system_buttons/home_button.cpp (renamed from src/core/hle/service/hid/controllers/home_button.cpp)9
-rw-r--r--src/hid_core/resources/system_buttons/home_button.h (renamed from src/core/hle/service/hid/controllers/home_button.h)2
-rw-r--r--src/hid_core/resources/system_buttons/sleep_button.cpp (renamed from src/core/hle/service/hid/controllers/sleep_button.cpp)9
-rw-r--r--src/hid_core/resources/system_buttons/sleep_button.h (renamed from src/core/hle/service/hid/controllers/sleep_button.h)2
-rw-r--r--src/hid_core/resources/touch_screen/gesture.cpp (renamed from src/core/hle/service/hid/controllers/gesture.cpp)16
-rw-r--r--src/hid_core/resources/touch_screen/gesture.h (renamed from src/core/hle/service/hid/controllers/gesture.h)4
-rw-r--r--src/hid_core/resources/touch_screen/gesture_types.h (renamed from src/core/hle/service/hid/controllers/types/gesture_types.h)0
-rw-r--r--src/hid_core/resources/touch_screen/touch_screen.cpp (renamed from src/core/hle/service/hid/controllers/touchscreen.cpp)12
-rw-r--r--src/hid_core/resources/touch_screen/touch_screen.h (renamed from src/core/hle/service/hid/controllers/touchscreen.h)6
-rw-r--r--src/hid_core/resources/touch_screen/touch_types.h (renamed from src/core/hle/service/hid/controllers/types/touch_types.h)2
-rw-r--r--src/hid_core/resources/unique_pad/unique_pad.cpp (renamed from src/core/hle/service/hid/controllers/unique_pad.cpp)8
-rw-r--r--src/hid_core/resources/unique_pad/unique_pad.h (renamed from src/core/hle/service/hid/controllers/unique_pad.h)2
-rw-r--r--src/input_common/CMakeLists.txt2
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_image.cpp12
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_instructions.h2
-rw-r--r--src/shader_recompiler/backend/spirv/spirv_emit_context.cpp2
-rw-r--r--src/video_core/renderer_opengl/gl_device.cpp11
-rw-r--r--src/yuzu/applets/qt_controller.cpp8
-rw-r--r--src/yuzu/applets/qt_software_keyboard.cpp8
-rw-r--r--src/yuzu/applets/qt_web_browser.cpp2
-rw-r--r--src/yuzu/configuration/configure_debug_controller.cpp2
-rw-r--r--src/yuzu/configuration/configure_hotkeys.cpp4
-rw-r--r--src/yuzu/configuration/configure_input.cpp4
-rw-r--r--src/yuzu/configuration/configure_input_advanced.cpp4
-rw-r--r--src/yuzu/configuration/configure_input_per_game.cpp4
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp6
-rw-r--r--src/yuzu/configuration/configure_input_player_widget.cpp2
-rw-r--r--src/yuzu/configuration/configure_input_player_widget.h4
-rw-r--r--src/yuzu/configuration/configure_ringcon.cpp4
-rw-r--r--src/yuzu/configuration/configure_vibration.cpp6
-rw-r--r--src/yuzu/configuration/shared_translation.cpp2
-rw-r--r--src/yuzu/debugger/controller.cpp4
-rw-r--r--src/yuzu/hotkeys.cpp2
-rw-r--r--src/yuzu/hotkeys.h2
-rw-r--r--src/yuzu/main.cpp4
-rw-r--r--src/yuzu/util/controller_navigation.cpp4
-rw-r--r--src/yuzu/util/overlay_dialog.cpp4
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp2
163 files changed, 2811 insertions, 1386 deletions
diff --git a/.github/workflows/android-merge.js b/.github/workflows/android-merge.js
index 7e02dc9e5..44ab56e44 100644
--- a/.github/workflows/android-merge.js
+++ b/.github/workflows/android-merge.js
@@ -10,7 +10,7 @@ const CHANGE_LABEL = 'android-merge';
// how far back in time should we consider the changes are "recent"? (default: 24 hours)
const DETECTION_TIME_FRAME = (parseInt(process.env.DETECTION_TIME_FRAME)) || (24 * 3600 * 1000);
-async function checkBaseChanges(github, context) {
+async function checkBaseChanges(github) {
// query the commit date of the latest commit on this branch
const query = `query($owner:String!, $name:String!, $ref:String!) {
repository(name:$name, owner:$owner) {
@@ -22,8 +22,8 @@ async function checkBaseChanges(github, context) {
}
}`;
const variables = {
- owner: context.repo.owner,
- name: context.repo.repo,
+ owner: 'yuzu-emu',
+ name: 'yuzu',
ref: 'refs/heads/master',
};
const result = await github.graphql(query, variables);
@@ -38,8 +38,8 @@ async function checkBaseChanges(github, context) {
return false;
}
-async function checkAndroidChanges(github, context) {
- if (checkBaseChanges(github, context)) return true;
+async function checkAndroidChanges(github) {
+ if (checkBaseChanges(github)) return true;
const query = `query($owner:String!, $name:String!, $label:String!) {
repository(name:$name, owner:$owner) {
pullRequests(labels: [$label], states: OPEN, first: 100) {
@@ -48,8 +48,8 @@ async function checkAndroidChanges(github, context) {
}
}`;
const variables = {
- owner: context.repo.owner,
- name: context.repo.repo,
+ owner: 'yuzu-emu',
+ name: 'yuzu',
label: CHANGE_LABEL,
};
const result = await github.graphql(query, variables);
@@ -90,8 +90,8 @@ async function tagAndPush(github, owner, repo, execa, commit=false) {
console.log(`New tag: ${newTag}`);
if (commit) {
let channelName = channel[0].toUpperCase() + channel.slice(1);
- console.info(`Committing pending commit as ${channelName} #${tagNumber + 1}`);
- await execa("git", ['commit', '-m', `${channelName} #${tagNumber + 1}`]);
+ console.info(`Committing pending commit as ${channelName} ${tagNumber + 1}`);
+ await execa("git", ['commit', '-m', `${channelName} ${tagNumber + 1}`]);
}
console.info('Pushing tags to GitHub ...');
await execa("git", ['tag', newTag]);
@@ -157,7 +157,7 @@ async function mergePullRequests(pulls, execa) {
process1.stdout.pipe(process.stdout);
await process1;
- const process2 = execa("git", ["commit", "-m", `Merge PR ${pr}`]);
+ const process2 = execa("git", ["commit", "-m", `Merge yuzu-emu#${pr}`]);
process2.stdout.pipe(process.stdout);
await process2;
@@ -182,7 +182,30 @@ async function mergePullRequests(pulls, execa) {
return mergeResults;
}
+async function resetBranch(execa) {
+ console.log("::group::Reset master branch");
+ let hasFailed = false;
+ try {
+ await execa("git", ["remote", "add", "source", "https://github.com/yuzu-emu/yuzu.git"]);
+ await execa("git", ["fetch", "source"]);
+ const process1 = await execa("git", ["rev-parse", "source/master"]);
+ const headCommit = process1.stdout;
+
+ await execa("git", ["reset", "--hard", headCommit]);
+ } catch (err) {
+ console.log(`::error title=Failed to reset master branch`);
+ hasFailed = true;
+ }
+ console.log("::endgroup::");
+ if (hasFailed) {
+ throw 'Failed to reset the master branch. Aborting!';
+ }
+}
+
async function mergebot(github, context, execa) {
+ // Reset our local copy of master to what appears on yuzu-emu/yuzu - master
+ await resetBranch(execa);
+
const query = `query ($owner:String!, $name:String!, $label:String!) {
repository(name:$name, owner:$owner) {
pullRequests(labels: [$label], states: OPEN, first: 100) {
@@ -193,8 +216,8 @@ async function mergebot(github, context, execa) {
}
}`;
const variables = {
- owner: context.repo.owner,
- name: context.repo.repo,
+ owner: 'yuzu-emu',
+ name: 'yuzu',
label: CHANGE_LABEL,
};
const result = await github.graphql(query, variables);
@@ -209,7 +232,7 @@ async function mergebot(github, context, execa) {
await fetchPullRequests(pulls, "https://github.com/yuzu-emu/yuzu", execa);
const mergeResults = await mergePullRequests(pulls, execa);
await generateReadme(pulls, context, mergeResults, execa);
- await tagAndPush(github, context.repo.owner, `${context.repo.repo}-android`, execa, true);
+ await tagAndPush(github, 'yuzu-emu', `yuzu-android`, execa, true);
}
module.exports.mergebot = mergebot;
diff --git a/.github/workflows/android-publish.yml b/.github/workflows/android-publish.yml
index 8f46fcf74..68e21c2f2 100644
--- a/.github/workflows/android-publish.yml
+++ b/.github/workflows/android-publish.yml
@@ -16,7 +16,7 @@ on:
jobs:
android:
runs-on: ubuntu-latest
- if: ${{ github.event.inputs.android != 'false' && github.repository == 'yuzu-emu/yuzu' }}
+ if: ${{ github.event.inputs.android != 'false' && github.repository == 'yuzu-emu/yuzu-android' }}
steps:
# this checkout is required to make sure the GitHub Actions scripts are available
- uses: actions/checkout@v3
@@ -33,7 +33,7 @@ jobs:
script: |
if (context.payload.inputs && context.payload.inputs.android === 'true') return true;
const checkAndroidChanges = require('./.github/workflows/android-merge.js').checkAndroidChanges;
- return checkAndroidChanges(github, context);
+ return checkAndroidChanges(github);
- run: npm install execa@5
if: ${{ steps.check-changes.outputs.result == 'true' }}
- uses: actions/checkout@v3
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e04d2418b..edca221b1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -185,6 +185,7 @@ add_subdirectory(common)
add_subdirectory(core)
add_subdirectory(audio_core)
add_subdirectory(video_core)
+add_subdirectory(hid_core)
add_subdirectory(network)
add_subdirectory(input_common)
add_subdirectory(frontend_common)
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt
index 43caac989..fee80bb21 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt
@@ -79,7 +79,18 @@ object Settings {
const val PREF_THEME_MODE = "ThemeMode"
const val PREF_BLACK_BACKGROUNDS = "BlackBackgrounds"
- const val LayoutOption_Unspecified = 0
- const val LayoutOption_MobilePortrait = 4
- const val LayoutOption_MobileLandscape = 5
+ enum class EmulationOrientation(val int: Int) {
+ Unspecified(0),
+ SensorLandscape(5),
+ Landscape(1),
+ ReverseLandscape(2),
+ SensorPortrait(6),
+ Portrait(4),
+ ReversePortrait(3);
+
+ companion object {
+ fun from(int: Int): EmulationOrientation =
+ entries.firstOrNull { it.int == int } ?: Unspecified
+ }
+ }
}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
index 510b2b5eb..9efc1705d 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
@@ -50,6 +50,7 @@ import org.yuzu.yuzu_emu.databinding.FragmentEmulationBinding
import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting
import org.yuzu.yuzu_emu.features.settings.model.IntSetting
import org.yuzu.yuzu_emu.features.settings.model.Settings
+import org.yuzu.yuzu_emu.features.settings.model.Settings.EmulationOrientation
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
import org.yuzu.yuzu_emu.model.DriverViewModel
import org.yuzu.yuzu_emu.model.Game
@@ -99,6 +100,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ updateOrientation()
val intentUri: Uri? = requireActivity().intent.data
var intentGame: Game? = null
@@ -458,13 +460,23 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
@SuppressLint("SourceLockedOrientationActivity")
private fun updateOrientation() {
emulationActivity?.let {
- it.requestedOrientation = when (IntSetting.RENDERER_SCREEN_LAYOUT.getInt()) {
- Settings.LayoutOption_MobileLandscape ->
+ val orientationSetting =
+ EmulationOrientation.from(IntSetting.RENDERER_SCREEN_LAYOUT.getInt())
+ it.requestedOrientation = when (orientationSetting) {
+ EmulationOrientation.Unspecified -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
+ EmulationOrientation.SensorLandscape ->
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
- Settings.LayoutOption_MobilePortrait ->
- ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
- Settings.LayoutOption_Unspecified -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
- else -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
+
+ EmulationOrientation.Landscape -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+ EmulationOrientation.ReverseLandscape ->
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
+
+ EmulationOrientation.SensorPortrait ->
+ ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
+
+ EmulationOrientation.Portrait -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+ EmulationOrientation.ReversePortrait ->
+ ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
}
}
}
@@ -651,7 +663,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
@SuppressLint("SourceLockedOrientationActivity")
private fun startConfiguringControls() {
// Lock the current orientation to prevent editing inconsistencies
- if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == Settings.LayoutOption_Unspecified) {
+ if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == EmulationOrientation.Unspecified.int) {
emulationActivity?.let {
it.requestedOrientation =
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
@@ -669,7 +681,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
binding.doneControlConfig.visibility = View.GONE
binding.surfaceInputOverlay.setIsInEditMode(false)
// Unlock the orientation if it was locked for editing
- if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == Settings.LayoutOption_Unspecified) {
+ if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == EmulationOrientation.Unspecified.int) {
emulationActivity?.let {
it.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt
index b1d3c0040..b04d1208f 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt
@@ -445,7 +445,8 @@ class GamePropertiesFragment : Fragment() {
val zipResult = FileUtil.zipFromInternalStorage(
File(saveLocation),
saveLocation.replaceAfterLast("/", ""),
- BufferedOutputStream(requireContext().contentResolver.openOutputStream(result))
+ BufferedOutputStream(requireContext().contentResolver.openOutputStream(result)),
+ compression = false
)
return@newInstance when (zipResult) {
TaskState.Completed -> getString(R.string.export_success)
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
index d19f20dc2..5ae05b5cc 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
@@ -167,13 +167,14 @@ class GamesViewModel : ViewModel() {
}
}
- fun onCloseGameFoldersFragment() =
+ fun onCloseGameFoldersFragment() {
+ NativeConfig.saveGlobalConfig()
viewModelScope.launch {
withContext(Dispatchers.IO) {
- NativeConfig.saveGlobalConfig()
getGameDirs(true)
}
}
+ }
private fun getGameDirs(reloadList: Boolean = false) {
val gameDirs = NativeConfig.getGameDirs()
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
index b4117d761..622ae996e 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
@@ -625,7 +625,8 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
File(DirectoryInitialization.userDirectory!!),
DirectoryInitialization.userDirectory!!,
BufferedOutputStream(contentResolver.openOutputStream(result)),
- taskViewModel.cancelled
+ taskViewModel.cancelled,
+ compression = false
)
return@newInstance when (zipResult) {
TaskState.Completed -> getString(R.string.user_data_export_success)
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt
index 00c6bf90e..132f002fb 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt
@@ -21,6 +21,7 @@ import org.yuzu.yuzu_emu.model.TaskState
import java.io.BufferedOutputStream
import java.lang.NullPointerException
import java.nio.charset.StandardCharsets
+import java.util.zip.Deflater
import java.util.zip.ZipOutputStream
import kotlin.IllegalStateException
@@ -312,15 +313,23 @@ object FileUtil {
* @param inputFile File representation of the item that will be zipped
* @param rootDir Directory containing the inputFile
* @param outputStream Stream where the zip file will be output
+ * @param cancelled [StateFlow] that reports whether this process has been cancelled
+ * @param compression Disables compression if true
*/
fun zipFromInternalStorage(
inputFile: File,
rootDir: String,
outputStream: BufferedOutputStream,
- cancelled: StateFlow<Boolean>? = null
+ cancelled: StateFlow<Boolean>? = null,
+ compression: Boolean = true
): TaskState {
try {
ZipOutputStream(outputStream).use { zos ->
+ if (!compression) {
+ zos.setMethod(ZipOutputStream.DEFLATED)
+ zos.setLevel(Deflater.NO_COMPRESSION)
+ }
+
inputFile.walkTopDown().forEach { file ->
if (cancelled?.value == true) {
return TaskState.Cancelled
@@ -338,6 +347,7 @@ object FileUtil {
}
}
} catch (e: Exception) {
+ Log.error("[FileUtil] Failed creating zip file - ${e.message}")
return TaskState.Failed
}
return TaskState.Completed
diff --git a/src/android/app/src/main/jni/android_config.cpp b/src/android/app/src/main/jni/android_config.cpp
index c86aa1c39..08aed3216 100644
--- a/src/android/app/src/main/jni/android_config.cpp
+++ b/src/android/app/src/main/jni/android_config.cpp
@@ -14,12 +14,6 @@ AndroidConfig::AndroidConfig(const std::string& config_name, ConfigType config_t
}
}
-AndroidConfig::~AndroidConfig() {
- if (global) {
- AndroidConfig::SaveAllValues();
- }
-}
-
void AndroidConfig::ReloadAllValues() {
Reload();
ReadAndroidValues();
diff --git a/src/android/app/src/main/jni/android_config.h b/src/android/app/src/main/jni/android_config.h
index d83852de9..693e1e3f0 100644
--- a/src/android/app/src/main/jni/android_config.h
+++ b/src/android/app/src/main/jni/android_config.h
@@ -9,7 +9,6 @@ class AndroidConfig final : public Config {
public:
explicit AndroidConfig(const std::string& config_name = "config",
ConfigType config_type = ConfigType::GlobalConfig);
- ~AndroidConfig() override;
void ReloadAllValues() override;
void SaveAllValues() override;
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp
index b0c00c1ea..136c8dee6 100644
--- a/src/android/app/src/main/jni/native.cpp
+++ b/src/android/app/src/main/jni/native.cpp
@@ -45,15 +45,15 @@
#include "core/frontend/applets/profile_select.h"
#include "core/frontend/applets/software_keyboard.h"
#include "core/frontend/applets/web_browser.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
#include "core/hle/service/am/applet_ae.h"
#include "core/hle/service/am/applet_oe.h"
#include "core/hle/service/am/applets/applets.h"
#include "core/hle/service/filesystem/filesystem.h"
#include "core/loader/loader.h"
#include "frontend_common/config.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
#include "jni/android_common/android_common.h"
#include "jni/id_cache.h"
#include "jni/native.h"
diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml
index 45d57c3ea..0363ff3b6 100644
--- a/src/android/app/src/main/res/values/arrays.xml
+++ b/src/android/app/src/main/res/values/arrays.xml
@@ -118,15 +118,23 @@
</integer-array>
<string-array name="rendererScreenLayoutNames">
+ <item>@string/screen_layout_auto</item>
+ <item>@string/screen_layout_sensor_landscape</item>
<item>@string/screen_layout_landscape</item>
+ <item>@string/screen_layout_reverse_landscape</item>
+ <item>@string/screen_layout_sensor_portrait</item>
<item>@string/screen_layout_portrait</item>
- <item>@string/screen_layout_auto</item>
+ <item>@string/screen_layout_reverse_portrait</item>
</string-array>
<integer-array name="rendererScreenLayoutValues">
+ <item>0</item>
<item>5</item>
+ <item>1</item>
+ <item>2</item>
+ <item>6</item>
<item>4</item>
- <item>0</item>
+ <item>3</item>
</integer-array>
<string-array name="rendererAspectRatioNames">
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml
index fd18067a2..3bb92ad67 100644
--- a/src/android/app/src/main/res/values/strings.xml
+++ b/src/android/app/src/main/res/values/strings.xml
@@ -473,9 +473,13 @@
<string name="anti_aliasing_smaa">SMAA</string>
<!-- Screen Layouts -->
+ <string name="screen_layout_auto">Auto</string>
+ <string name="screen_layout_sensor_landscape">Sensor landscape</string>
<string name="screen_layout_landscape">Landscape</string>
+ <string name="screen_layout_reverse_landscape">Reverse landscape</string>
+ <string name="screen_layout_sensor_portrait">Sensor portrait</string>
<string name="screen_layout_portrait">Portrait</string>
- <string name="screen_layout_auto">Auto</string>
+ <string name="screen_layout_reverse_portrait">Reverse portrait</string>
<!-- Aspect Ratios -->
<string name="ratio_default">Default (16:9)</string>
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index dfba79267..adcc23c18 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -183,22 +183,6 @@ add_library(core STATIC
frontend/framebuffer_layout.cpp
frontend/framebuffer_layout.h
frontend/graphics_context.h
- hid/emulated_console.cpp
- hid/emulated_console.h
- hid/emulated_controller.cpp
- hid/emulated_controller.h
- hid/emulated_devices.cpp
- hid/emulated_devices.h
- hid/hid_core.cpp
- hid/hid_core.h
- hid/hid_types.h
- hid/input_converter.cpp
- hid/input_converter.h
- hid/input_interpreter.cpp
- hid/input_interpreter.h
- hid/irs_types.h
- hid/motion_input.cpp
- hid/motion_input.h
hle/api_version.h
hle/ipc.h
hle/kernel/board/nintendo/nx/k_memory_layout.cpp
@@ -531,90 +515,16 @@ add_library(core STATIC
hle/service/hid/hid.h
hle/service/hid/hid_debug_server.cpp
hle/service/hid/hid_debug_server.h
- hle/service/hid/hid_firmware_settings.cpp
- hle/service/hid/hid_firmware_settings.h
hle/service/hid/hid_server.cpp
hle/service/hid/hid_server.h
hle/service/hid/hid_system_server.cpp
hle/service/hid/hid_system_server.h
- hle/service/hid/hid_util.h
hle/service/hid/hidbus.cpp
hle/service/hid/hidbus.h
hle/service/hid/irs.cpp
hle/service/hid/irs.h
- hle/service/hid/irs_ring_lifo.h
- hle/service/hid/resource_manager.cpp
- hle/service/hid/resource_manager.h
- hle/service/hid/ring_lifo.h
hle/service/hid/xcd.cpp
hle/service/hid/xcd.h
- hle/service/hid/errors.h
- hle/service/hid/controllers/types/debug_pad_types.h
- hle/service/hid/controllers/types/keyboard_types.h
- hle/service/hid/controllers/types/mouse_types.h
- hle/service/hid/controllers/types/npad_types.h
- hle/service/hid/controllers/types/shared_memory_format.h
- hle/service/hid/controllers/types/touch_types.h
- hle/service/hid/controllers/applet_resource.cpp
- hle/service/hid/controllers/applet_resource.h
- hle/service/hid/controllers/capture_button.cpp
- hle/service/hid/controllers/capture_button.h
- hle/service/hid/controllers/console_six_axis.cpp
- hle/service/hid/controllers/console_six_axis.h
- hle/service/hid/controllers/controller_base.cpp
- hle/service/hid/controllers/controller_base.h
- hle/service/hid/controllers/debug_mouse.cpp
- hle/service/hid/controllers/debug_mouse.h
- hle/service/hid/controllers/debug_pad.cpp
- hle/service/hid/controllers/debug_pad.h
- hle/service/hid/controllers/digitizer.cpp
- hle/service/hid/controllers/digitizer.h
- hle/service/hid/controllers/gesture.cpp
- hle/service/hid/controllers/gesture.h
- hle/service/hid/controllers/home_button.cpp
- hle/service/hid/controllers/home_button.h
- hle/service/hid/controllers/keyboard.cpp
- hle/service/hid/controllers/keyboard.h
- hle/service/hid/controllers/mouse.cpp
- hle/service/hid/controllers/mouse.h
- hle/service/hid/controllers/npad.cpp
- hle/service/hid/controllers/npad.h
- hle/service/hid/controllers/palma.cpp
- hle/service/hid/controllers/palma.h
- hle/service/hid/controllers/seven_six_axis.cpp
- hle/service/hid/controllers/seven_six_axis.h
- hle/service/hid/controllers/shared_memory_holder.cpp
- hle/service/hid/controllers/shared_memory_holder.h
- hle/service/hid/controllers/six_axis.cpp
- hle/service/hid/controllers/six_axis.h
- hle/service/hid/controllers/sleep_button.cpp
- hle/service/hid/controllers/sleep_button.h
- hle/service/hid/controllers/touchscreen.cpp
- hle/service/hid/controllers/touchscreen.h
- hle/service/hid/controllers/unique_pad.cpp
- hle/service/hid/controllers/unique_pad.h
- hle/service/hid/hidbus/hidbus_base.cpp
- hle/service/hid/hidbus/hidbus_base.h
- hle/service/hid/hidbus/ringcon.cpp
- hle/service/hid/hidbus/ringcon.h
- hle/service/hid/hidbus/starlink.cpp
- hle/service/hid/hidbus/starlink.h
- hle/service/hid/hidbus/stubbed.cpp
- hle/service/hid/hidbus/stubbed.h
- hle/service/hid/irsensor/clustering_processor.cpp
- hle/service/hid/irsensor/clustering_processor.h
- hle/service/hid/irsensor/image_transfer_processor.cpp
- hle/service/hid/irsensor/image_transfer_processor.h
- hle/service/hid/irsensor/ir_led_processor.cpp
- hle/service/hid/irsensor/ir_led_processor.h
- hle/service/hid/irsensor/moment_processor.cpp
- hle/service/hid/irsensor/moment_processor.h
- hle/service/hid/irsensor/pointing_processor.cpp
- hle/service/hid/irsensor/pointing_processor.h
- hle/service/hid/irsensor/processor_base.cpp
- hle/service/hid/irsensor/processor_base.h
- hle/service/hid/irsensor/tera_plugin_processor.cpp
- hle/service/hid/irsensor/tera_plugin_processor.h
hle/service/lbl/lbl.cpp
hle/service/lbl/lbl.h
hle/service/ldn/lan_discovery.cpp
@@ -955,7 +865,7 @@ endif()
create_target_directory_groups(core)
-target_link_libraries(core PUBLIC common PRIVATE audio_core network video_core nx_tzdb)
+target_link_libraries(core PUBLIC common PRIVATE audio_core hid_core network video_core nx_tzdb)
target_link_libraries(core PUBLIC Boost::headers PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls RenderDoc::API)
if (MINGW)
target_link_libraries(core PRIVATE ${MSWSOCK_LIBRARY})
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 66f444d39..c063f7719 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -28,7 +28,6 @@
#include "core/file_sys/savedata_factory.h"
#include "core/file_sys/vfs_concat.h"
#include "core/file_sys/vfs_real.h"
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_memory_manager.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/k_resource_limit.h"
@@ -52,6 +51,7 @@
#include "core/telemetry_session.h"
#include "core/tools/freezer.h"
#include "core/tools/renderdoc.h"
+#include "hid_core/hid_core.h"
#include "network/network.h"
#include "video_core/host1x/host1x.h"
#include "video_core/renderer_base.h"
diff --git a/src/core/frontend/applets/controller.cpp b/src/core/frontend/applets/controller.cpp
index 27755cb58..34fe23b6a 100644
--- a/src/core/frontend/applets/controller.cpp
+++ b/src/core/frontend/applets/controller.cpp
@@ -6,9 +6,9 @@
#include "common/settings.h"
#include "common/settings_enums.h"
#include "core/frontend/applets/controller.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
namespace Core::Frontend {
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index 24394d222..7d3421929 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -1258,11 +1258,11 @@ ThreadState KThread::RequestTerminate() {
// Change the thread's priority to be higher than any system thread's.
this->IncreaseBasePriority(TerminatingThreadPriority);
- // If the thread is runnable, send a termination interrupt to other cores.
+ // If the thread is runnable, send a termination interrupt to cores it may be running on.
if (this->GetState() == ThreadState::Runnable) {
- if (const u64 core_mask = m_physical_affinity_mask.GetAffinityMask() &
- ~(1ULL << GetCurrentCoreId(m_kernel));
- core_mask != 0) {
+ // NOTE: We do not mask the "current core", because this code may not actually be
+ // executing from the thread representing the "current core".
+ if (const u64 core_mask = m_physical_affinity_mask.GetAffinityMask(); core_mask != 0) {
Kernel::KInterruptManager::SendInterProcessorInterrupt(m_kernel, core_mask);
}
}
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 97eb56ff0..9e05bdafa 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -13,7 +13,6 @@
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/registered_cache.h"
#include "core/file_sys/savedata_factory.h"
-#include "core/hid/hid_types.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/result.h"
@@ -37,7 +36,6 @@
#include "core/hle/service/caps/caps_su.h"
#include "core/hle/service/caps/caps_types.h"
#include "core/hle/service/filesystem/filesystem.h"
-#include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/ns/ns.h"
#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
@@ -48,6 +46,8 @@
#include "core/hle/service/vi/vi.h"
#include "core/hle/service/vi/vi_results.h"
#include "core/memory.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/npad/npad.h"
namespace Service::AM {
diff --git a/src/core/hle/service/am/applets/applet_cabinet.cpp b/src/core/hle/service/am/applets/applet_cabinet.cpp
index 3906c0fa4..c2ff444a6 100644
--- a/src/core/hle/service/am/applets/applet_cabinet.cpp
+++ b/src/core/hle/service/am/applets/applet_cabinet.cpp
@@ -5,13 +5,13 @@
#include "common/logging/log.h"
#include "core/core.h"
#include "core/frontend/applets/cabinet.h"
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applets/applet_cabinet.h"
#include "core/hle/service/mii/mii_manager.h"
#include "core/hle/service/nfc/common/device.h"
+#include "hid_core/hid_core.h"
namespace Service::AM::Applets {
diff --git a/src/core/hle/service/am/applets/applet_controller.cpp b/src/core/hle/service/am/applets/applet_controller.cpp
index 9840d2547..0e4d9cc39 100644
--- a/src/core/hle/service/am/applets/applet_controller.cpp
+++ b/src/core/hle/service/am/applets/applet_controller.cpp
@@ -9,13 +9,13 @@
#include "common/string_util.h"
#include "core/core.h"
#include "core/frontend/applets/controller.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
#include "core/hle/result.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applets/applet_controller.h"
-#include "core/hle/service/hid/controllers/npad.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/npad/npad.h"
namespace Service::AM::Applets {
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
deleted file mode 100644
index 80cfcb2bb..000000000
--- a/src/core/hle/service/hid/controllers/npad.h
+++ /dev/null
@@ -1,197 +0,0 @@
-// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#pragma once
-
-#include <array>
-#include <atomic>
-#include <mutex>
-#include <span>
-
-#include "common/common_types.h"
-#include "core/hid/hid_types.h"
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/controllers/types/npad_types.h"
-
-namespace Core::HID {
-class EmulatedController;
-enum class ControllerTriggerType;
-} // namespace Core::HID
-
-namespace Kernel {
-class KEvent;
-class KReadableEvent;
-} // namespace Kernel
-
-namespace Service::KernelHelpers {
-class ServiceContext;
-} // namespace Service::KernelHelpers
-
-union Result;
-
-namespace Service::HID {
-class AppletResource;
-struct NpadInternalState;
-struct NpadSixAxisSensorLifo;
-struct NpadSharedMemoryFormat;
-
-class NPad final : public ControllerBase {
-public:
- explicit NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_);
- ~NPad() override;
-
- // Called when the controller is initialized
- void OnInit() override;
-
- // When the controller is released
- void OnRelease() override;
-
- // When the controller is requesting an update for the shared memory
- void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
-
- void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set);
- Core::HID::NpadStyleTag GetSupportedStyleSet() const;
-
- Result SetSupportedNpadIdTypes(std::span<const u8> data);
- void GetSupportedNpadIdTypes(u32* data, std::size_t max_length);
- std::size_t GetSupportedNpadIdTypesSize() const;
-
- void SetHoldType(NpadJoyHoldType joy_hold_type);
- NpadJoyHoldType GetHoldType() const;
-
- void SetNpadHandheldActivationMode(NpadHandheldActivationMode activation_mode);
- NpadHandheldActivationMode GetNpadHandheldActivationMode() const;
-
- void SetNpadCommunicationMode(NpadCommunicationMode communication_mode_);
- NpadCommunicationMode GetNpadCommunicationMode() const;
-
- bool SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id,
- NpadJoyDeviceType npad_device_type, NpadJoyAssignmentMode assignment_mode);
-
- bool VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index,
- const Core::HID::VibrationValue& vibration_value);
-
- void VibrateController(const Core::HID::VibrationDeviceHandle& vibration_device_handle,
- const Core::HID::VibrationValue& vibration_value);
-
- void VibrateControllers(
- std::span<const Core::HID::VibrationDeviceHandle> vibration_device_handles,
- std::span<const Core::HID::VibrationValue> vibration_values);
-
- Core::HID::VibrationValue GetLastVibration(
- const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
-
- void InitializeVibrationDevice(const Core::HID::VibrationDeviceHandle& vibration_device_handle);
-
- void InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index);
-
- void SetPermitVibrationSession(bool permit_vibration_session);
-
- bool IsVibrationDeviceMounted(
- const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
-
- Kernel::KReadableEvent& GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id);
- void SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const;
-
- // Adds a new controller at an index.
- void AddNewControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id);
- // Adds a new controller at an index with connection status.
- void UpdateControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id,
- bool connected);
-
- Result DisconnectNpad(Core::HID::NpadIdType npad_id);
-
- Result IsFirmwareUpdateAvailableForSixAxisSensor(
- const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const;
- Result ResetIsSixAxisSensorDeviceNewlyAssigned(
- const Core::HID::SixAxisSensorHandle& sixaxis_handle);
-
- Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
- Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
- bool& is_enabled) const;
- Result SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled,
- Core::HID::NpadIdType npad_id);
- void SetAnalogStickUseCenterClamp(bool use_center_clamp);
- void ClearAllConnectedControllers();
- void DisconnectAllConnectedControllers();
- void ConnectAllDisconnectedControllers();
- void ClearAllControllers();
-
- Result MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1,
- Core::HID::NpadIdType npad_id_2);
- void StartLRAssignmentMode();
- void StopLRAssignmentMode();
- Result SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2);
-
- // Logical OR for all buttons presses on all controllers
- // Specifically for cheat engine and other features.
- Core::HID::NpadButton GetAndResetPressState();
-
- void ApplyNpadSystemCommonPolicy();
-
- AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id);
-
-private:
- struct VibrationData {
- bool device_mounted{};
- Core::HID::VibrationValue latest_vibration_value{};
- std::chrono::steady_clock::time_point last_vibration_timepoint{};
- };
-
- struct NpadControllerData {
- Kernel::KEvent* styleset_changed_event{};
- NpadInternalState* shared_memory = nullptr;
- Core::HID::EmulatedController* device = nullptr;
-
- std::array<VibrationData, 2> vibration{};
- bool unintended_home_button_input_protection{};
- bool is_connected{};
-
- // Dual joycons can have only one side connected
- bool is_dual_left_connected{true};
- bool is_dual_right_connected{true};
-
- // Current pad state
- NPadGenericState npad_pad_state{};
- NPadGenericState npad_libnx_state{};
- NpadGcTriggerState npad_trigger_state{};
- int callback_key{};
- };
-
- void ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx);
- void InitNewlyAddedController(Core::HID::NpadIdType npad_id);
- bool IsControllerSupported(Core::HID::NpadStyleIndex controller) const;
- void RequestPadStateUpdate(Core::HID::NpadIdType npad_id);
- void WriteEmptyEntry(NpadInternalState* npad);
-
- NpadControllerData& GetControllerFromHandle(
- const Core::HID::VibrationDeviceHandle& device_handle);
- const NpadControllerData& GetControllerFromHandle(
- const Core::HID::VibrationDeviceHandle& device_handle) const;
- NpadControllerData& GetControllerFromHandle(
- const Core::HID::SixAxisSensorHandle& device_handle);
- const NpadControllerData& GetControllerFromHandle(
- const Core::HID::SixAxisSensorHandle& device_handle) const;
- NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id);
- const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const;
-
- Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
- const Core::HID::SixAxisSensorHandle& device_handle);
- const Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
- const Core::HID::SixAxisSensorHandle& device_handle) const;
-
- std::atomic<u64> press_state{};
-
- std::array<NpadControllerData, NpadCount> controller_data{};
- KernelHelpers::ServiceContext& service_context;
- std::mutex mutex;
- std::vector<Core::HID::NpadIdType> supported_npad_id_types{};
- NpadJoyHoldType hold_type{NpadJoyHoldType::Vertical};
- NpadHandheldActivationMode handheld_activation_mode{NpadHandheldActivationMode::Dual};
- NpadCommunicationMode communication_mode{NpadCommunicationMode::Default};
- bool permit_vibration_session_enabled{false};
- bool analog_stick_use_center_clamp{false};
- bool is_in_lr_assignment_mode{false};
- bool is_controller_initialized{false};
-};
-} // namespace Service::HID
diff --git a/src/core/hle/service/hid/errors.h b/src/core/hle/service/hid/errors.h
deleted file mode 100644
index 6dc976fe1..000000000
--- a/src/core/hle/service/hid/errors.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#pragma once
-
-#include "core/hle/result.h"
-
-namespace Service::HID {
-
-constexpr Result PalmaResultSuccess{ErrorModule::HID, 0};
-constexpr Result NpadInvalidHandle{ErrorModule::HID, 100};
-constexpr Result NpadDeviceIndexOutOfRange{ErrorModule::HID, 107};
-constexpr Result VibrationInvalidStyleIndex{ErrorModule::HID, 122};
-constexpr Result VibrationInvalidNpadId{ErrorModule::HID, 123};
-constexpr Result VibrationDeviceIndexOutOfRange{ErrorModule::HID, 124};
-constexpr Result InvalidSixAxisFusionRange{ErrorModule::HID, 423};
-constexpr Result NpadIsDualJoycon{ErrorModule::HID, 601};
-constexpr Result NpadIsSameType{ErrorModule::HID, 602};
-constexpr Result InvalidNpadId{ErrorModule::HID, 709};
-constexpr Result NpadNotConnected{ErrorModule::HID, 710};
-constexpr Result InvalidArraySize{ErrorModule::HID, 715};
-
-constexpr Result ResultAppletResourceOverflow{ErrorModule::HID, 1041};
-constexpr Result ResultAppletResourceNotInitialized{ErrorModule::HID, 1042};
-constexpr Result ResultSharedMemoryNotInitialized{ErrorModule::HID, 1043};
-constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044};
-constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046};
-constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047};
-
-constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
-
-} // namespace Service::HID
-
-namespace Service::IRS {
-
-constexpr Result InvalidProcessorState{ErrorModule::Irsensor, 78};
-constexpr Result InvalidIrCameraHandle{ErrorModule::Irsensor, 204};
-
-} // namespace Service::IRS
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index afbcb019f..fc8a3ab66 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -5,14 +5,14 @@
#include "core/hle/kernel/kernel.h"
#include "core/hle/service/hid/hid.h"
#include "core/hle/service/hid/hid_debug_server.h"
-#include "core/hle/service/hid/hid_firmware_settings.h"
#include "core/hle/service/hid/hid_server.h"
#include "core/hle/service/hid/hid_system_server.h"
#include "core/hle/service/hid/hidbus.h"
#include "core/hle/service/hid/irs.h"
-#include "core/hle/service/hid/resource_manager.h"
#include "core/hle/service/hid/xcd.h"
#include "core/hle/service/server_manager.h"
+#include "hid_core/resource_manager.h"
+#include "hid_core/resources/hid_firmware_settings.h"
namespace Service::HID {
@@ -25,6 +25,7 @@ void LoopProcess(Core::System& system) {
// TODO: Remove this hack until this service is emulated properly.
const auto process_list = system.Kernel().GetProcessList();
if (!process_list.empty()) {
+ resouce_manager->Initialize();
resouce_manager->RegisterAppletResourceUserId(process_list[0]->GetId(), true);
}
diff --git a/src/core/hle/service/hid/hid_debug_server.cpp b/src/core/hle/service/hid/hid_debug_server.cpp
index 6294f3dfb..f2a767d37 100644
--- a/src/core/hle/service/hid/hid_debug_server.cpp
+++ b/src/core/hle/service/hid/hid_debug_server.cpp
@@ -2,8 +2,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/hle/service/hid/hid_debug_server.h"
-#include "core/hle/service/hid/resource_manager.h"
#include "core/hle/service/ipc_helpers.h"
+#include "hid_core/resource_manager.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp
index 3174672af..2ff00d30d 100644
--- a/src/core/hle/service/hid/hid_server.cpp
+++ b/src/core/hle/service/hid/hid_server.cpp
@@ -5,30 +5,29 @@
#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/settings.h"
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_shared_memory.h"
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/kernel/kernel.h"
-#include "core/hle/service/hid/errors.h"
-#include "core/hle/service/hid/hid_firmware_settings.h"
#include "core/hle/service/hid/hid_server.h"
-#include "core/hle/service/hid/hid_util.h"
-#include "core/hle/service/hid/resource_manager.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/memory.h"
-
-#include "core/hle/service/hid/controllers/console_six_axis.h"
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/controllers/debug_pad.h"
-#include "core/hle/service/hid/controllers/gesture.h"
-#include "core/hle/service/hid/controllers/keyboard.h"
-#include "core/hle/service/hid/controllers/mouse.h"
-#include "core/hle/service/hid/controllers/npad.h"
-#include "core/hle/service/hid/controllers/palma.h"
-#include "core/hle/service/hid/controllers/seven_six_axis.h"
-#include "core/hle/service/hid/controllers/six_axis.h"
-#include "core/hle/service/hid/controllers/touchscreen.h"
-#include "core/hle/service/hid/controllers/types/npad_types.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/hid_util.h"
+#include "hid_core/resource_manager.h"
+#include "hid_core/resources/hid_firmware_settings.h"
+
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/debug_pad/debug_pad.h"
+#include "hid_core/resources/keyboard/keyboard.h"
+#include "hid_core/resources/mouse/mouse.h"
+#include "hid_core/resources/npad/npad.h"
+#include "hid_core/resources/npad/npad_types.h"
+#include "hid_core/resources/palma/palma.h"
+#include "hid_core/resources/six_axis/console_six_axis.h"
+#include "hid_core/resources/six_axis/seven_six_axis.h"
+#include "hid_core/resources/six_axis/six_axis.h"
+#include "hid_core/resources/touch_screen/gesture.h"
+#include "hid_core/resources/touch_screen/touch_screen.h"
namespace Service::HID {
@@ -785,8 +784,8 @@ void IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ct
bool is_firmware_available{};
auto controller = GetResourceManager()->GetNpad();
- controller->IsFirmwareUpdateAvailableForSixAxisSensor(parameters.sixaxis_handle,
- is_firmware_available);
+ controller->IsFirmwareUpdateAvailableForSixAxisSensor(
+ parameters.applet_resource_user_id, parameters.sixaxis_handle, is_firmware_available);
LOG_WARNING(
Service_HID,
@@ -924,8 +923,8 @@ void IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx)
const auto parameters{rp.PopRaw<Parameters>()};
auto controller = GetResourceManager()->GetNpad();
- const auto result =
- controller->ResetIsSixAxisSensorDeviceNewlyAssigned(parameters.sixaxis_handle);
+ const auto result = controller->ResetIsSixAxisSensorDeviceNewlyAssigned(
+ parameters.applet_resource_user_id, parameters.sixaxis_handle);
LOG_WARNING(
Service_HID,
@@ -970,7 +969,7 @@ void IHidServer::ActivateGesture(HLERequestContext& ctx) {
void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
struct Parameters {
- Core::HID::NpadStyleSet supported_styleset;
+ Core::HID::NpadStyleSet supported_style_set;
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
};
@@ -978,13 +977,25 @@ void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) {
const auto parameters{rp.PopRaw<Parameters>()};
- GetResourceManager()->GetNpad()->SetSupportedStyleSet({parameters.supported_styleset});
+ LOG_DEBUG(Service_HID, "called, supported_style_set={}, applet_resource_user_id={}",
+ parameters.supported_style_set, parameters.applet_resource_user_id);
- LOG_DEBUG(Service_HID, "called, supported_styleset={}, applet_resource_user_id={}",
- parameters.supported_styleset, parameters.applet_resource_user_id);
+ const auto npad = GetResourceManager()->GetNpad();
+ const Result result = npad->SetSupportedNpadStyleSet(parameters.applet_resource_user_id,
+ parameters.supported_style_set);
+
+ if (result.IsSuccess()) {
+ Core::HID::NpadStyleTag style_tag{parameters.supported_style_set};
+ const auto revision = npad->GetRevision(parameters.applet_resource_user_id);
+
+ if (style_tag.palma != 0 && revision < NpadRevision::Revision3) {
+ // GetResourceManager()->GetPalma()->EnableBoostMode(parameters.applet_resource_user_id,
+ // true);
+ }
+ }
IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
+ rb.Push(result);
}
void IHidServer::GetSupportedNpadStyleSet(HLERequestContext& ctx) {
@@ -993,19 +1004,31 @@ void IHidServer::GetSupportedNpadStyleSet(HLERequestContext& ctx) {
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+ Core::HID::NpadStyleSet supported_style_set{};
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result =
+ npad->GetSupportedNpadStyleSet(applet_resource_user_id, supported_style_set);
+
IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.PushEnum(GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw);
+ rb.Push(result);
+ rb.PushEnum(supported_style_set);
}
void IHidServer::SetSupportedNpadIdType(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto applet_resource_user_id{rp.Pop<u64>()};
-
- const auto result = GetResourceManager()->GetNpad()->SetSupportedNpadIdTypes(ctx.ReadBuffer());
+ const auto buffer = ctx.ReadBuffer();
+ const std::size_t elements = ctx.GetReadBufferNumElements<Core::HID::NpadIdType>();
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+ std::vector<Core::HID::NpadIdType> supported_npad_list(elements);
+ memcpy(supported_npad_list.data(), buffer.data(), buffer.size());
+
+ const auto npad = GetResourceManager()->GetNpad();
+ const Result result =
+ npad->SetSupportedNpadIdType(applet_resource_user_id, supported_npad_list);
+
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
}
@@ -1018,7 +1041,7 @@ void IHidServer::ActivateNpad(HLERequestContext& ctx) {
auto npad = GetResourceManager()->GetNpad();
- // TODO: npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0);
+ npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0);
const Result result = npad->Activate(applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
@@ -1052,13 +1075,13 @@ void IHidServer::AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx) {
LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}, unknown={}",
parameters.npad_id, parameters.applet_resource_user_id, parameters.unknown);
- // Games expect this event to be signaled after calling this function
- GetResourceManager()->GetNpad()->SignalStyleSetChangedEvent(parameters.npad_id);
+ Kernel::KReadableEvent* style_set_update_event;
+ const auto result = GetResourceManager()->GetNpad()->AcquireNpadStyleSetUpdateEventHandle(
+ parameters.applet_resource_user_id, &style_set_update_event, parameters.npad_id);
IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(
- GetResourceManager()->GetNpad()->GetStyleSetChangedEvent(parameters.npad_id));
+ rb.Push(result);
+ rb.PushCopyObjects(style_set_update_event);
}
void IHidServer::DisconnectNpad(HLERequestContext& ctx) {
@@ -1073,7 +1096,7 @@ void IHidServer::DisconnectNpad(HLERequestContext& ctx) {
const auto parameters{rp.PopRaw<Parameters>()};
auto controller = GetResourceManager()->GetNpad();
- controller->DisconnectNpad(parameters.npad_id);
+ controller->DisconnectNpad(parameters.applet_resource_user_id, parameters.npad_id);
LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
parameters.applet_resource_user_id);
@@ -1113,7 +1136,7 @@ void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) {
auto npad = GetResourceManager()->GetNpad();
- // TODO: npad->SetRevision(applet_resource_user_id, revision);
+ npad->SetRevision(parameters.applet_resource_user_id, parameters.revision);
const auto result = npad->Activate(parameters.applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
@@ -1125,13 +1148,19 @@ void IHidServer::SetNpadJoyHoldType(HLERequestContext& ctx) {
const auto applet_resource_user_id{rp.Pop<u64>()};
const auto hold_type{rp.PopEnum<NpadJoyHoldType>()};
- GetResourceManager()->GetNpad()->SetHoldType(hold_type);
-
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, hold_type={}",
applet_resource_user_id, hold_type);
+ if (hold_type != NpadJoyHoldType::Horizontal && hold_type != NpadJoyHoldType::Vertical) {
+ // This should crash console
+ ASSERT_MSG(false, "Invalid npad joy hold type");
+ }
+
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result = npad->SetNpadJoyHoldType(applet_resource_user_id, hold_type);
+
IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
+ rb.Push(result);
}
void IHidServer::GetNpadJoyHoldType(HLERequestContext& ctx) {
@@ -1140,9 +1169,13 @@ void IHidServer::GetNpadJoyHoldType(HLERequestContext& ctx) {
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+ NpadJoyHoldType hold_type{};
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result = npad->GetNpadJoyHoldType(applet_resource_user_id, hold_type);
+
IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.PushEnum(GetResourceManager()->GetNpad()->GetHoldType());
+ rb.Push(result);
+ rb.PushEnum(hold_type);
}
void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx) {
@@ -1158,8 +1191,8 @@ void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx)
Core::HID::NpadIdType new_npad_id{};
auto controller = GetResourceManager()->GetNpad();
- controller->SetNpadMode(new_npad_id, parameters.npad_id, NpadJoyDeviceType::Left,
- NpadJoyAssignmentMode::Single);
+ controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id,
+ NpadJoyDeviceType::Left, NpadJoyAssignmentMode::Single);
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
parameters.applet_resource_user_id);
@@ -1182,8 +1215,8 @@ void IHidServer::SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx) {
Core::HID::NpadIdType new_npad_id{};
auto controller = GetResourceManager()->GetNpad();
- controller->SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type,
- NpadJoyAssignmentMode::Single);
+ controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id,
+ parameters.npad_joy_device_type, NpadJoyAssignmentMode::Single);
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
parameters.npad_id, parameters.applet_resource_user_id,
@@ -1206,7 +1239,8 @@ void IHidServer::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) {
Core::HID::NpadIdType new_npad_id{};
auto controller = GetResourceManager()->GetNpad();
- controller->SetNpadMode(new_npad_id, parameters.npad_id, {}, NpadJoyAssignmentMode::Dual);
+ controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id, {},
+ NpadJoyAssignmentMode::Dual);
LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
parameters.applet_resource_user_id); // Spams a lot when controller applet is open
@@ -1222,7 +1256,8 @@ void IHidServer::MergeSingleJoyAsDualJoy(HLERequestContext& ctx) {
const auto applet_resource_user_id{rp.Pop<u64>()};
auto controller = GetResourceManager()->GetNpad();
- const auto result = controller->MergeSingleJoyAsDualJoy(npad_id_1, npad_id_2);
+ const auto result =
+ controller->MergeSingleJoyAsDualJoy(applet_resource_user_id, npad_id_1, npad_id_2);
LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}",
npad_id_1, npad_id_2, applet_resource_user_id);
@@ -1235,10 +1270,10 @@ void IHidServer::StartLrAssignmentMode(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto applet_resource_user_id{rp.Pop<u64>()};
- GetResourceManager()->GetNpad()->StartLRAssignmentMode();
-
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+ GetResourceManager()->GetNpad()->StartLrAssignmentMode(applet_resource_user_id);
+
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
}
@@ -1247,10 +1282,10 @@ void IHidServer::StopLrAssignmentMode(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto applet_resource_user_id{rp.Pop<u64>()};
- GetResourceManager()->GetNpad()->StopLRAssignmentMode();
-
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+ GetResourceManager()->GetNpad()->StopLrAssignmentMode(applet_resource_user_id);
+
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
}
@@ -1260,13 +1295,23 @@ void IHidServer::SetNpadHandheldActivationMode(HLERequestContext& ctx) {
const auto applet_resource_user_id{rp.Pop<u64>()};
const auto activation_mode{rp.PopEnum<NpadHandheldActivationMode>()};
- GetResourceManager()->GetNpad()->SetNpadHandheldActivationMode(activation_mode);
-
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, activation_mode={}",
applet_resource_user_id, activation_mode);
+ if (activation_mode >= NpadHandheldActivationMode::MaxActivationMode) {
+ // Console should crash here
+ ASSERT_MSG(false, "Activation mode should be always None, Single or Dual");
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(ResultSuccess);
+ return;
+ }
+
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result =
+ npad->SetNpadHandheldActivationMode(applet_resource_user_id, activation_mode);
+
IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
+ rb.Push(result);
}
void IHidServer::GetNpadHandheldActivationMode(HLERequestContext& ctx) {
@@ -1275,9 +1320,14 @@ void IHidServer::GetNpadHandheldActivationMode(HLERequestContext& ctx) {
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+ NpadHandheldActivationMode activation_mode{};
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result =
+ npad->GetNpadHandheldActivationMode(applet_resource_user_id, activation_mode);
+
IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.PushEnum(GetResourceManager()->GetNpad()->GetNpadHandheldActivationMode());
+ rb.Push(result);
+ rb.PushEnum(activation_mode);
}
void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) {
@@ -1286,12 +1336,12 @@ void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) {
const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()};
const auto applet_resource_user_id{rp.Pop<u64>()};
- auto controller = GetResourceManager()->GetNpad();
- const auto result = controller->SwapNpadAssignment(npad_id_1, npad_id_2);
-
LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}",
npad_id_1, npad_id_2, applet_resource_user_id);
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result = npad->SwapNpadAssignment(applet_resource_user_id, npad_id_1, npad_id_2);
+
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
}
@@ -1307,13 +1357,19 @@ void IHidServer::IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext&
const auto parameters{rp.PopRaw<Parameters>()};
- bool is_enabled = false;
- auto controller = GetResourceManager()->GetNpad();
- const auto result =
- controller->IsUnintendedHomeButtonInputProtectionEnabled(parameters.npad_id, is_enabled);
+ LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
+ parameters.applet_resource_user_id);
- LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}",
- parameters.npad_id, parameters.applet_resource_user_id);
+ if (!IsNpadIdValid(parameters.npad_id)) {
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(ResultInvalidNpadId);
+ return;
+ }
+
+ bool is_enabled{};
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result = npad->IsUnintendedHomeButtonInputProtectionEnabled(
+ is_enabled, parameters.applet_resource_user_id, parameters.npad_id);
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(result);
@@ -1332,13 +1388,18 @@ void IHidServer::EnableUnintendedHomeButtonInputProtection(HLERequestContext& ct
const auto parameters{rp.PopRaw<Parameters>()};
- auto controller = GetResourceManager()->GetNpad();
- const auto result = controller->SetUnintendedHomeButtonInputProtectionEnabled(
- parameters.is_enabled, parameters.npad_id);
+ LOG_INFO(Service_HID, "called, is_enabled={}, npad_id={}, applet_resource_user_id={}",
+ parameters.is_enabled, parameters.npad_id, parameters.applet_resource_user_id);
- LOG_DEBUG(Service_HID,
- "(STUBBED) called, is_enabled={}, npad_id={}, applet_resource_user_id={}",
- parameters.is_enabled, parameters.npad_id, parameters.applet_resource_user_id);
+ if (!IsNpadIdValid(parameters.npad_id)) {
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(ResultInvalidNpadId);
+ return;
+ }
+
+ const auto npad = GetResourceManager()->GetNpad();
+ const auto result = npad->EnableUnintendedHomeButtonInputProtection(
+ parameters.applet_resource_user_id, parameters.npad_id, parameters.is_enabled);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
@@ -1359,8 +1420,8 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext
Core::HID::NpadIdType new_npad_id{};
auto controller = GetResourceManager()->GetNpad();
const auto is_reassigned =
- controller->SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type,
- NpadJoyAssignmentMode::Single);
+ controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id,
+ parameters.npad_joy_device_type, NpadJoyAssignmentMode::Single);
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
parameters.npad_id, parameters.applet_resource_user_id,
@@ -1375,7 +1436,7 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext
void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
struct Parameters {
- bool analog_stick_use_center_clamp;
+ bool use_center_clamp;
INSERT_PADDING_BYTES_NOINIT(7);
u64 applet_resource_user_id;
};
@@ -1383,12 +1444,11 @@ void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) {
const auto parameters{rp.PopRaw<Parameters>()};
- GetResourceManager()->GetNpad()->SetAnalogStickUseCenterClamp(
- parameters.analog_stick_use_center_clamp);
+ LOG_WARNING(Service_HID, "(STUBBED) called, use_center_clamp={}, applet_resource_user_id={}",
+ parameters.use_center_clamp, parameters.applet_resource_user_id);
- LOG_WARNING(Service_HID,
- "(STUBBED) called, analog_stick_use_center_clamp={}, applet_resource_user_id={}",
- parameters.analog_stick_use_center_clamp, parameters.applet_resource_user_id);
+ GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp(
+ parameters.applet_resource_user_id, parameters.use_center_clamp);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
@@ -1496,7 +1556,8 @@ void IHidServer::SendVibrationValue(HLERequestContext& ctx) {
const auto parameters{rp.PopRaw<Parameters>()};
- GetResourceManager()->GetNpad()->VibrateController(parameters.vibration_device_handle,
+ GetResourceManager()->GetNpad()->VibrateController(parameters.applet_resource_user_id,
+ parameters.vibration_device_handle,
parameters.vibration_value);
LOG_DEBUG(Service_HID,
@@ -1528,8 +1589,8 @@ void IHidServer::GetActualVibrationValue(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 6};
rb.Push(ResultSuccess);
- rb.PushRaw(
- GetResourceManager()->GetNpad()->GetLastVibration(parameters.vibration_device_handle));
+ rb.PushRaw(GetResourceManager()->GetNpad()->GetLastVibration(
+ parameters.applet_resource_user_id, parameters.vibration_device_handle));
}
void IHidServer::CreateActiveVibrationDeviceList(HLERequestContext& ctx) {
@@ -1580,7 +1641,8 @@ void IHidServer::SendVibrationValues(HLERequestContext& ctx) {
auto vibration_values = std::span(
reinterpret_cast<const Core::HID::VibrationValue*>(vibration_data.data()), vibration_count);
- GetResourceManager()->GetNpad()->VibrateControllers(vibration_device_handles, vibration_values);
+ GetResourceManager()->GetNpad()->VibrateControllers(applet_resource_user_id,
+ vibration_device_handles, vibration_values);
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
@@ -1634,8 +1696,8 @@ void IHidServer::SendVibrationGcErmCommand(HLERequestContext& ctx) {
}
}();
- GetResourceManager()->GetNpad()->VibrateController(parameters.vibration_device_handle,
- vibration_value);
+ GetResourceManager()->GetNpad()->VibrateController(
+ parameters.applet_resource_user_id, parameters.vibration_device_handle, vibration_value);
LOG_DEBUG(Service_HID,
"called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, "
@@ -1659,8 +1721,8 @@ void IHidServer::GetActualVibrationGcErmCommand(HLERequestContext& ctx) {
const auto parameters{rp.PopRaw<Parameters>()};
- const auto last_vibration =
- GetResourceManager()->GetNpad()->GetLastVibration(parameters.vibration_device_handle);
+ const auto last_vibration = GetResourceManager()->GetNpad()->GetLastVibration(
+ parameters.applet_resource_user_id, parameters.vibration_device_handle);
const auto gc_erm_command = [last_vibration] {
if (last_vibration.low_amplitude != 0.0f || last_vibration.high_amplitude != 0.0f) {
@@ -1732,7 +1794,7 @@ void IHidServer::IsVibrationDeviceMounted(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess);
rb.Push(GetResourceManager()->GetNpad()->IsVibrationDeviceMounted(
- parameters.vibration_device_handle));
+ parameters.applet_resource_user_id, parameters.vibration_device_handle));
}
void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) {
@@ -2315,10 +2377,10 @@ void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) {
const auto applet_resource_user_id{rp.Pop<u64>()};
const auto communication_mode{rp.PopEnum<NpadCommunicationMode>()};
- GetResourceManager()->GetNpad()->SetNpadCommunicationMode(communication_mode);
+ LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, communication_mode={}",
+ applet_resource_user_id, communication_mode);
- LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}, communication_mode={}",
- applet_resource_user_id, communication_mode);
+ // This function has been stubbed since 2.0.0+
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
@@ -2326,12 +2388,15 @@ void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) {
void IHidServer::GetNpadCommunicationMode(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
+ const auto applet_resource_user_id{rp.Pop<u64>()};
- LOG_WARNING(Service_HID, "(STUBBED) called");
+ LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+
+ // This function has been stubbed since 2.0.0+
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(ResultSuccess);
- rb.PushEnum(GetResourceManager()->GetNpad()->GetNpadCommunicationMode());
+ rb.PushEnum(NpadCommunicationMode::Default);
}
void IHidServer::SetTouchScreenConfiguration(HLERequestContext& ctx) {
diff --git a/src/core/hle/service/hid/hid_system_server.cpp b/src/core/hle/service/hid/hid_system_server.cpp
index 5cc88c4a1..2a65615e8 100644
--- a/src/core/hle/service/hid/hid_system_server.cpp
+++ b/src/core/hle/service/hid/hid_system_server.cpp
@@ -1,15 +1,14 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/npad.h"
-#include "core/hle/service/hid/controllers/palma.h"
-#include "core/hle/service/hid/controllers/touchscreen.h"
-#include "core/hle/service/hid/controllers/types/npad_types.h"
-#include "core/hle/service/hid/errors.h"
#include "core/hle/service/hid/hid_system_server.h"
-#include "core/hle/service/hid/resource_manager.h"
#include "core/hle/service/ipc_helpers.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/resource_manager.h"
+#include "hid_core/resources/npad/npad.h"
+#include "hid_core/resources/npad/npad_types.h"
+#include "hid_core/resources/palma/palma.h"
+#include "hid_core/resources/touch_screen/touch_screen.h"
namespace Service::HID {
@@ -82,7 +81,7 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
{522, nullptr, "SetJoyConRailEnabled"},
{523, nullptr, "IsJoyConRailEnabled"},
{524, nullptr, "IsHandheldHidsEnabled"},
- {525, nullptr, "IsJoyConAttachedOnAllRail"},
+ {525, &IHidSystemServer::IsJoyConAttachedOnAllRail, "IsJoyConAttachedOnAllRail"},
{540, nullptr, "AcquirePlayReportControllerUsageUpdateEvent"},
{541, nullptr, "GetPlayReportControllerUsages"},
{542, nullptr, "AcquirePlayReportRegisteredDeviceUpdateEvent"},
@@ -132,7 +131,7 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
{1001, nullptr, "GetFirmwareVersion"},
{1002, nullptr, "GetAvailableFirmwareVersion"},
{1003, nullptr, "IsFirmwareUpdateAvailable"},
- {1004, nullptr, "CheckFirmwareUpdateRequired"},
+ {1004, &IHidSystemServer::CheckFirmwareUpdateRequired, "CheckFirmwareUpdateRequired"},
{1005, nullptr, "StartFirmwareUpdate"},
{1006, nullptr, "AbortFirmwareUpdate"},
{1007, nullptr, "GetFirmwareUpdateState"},
@@ -145,9 +144,9 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
{1052, nullptr, "CancelSixAxisSensorAccurateUserCalibration"},
{1053, nullptr, "GetSixAxisSensorAccurateUserCalibrationState"},
{1100, nullptr, "GetHidbusSystemServiceObject"},
- {1120, nullptr, "SetFirmwareHotfixUpdateSkipEnabled"},
- {1130, nullptr, "InitializeUsbFirmwareUpdate"},
- {1131, nullptr, "FinalizeUsbFirmwareUpdate"},
+ {1120, &IHidSystemServer::SetFirmwareHotfixUpdateSkipEnabled, "SetFirmwareHotfixUpdateSkipEnabled"},
+ {1130, &IHidSystemServer::InitializeUsbFirmwareUpdate, "InitializeUsbFirmwareUpdate"},
+ {1131, &IHidSystemServer::FinalizeUsbFirmwareUpdate, "FinalizeUsbFirmwareUpdate"},
{1132, nullptr, "CheckUsbFirmwareUpdateRequired"},
{1133, nullptr, "StartUsbFirmwareUpdate"},
{1134, nullptr, "GetUsbFirmwareUpdateState"},
@@ -197,7 +196,7 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
{1268, nullptr, "DeleteButtonConfigStorageFull"},
{1269, nullptr, "DeleteButtonConfigStorageLeft"},
{1270, nullptr, "DeleteButtonConfigStorageRight"},
- {1271, nullptr, "IsUsingCustomButtonConfig"},
+ {1271, &IHidSystemServer::IsUsingCustomButtonConfig, "IsUsingCustomButtonConfig"},
{1272, nullptr, "IsAnyCustomButtonConfigEnabled"},
{1273, nullptr, "SetAllCustomButtonConfigEnabled"},
{1274, nullptr, "SetDefaultButtonConfig"},
@@ -240,9 +239,12 @@ IHidSystemServer::~IHidSystemServer() {
};
void IHidSystemServer::ApplyNpadSystemCommonPolicy(HLERequestContext& ctx) {
- LOG_WARNING(Service_HID, "called");
+ IPC::RequestParser rp{ctx};
+ const auto applet_resource_user_id{rp.Pop<u64>()};
+
+ LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
- GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy();
+ GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy(applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
@@ -267,13 +269,16 @@ void IHidSystemServer::GetLastActiveNpad(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess);
- rb.PushEnum(system.HIDCore().GetLastActiveController());
+ rb.Push(0); // Dont forget to fix this
}
void IHidSystemServer::ApplyNpadSystemCommonPolicyFull(HLERequestContext& ctx) {
- LOG_WARNING(Service_HID, "called");
+ IPC::RequestParser rp{ctx};
+ const auto applet_resource_user_id{rp.Pop<u64>()};
- GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy();
+ LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
+
+ GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicyFull(applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
@@ -298,28 +303,32 @@ void IHidSystemServer::GetNpadFullKeyGripColor(HLERequestContext& ctx) {
void IHidSystemServer::GetMaskedSupportedNpadStyleSet(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
+ const auto applet_resource_user_id{rp.Pop<u64>()};
- LOG_INFO(Service_HID, "(STUBBED) called");
+ LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
- Core::HID::NpadStyleSet supported_styleset =
- GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw;
+ Core::HID::NpadStyleSet supported_styleset{};
+ const auto& npad = GetResourceManager()->GetNpad();
+ const Result result =
+ npad->GetMaskedSupportedNpadStyleSet(applet_resource_user_id, supported_styleset);
IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
+ rb.Push(result);
rb.PushEnum(supported_styleset);
}
void IHidSystemServer::SetSupportedNpadStyleSetAll(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
+ const auto applet_resource_user_id{rp.Pop<u64>()};
- LOG_INFO(Service_HID, "(STUBBED) called");
+ LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
- Core::HID::NpadStyleSet supported_styleset =
- GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw;
+ const auto& npad = GetResourceManager()->GetNpad();
+ const auto result =
+ npad->SetSupportedNpadStyleSet(applet_resource_user_id, Core::HID::NpadStyleSet::All);
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.PushEnum(supported_styleset);
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(result);
}
void IHidSystemServer::GetAppletDetailedUiType(HLERequestContext& ctx) {
@@ -546,6 +555,16 @@ void IHidSystemServer::EnableAppletToGetTouchScreen(HLERequestContext& ctx) {
rb.Push(ResultSuccess);
}
+void IHidSystemServer::IsJoyConAttachedOnAllRail(HLERequestContext& ctx) {
+ const bool is_attached = true;
+
+ LOG_DEBUG(Service_HID, "(STUBBED) called, is_attached={}", is_attached);
+
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(ResultSuccess);
+ rb.Push(is_attached);
+}
+
void IHidSystemServer::AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx) {
LOG_INFO(Service_AM, "(STUBBED) called");
@@ -632,6 +651,34 @@ void IHidSystemServer::InitializeFirmwareUpdate(HLERequestContext& ctx) {
rb.Push(ResultSuccess);
}
+void IHidSystemServer::CheckFirmwareUpdateRequired(HLERequestContext& ctx) {
+ LOG_WARNING(Service_HID, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(ResultSuccess);
+}
+
+void IHidSystemServer::SetFirmwareHotfixUpdateSkipEnabled(HLERequestContext& ctx) {
+ LOG_WARNING(Service_HID, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(ResultSuccess);
+}
+
+void IHidSystemServer::InitializeUsbFirmwareUpdate(HLERequestContext& ctx) {
+ LOG_WARNING(Service_HID, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(ResultSuccess);
+}
+
+void IHidSystemServer::FinalizeUsbFirmwareUpdate(HLERequestContext& ctx) {
+ LOG_WARNING(Service_HID, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(ResultSuccess);
+}
+
void IHidSystemServer::InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContext& ctx) {
LOG_WARNING(Service_HID, "(STUBBED) called");
@@ -656,6 +703,16 @@ void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx
rb.PushRaw(touchscreen_config);
}
+void IHidSystemServer::IsUsingCustomButtonConfig(HLERequestContext& ctx) {
+ const bool is_enabled = false;
+
+ LOG_DEBUG(Service_HID, "(STUBBED) called, is_enabled={}", is_enabled);
+
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(ResultSuccess);
+ rb.Push(is_enabled);
+}
+
std::shared_ptr<ResourceManager> IHidSystemServer::GetResourceManager() {
resource_manager->Initialize();
return resource_manager;
diff --git a/src/core/hle/service/hid/hid_system_server.h b/src/core/hle/service/hid/hid_system_server.h
index 1e623dfc2..f467e2aa8 100644
--- a/src/core/hle/service/hid/hid_system_server.h
+++ b/src/core/hle/service/hid/hid_system_server.h
@@ -44,6 +44,7 @@ private:
void EnableAppletToGetSixAxisSensor(HLERequestContext& ctx);
void EnableAppletToGetPadInput(HLERequestContext& ctx);
void EnableAppletToGetTouchScreen(HLERequestContext& ctx);
+ void IsJoyConAttachedOnAllRail(HLERequestContext& ctx);
void AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx);
void AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx);
void GetRegisteredDevices(HLERequestContext& ctx);
@@ -53,8 +54,13 @@ private:
void IsUsbFullKeyControllerEnabled(HLERequestContext& ctx);
void IsHandheldButtonPressedOnConsoleMode(HLERequestContext& ctx);
void InitializeFirmwareUpdate(HLERequestContext& ctx);
+ void CheckFirmwareUpdateRequired(HLERequestContext& ctx);
+ void SetFirmwareHotfixUpdateSkipEnabled(HLERequestContext& ctx);
+ void InitializeUsbFirmwareUpdate(HLERequestContext& ctx);
+ void FinalizeUsbFirmwareUpdate(HLERequestContext& ctx);
void InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContext& ctx);
void GetTouchScreenDefaultConfiguration(HLERequestContext& ctx);
+ void IsUsingCustomButtonConfig(HLERequestContext& ctx);
std::shared_ptr<ResourceManager> GetResourceManager();
diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp
index ffa7e144d..46f503d38 100644
--- a/src/core/hle/service/hid/hidbus.cpp
+++ b/src/core/hle/service/hid/hidbus.cpp
@@ -5,18 +5,18 @@
#include "common/settings.h"
#include "core/core.h"
#include "core/core_timing.h"
-#include "core/hid/hid_types.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
#include "core/hle/kernel/k_shared_memory.h"
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/service/hid/hidbus.h"
-#include "core/hle/service/hid/hidbus/ringcon.h"
-#include "core/hle/service/hid/hidbus/starlink.h"
-#include "core/hle/service/hid/hidbus/stubbed.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/service.h"
#include "core/memory.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/hidbus/ringcon.h"
+#include "hid_core/hidbus/starlink.h"
+#include "hid_core/hidbus/stubbed.h"
namespace Service::HID {
// (15ms, 66Hz)
diff --git a/src/core/hle/service/hid/hidbus.h b/src/core/hle/service/hid/hidbus.h
index 85a1df133..05f62f634 100644
--- a/src/core/hle/service/hid/hidbus.h
+++ b/src/core/hle/service/hid/hidbus.h
@@ -5,9 +5,9 @@
#include <functional>
-#include "core/hle/service/hid/hidbus/hidbus_base.h"
#include "core/hle/service/kernel_helpers.h"
#include "core/hle/service/service.h"
+#include "hid_core/hidbus/hidbus_base.h"
namespace Core::Timing {
struct EventType;
diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp
index 008debfd1..18e544f2f 100644
--- a/src/core/hle/service/hid/irs.cpp
+++ b/src/core/hle/service/hid/irs.cpp
@@ -6,22 +6,22 @@
#include "core/core.h"
#include "core/core_timing.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_shared_memory.h"
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/kernel/kernel.h"
-#include "core/hle/service/hid/errors.h"
-#include "core/hle/service/hid/hid_util.h"
#include "core/hle/service/hid/irs.h"
-#include "core/hle/service/hid/irsensor/clustering_processor.h"
-#include "core/hle/service/hid/irsensor/image_transfer_processor.h"
-#include "core/hle/service/hid/irsensor/ir_led_processor.h"
-#include "core/hle/service/hid/irsensor/moment_processor.h"
-#include "core/hle/service/hid/irsensor/pointing_processor.h"
-#include "core/hle/service/hid/irsensor/tera_plugin_processor.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/memory.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/hid_util.h"
+#include "hid_core/irsensor/clustering_processor.h"
+#include "hid_core/irsensor/image_transfer_processor.h"
+#include "hid_core/irsensor/ir_led_processor.h"
+#include "hid_core/irsensor/moment_processor.h"
+#include "hid_core/irsensor/pointing_processor.h"
+#include "hid_core/irsensor/tera_plugin_processor.h"
namespace Service::IRS {
@@ -315,7 +315,7 @@ void IRS::GetNpadIrCameraHandle(HLERequestContext& ctx) {
if (npad_id > Core::HID::NpadIdType::Player8 && npad_id != Core::HID::NpadIdType::Invalid &&
npad_id != Core::HID::NpadIdType::Handheld) {
IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(Service::HID::InvalidNpadId);
+ rb.Push(Service::HID::ResultInvalidNpadId);
return;
}
diff --git a/src/core/hle/service/hid/irs.h b/src/core/hle/service/hid/irs.h
index c8e6dab17..06b7279ee 100644
--- a/src/core/hle/service/hid/irs.h
+++ b/src/core/hle/service/hid/irs.h
@@ -4,10 +4,10 @@
#pragma once
#include "core/core.h"
-#include "core/hid/hid_types.h"
-#include "core/hid/irs_types.h"
-#include "core/hle/service/hid/irsensor/processor_base.h"
#include "core/hle/service/service.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/irsensor/irs_types.h"
+#include "hid_core/irsensor/processor_base.h"
namespace Core::HID {
class EmulatedController;
diff --git a/src/core/hle/service/nfc/common/device.cpp b/src/core/hle/service/nfc/common/device.cpp
index f97e5b44c..b37fb6da3 100644
--- a/src/core/hle/service/nfc/common/device.cpp
+++ b/src/core/hle/service/nfc/common/device.cpp
@@ -22,9 +22,6 @@
#include "common/string_util.h"
#include "common/tiny_mt.h"
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/mii/mii_manager.h"
@@ -33,6 +30,9 @@
#include "core/hle/service/nfc/mifare_result.h"
#include "core/hle/service/nfc/nfc_result.h"
#include "core/hle/service/time/time_manager.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
namespace Service::NFC {
NfcDevice::NfcDevice(Core::HID::NpadIdType npad_id_, Core::System& system_,
diff --git a/src/core/hle/service/nfc/common/device_manager.cpp b/src/core/hle/service/nfc/common/device_manager.cpp
index ad534177d..44f651b87 100644
--- a/src/core/hle/service/nfc/common/device_manager.cpp
+++ b/src/core/hle/service/nfc/common/device_manager.cpp
@@ -5,15 +5,15 @@
#include "common/logging/log.h"
#include "core/core.h"
-#include "core/hid/hid_types.h"
#include "core/hle/kernel/k_event.h"
-#include "core/hle/service/hid/hid_util.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/nfc/common/device.h"
#include "core/hle/service/nfc/common/device_manager.h"
#include "core/hle/service/nfc/nfc_result.h"
#include "core/hle/service/time/clock_types.h"
#include "core/hle/service/time/time_manager.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/hid_util.h"
namespace Service::NFC {
diff --git a/src/core/hle/service/nfc/common/device_manager.h b/src/core/hle/service/nfc/common/device_manager.h
index c9f038e32..f02bdccf5 100644
--- a/src/core/hle/service/nfc/common/device_manager.h
+++ b/src/core/hle/service/nfc/common/device_manager.h
@@ -8,13 +8,13 @@
#include <optional>
#include <span>
-#include "core/hid/hid_types.h"
#include "core/hle/service/kernel_helpers.h"
#include "core/hle/service/nfc/mifare_types.h"
#include "core/hle/service/nfc/nfc_types.h"
#include "core/hle/service/nfp/nfp_types.h"
#include "core/hle/service/service.h"
#include "core/hle/service/time/clock_types.h"
+#include "hid_core/hid_types.h"
namespace Service::NFC {
class NfcDevice;
diff --git a/src/core/hle/service/nfc/nfc_interface.cpp b/src/core/hle/service/nfc/nfc_interface.cpp
index 179c7ba2c..a71cf74b8 100644
--- a/src/core/hle/service/nfc/nfc_interface.cpp
+++ b/src/core/hle/service/nfc/nfc_interface.cpp
@@ -3,7 +3,6 @@
#include "common/logging/log.h"
#include "core/core.h"
-#include "core/hid/hid_types.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/nfc/common/device.h"
@@ -15,6 +14,7 @@
#include "core/hle/service/nfc/nfc_types.h"
#include "core/hle/service/nfp/nfp_result.h"
#include "core/hle/service/time/clock_types.h"
+#include "hid_core/hid_types.h"
namespace Service::NFC {
diff --git a/src/core/hle/service/nfp/nfp_interface.cpp b/src/core/hle/service/nfp/nfp_interface.cpp
index 34ef9d82d..5ba6d1742 100644
--- a/src/core/hle/service/nfp/nfp_interface.cpp
+++ b/src/core/hle/service/nfp/nfp_interface.cpp
@@ -3,7 +3,6 @@
#include "common/logging/log.h"
#include "core/core.h"
-#include "core/hid/hid_types.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/nfc/common/device.h"
@@ -12,6 +11,7 @@
#include "core/hle/service/nfp/nfp_interface.h"
#include "core/hle/service/nfp/nfp_result.h"
#include "core/hle/service/nfp/nfp_types.h"
+#include "hid_core/hid_types.h"
namespace Service::NFP {
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp
index 7bc5b5ae5..96fa7fa3a 100644
--- a/src/core/memory/cheat_engine.cpp
+++ b/src/core/memory/cheat_engine.cpp
@@ -9,12 +9,12 @@
#include "core/core_timing.h"
#include "core/hle/kernel/k_page_table.h"
#include "core/hle/kernel/k_process.h"
-#include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/hid/hid_server.h"
-#include "core/hle/service/hid/resource_manager.h"
#include "core/hle/service/sm/sm.h"
#include "core/memory.h"
#include "core/memory/cheat_engine.h"
+#include "hid_core/resource_manager.h"
+#include "hid_core/resources/npad/npad.h"
namespace Core::Memory {
namespace {
diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp
index 51576b4ee..9eb4799a6 100644
--- a/src/frontend_common/config.cpp
+++ b/src/frontend_common/config.cpp
@@ -11,7 +11,7 @@
#include "config.h"
#include "core/core.h"
#include "core/hle/service/acc/profile_manager.h"
-#include "core/hle/service/hid/controllers/npad.h"
+#include "hid_core/resources/npad/npad.h"
#include "network/network.h"
#include <boost/algorithm/string/replace.hpp>
@@ -762,17 +762,6 @@ void Config::WriteBooleanSetting(const std::string& key, const bool& value,
WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
}
-template <typename T>
-std::enable_if_t<std::is_integral_v<T>> Config::WriteIntegerSetting(
- const std::string& key, const T& value, const std::optional<T>& default_value,
- const std::optional<bool>& use_global) {
- std::optional<std::string> string_default = std::nullopt;
- if (default_value.has_value()) {
- string_default = std::make_optional(ToString(default_value.value()));
- }
- WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
-}
-
void Config::WriteDoubleSetting(const std::string& key, const double& value,
const std::optional<double>& default_value,
const std::optional<bool>& use_global) {
@@ -894,9 +883,10 @@ void Config::WriteSettingGeneric(const Settings::BasicSetting* const setting) {
WriteBooleanSetting(std::string(key).append("\\use_global"), setting->UsingGlobal());
}
if (global || !setting->UsingGlobal()) {
+ auto value = global ? setting->ToStringGlobal() : setting->ToString();
WriteBooleanSetting(std::string(key).append("\\default"),
- setting->ToString() == setting->DefaultToString());
- WriteStringSetting(key, setting->ToString());
+ value == setting->DefaultToString());
+ WriteStringSetting(key, value);
}
} else if (global) {
WriteBooleanSetting(std::string(key).append("\\default"),
diff --git a/src/frontend_common/config.h b/src/frontend_common/config.h
index 0c4d505b8..b01631649 100644
--- a/src/frontend_common/config.h
+++ b/src/frontend_common/config.h
@@ -157,17 +157,23 @@ protected:
void WriteBooleanSetting(const std::string& key, const bool& value,
const std::optional<bool>& default_value = std::nullopt,
const std::optional<bool>& use_global = std::nullopt);
- template <typename T>
- std::enable_if_t<std::is_integral_v<T>> WriteIntegerSetting(
- const std::string& key, const T& value,
- const std::optional<T>& default_value = std::nullopt,
- const std::optional<bool>& use_global = std::nullopt);
void WriteDoubleSetting(const std::string& key, const double& value,
const std::optional<double>& default_value = std::nullopt,
const std::optional<bool>& use_global = std::nullopt);
void WriteStringSetting(const std::string& key, const std::string& value,
const std::optional<std::string>& default_value = std::nullopt,
const std::optional<bool>& use_global = std::nullopt);
+ template <typename T>
+ std::enable_if_t<std::is_integral_v<T>> WriteIntegerSetting(
+ const std::string& key, const T& value,
+ const std::optional<T>& default_value = std::nullopt,
+ const std::optional<bool>& use_global = std::nullopt) {
+ std::optional<std::string> string_default = std::nullopt;
+ if (default_value.has_value()) {
+ string_default = std::make_optional(ToString(default_value.value()));
+ }
+ WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
+ }
void ReadCategory(Settings::Category category);
void WriteCategory(Settings::Category category);
diff --git a/src/hid_core/CMakeLists.txt b/src/hid_core/CMakeLists.txt
new file mode 100644
index 000000000..cce4e6857
--- /dev/null
+++ b/src/hid_core/CMakeLists.txt
@@ -0,0 +1,126 @@
+# SPDX-FileCopyrightText: 2018 yuzu Emulator Project
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+add_library(hid_core STATIC
+ frontend/emulated_console.cpp
+ frontend/emulated_console.h
+ frontend/emulated_controller.cpp
+ frontend/emulated_controller.h
+ frontend/emulated_devices.cpp
+ frontend/emulated_devices.h
+ frontend/input_converter.cpp
+ frontend/input_converter.h
+ frontend/input_interpreter.cpp
+ frontend/input_interpreter.h
+ frontend/motion_input.cpp
+ frontend/motion_input.h
+ hidbus/hidbus_base.cpp
+ hidbus/hidbus_base.h
+ hidbus/ringcon.cpp
+ hidbus/ringcon.h
+ hidbus/starlink.cpp
+ hidbus/starlink.h
+ hidbus/stubbed.cpp
+ hidbus/stubbed.h
+ irsensor/clustering_processor.cpp
+ irsensor/clustering_processor.h
+ irsensor/image_transfer_processor.cpp
+ irsensor/image_transfer_processor.h
+ irsensor/ir_led_processor.cpp
+ irsensor/ir_led_processor.h
+ irsensor/moment_processor.cpp
+ irsensor/moment_processor.h
+ irsensor/pointing_processor.cpp
+ irsensor/pointing_processor.h
+ irsensor/processor_base.cpp
+ irsensor/processor_base.h
+ irsensor/tera_plugin_processor.cpp
+ irsensor/tera_plugin_processor.h
+ resources/debug_pad/debug_pad.cpp
+ resources/debug_pad/debug_pad.h
+ resources/debug_pad/debug_pad_types.h
+ resources/digitizer/digitizer.cpp
+ resources/digitizer/digitizer.h
+ resources/keyboard/keyboard.cpp
+ resources/keyboard/keyboard.h
+ resources/keyboard/keyboard_types.h
+ resources/mouse/debug_mouse.cpp
+ resources/mouse/debug_mouse.h
+ resources/mouse/mouse.cpp
+ resources/mouse/mouse.h
+ resources/mouse/mouse_types.h
+ resources/npad/npad.cpp
+ resources/npad/npad.h
+ resources/npad/npad_data.cpp
+ resources/npad/npad_data.h
+ resources/npad/npad_resource.cpp
+ resources/npad/npad_resource.h
+ resources/npad/npad_types.h
+ resources/palma/palma.cpp
+ resources/palma/palma.h
+ resources/six_axis/console_six_axis.cpp
+ resources/six_axis/console_six_axis.h
+ resources/six_axis/seven_six_axis.cpp
+ resources/six_axis/seven_six_axis.h
+ resources/six_axis/six_axis.cpp
+ resources/six_axis/six_axis.h
+ resources/system_buttons/capture_button.cpp
+ resources/system_buttons/capture_button.h
+ resources/system_buttons/home_button.cpp
+ resources/system_buttons/home_button.h
+ resources/system_buttons/sleep_button.cpp
+ resources/system_buttons/sleep_button.h
+ resources/touch_screen/gesture.cpp
+ resources/touch_screen/gesture.h
+ resources/touch_screen/gesture_types.h
+ resources/touch_screen/touch_screen.cpp
+ resources/touch_screen/touch_screen.h
+ resources/touch_screen/touch_types.h
+ resources/unique_pad/unique_pad.cpp
+ resources/unique_pad/unique_pad.h
+ resources/applet_resource.cpp
+ resources/applet_resource.h
+ resources/controller_base.cpp
+ resources/controller_base.h
+ resources/hid_firmware_settings.cpp
+ resources/hid_firmware_settings.h
+ resources/irs_ring_lifo.h
+ resources/ring_lifo.h
+ resources/shared_memory_format.h
+ resources/shared_memory_holder.cpp
+ resources/shared_memory_holder.h
+ hid_core.cpp
+ hid_core.h
+ hid_result.h
+ hid_types.h
+ hid_util.h
+ precompiled_headers.h
+ resource_manager.cpp
+ resource_manager.h
+)
+
+if (MSVC)
+ target_compile_options(hid_core PRIVATE
+ /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
+ /we4244 # 'conversion': conversion from 'type1' to 'type2', possible loss of data
+ /we4245 # 'conversion': conversion from 'type1' to 'type2', signed/unsigned mismatch
+ /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
+ /we4800 # Implicit conversion from 'type' to bool. Possible information loss
+ )
+else()
+ target_compile_options(hid_core PRIVATE
+ -Werror=conversion
+
+ -Wno-sign-conversion
+ -Wno-cast-function-type
+
+ $<$<CXX_COMPILER_ID:Clang>:-fsized-deallocation>
+ )
+endif()
+
+create_target_directory_groups(hid_core)
+target_link_libraries(hid_core PUBLIC core)
+
+if (YUZU_USE_PRECOMPILED_HEADERS)
+ target_precompile_headers(hid_core PRIVATE precompiled_headers.h)
+endif()
diff --git a/src/core/hid/emulated_console.cpp b/src/hid_core/frontend/emulated_console.cpp
index b4afd930e..114c22fb7 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/hid_core/frontend/emulated_console.cpp
@@ -2,8 +2,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
-#include "core/hid/emulated_console.h"
-#include "core/hid/input_converter.h"
+#include "hid_core/frontend/emulated_console.h"
+#include "hid_core/frontend/input_converter.h"
namespace Core::HID {
EmulatedConsole::EmulatedConsole() = default;
diff --git a/src/core/hid/emulated_console.h b/src/hid_core/frontend/emulated_console.h
index fae15a556..847551395 100644
--- a/src/core/hid/emulated_console.h
+++ b/src/hid_core/frontend/emulated_console.h
@@ -17,8 +17,8 @@
#include "common/point.h"
#include "common/quaternion.h"
#include "common/vector_math.h"
-#include "core/hid/hid_types.h"
-#include "core/hid/motion_input.h"
+#include "hid_core/frontend/motion_input.h"
+#include "hid_core/hid_types.h"
namespace Core::HID {
static constexpr std::size_t MaxTouchDevices = 32;
diff --git a/src/core/hid/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp
index a6e681e15..3d2d1e9f9 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/hid_core/frontend/emulated_controller.cpp
@@ -6,9 +6,9 @@
#include "common/polyfill_ranges.h"
#include "common/thread.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/input_converter.h"
-#include "core/hle/service/hid/hid_util.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/frontend/input_converter.h"
+#include "hid_core/hid_util.h"
namespace Core::HID {
constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
diff --git a/src/core/hid/emulated_controller.h b/src/hid_core/frontend/emulated_controller.h
index d6e20ab66..94798164d 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/hid_core/frontend/emulated_controller.h
@@ -15,9 +15,9 @@
#include "common/param_package.h"
#include "common/settings.h"
#include "common/vector_math.h"
-#include "core/hid/hid_types.h"
-#include "core/hid/irs_types.h"
-#include "core/hid/motion_input.h"
+#include "hid_core/frontend/motion_input.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/irsensor/irs_types.h"
namespace Core::HID {
const std::size_t max_emulated_controllers = 2;
diff --git a/src/core/hid/emulated_devices.cpp b/src/hid_core/frontend/emulated_devices.cpp
index 8e165dded..a827aa9b7 100644
--- a/src/core/hid/emulated_devices.cpp
+++ b/src/hid_core/frontend/emulated_devices.cpp
@@ -4,8 +4,8 @@
#include <algorithm>
#include <fmt/format.h>
-#include "core/hid/emulated_devices.h"
-#include "core/hid/input_converter.h"
+#include "hid_core/frontend/emulated_devices.h"
+#include "hid_core/frontend/input_converter.h"
namespace Core::HID {
diff --git a/src/core/hid/emulated_devices.h b/src/hid_core/frontend/emulated_devices.h
index 5eab693e4..b2e57318c 100644
--- a/src/core/hid/emulated_devices.h
+++ b/src/hid_core/frontend/emulated_devices.h
@@ -14,7 +14,7 @@
#include "common/input.h"
#include "common/param_package.h"
#include "common/settings.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
namespace Core::HID {
using KeyboardDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
diff --git a/src/core/hid/input_converter.cpp b/src/hid_core/frontend/input_converter.cpp
index a05716fd8..f245a3f76 100644
--- a/src/core/hid/input_converter.cpp
+++ b/src/hid_core/frontend/input_converter.cpp
@@ -5,7 +5,7 @@
#include <random>
#include "common/input.h"
-#include "core/hid/input_converter.h"
+#include "hid_core/frontend/input_converter.h"
namespace Core::HID {
diff --git a/src/core/hid/input_converter.h b/src/hid_core/frontend/input_converter.h
index c51c03e57..c51c03e57 100644
--- a/src/core/hid/input_converter.h
+++ b/src/hid_core/frontend/input_converter.h
diff --git a/src/core/hid/input_interpreter.cpp b/src/hid_core/frontend/input_interpreter.cpp
index 072f38a68..b6c8d8c5d 100644
--- a/src/core/hid/input_interpreter.cpp
+++ b/src/hid_core/frontend/input_interpreter.cpp
@@ -2,12 +2,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
-#include "core/hid/hid_types.h"
-#include "core/hid/input_interpreter.h"
-#include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/hid/hid_server.h"
-#include "core/hle/service/hid/resource_manager.h"
#include "core/hle/service/sm/sm.h"
+#include "hid_core/frontend/input_interpreter.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resource_manager.h"
+#include "hid_core/resources/npad/npad.h"
InputInterpreter::InputInterpreter(Core::System& system)
: npad{system.ServiceManager()
diff --git a/src/core/hid/input_interpreter.h b/src/hid_core/frontend/input_interpreter.h
index 3569aac93..3569aac93 100644
--- a/src/core/hid/input_interpreter.h
+++ b/src/hid_core/frontend/input_interpreter.h
diff --git a/src/core/hid/motion_input.cpp b/src/hid_core/frontend/motion_input.cpp
index f56f2ae1d..417cd03f9 100644
--- a/src/core/hid/motion_input.cpp
+++ b/src/hid_core/frontend/motion_input.cpp
@@ -4,7 +4,7 @@
#include <cmath>
#include "common/math_util.h"
-#include "core/hid/motion_input.h"
+#include "hid_core/frontend/motion_input.h"
namespace Core::HID {
diff --git a/src/core/hid/motion_input.h b/src/hid_core/frontend/motion_input.h
index 11678983d..11678983d 100644
--- a/src/core/hid/motion_input.h
+++ b/src/hid_core/frontend/motion_input.h
diff --git a/src/core/hid/hid_core.cpp b/src/hid_core/hid_core.cpp
index 2cf25a870..410c84afb 100644
--- a/src/core/hid/hid_core.cpp
+++ b/src/hid_core/hid_core.cpp
@@ -2,11 +2,11 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/assert.h"
-#include "core/hid/emulated_console.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/emulated_devices.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/hid_util.h"
+#include "hid_core/frontend/emulated_console.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/frontend/emulated_devices.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_util.h"
namespace Core::HID {
diff --git a/src/core/hid/hid_core.h b/src/hid_core/hid_core.h
index 80abab18b..dae29c506 100644
--- a/src/core/hid/hid_core.h
+++ b/src/hid_core/hid_core.h
@@ -6,7 +6,7 @@
#include <memory>
#include "common/common_funcs.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
namespace Core::HID {
class EmulatedConsole;
diff --git a/src/hid_core/hid_result.h b/src/hid_core/hid_result.h
new file mode 100644
index 000000000..bb14aa61e
--- /dev/null
+++ b/src/hid_core/hid_result.h
@@ -0,0 +1,59 @@
+// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "core/hle/result.h"
+
+namespace Service::HID {
+
+constexpr Result PalmaResultSuccess{ErrorModule::HID, 0};
+constexpr Result NpadInvalidHandle{ErrorModule::HID, 100};
+constexpr Result NpadDeviceIndexOutOfRange{ErrorModule::HID, 107};
+
+constexpr Result ResultVibrationNotInitialized{ErrorModule::HID, 121};
+constexpr Result ResultVibrationInvalidStyleIndex{ErrorModule::HID, 122};
+constexpr Result ResultVibrationInvalidNpadId{ErrorModule::HID, 123};
+constexpr Result ResultVibrationDeviceIndexOutOfRange{ErrorModule::HID, 124};
+constexpr Result ResultVibrationStrenghtOutOfRange{ErrorModule::HID, 126};
+constexpr Result ResultVibrationArraySizeMismatch{ErrorModule::HID, 131};
+
+constexpr Result InvalidSixAxisFusionRange{ErrorModule::HID, 423};
+
+constexpr Result ResultNfcIsNotReady{ErrorModule::HID, 461};
+constexpr Result ResultNfcXcdHandleIsNotInitialized{ErrorModule::HID, 464};
+constexpr Result ResultIrSensorIsNotReady{ErrorModule::HID, 501};
+constexpr Result ResultMcuIsNotReady{ErrorModule::HID, 541};
+
+constexpr Result NpadIsDualJoycon{ErrorModule::HID, 601};
+constexpr Result NpadIsSameType{ErrorModule::HID, 602};
+constexpr Result ResultNpadIsNotProController{ErrorModule::HID, 604};
+
+constexpr Result ResultInvalidNpadId{ErrorModule::HID, 709};
+constexpr Result ResultNpadNotConnected{ErrorModule::HID, 710};
+constexpr Result ResultNpadHandlerOverflow{ErrorModule::HID, 711};
+constexpr Result ResultNpadHandlerNotInitialized{ErrorModule::HID, 712};
+constexpr Result ResultInvalidArraySize{ErrorModule::HID, 715};
+constexpr Result ResultUndefinedStyleset{ErrorModule::HID, 716};
+constexpr Result ResultMultipleStyleSetSelected{ErrorModule::HID, 717};
+
+constexpr Result ResultAppletResourceOverflow{ErrorModule::HID, 1041};
+constexpr Result ResultAppletResourceNotInitialized{ErrorModule::HID, 1042};
+constexpr Result ResultSharedMemoryNotInitialized{ErrorModule::HID, 1043};
+constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044};
+constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046};
+constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047};
+
+constexpr Result ResultNpadResourceOverflow{ErrorModule::HID, 2001};
+constexpr Result ResultNpadResourceNotInitialized{ErrorModule::HID, 2002};
+
+constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
+
+} // namespace Service::HID
+
+namespace Service::IRS {
+
+constexpr Result InvalidProcessorState{ErrorModule::Irsensor, 78};
+constexpr Result InvalidIrCameraHandle{ErrorModule::Irsensor, 204};
+
+} // namespace Service::IRS
diff --git a/src/core/hid/hid_types.h b/src/hid_core/hid_types.h
index 4bf285f36..a81ed6af0 100644
--- a/src/core/hid/hid_types.h
+++ b/src/hid_core/hid_types.h
@@ -267,6 +267,7 @@ enum class NpadStyleSet : u32 {
All = 0xFFFFFFFFU,
};
static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size");
+DECLARE_ENUM_FLAG_OPERATORS(NpadStyleSet)
// This is nn::hid::VibrationDevicePosition
enum class VibrationDevicePosition : u32 {
diff --git a/src/core/hle/service/hid/hid_util.h b/src/hid_core/hid_util.h
index b87cc10e3..94ff2d23a 100644
--- a/src/core/hle/service/hid/hid_util.h
+++ b/src/hid_core/hid_util.h
@@ -3,8 +3,8 @@
#pragma once
-#include "core/hid/hid_types.h"
-#include "core/hle/service/hid/errors.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/hid_types.h"
namespace Service::HID {
@@ -31,7 +31,7 @@ constexpr Result IsSixaxisHandleValid(const Core::HID::SixAxisSensorHandle& hand
const bool device_index = handle.device_index < Core::HID::DeviceIndex::MaxDeviceIndex;
if (!npad_id) {
- return InvalidNpadId;
+ return ResultInvalidNpadId;
}
if (!device_index) {
return NpadDeviceIndexOutOfRange;
@@ -54,15 +54,15 @@ constexpr Result IsVibrationHandleValid(const Core::HID::VibrationDeviceHandle&
// These support vibration
break;
default:
- return VibrationInvalidStyleIndex;
+ return ResultVibrationInvalidStyleIndex;
}
if (!IsNpadIdValid(static_cast<Core::HID::NpadIdType>(handle.npad_id))) {
- return VibrationInvalidNpadId;
+ return ResultVibrationInvalidNpadId;
}
if (handle.device_index >= Core::HID::DeviceIndex::MaxDeviceIndex) {
- return VibrationDeviceIndexOutOfRange;
+ return ResultVibrationDeviceIndexOutOfRange;
}
return ResultSuccess;
diff --git a/src/core/hle/service/hid/hidbus/hidbus_base.cpp b/src/hid_core/hidbus/hidbus_base.cpp
index 8c44f93e8..632bb173b 100644
--- a/src/core/hle/service/hid/hidbus/hidbus_base.cpp
+++ b/src/hid_core/hidbus/hidbus_base.cpp
@@ -1,11 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
-#include "core/hle/service/hid/hidbus/hidbus_base.h"
#include "core/hle/service/kernel_helpers.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hidbus/hidbus_base.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/hidbus/hidbus_base.h b/src/hid_core/hidbus/hidbus_base.h
index ec41684e1..ec41684e1 100644
--- a/src/core/hle/service/hid/hidbus/hidbus_base.h
+++ b/src/hid_core/hidbus/hidbus_base.h
diff --git a/src/core/hle/service/hid/hidbus/ringcon.cpp b/src/hid_core/hidbus/ringcon.cpp
index 378108012..cedf25c16 100644
--- a/src/core/hle/service/hid/hidbus/ringcon.cpp
+++ b/src/hid_core/hidbus/ringcon.cpp
@@ -2,12 +2,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
-#include "core/hle/service/hid/hidbus/ringcon.h"
#include "core/memory.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hidbus/ringcon.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/hidbus/ringcon.h b/src/hid_core/hidbus/ringcon.h
index f42f3ea41..0953e8100 100644
--- a/src/core/hle/service/hid/hidbus/ringcon.h
+++ b/src/hid_core/hidbus/ringcon.h
@@ -7,7 +7,7 @@
#include <span>
#include "common/common_types.h"
-#include "core/hle/service/hid/hidbus/hidbus_base.h"
+#include "hid_core/hidbus/hidbus_base.h"
namespace Core::HID {
class EmulatedController;
diff --git a/src/core/hle/service/hid/hidbus/starlink.cpp b/src/hid_core/hidbus/starlink.cpp
index 36573274e..31b263aa1 100644
--- a/src/core/hle/service/hid/hidbus/starlink.cpp
+++ b/src/hid_core/hidbus/starlink.cpp
@@ -1,9 +1,9 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/hidbus/starlink.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hidbus/starlink.h"
namespace Service::HID {
constexpr u8 DEVICE_ID = 0x28;
diff --git a/src/core/hle/service/hid/hidbus/starlink.h b/src/hid_core/hidbus/starlink.h
index a276aa88f..ee37763b4 100644
--- a/src/core/hle/service/hid/hidbus/starlink.h
+++ b/src/hid_core/hidbus/starlink.h
@@ -4,7 +4,7 @@
#pragma once
#include "common/common_types.h"
-#include "core/hle/service/hid/hidbus/hidbus_base.h"
+#include "hid_core/hidbus/hidbus_base.h"
namespace Core::HID {
class EmulatedController;
diff --git a/src/core/hle/service/hid/hidbus/stubbed.cpp b/src/hid_core/hidbus/stubbed.cpp
index 8160b7218..f16051aa9 100644
--- a/src/core/hle/service/hid/hidbus/stubbed.cpp
+++ b/src/hid_core/hidbus/stubbed.cpp
@@ -1,9 +1,9 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/hidbus/stubbed.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hidbus/stubbed.h"
namespace Service::HID {
constexpr u8 DEVICE_ID = 0xFF;
diff --git a/src/core/hle/service/hid/hidbus/stubbed.h b/src/hid_core/hidbus/stubbed.h
index 2e58d42fc..7a711cea0 100644
--- a/src/core/hle/service/hid/hidbus/stubbed.h
+++ b/src/hid_core/hidbus/stubbed.h
@@ -4,7 +4,7 @@
#pragma once
#include "common/common_types.h"
-#include "core/hle/service/hid/hidbus/hidbus_base.h"
+#include "hid_core/hidbus/hidbus_base.h"
namespace Core::HID {
class EmulatedController;
diff --git a/src/core/hle/service/hid/irsensor/clustering_processor.cpp b/src/hid_core/irsensor/clustering_processor.cpp
index c559eb0d5..3abe19365 100644
--- a/src/core/hle/service/hid/irsensor/clustering_processor.cpp
+++ b/src/hid_core/irsensor/clustering_processor.cpp
@@ -5,9 +5,9 @@
#include "core/core.h"
#include "core/core_timing.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/irsensor/clustering_processor.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/irsensor/clustering_processor.h"
namespace Service::IRS {
ClusteringProcessor::ClusteringProcessor(Core::System& system_,
diff --git a/src/core/hle/service/hid/irsensor/clustering_processor.h b/src/hid_core/irsensor/clustering_processor.h
index 83f34734a..e3b60d9b0 100644
--- a/src/core/hle/service/hid/irsensor/clustering_processor.h
+++ b/src/hid_core/irsensor/clustering_processor.h
@@ -4,9 +4,9 @@
#pragma once
#include "common/common_types.h"
-#include "core/hid/irs_types.h"
-#include "core/hle/service/hid/irs_ring_lifo.h"
-#include "core/hle/service/hid/irsensor/processor_base.h"
+#include "hid_core/irsensor/irs_types.h"
+#include "hid_core/irsensor/processor_base.h"
+#include "hid_core/resources/irs_ring_lifo.h"
namespace Core {
class System;
diff --git a/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp b/src/hid_core/irsensor/image_transfer_processor.cpp
index 22067a591..d6573f8dc 100644
--- a/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp
+++ b/src/hid_core/irsensor/image_transfer_processor.cpp
@@ -2,10 +2,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/irsensor/image_transfer_processor.h"
#include "core/memory.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/irsensor/image_transfer_processor.h"
namespace Service::IRS {
ImageTransferProcessor::ImageTransferProcessor(Core::System& system_,
diff --git a/src/core/hle/service/hid/irsensor/image_transfer_processor.h b/src/hid_core/irsensor/image_transfer_processor.h
index 7f42d8453..4e0117084 100644
--- a/src/core/hle/service/hid/irsensor/image_transfer_processor.h
+++ b/src/hid_core/irsensor/image_transfer_processor.h
@@ -4,8 +4,8 @@
#pragma once
#include "common/typed_address.h"
-#include "core/hid/irs_types.h"
-#include "core/hle/service/hid/irsensor/processor_base.h"
+#include "hid_core/irsensor/irs_types.h"
+#include "hid_core/irsensor/processor_base.h"
namespace Core {
class System;
diff --git a/src/core/hle/service/hid/irsensor/ir_led_processor.cpp b/src/hid_core/irsensor/ir_led_processor.cpp
index 8e6dd99e4..4b04e05b5 100644
--- a/src/core/hle/service/hid/irsensor/ir_led_processor.cpp
+++ b/src/hid_core/irsensor/ir_led_processor.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "core/hle/service/hid/irsensor/ir_led_processor.h"
+#include "hid_core/irsensor/ir_led_processor.h"
namespace Service::IRS {
IrLedProcessor::IrLedProcessor(Core::IrSensor::DeviceFormat& device_format)
diff --git a/src/core/hle/service/hid/irsensor/ir_led_processor.h b/src/hid_core/irsensor/ir_led_processor.h
index c3d8693c9..03d0c4245 100644
--- a/src/core/hle/service/hid/irsensor/ir_led_processor.h
+++ b/src/hid_core/irsensor/ir_led_processor.h
@@ -5,8 +5,8 @@
#include "common/bit_field.h"
#include "common/common_types.h"
-#include "core/hid/irs_types.h"
-#include "core/hle/service/hid/irsensor/processor_base.h"
+#include "hid_core/irsensor/irs_types.h"
+#include "hid_core/irsensor/processor_base.h"
namespace Service::IRS {
class IrLedProcessor final : public ProcessorBase {
diff --git a/src/core/hid/irs_types.h b/src/hid_core/irsensor/irs_types.h
index 0d1bfe53f..017f38e6c 100644
--- a/src/core/hid/irs_types.h
+++ b/src/hid_core/irsensor/irs_types.h
@@ -5,7 +5,7 @@
#include "common/common_funcs.h"
#include "common/common_types.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
namespace Core::IrSensor {
diff --git a/src/core/hle/service/hid/irsensor/moment_processor.cpp b/src/hid_core/irsensor/moment_processor.cpp
index cf045bda7..0284a58bd 100644
--- a/src/core/hle/service/hid/irsensor/moment_processor.cpp
+++ b/src/hid_core/irsensor/moment_processor.cpp
@@ -3,9 +3,9 @@
#include "core/core.h"
#include "core/core_timing.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/irsensor/moment_processor.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/irsensor/moment_processor.h"
namespace Service::IRS {
static constexpr auto format = Core::IrSensor::ImageTransferProcessorFormat::Size40x30;
diff --git a/src/core/hle/service/hid/irsensor/moment_processor.h b/src/hid_core/irsensor/moment_processor.h
index 398cfbdc1..78c9c035f 100644
--- a/src/core/hle/service/hid/irsensor/moment_processor.h
+++ b/src/hid_core/irsensor/moment_processor.h
@@ -5,9 +5,9 @@
#include "common/bit_field.h"
#include "common/common_types.h"
-#include "core/hid/irs_types.h"
-#include "core/hle/service/hid/irs_ring_lifo.h"
-#include "core/hle/service/hid/irsensor/processor_base.h"
+#include "hid_core/irsensor/irs_types.h"
+#include "hid_core/irsensor/processor_base.h"
+#include "hid_core/resources/irs_ring_lifo.h"
namespace Core {
class System;
diff --git a/src/core/hle/service/hid/irsensor/pointing_processor.cpp b/src/hid_core/irsensor/pointing_processor.cpp
index 929f177fc..c1d6c1bb6 100644
--- a/src/core/hle/service/hid/irsensor/pointing_processor.cpp
+++ b/src/hid_core/irsensor/pointing_processor.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "core/hle/service/hid/irsensor/pointing_processor.h"
+#include "hid_core/irsensor/pointing_processor.h"
namespace Service::IRS {
PointingProcessor::PointingProcessor(Core::IrSensor::DeviceFormat& device_format)
diff --git a/src/core/hle/service/hid/irsensor/pointing_processor.h b/src/hid_core/irsensor/pointing_processor.h
index d63423aff..968c2e5bd 100644
--- a/src/core/hle/service/hid/irsensor/pointing_processor.h
+++ b/src/hid_core/irsensor/pointing_processor.h
@@ -4,8 +4,8 @@
#pragma once
#include "common/common_types.h"
-#include "core/hid/irs_types.h"
-#include "core/hle/service/hid/irsensor/processor_base.h"
+#include "hid_core/irsensor/irs_types.h"
+#include "hid_core/irsensor/processor_base.h"
namespace Service::IRS {
class PointingProcessor final : public ProcessorBase {
diff --git a/src/core/hle/service/hid/irsensor/processor_base.cpp b/src/hid_core/irsensor/processor_base.cpp
index 4d43ca17a..91a513a70 100644
--- a/src/core/hle/service/hid/irsensor/processor_base.cpp
+++ b/src/hid_core/irsensor/processor_base.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "core/hle/service/hid/irsensor/processor_base.h"
+#include "hid_core/irsensor/processor_base.h"
namespace Service::IRS {
diff --git a/src/core/hle/service/hid/irsensor/processor_base.h b/src/hid_core/irsensor/processor_base.h
index bc0d2977b..48beeafba 100644
--- a/src/core/hle/service/hid/irsensor/processor_base.h
+++ b/src/hid_core/irsensor/processor_base.h
@@ -4,7 +4,7 @@
#pragma once
#include "common/common_types.h"
-#include "core/hid/irs_types.h"
+#include "hid_core/irsensor/irs_types.h"
namespace Service::IRS {
class ProcessorBase {
diff --git a/src/core/hle/service/hid/irsensor/tera_plugin_processor.cpp b/src/hid_core/irsensor/tera_plugin_processor.cpp
index e691c840a..2382e208a 100644
--- a/src/core/hle/service/hid/irsensor/tera_plugin_processor.cpp
+++ b/src/hid_core/irsensor/tera_plugin_processor.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "core/hle/service/hid/irsensor/tera_plugin_processor.h"
+#include "hid_core/irsensor/tera_plugin_processor.h"
namespace Service::IRS {
TeraPluginProcessor::TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format)
diff --git a/src/core/hle/service/hid/irsensor/tera_plugin_processor.h b/src/hid_core/irsensor/tera_plugin_processor.h
index bbea7ed0b..dc8fe7d07 100644
--- a/src/core/hle/service/hid/irsensor/tera_plugin_processor.h
+++ b/src/hid_core/irsensor/tera_plugin_processor.h
@@ -5,8 +5,8 @@
#include "common/bit_field.h"
#include "common/common_types.h"
-#include "core/hid/irs_types.h"
-#include "core/hle/service/hid/irsensor/processor_base.h"
+#include "hid_core/irsensor/irs_types.h"
+#include "hid_core/irsensor/processor_base.h"
namespace Service::IRS {
class TeraPluginProcessor final : public ProcessorBase {
diff --git a/src/hid_core/precompiled_headers.h b/src/hid_core/precompiled_headers.h
new file mode 100644
index 000000000..aabae730b
--- /dev/null
+++ b/src/hid_core/precompiled_headers.h
@@ -0,0 +1,6 @@
+// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "common/common_precompiled_headers.h"
diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/hid_core/resource_manager.cpp
index 84b4be3ed..2c5fe6d51 100644
--- a/src/core/hle/service/hid/resource_manager.cpp
+++ b/src/hid_core/resource_manager.cpp
@@ -4,29 +4,29 @@
#include "common/logging/log.h"
#include "core/core.h"
#include "core/core_timing.h"
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_shared_memory.h"
-#include "core/hle/service/hid/resource_manager.h"
#include "core/hle/service/ipc_helpers.h"
-
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/capture_button.h"
-#include "core/hle/service/hid/controllers/console_six_axis.h"
-#include "core/hle/service/hid/controllers/debug_mouse.h"
-#include "core/hle/service/hid/controllers/debug_pad.h"
-#include "core/hle/service/hid/controllers/digitizer.h"
-#include "core/hle/service/hid/controllers/gesture.h"
-#include "core/hle/service/hid/controllers/home_button.h"
-#include "core/hle/service/hid/controllers/keyboard.h"
-#include "core/hle/service/hid/controllers/mouse.h"
-#include "core/hle/service/hid/controllers/npad.h"
-#include "core/hle/service/hid/controllers/palma.h"
-#include "core/hle/service/hid/controllers/seven_six_axis.h"
-#include "core/hle/service/hid/controllers/six_axis.h"
-#include "core/hle/service/hid/controllers/sleep_button.h"
-#include "core/hle/service/hid/controllers/touchscreen.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
-#include "core/hle/service/hid/controllers/unique_pad.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resource_manager.h"
+
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/debug_pad/debug_pad.h"
+#include "hid_core/resources/digitizer/digitizer.h"
+#include "hid_core/resources/keyboard/keyboard.h"
+#include "hid_core/resources/mouse/debug_mouse.h"
+#include "hid_core/resources/mouse/mouse.h"
+#include "hid_core/resources/npad/npad.h"
+#include "hid_core/resources/palma/palma.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/six_axis/console_six_axis.h"
+#include "hid_core/resources/six_axis/seven_six_axis.h"
+#include "hid_core/resources/six_axis/six_axis.h"
+#include "hid_core/resources/system_buttons/capture_button.h"
+#include "hid_core/resources/system_buttons/home_button.h"
+#include "hid_core/resources/system_buttons/sleep_button.h"
+#include "hid_core/resources/touch_screen/gesture.h"
+#include "hid_core/resources/touch_screen/touch_screen.h"
+#include "hid_core/resources/unique_pad/unique_pad.h"
namespace Service::HID {
@@ -129,12 +129,12 @@ std::shared_ptr<UniquePad> ResourceManager::GetUniquePad() const {
}
Result ResourceManager::CreateAppletResource(u64 aruid) {
- if (aruid == 0) {
+ if (aruid == SystemAruid) {
const auto result = RegisterCoreAppletResource();
if (result.IsError()) {
return result;
}
- return GetNpad()->Activate();
+ return GetNpad()->ActivateNpadResource();
}
const auto result = CreateAppletResourceImpl(aruid);
@@ -147,7 +147,7 @@ Result ResourceManager::CreateAppletResource(u64 aruid) {
six_axis->Activate();
touch_screen->Activate();
- return GetNpad()->Activate(aruid);
+ return GetNpad()->ActivateNpadResource(aruid);
}
Result ResourceManager::CreateAppletResourceImpl(u64 aruid) {
@@ -171,31 +171,31 @@ void ResourceManager::InitializeHidCommonSampler() {
palma = std::make_shared<Palma>(system.HIDCore(), service_context);
six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad);
- debug_pad->SetAppletResource(applet_resource);
- digitizer->SetAppletResource(applet_resource);
- keyboard->SetAppletResource(applet_resource);
- npad->SetAppletResource(applet_resource);
- six_axis->SetAppletResource(applet_resource);
- mouse->SetAppletResource(applet_resource);
- debug_mouse->SetAppletResource(applet_resource);
- home_button->SetAppletResource(applet_resource);
- sleep_button->SetAppletResource(applet_resource);
- capture_button->SetAppletResource(applet_resource);
+ debug_pad->SetAppletResource(applet_resource, &shared_mutex);
+ digitizer->SetAppletResource(applet_resource, &shared_mutex);
+ keyboard->SetAppletResource(applet_resource, &shared_mutex);
+ npad->SetNpadExternals(applet_resource, &shared_mutex);
+ six_axis->SetAppletResource(applet_resource, &shared_mutex);
+ mouse->SetAppletResource(applet_resource, &shared_mutex);
+ debug_mouse->SetAppletResource(applet_resource, &shared_mutex);
+ home_button->SetAppletResource(applet_resource, &shared_mutex);
+ sleep_button->SetAppletResource(applet_resource, &shared_mutex);
+ capture_button->SetAppletResource(applet_resource, &shared_mutex);
}
void ResourceManager::InitializeTouchScreenSampler() {
gesture = std::make_shared<Gesture>(system.HIDCore());
touch_screen = std::make_shared<TouchScreen>(system.HIDCore());
- touch_screen->SetAppletResource(applet_resource);
- gesture->SetAppletResource(applet_resource);
+ touch_screen->SetAppletResource(applet_resource, &shared_mutex);
+ gesture->SetAppletResource(applet_resource, &shared_mutex);
}
void ResourceManager::InitializeConsoleSixAxisSampler() {
console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore());
seven_six_axis = std::make_shared<SevenSixAxis>(system);
- console_six_axis->SetAppletResource(applet_resource);
+ console_six_axis->SetAppletResource(applet_resource, &shared_mutex);
}
void ResourceManager::InitializeAHidSampler() {
@@ -214,12 +214,17 @@ Result ResourceManager::UnregisterCoreAppletResource() {
Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) {
std::scoped_lock lock{shared_mutex};
- return applet_resource->RegisterAppletResourceUserId(aruid, bool_value);
+ auto result = applet_resource->RegisterAppletResourceUserId(aruid, bool_value);
+ if (result.IsSuccess()) {
+ result = npad->RegisterAppletResourceUserId(aruid);
+ }
+ return result;
}
void ResourceManager::UnregisterAppletResourceUserId(u64 aruid) {
std::scoped_lock lock{shared_mutex};
applet_resource->UnregisterAppletResourceUserId(aruid);
+ npad->UnregisterAppletResourceUserId(aruid);
}
Result ResourceManager::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
diff --git a/src/core/hle/service/hid/resource_manager.h b/src/hid_core/resource_manager.h
index 70d9b6550..7a21d8eb8 100644
--- a/src/core/hle/service/hid/resource_manager.h
+++ b/src/hid_core/resource_manager.h
@@ -93,7 +93,7 @@ private:
bool is_initialized{false};
- mutable std::mutex shared_mutex;
+ mutable std::recursive_mutex shared_mutex;
std::shared_ptr<AppletResource> applet_resource = nullptr;
std::shared_ptr<CaptureButton> capture_button = nullptr;
diff --git a/src/core/hle/service/hid/controllers/applet_resource.cpp b/src/hid_core/resources/applet_resource.cpp
index b4ff663c2..d09a525c6 100644
--- a/src/core/hle/service/hid/controllers/applet_resource.cpp
+++ b/src/hid_core/resources/applet_resource.cpp
@@ -3,9 +3,9 @@
#include "core/core.h"
#include "core/hle/kernel/k_shared_memory.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
-#include "core/hle/service/hid/errors.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
@@ -87,7 +87,9 @@ Result AppletResource::RegisterAppletResourceUserId(u64 aruid, bool enable_input
data_index = i;
break;
}
- if (registration_list.flag[i] == RegistrationStatus::None) {
+ // TODO: Don't Handle pending delete here
+ if (registration_list.flag[i] == RegistrationStatus::None ||
+ registration_list.flag[i] == RegistrationStatus::PendingDelete) {
data_index = i;
break;
}
@@ -104,30 +106,22 @@ Result AppletResource::RegisterAppletResourceUserId(u64 aruid, bool enable_input
}
void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
- u64 index = GetIndexFromAruid(aruid);
+ const u64 index = GetIndexFromAruid(aruid);
- if (index < AruidIndexMax) {
- if (data[index].flag.is_assigned) {
- data[index].shared_memory_format = nullptr;
- data[index].flag.is_assigned.Assign(false);
- }
+ if (index >= AruidIndexMax) {
+ return;
}
- index = GetIndexFromAruid(aruid);
- if (index < AruidIndexMax) {
- DestroySevenSixAxisTransferMemory();
- data[index].flag.raw = 0;
- data[index].aruid = 0;
+ FreeAppletResourceId(aruid);
+ DestroySevenSixAxisTransferMemory();
+ data[index].flag.raw = 0;
+ data[index].aruid = 0;
- index = GetIndexFromAruid(aruid);
- if (index < AruidIndexMax) {
- registration_list.flag[index] = RegistrationStatus::PendingDelete;
- }
- }
+ registration_list.flag[index] = RegistrationStatus::PendingDelete;
}
void AppletResource::FreeAppletResourceId(u64 aruid) {
- u64 index = GetIndexFromAruid(aruid);
+ const u64 index = GetIndexFromAruid(aruid);
if (index >= AruidIndexMax) {
return;
}
@@ -144,7 +138,7 @@ u64 AppletResource::GetActiveAruid() {
}
Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
- u64 index = GetIndexFromAruid(aruid);
+ const u64 index = GetIndexFromAruid(aruid);
if (index >= AruidIndexMax) {
return ResultAruidNotRegistered;
}
@@ -155,7 +149,7 @@ Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle,
Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format,
u64 aruid) {
- u64 index = GetIndexFromAruid(aruid);
+ const u64 index = GetIndexFromAruid(aruid);
if (index >= AruidIndexMax) {
return ResultAruidNotRegistered;
}
diff --git a/src/core/hle/service/hid/controllers/applet_resource.h b/src/hid_core/resources/applet_resource.h
index 52cc4cf42..f3f32bac1 100644
--- a/src/core/hle/service/hid/controllers/applet_resource.h
+++ b/src/hid_core/resources/applet_resource.h
@@ -9,7 +9,7 @@
#include "common/bit_field.h"
#include "common/common_types.h"
#include "core/hle/result.h"
-#include "core/hle/service/hid/controllers/shared_memory_holder.h"
+#include "hid_core/resources/shared_memory_holder.h"
namespace Core {
class System;
@@ -25,6 +25,7 @@ class AppletResource;
class NPadResource;
static constexpr std::size_t AruidIndexMax = 0x20;
+static constexpr u64 SystemAruid = 0;
enum class RegistrationStatus : u32 {
None,
diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/hid_core/resources/controller_base.cpp
index 2083ccfad..df5f5c884 100644
--- a/src/core/hle/service/hid/controllers/controller_base.cpp
+++ b/src/hid_core/resources/controller_base.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/resources/controller_base.h"
namespace Service::HID {
@@ -32,8 +32,10 @@ bool ControllerBase::IsControllerActivated() const {
return is_activated;
}
-void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource) {
+void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource,
+ std::recursive_mutex* resource_mutex) {
applet_resource = resource;
+ shared_mutex = resource_mutex;
}
} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/hid_core/resources/controller_base.h
index 759ae0053..e61bc6376 100644
--- a/src/core/hle/service/hid/controllers/controller_base.h
+++ b/src/hid_core/resources/controller_base.h
@@ -7,7 +7,7 @@
#include "common/common_types.h"
#include "core/hle/result.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
+#include "hid_core/resources/applet_resource.h"
namespace Core::Timing {
class CoreTiming;
@@ -42,11 +42,13 @@ public:
bool IsControllerActivated() const;
- void SetAppletResource(std::shared_ptr<AppletResource> resource);
+ void SetAppletResource(std::shared_ptr<AppletResource> resource,
+ std::recursive_mutex* resource_mutex);
protected:
bool is_activated{false};
std::shared_ptr<AppletResource> applet_resource{nullptr};
+ std::recursive_mutex* shared_mutex{nullptr};
Core::HID::HIDCore& hid_core;
};
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/hid_core/resources/debug_pad/debug_pad.cpp
index 1811cf620..1102dad6c 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.cpp
+++ b/src/hid_core/resources/debug_pad/debug_pad.cpp
@@ -3,12 +3,12 @@
#include "common/settings.h"
#include "core/core_timing.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/debug_pad.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/debug_pad/debug_pad.h"
+#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
@@ -23,10 +23,11 @@ void DebugPad::OnInit() {}
void DebugPad::OnRelease() {}
void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/hid_core/resources/debug_pad/debug_pad.h
index dd00b2402..73c3d4421 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.h
+++ b/src/hid_core/resources/debug_pad/debug_pad.h
@@ -3,12 +3,13 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/controllers/types/debug_pad_types.h"
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/debug_pad/debug_pad_types.h"
namespace Core::HID {
class HIDCore;
-}
+class EmulatedController;
+} // namespace Core::HID
namespace Core::Timing {
class CoreTiming;
diff --git a/src/core/hle/service/hid/controllers/types/debug_pad_types.h b/src/hid_core/resources/debug_pad/debug_pad_types.h
index a96171b62..8b5eb108e 100644
--- a/src/core/hle/service/hid/controllers/types/debug_pad_types.h
+++ b/src/hid_core/resources/debug_pad/debug_pad_types.h
@@ -5,7 +5,7 @@
#include "common/bit_field.h"
#include "common/common_types.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/digitizer.cpp b/src/hid_core/resources/digitizer/digitizer.cpp
index c01580fd6..cd72fd6e5 100644
--- a/src/core/hle/service/hid/controllers/digitizer.cpp
+++ b/src/hid_core/resources/digitizer/digitizer.cpp
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/digitizer.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/digitizer/digitizer.h"
+#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
@@ -21,10 +21,11 @@ void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return;
}
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/digitizer.h b/src/hid_core/resources/digitizer/digitizer.h
index d81f814c3..e031a16b0 100644
--- a/src/core/hle/service/hid/controllers/digitizer.h
+++ b/src/hid_core/resources/digitizer/digitizer.h
@@ -3,7 +3,7 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/resources/controller_base.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/hid_firmware_settings.cpp b/src/hid_core/resources/hid_firmware_settings.cpp
index 59bd6825c..e76b3a016 100644
--- a/src/core/hle/service/hid/hid_firmware_settings.cpp
+++ b/src/hid_core/resources/hid_firmware_settings.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "core/hle/service/hid/hid_firmware_settings.h"
+#include "hid_core/resources/hid_firmware_settings.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/hid_firmware_settings.h b/src/hid_core/resources/hid_firmware_settings.h
index 6c10c440b..6c10c440b 100644
--- a/src/core/hle/service/hid/hid_firmware_settings.h
+++ b/src/hid_core/resources/hid_firmware_settings.h
diff --git a/src/core/hle/service/hid/irs_ring_lifo.h b/src/hid_core/resources/irs_ring_lifo.h
index 255d1d296..255d1d296 100644
--- a/src/core/hle/service/hid/irs_ring_lifo.h
+++ b/src/hid_core/resources/irs_ring_lifo.h
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/hid_core/resources/keyboard/keyboard.cpp
index c72b3e5ce..340e8a65c 100644
--- a/src/core/hle/service/hid/controllers/keyboard.cpp
+++ b/src/hid_core/resources/keyboard/keyboard.cpp
@@ -3,11 +3,11 @@
#include "common/settings.h"
#include "core/core_timing.h"
-#include "core/hid/emulated_devices.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/keyboard.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/frontend/emulated_devices.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/keyboard/keyboard.h"
+#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
@@ -22,10 +22,11 @@ void Keyboard::OnInit() {}
void Keyboard::OnRelease() {}
void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/hid_core/resources/keyboard/keyboard.h
index e8ca326c6..4bcc1c1b2 100644
--- a/src/core/hle/service/hid/controllers/keyboard.h
+++ b/src/hid_core/resources/keyboard/keyboard.h
@@ -3,8 +3,13 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/controllers/types/keyboard_types.h"
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/keyboard/keyboard_types.h"
+
+namespace Core::HID {
+class HIDCore;
+class EmulatedDevices;
+} // namespace Core::HID
namespace Service::HID {
class Keyboard final : public ControllerBase {
diff --git a/src/core/hle/service/hid/controllers/types/keyboard_types.h b/src/hid_core/resources/keyboard/keyboard_types.h
index f44a536b9..4d7ff2f0a 100644
--- a/src/core/hle/service/hid/controllers/types/keyboard_types.h
+++ b/src/hid_core/resources/keyboard/keyboard_types.h
@@ -4,7 +4,7 @@
#pragma once
#include "common/common_types.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/debug_mouse.cpp b/src/hid_core/resources/mouse/debug_mouse.cpp
index f2f1a27f8..5f6f6e8e1 100644
--- a/src/core/hle/service/hid/controllers/debug_mouse.cpp
+++ b/src/hid_core/resources/mouse/debug_mouse.cpp
@@ -3,11 +3,11 @@
#include "core/core_timing.h"
#include "core/frontend/emu_window.h"
-#include "core/hid/emulated_devices.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/debug_mouse.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/frontend/emulated_devices.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/mouse/debug_mouse.h"
+#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
@@ -21,10 +21,11 @@ void DebugMouse::OnInit() {}
void DebugMouse::OnRelease() {}
void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/debug_mouse.h b/src/hid_core/resources/mouse/debug_mouse.h
index ec939fa9f..006b53da6 100644
--- a/src/core/hle/service/hid/controllers/debug_mouse.h
+++ b/src/hid_core/resources/mouse/debug_mouse.h
@@ -3,12 +3,12 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/controller_base.h"
namespace Core::HID {
+class HIDCore;
class EmulatedDevices;
-struct MouseState;
-struct AnalogStickState;
} // namespace Core::HID
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/hid_core/resources/mouse/mouse.cpp
index 58deafbc5..53a8938a1 100644
--- a/src/core/hle/service/hid/controllers/mouse.cpp
+++ b/src/hid_core/resources/mouse/mouse.cpp
@@ -3,11 +3,11 @@
#include "core/core_timing.h"
#include "core/frontend/emu_window.h"
-#include "core/hid/emulated_devices.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/mouse.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/frontend/emulated_devices.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/mouse/mouse.h"
+#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
@@ -21,10 +21,11 @@ void Mouse::OnInit() {}
void Mouse::OnRelease() {}
void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/hid_core/resources/mouse/mouse.h
index cefad956c..e9ac6ad36 100644
--- a/src/core/hle/service/hid/controllers/mouse.h
+++ b/src/hid_core/resources/mouse/mouse.h
@@ -3,12 +3,12 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/controller_base.h"
namespace Core::HID {
+class HIDCore;
class EmulatedDevices;
-struct MouseState;
-struct AnalogStickState;
} // namespace Core::HID
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/types/mouse_types.h b/src/hid_core/resources/mouse/mouse_types.h
index 8bd6e167c..8bd6e167c 100644
--- a/src/core/hle/service/hid/controllers/types/mouse_types.h
+++ b/src/hid_core/resources/mouse/mouse_types.h
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/hid_core/resources/npad/npad.cpp
index c7aa606bc..e6c035628 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/hid_core/resources/npad/npad.cpp
@@ -12,49 +12,106 @@
#include "common/logging/log.h"
#include "common/settings.h"
#include "core/core_timing.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/npad.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
-#include "core/hle/service/hid/errors.h"
-#include "core/hle/service/hid/hid_util.h"
#include "core/hle/service/kernel_helpers.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/hid_util.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/npad/npad.h"
+#include "hid_core/resources/shared_memory_format.h"
namespace Service::HID {
-constexpr std::array<Core::HID::NpadIdType, 10> npad_id_list{
- Core::HID::NpadIdType::Player1, Core::HID::NpadIdType::Player2, Core::HID::NpadIdType::Player3,
- Core::HID::NpadIdType::Player4, Core::HID::NpadIdType::Player5, Core::HID::NpadIdType::Player6,
- Core::HID::NpadIdType::Player7, Core::HID::NpadIdType::Player8, Core::HID::NpadIdType::Other,
- Core::HID::NpadIdType::Handheld,
-};
NPad::NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_)
- : ControllerBase{hid_core_}, service_context{service_context_} {
- for (std::size_t i = 0; i < controller_data.size(); ++i) {
- auto& controller = controller_data[i];
- controller.device = hid_core.GetEmulatedControllerByIndex(i);
- controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value =
- Core::HID::DEFAULT_VIBRATION_VALUE;
- controller.vibration[Core::HID::EmulatedDeviceIndex::RightIndex].latest_vibration_value =
- Core::HID::DEFAULT_VIBRATION_VALUE;
- Core::HID::ControllerUpdateCallback engine_callback{
- .on_change = [this,
- i](Core::HID::ControllerTriggerType type) { ControllerUpdate(type, i); },
- .is_npad_service = true,
- };
- controller.callback_key = controller.device->SetCallback(engine_callback);
+ : hid_core{hid_core_}, service_context{service_context_}, npad_resource{service_context} {
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; ++aruid_index) {
+ for (std::size_t i = 0; i < controller_data[aruid_index].size(); ++i) {
+ auto& controller = controller_data[aruid_index][i];
+ controller.device = hid_core.GetEmulatedControllerByIndex(i);
+ controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value =
+ Core::HID::DEFAULT_VIBRATION_VALUE;
+ controller.vibration[Core::HID::EmulatedDeviceIndex::RightIndex]
+ .latest_vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE;
+ Core::HID::ControllerUpdateCallback engine_callback{
+ .on_change =
+ [this, i](Core::HID::ControllerTriggerType type) { ControllerUpdate(type, i); },
+ .is_npad_service = true,
+ };
+ controller.callback_key = controller.device->SetCallback(engine_callback);
+ }
}
}
NPad::~NPad() {
- for (std::size_t i = 0; i < controller_data.size(); ++i) {
- auto& controller = controller_data[i];
- controller.device->DeleteCallback(controller.callback_key);
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; ++aruid_index) {
+ for (std::size_t i = 0; i < controller_data[aruid_index].size(); ++i) {
+ auto& controller = controller_data[aruid_index][i];
+ controller.device->DeleteCallback(controller.callback_key);
+ }
+ }
+}
+
+Result NPad::Activate() {
+ if (ref_counter == std::numeric_limits<s32>::max() - 1) {
+ return ResultNpadResourceOverflow;
+ }
+
+ if (ref_counter == 0) {
+ std::scoped_lock lock{mutex};
+
+ // TODO: Activate handlers and AbstractedPad
+ }
+
+ ref_counter++;
+ return ResultSuccess;
+}
+
+Result NPad::Activate(u64 aruid) {
+ std::scoped_lock lock{mutex};
+ std::scoped_lock shared_lock{*applet_resource_holder.shared_mutex};
+
+ auto* data = applet_resource_holder.applet_resource->GetAruidData(aruid);
+ const auto aruid_index = applet_resource_holder.applet_resource->GetIndexFromAruid(aruid);
+
+ if (data == nullptr || !data->flag.is_assigned) {
+ return ResultSuccess;
+ }
+
+ for (std::size_t i = 0; i < controller_data[aruid_index].size(); ++i) {
+ auto& controller = controller_data[aruid_index][i];
+ controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
+ }
+
+ // Prefill controller buffers
+ for (auto& controller : controller_data[aruid_index]) {
+ auto* npad = controller.shared_memory;
+ npad->fullkey_color = {
+ .attribute = ColorAttribute::NoController,
+ .fullkey = {},
+ };
+ npad->joycon_color = {
+ .attribute = ColorAttribute::NoController,
+ .left = {},
+ .right = {},
+ };
+ // HW seems to initialize the first 19 entries
+ for (std::size_t i = 0; i < 19; ++i) {
+ WriteEmptyEntry(npad);
+ }
}
- OnRelease();
+
+ return ResultSuccess;
+}
+
+Result NPad::ActivateNpadResource() {
+ return npad_resource.Activate();
+}
+
+Result NPad::ActivateNpadResource(u64 aruid) {
+ return npad_resource.Activate(aruid);
}
void NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx) {
@@ -63,41 +120,50 @@ void NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t c
ControllerUpdate(Core::HID::ControllerTriggerType::Battery, controller_idx);
return;
}
- if (controller_idx >= controller_data.size()) {
- return;
- }
- auto& controller = controller_data[controller_idx];
- const auto is_connected = controller.device->IsConnected();
- const auto npad_type = controller.device->GetNpadStyleIndex();
- const auto npad_id = controller.device->GetNpadIdType();
- switch (type) {
- case Core::HID::ControllerTriggerType::Connected:
- case Core::HID::ControllerTriggerType::Disconnected:
- if (is_connected == controller.is_connected) {
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
+ if (controller_idx >= controller_data[aruid_index].size()) {
return;
}
- UpdateControllerAt(npad_type, npad_id, is_connected);
- break;
- case Core::HID::ControllerTriggerType::Battery: {
- if (!controller.device->IsConnected()) {
- return;
+
+ auto* data = applet_resource_holder.applet_resource->GetAruidDataByIndex(aruid_index);
+
+ if (!data->flag.is_assigned) {
+ continue;
+ }
+
+ auto& controller = controller_data[aruid_index][controller_idx];
+ const auto is_connected = controller.device->IsConnected();
+ const auto npad_type = controller.device->GetNpadStyleIndex();
+ const auto npad_id = controller.device->GetNpadIdType();
+ switch (type) {
+ case Core::HID::ControllerTriggerType::Connected:
+ case Core::HID::ControllerTriggerType::Disconnected:
+ if (is_connected == controller.is_connected) {
+ return;
+ }
+ UpdateControllerAt(data->aruid, npad_type, npad_id, is_connected);
+ break;
+ case Core::HID::ControllerTriggerType::Battery: {
+ if (!controller.device->IsConnected()) {
+ return;
+ }
+ auto* shared_memory = controller.shared_memory;
+ const auto& battery_level = controller.device->GetBattery();
+ shared_memory->battery_level_dual = battery_level.dual.battery_level;
+ shared_memory->battery_level_left = battery_level.left.battery_level;
+ shared_memory->battery_level_right = battery_level.right.battery_level;
+ break;
+ }
+ default:
+ break;
}
- auto* shared_memory = controller.shared_memory;
- const auto& battery_level = controller.device->GetBattery();
- shared_memory->battery_level_dual = battery_level.dual.battery_level;
- shared_memory->battery_level_left = battery_level.left.battery_level;
- shared_memory->battery_level_right = battery_level.right.battery_level;
- break;
- }
- default:
- break;
}
}
-void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
- auto& controller = GetControllerFromNpadIdType(npad_id);
- if (!IsControllerSupported(controller.device->GetNpadStyleIndex())) {
+void NPad::InitNewlyAddedController(u64 aruid, Core::HID::NpadIdType npad_id) {
+ auto& controller = GetControllerFromNpadIdType(aruid, npad_id);
+ if (!npad_resource.IsControllerSupported(aruid, controller.device->GetNpadStyleIndex())) {
return;
}
LOG_DEBUG(Service_HID, "Npad connected {}", npad_id);
@@ -106,7 +172,7 @@ void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
const auto& battery_level = controller.device->GetBattery();
auto* shared_memory = controller.shared_memory;
if (controller_type == Core::HID::NpadStyleIndex::None) {
- controller.styleset_changed_event->Signal();
+ npad_resource.SignalStyleSetUpdateEvent(aruid, npad_id);
return;
}
@@ -290,53 +356,11 @@ void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
Common::Input::PollingMode::Active);
}
- SignalStyleSetChangedEvent(npad_id);
+ npad_resource.SignalStyleSetUpdateEvent(aruid, npad_id);
WriteEmptyEntry(controller.shared_memory);
hid_core.SetLastActiveController(npad_id);
}
-void NPad::OnInit() {
- const u64 aruid = applet_resource->GetActiveAruid();
- auto* data = applet_resource->GetAruidData(aruid);
-
- if (data == nullptr) {
- return;
- }
-
- if (!IsControllerActivated()) {
- return;
- }
-
- for (std::size_t i = 0; i < controller_data.size(); ++i) {
- auto& controller = controller_data[i];
- controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
- controller.styleset_changed_event =
- service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i));
- }
-
- supported_npad_id_types.resize(npad_id_list.size());
- std::memcpy(supported_npad_id_types.data(), npad_id_list.data(),
- npad_id_list.size() * sizeof(Core::HID::NpadIdType));
-
- // Prefill controller buffers
- for (auto& controller : controller_data) {
- auto* npad = controller.shared_memory;
- npad->fullkey_color = {
- .attribute = ColorAttribute::NoController,
- .fullkey = {},
- };
- npad->joycon_color = {
- .attribute = ColorAttribute::NoController,
- .left = {},
- .right = {},
- };
- // HW seems to initialize the first 19 entries
- for (std::size_t i = 0; i < 19; ++i) {
- WriteEmptyEntry(npad);
- }
- }
-}
-
void NPad::WriteEmptyEntry(NpadInternalState* npad) {
NPadGenericState dummy_pad_state{};
NpadGcTriggerState dummy_gc_state{};
@@ -358,33 +382,20 @@ void NPad::WriteEmptyEntry(NpadInternalState* npad) {
npad->gc_trigger_lifo.WriteNextEntry(dummy_gc_state);
}
-void NPad::OnRelease() {
- is_controller_initialized = false;
- for (std::size_t i = 0; i < controller_data.size(); ++i) {
- auto& controller = controller_data[i];
- if (controller.styleset_changed_event) {
- service_context.CloseEvent(controller.styleset_changed_event);
- }
- for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) {
- VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_idx, {});
- }
- }
-}
-
-void NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) {
- std::scoped_lock lock{mutex};
- auto& controller = GetControllerFromNpadIdType(npad_id);
+void NPad::RequestPadStateUpdate(u64 aruid, Core::HID::NpadIdType npad_id) {
+ std::scoped_lock lock{*applet_resource_holder.shared_mutex};
+ auto& controller = GetControllerFromNpadIdType(aruid, npad_id);
const auto controller_type = controller.device->GetNpadStyleIndex();
if (!controller.device->IsConnected() && controller.is_connected) {
- DisconnectNpad(npad_id);
+ DisconnectNpad(aruid, npad_id);
return;
}
if (!controller.device->IsConnected()) {
return;
}
if (controller.device->IsConnected() && !controller.is_connected) {
- InitNewlyAddedController(npad_id);
+ InitNewlyAddedController(aruid, npad_id);
}
// This function is unique to yuzu for the turbo buttons and motion to work properly
@@ -441,230 +452,232 @@ void NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) {
}
void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
- const u64 aruid = applet_resource->GetActiveAruid();
- auto* data = applet_resource->GetAruidData(aruid);
-
- if (data == nullptr) {
- return;
- }
-
- if (!IsControllerActivated()) {
+ if (ref_counter == 0) {
return;
}
- for (std::size_t i = 0; i < controller_data.size(); ++i) {
- auto& controller = controller_data[i];
- controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
- auto* npad = controller.shared_memory;
+ std::scoped_lock lock{*applet_resource_holder.shared_mutex};
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; ++aruid_index) {
+ const auto* data = applet_resource_holder.applet_resource->GetAruidDataByIndex(aruid_index);
+ const auto aruid = data->aruid;
- const auto& controller_type = controller.device->GetNpadStyleIndex();
-
- if (controller_type == Core::HID::NpadStyleIndex::None ||
- !controller.device->IsConnected()) {
+ if (!data->flag.is_assigned) {
continue;
}
- RequestPadStateUpdate(controller.device->GetNpadIdType());
- auto& pad_state = controller.npad_pad_state;
- auto& libnx_state = controller.npad_libnx_state;
- auto& trigger_state = controller.npad_trigger_state;
-
- // LibNX exclusively uses this section, so we always update it since LibNX doesn't activate
- // any controllers.
- libnx_state.connection_status.raw = 0;
- libnx_state.connection_status.is_connected.Assign(1);
- switch (controller_type) {
- case Core::HID::NpadStyleIndex::None:
- ASSERT(false);
- break;
- case Core::HID::NpadStyleIndex::ProController:
- case Core::HID::NpadStyleIndex::NES:
- case Core::HID::NpadStyleIndex::SNES:
- case Core::HID::NpadStyleIndex::N64:
- case Core::HID::NpadStyleIndex::SegaGenesis:
- pad_state.connection_status.raw = 0;
- pad_state.connection_status.is_connected.Assign(1);
- pad_state.connection_status.is_wired.Assign(1);
-
- libnx_state.connection_status.is_wired.Assign(1);
- pad_state.sampling_number =
- npad->fullkey_lifo.ReadCurrentEntry().state.sampling_number + 1;
- npad->fullkey_lifo.WriteNextEntry(pad_state);
- break;
- case Core::HID::NpadStyleIndex::Handheld:
- pad_state.connection_status.raw = 0;
- pad_state.connection_status.is_connected.Assign(1);
- pad_state.connection_status.is_wired.Assign(1);
- pad_state.connection_status.is_left_connected.Assign(1);
- pad_state.connection_status.is_right_connected.Assign(1);
- pad_state.connection_status.is_left_wired.Assign(1);
- pad_state.connection_status.is_right_wired.Assign(1);
-
- libnx_state.connection_status.is_wired.Assign(1);
- libnx_state.connection_status.is_left_connected.Assign(1);
- libnx_state.connection_status.is_right_connected.Assign(1);
- libnx_state.connection_status.is_left_wired.Assign(1);
- libnx_state.connection_status.is_right_wired.Assign(1);
- pad_state.sampling_number =
- npad->handheld_lifo.ReadCurrentEntry().state.sampling_number + 1;
- npad->handheld_lifo.WriteNextEntry(pad_state);
- break;
- case Core::HID::NpadStyleIndex::JoyconDual:
- pad_state.connection_status.raw = 0;
- pad_state.connection_status.is_connected.Assign(1);
- if (controller.is_dual_left_connected) {
+ for (std::size_t i = 0; i < controller_data[aruid_index].size(); ++i) {
+ auto& controller = controller_data[aruid_index][i];
+ controller.shared_memory =
+ &data->shared_memory_format->npad.npad_entry[i].internal_state;
+ auto* npad = controller.shared_memory;
+
+ const auto& controller_type = controller.device->GetNpadStyleIndex();
+
+ if (controller_type == Core::HID::NpadStyleIndex::None ||
+ !controller.device->IsConnected()) {
+ continue;
+ }
+
+ RequestPadStateUpdate(aruid, controller.device->GetNpadIdType());
+ auto& pad_state = controller.npad_pad_state;
+ auto& libnx_state = controller.npad_libnx_state;
+ auto& trigger_state = controller.npad_trigger_state;
+
+ // LibNX exclusively uses this section, so we always update it since LibNX doesn't
+ // activate any controllers.
+ libnx_state.connection_status.raw = 0;
+ libnx_state.connection_status.is_connected.Assign(1);
+ switch (controller_type) {
+ case Core::HID::NpadStyleIndex::None:
+ ASSERT(false);
+ break;
+ case Core::HID::NpadStyleIndex::ProController:
+ case Core::HID::NpadStyleIndex::NES:
+ case Core::HID::NpadStyleIndex::SNES:
+ case Core::HID::NpadStyleIndex::N64:
+ case Core::HID::NpadStyleIndex::SegaGenesis:
+ pad_state.connection_status.raw = 0;
+ pad_state.connection_status.is_connected.Assign(1);
+ pad_state.connection_status.is_wired.Assign(1);
+
+ libnx_state.connection_status.is_wired.Assign(1);
+ pad_state.sampling_number =
+ npad->fullkey_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ npad->fullkey_lifo.WriteNextEntry(pad_state);
+ break;
+ case Core::HID::NpadStyleIndex::Handheld:
+ pad_state.connection_status.raw = 0;
+ pad_state.connection_status.is_connected.Assign(1);
+ pad_state.connection_status.is_wired.Assign(1);
pad_state.connection_status.is_left_connected.Assign(1);
+ pad_state.connection_status.is_right_connected.Assign(1);
+ pad_state.connection_status.is_left_wired.Assign(1);
+ pad_state.connection_status.is_right_wired.Assign(1);
+
+ libnx_state.connection_status.is_wired.Assign(1);
libnx_state.connection_status.is_left_connected.Assign(1);
- }
- if (controller.is_dual_right_connected) {
+ libnx_state.connection_status.is_right_connected.Assign(1);
+ libnx_state.connection_status.is_left_wired.Assign(1);
+ libnx_state.connection_status.is_right_wired.Assign(1);
+ pad_state.sampling_number =
+ npad->handheld_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ npad->handheld_lifo.WriteNextEntry(pad_state);
+ break;
+ case Core::HID::NpadStyleIndex::JoyconDual:
+ pad_state.connection_status.raw = 0;
+ pad_state.connection_status.is_connected.Assign(1);
+ if (controller.is_dual_left_connected) {
+ pad_state.connection_status.is_left_connected.Assign(1);
+ libnx_state.connection_status.is_left_connected.Assign(1);
+ }
+ if (controller.is_dual_right_connected) {
+ pad_state.connection_status.is_right_connected.Assign(1);
+ libnx_state.connection_status.is_right_connected.Assign(1);
+ }
+
+ pad_state.sampling_number =
+ npad->joy_dual_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ npad->joy_dual_lifo.WriteNextEntry(pad_state);
+ break;
+ case Core::HID::NpadStyleIndex::JoyconLeft:
+ pad_state.connection_status.raw = 0;
+ pad_state.connection_status.is_connected.Assign(1);
+ pad_state.connection_status.is_left_connected.Assign(1);
+
+ libnx_state.connection_status.is_left_connected.Assign(1);
+ pad_state.sampling_number =
+ npad->joy_left_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ npad->joy_left_lifo.WriteNextEntry(pad_state);
+ break;
+ case Core::HID::NpadStyleIndex::JoyconRight:
+ pad_state.connection_status.raw = 0;
+ pad_state.connection_status.is_connected.Assign(1);
pad_state.connection_status.is_right_connected.Assign(1);
+
libnx_state.connection_status.is_right_connected.Assign(1);
+ pad_state.sampling_number =
+ npad->joy_right_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ npad->joy_right_lifo.WriteNextEntry(pad_state);
+ break;
+ case Core::HID::NpadStyleIndex::GameCube:
+ pad_state.connection_status.raw = 0;
+ pad_state.connection_status.is_connected.Assign(1);
+ pad_state.connection_status.is_wired.Assign(1);
+
+ libnx_state.connection_status.is_wired.Assign(1);
+ pad_state.sampling_number =
+ npad->fullkey_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ trigger_state.sampling_number =
+ npad->gc_trigger_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ npad->fullkey_lifo.WriteNextEntry(pad_state);
+ npad->gc_trigger_lifo.WriteNextEntry(trigger_state);
+ break;
+ case Core::HID::NpadStyleIndex::Pokeball:
+ pad_state.connection_status.raw = 0;
+ pad_state.connection_status.is_connected.Assign(1);
+ pad_state.sampling_number =
+ npad->palma_lifo.ReadCurrentEntry().state.sampling_number + 1;
+ npad->palma_lifo.WriteNextEntry(pad_state);
+ break;
+ default:
+ break;
}
- pad_state.sampling_number =
- npad->joy_dual_lifo.ReadCurrentEntry().state.sampling_number + 1;
- npad->joy_dual_lifo.WriteNextEntry(pad_state);
- break;
- case Core::HID::NpadStyleIndex::JoyconLeft:
- pad_state.connection_status.raw = 0;
- pad_state.connection_status.is_connected.Assign(1);
- pad_state.connection_status.is_left_connected.Assign(1);
-
- libnx_state.connection_status.is_left_connected.Assign(1);
- pad_state.sampling_number =
- npad->joy_left_lifo.ReadCurrentEntry().state.sampling_number + 1;
- npad->joy_left_lifo.WriteNextEntry(pad_state);
- break;
- case Core::HID::NpadStyleIndex::JoyconRight:
- pad_state.connection_status.raw = 0;
- pad_state.connection_status.is_connected.Assign(1);
- pad_state.connection_status.is_right_connected.Assign(1);
-
- libnx_state.connection_status.is_right_connected.Assign(1);
- pad_state.sampling_number =
- npad->joy_right_lifo.ReadCurrentEntry().state.sampling_number + 1;
- npad->joy_right_lifo.WriteNextEntry(pad_state);
- break;
- case Core::HID::NpadStyleIndex::GameCube:
- pad_state.connection_status.raw = 0;
- pad_state.connection_status.is_connected.Assign(1);
- pad_state.connection_status.is_wired.Assign(1);
-
- libnx_state.connection_status.is_wired.Assign(1);
- pad_state.sampling_number =
- npad->fullkey_lifo.ReadCurrentEntry().state.sampling_number + 1;
- trigger_state.sampling_number =
- npad->gc_trigger_lifo.ReadCurrentEntry().state.sampling_number + 1;
- npad->fullkey_lifo.WriteNextEntry(pad_state);
- npad->gc_trigger_lifo.WriteNextEntry(trigger_state);
- break;
- case Core::HID::NpadStyleIndex::Pokeball:
- pad_state.connection_status.raw = 0;
- pad_state.connection_status.is_connected.Assign(1);
- pad_state.sampling_number =
- npad->palma_lifo.ReadCurrentEntry().state.sampling_number + 1;
- npad->palma_lifo.WriteNextEntry(pad_state);
- break;
- default:
- break;
- }
-
- libnx_state.npad_buttons.raw = pad_state.npad_buttons.raw;
- libnx_state.l_stick = pad_state.l_stick;
- libnx_state.r_stick = pad_state.r_stick;
- npad->system_ext_lifo.WriteNextEntry(pad_state);
+ libnx_state.npad_buttons.raw = pad_state.npad_buttons.raw;
+ libnx_state.l_stick = pad_state.l_stick;
+ libnx_state.r_stick = pad_state.r_stick;
+ npad->system_ext_lifo.WriteNextEntry(pad_state);
- press_state |= static_cast<u64>(pad_state.npad_buttons.raw);
+ press_state |= static_cast<u64>(pad_state.npad_buttons.raw);
+ }
}
}
-void NPad::SetSupportedStyleSet(Core::HID::NpadStyleTag style_set) {
- hid_core.SetSupportedStyleTag(style_set);
-
- if (is_controller_initialized) {
- return;
+Result NPad::SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet supported_style_set) {
+ std::scoped_lock lock{mutex};
+ hid_core.SetSupportedStyleTag({supported_style_set});
+ const Result result = npad_resource.SetSupportedNpadStyleSet(aruid, supported_style_set);
+ if (result.IsSuccess()) {
+ OnUpdate({});
}
-
- // Once SetSupportedStyleSet is called controllers are fully initialized
- is_controller_initialized = true;
+ return result;
}
-Core::HID::NpadStyleTag NPad::GetSupportedStyleSet() const {
- if (!is_controller_initialized) {
- return {Core::HID::NpadStyleSet::None};
+Result NPad::GetSupportedNpadStyleSet(u64 aruid,
+ Core::HID::NpadStyleSet& out_supported_style_set) const {
+ std::scoped_lock lock{mutex};
+ const Result result = npad_resource.GetSupportedNpadStyleSet(out_supported_style_set, aruid);
+
+ if (result == ResultUndefinedStyleset) {
+ out_supported_style_set = Core::HID::NpadStyleSet::None;
+ return ResultSuccess;
}
- return hid_core.GetSupportedStyleTag();
+
+ return result;
}
-Result NPad::SetSupportedNpadIdTypes(std::span<const u8> data) {
- constexpr std::size_t max_number_npad_ids = 0xa;
- const auto length = data.size();
- ASSERT(length > 0 && (length % sizeof(u32)) == 0);
- const std::size_t elements = length / sizeof(u32);
+Result NPad::GetMaskedSupportedNpadStyleSet(
+ u64 aruid, Core::HID::NpadStyleSet& out_supported_style_set) const {
+ std::scoped_lock lock{mutex};
+ const Result result =
+ npad_resource.GetMaskedSupportedNpadStyleSet(out_supported_style_set, aruid);
- if (elements > max_number_npad_ids) {
- return InvalidArraySize;
+ if (result == ResultUndefinedStyleset) {
+ out_supported_style_set = Core::HID::NpadStyleSet::None;
+ return ResultSuccess;
}
- supported_npad_id_types.clear();
- supported_npad_id_types.resize(elements);
- std::memcpy(supported_npad_id_types.data(), data.data(), length);
- return ResultSuccess;
+ return result;
}
-void NPad::GetSupportedNpadIdTypes(u32* data, std::size_t max_length) {
- const auto copy_amount = supported_npad_id_types.size() * sizeof(u32);
- ASSERT(max_length <= copy_amount);
- std::memcpy(data, supported_npad_id_types.data(), copy_amount);
-}
+Result NPad::SetSupportedNpadIdType(u64 aruid,
+ std::span<const Core::HID::NpadIdType> supported_npad_list) {
+ std::scoped_lock lock{mutex};
+ if (supported_npad_list.size() > MaxSupportedNpadIdTypes) {
+ return ResultInvalidArraySize;
+ }
-std::size_t NPad::GetSupportedNpadIdTypesSize() const {
- return supported_npad_id_types.size();
-}
+ Result result = npad_resource.SetSupportedNpadIdType(aruid, supported_npad_list);
-void NPad::SetHoldType(NpadJoyHoldType joy_hold_type) {
- if (joy_hold_type != NpadJoyHoldType::Horizontal &&
- joy_hold_type != NpadJoyHoldType::Vertical) {
- LOG_ERROR(Service_HID, "Npad joy hold type needs to be valid, joy_hold_type={}",
- joy_hold_type);
- return;
+ if (result.IsSuccess()) {
+ OnUpdate({});
}
- hold_type = joy_hold_type;
-}
-NpadJoyHoldType NPad::GetHoldType() const {
- return hold_type;
+ return result;
}
-void NPad::SetNpadHandheldActivationMode(NpadHandheldActivationMode activation_mode) {
- if (activation_mode >= NpadHandheldActivationMode::MaxActivationMode) {
- ASSERT_MSG(false, "Activation mode should be always None, Single or Dual");
- return;
- }
-
- handheld_activation_mode = activation_mode;
+Result NPad::SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type) {
+ std::scoped_lock lock{mutex};
+ return npad_resource.SetNpadJoyHoldType(aruid, hold_type);
}
-NpadHandheldActivationMode NPad::GetNpadHandheldActivationMode() const {
- return handheld_activation_mode;
+Result NPad::GetNpadJoyHoldType(u64 aruid, NpadJoyHoldType& out_hold_type) const {
+ std::scoped_lock lock{mutex};
+ return npad_resource.GetNpadJoyHoldType(out_hold_type, aruid);
}
-void NPad::SetNpadCommunicationMode(NpadCommunicationMode communication_mode_) {
- communication_mode = communication_mode_;
+Result NPad::SetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode mode) {
+ std::scoped_lock lock{mutex};
+ Result result = npad_resource.SetNpadHandheldActivationMode(aruid, mode);
+ if (result.IsSuccess()) {
+ OnUpdate({});
+ }
+ return result;
}
-NpadCommunicationMode NPad::GetNpadCommunicationMode() const {
- return communication_mode;
+Result NPad::GetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode& out_mode) const {
+ std::scoped_lock lock{mutex};
+ return npad_resource.GetNpadHandheldActivationMode(out_mode, aruid);
}
-bool NPad::SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id,
+bool NPad::SetNpadMode(u64 aruid, Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id,
NpadJoyDeviceType npad_device_type, NpadJoyAssignmentMode assignment_mode) {
if (!IsNpadIdValid(npad_id)) {
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
return false;
}
- auto& controller = GetControllerFromNpadIdType(npad_id);
+ auto& controller = GetControllerFromNpadIdType(aruid, npad_id);
if (controller.shared_memory->assignment_mode != assignment_mode) {
controller.shared_memory->assignment_mode = assignment_mode;
}
@@ -675,17 +688,17 @@ bool NPad::SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType
if (assignment_mode == NpadJoyAssignmentMode::Dual) {
if (controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconLeft) {
- DisconnectNpad(npad_id);
+ DisconnectNpad(aruid, npad_id);
controller.is_dual_left_connected = true;
controller.is_dual_right_connected = false;
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
return false;
}
if (controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconRight) {
- DisconnectNpad(npad_id);
+ DisconnectNpad(aruid, npad_id);
controller.is_dual_left_connected = false;
controller.is_dual_right_connected = true;
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
return false;
}
return false;
@@ -699,37 +712,38 @@ bool NPad::SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType
}
if (controller.is_dual_left_connected && !controller.is_dual_right_connected) {
- DisconnectNpad(npad_id);
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconLeft, npad_id, true);
+ DisconnectNpad(aruid, npad_id);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconLeft, npad_id, true);
return false;
}
if (!controller.is_dual_left_connected && controller.is_dual_right_connected) {
- DisconnectNpad(npad_id);
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconRight, npad_id, true);
+ DisconnectNpad(aruid, npad_id);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconRight, npad_id, true);
return false;
}
// We have two controllers connected to the same npad_id we need to split them
new_npad_id = hid_core.GetFirstDisconnectedNpadId();
- auto& controller_2 = GetControllerFromNpadIdType(new_npad_id);
- DisconnectNpad(npad_id);
+ auto& controller_2 = GetControllerFromNpadIdType(aruid, new_npad_id);
+ DisconnectNpad(aruid, npad_id);
if (npad_device_type == NpadJoyDeviceType::Left) {
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconLeft, npad_id, true);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconLeft, npad_id, true);
controller_2.is_dual_left_connected = false;
controller_2.is_dual_right_connected = true;
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, new_npad_id, true);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconDual, new_npad_id, true);
} else {
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconRight, npad_id, true);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconRight, npad_id, true);
controller_2.is_dual_left_connected = true;
controller_2.is_dual_right_connected = false;
- UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, new_npad_id, true);
+ UpdateControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconDual, new_npad_id, true);
}
return true;
}
-bool NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index,
+bool NPad::VibrateControllerAtIndex(u64 aruid, Core::HID::NpadIdType npad_id,
+ std::size_t device_index,
const Core::HID::VibrationValue& vibration_value) {
- auto& controller = GetControllerFromNpadIdType(npad_id);
+ auto& controller = GetControllerFromNpadIdType(aruid, npad_id);
if (!controller.device->IsConnected()) {
return false;
}
@@ -772,7 +786,8 @@ bool NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t d
return controller.device->SetVibration(device_index, vibration);
}
-void NPad::VibrateController(const Core::HID::VibrationDeviceHandle& vibration_device_handle,
+void NPad::VibrateController(u64 aruid,
+ const Core::HID::VibrationDeviceHandle& vibration_device_handle,
const Core::HID::VibrationValue& vibration_value) {
if (IsVibrationHandleValid(vibration_device_handle).IsError()) {
return;
@@ -782,7 +797,7 @@ void NPad::VibrateController(const Core::HID::VibrationDeviceHandle& vibration_d
return;
}
- auto& controller = GetControllerFromHandle(vibration_device_handle);
+ auto& controller = GetControllerFromHandle(aruid, vibration_device_handle);
const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index);
if (!controller.vibration[device_index].device_mounted || !controller.device->IsConnected()) {
@@ -812,14 +827,14 @@ void NPad::VibrateController(const Core::HID::VibrationDeviceHandle& vibration_d
return;
}
- if (VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_index,
+ if (VibrateControllerAtIndex(aruid, controller.device->GetNpadIdType(), device_index,
vibration_value)) {
controller.vibration[device_index].latest_vibration_value = vibration_value;
}
}
void NPad::VibrateControllers(
- std::span<const Core::HID::VibrationDeviceHandle> vibration_device_handles,
+ u64 aruid, std::span<const Core::HID::VibrationDeviceHandle> vibration_device_handles,
std::span<const Core::HID::VibrationValue> vibration_values) {
if (!Settings::values.vibration_enabled.GetValue() && !permit_vibration_session_enabled) {
return;
@@ -831,17 +846,17 @@ void NPad::VibrateControllers(
"this is undefined behavior!");
for (std::size_t i = 0; i < vibration_device_handles.size(); ++i) {
- VibrateController(vibration_device_handles[i], vibration_values[i]);
+ VibrateController(aruid, vibration_device_handles[i], vibration_values[i]);
}
}
Core::HID::VibrationValue NPad::GetLastVibration(
- const Core::HID::VibrationDeviceHandle& vibration_device_handle) const {
+ u64 aruid, const Core::HID::VibrationDeviceHandle& vibration_device_handle) const {
if (IsVibrationHandleValid(vibration_device_handle).IsError()) {
return {};
}
- const auto& controller = GetControllerFromHandle(vibration_device_handle);
+ const auto& controller = GetControllerFromHandle(aruid, vibration_device_handle);
const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index);
return controller.vibration[device_index].latest_vibration_value;
}
@@ -852,14 +867,15 @@ void NPad::InitializeVibrationDevice(
return;
}
+ const auto aruid = applet_resource_holder.applet_resource->GetActiveAruid();
const auto npad_index = static_cast<Core::HID::NpadIdType>(vibration_device_handle.npad_id);
const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index);
- InitializeVibrationDeviceAtIndex(npad_index, device_index);
+ InitializeVibrationDeviceAtIndex(aruid, npad_index, device_index);
}
-void NPad::InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id,
+void NPad::InitializeVibrationDeviceAtIndex(u64 aruid, Core::HID::NpadIdType npad_id,
std::size_t device_index) {
- auto& controller = GetControllerFromNpadIdType(npad_id);
+ auto& controller = GetControllerFromNpadIdType(aruid, npad_id);
if (!Settings::values.vibration_enabled.GetValue()) {
controller.vibration[device_index].device_mounted = false;
return;
@@ -874,60 +890,50 @@ void NPad::SetPermitVibrationSession(bool permit_vibration_session) {
}
bool NPad::IsVibrationDeviceMounted(
- const Core::HID::VibrationDeviceHandle& vibration_device_handle) const {
+ u64 aruid, const Core::HID::VibrationDeviceHandle& vibration_device_handle) const {
if (IsVibrationHandleValid(vibration_device_handle).IsError()) {
return false;
}
- const auto& controller = GetControllerFromHandle(vibration_device_handle);
+ const auto& controller = GetControllerFromHandle(aruid, vibration_device_handle);
const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index);
return controller.vibration[device_index].device_mounted;
}
-Kernel::KReadableEvent& NPad::GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id) {
- if (!IsNpadIdValid(npad_id)) {
- LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
- // Fallback to player 1
- const auto& controller = GetControllerFromNpadIdType(Core::HID::NpadIdType::Player1);
- return controller.styleset_changed_event->GetReadableEvent();
- }
-
- const auto& controller = GetControllerFromNpadIdType(npad_id);
- return controller.styleset_changed_event->GetReadableEvent();
-}
-
-void NPad::SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const {
- const auto& controller = GetControllerFromNpadIdType(npad_id);
- controller.styleset_changed_event->Signal();
+Result NPad::AcquireNpadStyleSetUpdateEventHandle(u64 aruid, Kernel::KReadableEvent** out_event,
+ Core::HID::NpadIdType npad_id) {
+ std::scoped_lock lock{mutex};
+ return npad_resource.AcquireNpadStyleSetUpdateEventHandle(aruid, out_event, npad_id);
}
-void NPad::AddNewControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id) {
- UpdateControllerAt(controller, npad_id, true);
+void NPad::AddNewControllerAt(u64 aruid, Core::HID::NpadStyleIndex controller,
+ Core::HID::NpadIdType npad_id) {
+ UpdateControllerAt(aruid, controller, npad_id, true);
}
-void NPad::UpdateControllerAt(Core::HID::NpadStyleIndex type, Core::HID::NpadIdType npad_id,
- bool connected) {
- auto& controller = GetControllerFromNpadIdType(npad_id);
+void NPad::UpdateControllerAt(u64 aruid, Core::HID::NpadStyleIndex type,
+ Core::HID::NpadIdType npad_id, bool connected) {
+ auto& controller = GetControllerFromNpadIdType(aruid, npad_id);
if (!connected) {
- DisconnectNpad(npad_id);
+ DisconnectNpad(aruid, npad_id);
return;
}
controller.device->SetNpadStyleIndex(type);
- InitNewlyAddedController(npad_id);
+ InitNewlyAddedController(aruid, npad_id);
}
-Result NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) {
+Result NPad::DisconnectNpad(u64 aruid, Core::HID::NpadIdType npad_id) {
if (!IsNpadIdValid(npad_id)) {
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
- return InvalidNpadId;
+ return ResultInvalidNpadId;
}
LOG_DEBUG(Service_HID, "Npad disconnected {}", npad_id);
- auto& controller = GetControllerFromNpadIdType(npad_id);
+ auto& controller = GetControllerFromNpadIdType(aruid, npad_id);
for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) {
// Send an empty vibration to stop any vibrations.
- VibrateControllerAtIndex(npad_id, device_idx, {});
+ VibrateControllerAtIndex(aruid, npad_id, device_idx, {});
controller.vibration[device_idx].device_mounted = false;
}
@@ -961,47 +967,48 @@ Result NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) {
controller.is_dual_right_connected = true;
controller.is_connected = false;
controller.device->Disconnect();
- SignalStyleSetChangedEvent(npad_id);
+ npad_resource.SignalStyleSetUpdateEvent(aruid, npad_id);
WriteEmptyEntry(shared_memory);
return ResultSuccess;
}
Result NPad::IsFirmwareUpdateAvailableForSixAxisSensor(
- const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const {
+ u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle,
+ bool& is_firmware_available) const {
const auto is_valid = IsSixaxisHandleValid(sixaxis_handle);
if (is_valid.IsError()) {
LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw);
return is_valid;
}
- const auto& sixaxis_properties = GetSixaxisProperties(sixaxis_handle);
+ const auto& sixaxis_properties = GetSixaxisProperties(aruid, sixaxis_handle);
is_firmware_available = sixaxis_properties.is_firmware_update_available != 0;
return ResultSuccess;
}
Result NPad::ResetIsSixAxisSensorDeviceNewlyAssigned(
- const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
+ u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
const auto is_valid = IsSixaxisHandleValid(sixaxis_handle);
if (is_valid.IsError()) {
LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw);
return is_valid;
}
- auto& sixaxis_properties = GetSixaxisProperties(sixaxis_handle);
+ auto& sixaxis_properties = GetSixaxisProperties(aruid, sixaxis_handle);
sixaxis_properties.is_newly_assigned.Assign(0);
return ResultSuccess;
}
-Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1,
+Result NPad::MergeSingleJoyAsDualJoy(u64 aruid, Core::HID::NpadIdType npad_id_1,
Core::HID::NpadIdType npad_id_2) {
if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) {
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id_1:{}, npad_id_2:{}", npad_id_1,
npad_id_2);
- return InvalidNpadId;
+ return ResultInvalidNpadId;
}
- auto& controller_1 = GetControllerFromNpadIdType(npad_id_1);
- auto& controller_2 = GetControllerFromNpadIdType(npad_id_2);
+ auto& controller_1 = GetControllerFromNpadIdType(aruid, npad_id_1);
+ auto& controller_2 = GetControllerFromNpadIdType(aruid, npad_id_2);
auto controller_style_1 = controller_1.device->GetNpadStyleIndex();
auto controller_style_2 = controller_2.device->GetNpadStyleIndex();
@@ -1048,51 +1055,62 @@ Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1,
}
// Disconnect the joycons and connect them as dual joycon at the first index.
- DisconnectNpad(npad_id_1);
- DisconnectNpad(npad_id_2);
+ DisconnectNpad(aruid, npad_id_1);
+ DisconnectNpad(aruid, npad_id_2);
controller_1.is_dual_left_connected = true;
controller_1.is_dual_right_connected = true;
- AddNewControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id_1);
+ AddNewControllerAt(aruid, Core::HID::NpadStyleIndex::JoyconDual, npad_id_1);
return ResultSuccess;
}
-void NPad::StartLRAssignmentMode() {
- // Nothing internally is used for lr assignment mode. Since we have the ability to set the
- // controller types from boot, it doesn't really matter about showing a selection screen
- is_in_lr_assignment_mode = true;
+Result NPad::StartLrAssignmentMode(u64 aruid) {
+ std::scoped_lock lock{mutex};
+ bool is_enabled{};
+ Result result = npad_resource.GetLrAssignmentMode(is_enabled, aruid);
+ if (result.IsSuccess() && is_enabled == false) {
+ result = npad_resource.SetLrAssignmentMode(aruid, true);
+ }
+ return result;
}
-void NPad::StopLRAssignmentMode() {
- is_in_lr_assignment_mode = false;
+Result NPad::StopLrAssignmentMode(u64 aruid) {
+ std::scoped_lock lock{mutex};
+ bool is_enabled{};
+ Result result = npad_resource.GetLrAssignmentMode(is_enabled, aruid);
+ if (result.IsSuccess() && is_enabled == true) {
+ result = npad_resource.SetLrAssignmentMode(aruid, false);
+ }
+ return result;
}
-Result NPad::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2) {
+Result NPad::SwapNpadAssignment(u64 aruid, Core::HID::NpadIdType npad_id_1,
+ Core::HID::NpadIdType npad_id_2) {
if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) {
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id_1:{}, npad_id_2:{}", npad_id_1,
npad_id_2);
- return InvalidNpadId;
+ return ResultInvalidNpadId;
}
if (npad_id_1 == Core::HID::NpadIdType::Handheld ||
npad_id_2 == Core::HID::NpadIdType::Handheld || npad_id_1 == Core::HID::NpadIdType::Other ||
npad_id_2 == Core::HID::NpadIdType::Other) {
return ResultSuccess;
}
- const auto& controller_1 = GetControllerFromNpadIdType(npad_id_1).device;
- const auto& controller_2 = GetControllerFromNpadIdType(npad_id_2).device;
+ const auto& controller_1 = GetControllerFromNpadIdType(aruid, npad_id_1).device;
+ const auto& controller_2 = GetControllerFromNpadIdType(aruid, npad_id_2).device;
const auto type_index_1 = controller_1->GetNpadStyleIndex();
const auto type_index_2 = controller_2->GetNpadStyleIndex();
const auto is_connected_1 = controller_1->IsConnected();
const auto is_connected_2 = controller_2->IsConnected();
- if (!IsControllerSupported(type_index_1) && is_connected_1) {
- return NpadNotConnected;
+ if (!npad_resource.IsControllerSupported(aruid, type_index_1) && is_connected_1) {
+ return ResultNpadNotConnected;
}
- if (!IsControllerSupported(type_index_2) && is_connected_2) {
- return NpadNotConnected;
+ if (!npad_resource.IsControllerSupported(aruid, type_index_2) && is_connected_2) {
+ return ResultNpadNotConnected;
}
- UpdateControllerAt(type_index_2, npad_id_1, is_connected_2);
- UpdateControllerAt(type_index_1, npad_id_2, is_connected_1);
+ UpdateControllerAt(aruid, type_index_2, npad_id_1, is_connected_2);
+ UpdateControllerAt(aruid, type_index_1, npad_id_2, is_connected_1);
return ResultSuccess;
}
@@ -1100,68 +1118,68 @@ Result NPad::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::Npad
Result NPad::GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const {
if (!IsNpadIdValid(npad_id)) {
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
- return InvalidNpadId;
+ return ResultInvalidNpadId;
}
- const auto& controller = GetControllerFromNpadIdType(npad_id).device;
+ const auto aruid = applet_resource_holder.applet_resource->GetActiveAruid();
+ const auto& controller = GetControllerFromNpadIdType(aruid, npad_id).device;
pattern = controller->GetLedPattern();
return ResultSuccess;
}
-Result NPad::IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
- bool& is_valid) const {
- if (!IsNpadIdValid(npad_id)) {
- LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
- return InvalidNpadId;
- }
- const auto& controller = GetControllerFromNpadIdType(npad_id);
- is_valid = controller.unintended_home_button_input_protection;
- return ResultSuccess;
+Result NPad::IsUnintendedHomeButtonInputProtectionEnabled(bool& out_is_enabled, u64 aruid,
+ Core::HID::NpadIdType npad_id) const {
+ std::scoped_lock lock{mutex};
+ return npad_resource.GetHomeProtectionEnabled(out_is_enabled, aruid, npad_id);
}
-Result NPad::SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled,
- Core::HID::NpadIdType npad_id) {
- if (!IsNpadIdValid(npad_id)) {
- LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
- return InvalidNpadId;
- }
- auto& controller = GetControllerFromNpadIdType(npad_id);
- controller.unintended_home_button_input_protection = is_protection_enabled;
- return ResultSuccess;
+Result NPad::EnableUnintendedHomeButtonInputProtection(u64 aruid, Core::HID::NpadIdType npad_id,
+ bool is_enabled) {
+ std::scoped_lock lock{mutex};
+ return npad_resource.SetHomeProtectionEnabled(aruid, npad_id, is_enabled);
}
-void NPad::SetAnalogStickUseCenterClamp(bool use_center_clamp) {
- analog_stick_use_center_clamp = use_center_clamp;
+void NPad::SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled) {
+ std::scoped_lock lock{mutex};
+ npad_resource.SetNpadAnalogStickUseCenterClamp(aruid, is_enabled);
}
void NPad::ClearAllConnectedControllers() {
- for (auto& controller : controller_data) {
- if (controller.device->IsConnected() &&
- controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::None) {
- controller.device->Disconnect();
- controller.device->SetNpadStyleIndex(Core::HID::NpadStyleIndex::None);
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
+ for (auto& controller : controller_data[aruid_index]) {
+ if (controller.device->IsConnected() &&
+ controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::None) {
+ controller.device->Disconnect();
+ controller.device->SetNpadStyleIndex(Core::HID::NpadStyleIndex::None);
+ }
}
}
}
void NPad::DisconnectAllConnectedControllers() {
- for (auto& controller : controller_data) {
- controller.device->Disconnect();
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
+ for (auto& controller : controller_data[aruid_index]) {
+ controller.device->Disconnect();
+ }
}
}
void NPad::ConnectAllDisconnectedControllers() {
- for (auto& controller : controller_data) {
- if (controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::None &&
- !controller.device->IsConnected()) {
- controller.device->Connect();
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
+ for (auto& controller : controller_data[aruid_index]) {
+ if (controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::None &&
+ !controller.device->IsConnected()) {
+ controller.device->Connect();
+ }
}
}
}
void NPad::ClearAllControllers() {
- for (auto& controller : controller_data) {
- controller.device->Disconnect();
- controller.device->SetNpadStyleIndex(Core::HID::NpadStyleIndex::None);
+ for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
+ for (auto& controller : controller_data[aruid_index]) {
+ controller.device->Disconnect();
+ controller.device->SetNpadStyleIndex(Core::HID::NpadStyleIndex::None);
+ }
}
}
@@ -1169,128 +1187,105 @@ Core::HID::NpadButton NPad::GetAndResetPressState() {
return static_cast<Core::HID::NpadButton>(press_state.exchange(0));
}
-void NPad::ApplyNpadSystemCommonPolicy() {
- Core::HID::NpadStyleTag styletag{};
- styletag.fullkey.Assign(1);
- styletag.handheld.Assign(1);
- styletag.joycon_dual.Assign(1);
- styletag.system_ext.Assign(1);
- styletag.system.Assign(1);
- SetSupportedStyleSet(styletag);
-
- SetNpadHandheldActivationMode(NpadHandheldActivationMode::Dual);
-
- supported_npad_id_types.clear();
- supported_npad_id_types.resize(10);
- supported_npad_id_types[0] = Core::HID::NpadIdType::Player1;
- supported_npad_id_types[1] = Core::HID::NpadIdType::Player2;
- supported_npad_id_types[2] = Core::HID::NpadIdType::Player3;
- supported_npad_id_types[3] = Core::HID::NpadIdType::Player4;
- supported_npad_id_types[4] = Core::HID::NpadIdType::Player5;
- supported_npad_id_types[5] = Core::HID::NpadIdType::Player6;
- supported_npad_id_types[6] = Core::HID::NpadIdType::Player7;
- supported_npad_id_types[7] = Core::HID::NpadIdType::Player8;
- supported_npad_id_types[8] = Core::HID::NpadIdType::Other;
- supported_npad_id_types[9] = Core::HID::NpadIdType::Handheld;
-}
-
-bool NPad::IsControllerSupported(Core::HID::NpadStyleIndex controller) const {
- if (controller == Core::HID::NpadStyleIndex::Handheld) {
- const bool support_handheld =
- std::find(supported_npad_id_types.begin(), supported_npad_id_types.end(),
- Core::HID::NpadIdType::Handheld) != supported_npad_id_types.end();
- // Handheld is not even a supported type, lets stop here
- if (!support_handheld) {
- return false;
- }
- // Handheld shouldn't be supported in docked mode
- if (Settings::IsDockedMode()) {
- return false;
- }
+Result NPad::ApplyNpadSystemCommonPolicy(u64 aruid) {
+ std::scoped_lock lock{mutex};
+ const Result result = npad_resource.ApplyNpadSystemCommonPolicy(aruid, false);
+ if (result.IsSuccess()) {
+ OnUpdate({});
+ }
+ return result;
+}
- return true;
- }
-
- if (std::any_of(supported_npad_id_types.begin(), supported_npad_id_types.end(),
- [](Core::HID::NpadIdType npad_id) {
- return npad_id <= Core::HID::NpadIdType::Player8;
- })) {
- Core::HID::NpadStyleTag style = GetSupportedStyleSet();
- switch (controller) {
- case Core::HID::NpadStyleIndex::ProController:
- return style.fullkey.As<bool>();
- case Core::HID::NpadStyleIndex::JoyconDual:
- return style.joycon_dual.As<bool>();
- case Core::HID::NpadStyleIndex::JoyconLeft:
- return style.joycon_left.As<bool>();
- case Core::HID::NpadStyleIndex::JoyconRight:
- return style.joycon_right.As<bool>();
- case Core::HID::NpadStyleIndex::GameCube:
- return style.gamecube.As<bool>();
- case Core::HID::NpadStyleIndex::Pokeball:
- return style.palma.As<bool>();
- case Core::HID::NpadStyleIndex::NES:
- return style.lark.As<bool>();
- case Core::HID::NpadStyleIndex::SNES:
- return style.lucia.As<bool>();
- case Core::HID::NpadStyleIndex::N64:
- return style.lagoon.As<bool>();
- case Core::HID::NpadStyleIndex::SegaGenesis:
- return style.lager.As<bool>();
- default:
- return false;
- }
+Result NPad::ApplyNpadSystemCommonPolicyFull(u64 aruid) {
+ std::scoped_lock lock{mutex};
+ const Result result = npad_resource.ApplyNpadSystemCommonPolicy(aruid, true);
+ if (result.IsSuccess()) {
+ OnUpdate({});
}
+ return result;
+}
+
+Result NPad::ClearNpadSystemCommonPolicy(u64 aruid) {
+ std::scoped_lock lock{mutex};
+ const Result result = npad_resource.ClearNpadSystemCommonPolicy(aruid);
+ if (result.IsSuccess()) {
+ OnUpdate({});
+ }
+ return result;
+}
+
+void NPad::SetRevision(u64 aruid, NpadRevision revision) {
+ npad_resource.SetNpadRevision(aruid, revision);
+}
+
+NpadRevision NPad::GetRevision(u64 aruid) {
+ return npad_resource.GetNpadRevision(aruid);
+}
+
+Result NPad::RegisterAppletResourceUserId(u64 aruid) {
+ return npad_resource.RegisterAppletResourceUserId(aruid);
+}
+
+void NPad::UnregisterAppletResourceUserId(u64 aruid) {
+ npad_resource.UnregisterAppletResourceUserId(aruid);
+}
- return false;
+void NPad::SetNpadExternals(std::shared_ptr<AppletResource> resource,
+ std::recursive_mutex* shared_mutex) {
+ applet_resource_holder.applet_resource = resource;
+ applet_resource_holder.shared_mutex = shared_mutex;
+ applet_resource_holder.shared_npad_resource = &npad_resource;
}
NPad::NpadControllerData& NPad::GetControllerFromHandle(
- const Core::HID::VibrationDeviceHandle& device_handle) {
+ u64 aruid, const Core::HID::VibrationDeviceHandle& device_handle) {
const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id);
- return GetControllerFromNpadIdType(npad_id);
+ return GetControllerFromNpadIdType(aruid, npad_id);
}
const NPad::NpadControllerData& NPad::GetControllerFromHandle(
- const Core::HID::VibrationDeviceHandle& device_handle) const {
+ u64 aruid, const Core::HID::VibrationDeviceHandle& device_handle) const {
const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id);
- return GetControllerFromNpadIdType(npad_id);
+ return GetControllerFromNpadIdType(aruid, npad_id);
}
NPad::NpadControllerData& NPad::GetControllerFromHandle(
- const Core::HID::SixAxisSensorHandle& device_handle) {
+ u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle) {
const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id);
- return GetControllerFromNpadIdType(npad_id);
+ return GetControllerFromNpadIdType(aruid, npad_id);
}
const NPad::NpadControllerData& NPad::GetControllerFromHandle(
- const Core::HID::SixAxisSensorHandle& device_handle) const {
+ u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle) const {
const auto npad_id = static_cast<Core::HID::NpadIdType>(device_handle.npad_id);
- return GetControllerFromNpadIdType(npad_id);
+ return GetControllerFromNpadIdType(aruid, npad_id);
}
-NPad::NpadControllerData& NPad::GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) {
+NPad::NpadControllerData& NPad::GetControllerFromNpadIdType(u64 aruid,
+ Core::HID::NpadIdType npad_id) {
if (!IsNpadIdValid(npad_id)) {
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
npad_id = Core::HID::NpadIdType::Player1;
}
const auto npad_index = NpadIdTypeToIndex(npad_id);
- return controller_data[npad_index];
+ const auto aruid_index = applet_resource_holder.applet_resource->GetIndexFromAruid(aruid);
+ return controller_data[aruid_index][npad_index];
}
const NPad::NpadControllerData& NPad::GetControllerFromNpadIdType(
- Core::HID::NpadIdType npad_id) const {
+ u64 aruid, Core::HID::NpadIdType npad_id) const {
if (!IsNpadIdValid(npad_id)) {
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
npad_id = Core::HID::NpadIdType::Player1;
}
const auto npad_index = NpadIdTypeToIndex(npad_id);
- return controller_data[npad_index];
+ const auto aruid_index = applet_resource_holder.applet_resource->GetIndexFromAruid(aruid);
+ return controller_data[aruid_index][npad_index];
}
Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties(
- const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
- auto& controller = GetControllerFromHandle(sixaxis_handle);
+ 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::Pokeball:
@@ -1312,8 +1307,8 @@ Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties(
}
const Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties(
- const Core::HID::SixAxisSensorHandle& sixaxis_handle) const {
- const auto& controller = GetControllerFromHandle(sixaxis_handle);
+ 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::Pokeball:
@@ -1335,7 +1330,8 @@ const Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties(
}
AppletDetailedUiType NPad::GetAppletDetailedUiType(Core::HID::NpadIdType npad_id) {
- const auto& shared_memory = GetControllerFromNpadIdType(npad_id).shared_memory;
+ const auto aruid = applet_resource_holder.applet_resource->GetActiveAruid();
+ const auto& shared_memory = GetControllerFromNpadIdType(aruid, npad_id).shared_memory;
return {
.ui_variant = 0,
diff --git a/src/hid_core/resources/npad/npad.h b/src/hid_core/resources/npad/npad.h
new file mode 100644
index 000000000..58f8c7acf
--- /dev/null
+++ b/src/hid_core/resources/npad/npad.h
@@ -0,0 +1,214 @@
+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <array>
+#include <atomic>
+#include <mutex>
+#include <span>
+
+#include "common/common_types.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/npad/npad_resource.h"
+#include "hid_core/resources/npad/npad_types.h"
+
+namespace Core::HID {
+class EmulatedController;
+enum class ControllerTriggerType;
+} // namespace Core::HID
+
+namespace Kernel {
+class KEvent;
+class KReadableEvent;
+} // namespace Kernel
+
+namespace Service::KernelHelpers {
+class ServiceContext;
+} // namespace Service::KernelHelpers
+
+union Result;
+
+namespace Service::HID {
+class AppletResource;
+struct NpadInternalState;
+struct NpadSixAxisSensorLifo;
+struct NpadSharedMemoryFormat;
+
+class NPad final {
+public:
+ explicit NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_);
+ ~NPad();
+
+ Result Activate();
+ Result Activate(u64 aruid);
+
+ Result ActivateNpadResource();
+ Result ActivateNpadResource(u64 aruid);
+
+ // When the controller is requesting an update for the shared memory
+ void OnUpdate(const Core::Timing::CoreTiming& core_timing);
+
+ Result SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet supported_style_set);
+ Result GetSupportedNpadStyleSet(u64 aruid,
+ Core::HID::NpadStyleSet& out_supported_style_set) const;
+ Result GetMaskedSupportedNpadStyleSet(u64 aruid,
+ Core::HID::NpadStyleSet& out_supported_style_set) const;
+
+ Result SetSupportedNpadIdType(u64 aruid,
+ std::span<const Core::HID::NpadIdType> supported_npad_list);
+
+ Result SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type);
+ Result GetNpadJoyHoldType(u64 aruid, NpadJoyHoldType& out_hold_type) const;
+
+ Result SetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode mode);
+ Result GetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode& out_mode) const;
+
+ bool SetNpadMode(u64 aruid, Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id,
+ NpadJoyDeviceType npad_device_type, NpadJoyAssignmentMode assignment_mode);
+
+ bool VibrateControllerAtIndex(u64 aruid, Core::HID::NpadIdType npad_id,
+ std::size_t device_index,
+ const Core::HID::VibrationValue& vibration_value);
+
+ void VibrateController(u64 aruid,
+ const Core::HID::VibrationDeviceHandle& vibration_device_handle,
+ const Core::HID::VibrationValue& vibration_value);
+
+ void VibrateControllers(
+ u64 aruid, std::span<const Core::HID::VibrationDeviceHandle> vibration_device_handles,
+ std::span<const Core::HID::VibrationValue> vibration_values);
+
+ Core::HID::VibrationValue GetLastVibration(
+ u64 aruid, const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
+
+ void InitializeVibrationDevice(const Core::HID::VibrationDeviceHandle& vibration_device_handle);
+
+ void InitializeVibrationDeviceAtIndex(u64 aruid, Core::HID::NpadIdType npad_id,
+ std::size_t device_index);
+
+ void SetPermitVibrationSession(bool permit_vibration_session);
+
+ bool IsVibrationDeviceMounted(
+ u64 aruid, const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
+
+ Result AcquireNpadStyleSetUpdateEventHandle(u64 aruid, Kernel::KReadableEvent** out_event,
+ Core::HID::NpadIdType npad_id);
+
+ // Adds a new controller at an index.
+ void AddNewControllerAt(u64 aruid, Core::HID::NpadStyleIndex controller,
+ Core::HID::NpadIdType npad_id);
+ // Adds a new controller at an index with connection status.
+ void UpdateControllerAt(u64 aruid, Core::HID::NpadStyleIndex controller,
+ Core::HID::NpadIdType npad_id, bool connected);
+
+ Result DisconnectNpad(u64 aruid, Core::HID::NpadIdType npad_id);
+
+ Result IsFirmwareUpdateAvailableForSixAxisSensor(
+ u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle,
+ bool& is_firmware_available) const;
+ Result ResetIsSixAxisSensorDeviceNewlyAssigned(
+ u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle);
+
+ Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
+
+ Result IsUnintendedHomeButtonInputProtectionEnabled(bool& out_is_enabled, u64 aruid,
+ Core::HID::NpadIdType npad_id) const;
+ Result EnableUnintendedHomeButtonInputProtection(u64 aruid, Core::HID::NpadIdType npad_id,
+ bool is_enabled);
+
+ void SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled);
+ void ClearAllConnectedControllers();
+ void DisconnectAllConnectedControllers();
+ void ConnectAllDisconnectedControllers();
+ void ClearAllControllers();
+
+ Result MergeSingleJoyAsDualJoy(u64 aruid, Core::HID::NpadIdType npad_id_1,
+ Core::HID::NpadIdType npad_id_2);
+ Result StartLrAssignmentMode(u64 aruid);
+ Result StopLrAssignmentMode(u64 aruid);
+ Result SwapNpadAssignment(u64 aruid, Core::HID::NpadIdType npad_id_1,
+ Core::HID::NpadIdType npad_id_2);
+
+ // Logical OR for all buttons presses on all controllers
+ // Specifically for cheat engine and other features.
+ Core::HID::NpadButton GetAndResetPressState();
+
+ Result ApplyNpadSystemCommonPolicy(u64 aruid);
+ Result ApplyNpadSystemCommonPolicyFull(u64 aruid);
+ Result ClearNpadSystemCommonPolicy(u64 aruid);
+
+ void SetRevision(u64 aruid, NpadRevision revision);
+ NpadRevision GetRevision(u64 aruid);
+
+ Result RegisterAppletResourceUserId(u64 aruid);
+ void UnregisterAppletResourceUserId(u64 aruid);
+ void SetNpadExternals(std::shared_ptr<AppletResource> resource,
+ std::recursive_mutex* shared_mutex);
+
+ AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id);
+
+private:
+ struct VibrationData {
+ bool device_mounted{};
+ Core::HID::VibrationValue latest_vibration_value{};
+ std::chrono::steady_clock::time_point last_vibration_timepoint{};
+ };
+
+ struct NpadControllerData {
+ NpadInternalState* shared_memory = nullptr;
+ Core::HID::EmulatedController* device = nullptr;
+
+ std::array<VibrationData, 2> vibration{};
+ bool is_connected{};
+
+ // Dual joycons can have only one side connected
+ bool is_dual_left_connected{true};
+ bool is_dual_right_connected{true};
+
+ // Current pad state
+ NPadGenericState npad_pad_state{};
+ NPadGenericState npad_libnx_state{};
+ NpadGcTriggerState npad_trigger_state{};
+ int callback_key{};
+ };
+
+ void ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx);
+ void InitNewlyAddedController(u64 aruid, Core::HID::NpadIdType npad_id);
+ void RequestPadStateUpdate(u64 aruid, Core::HID::NpadIdType npad_id);
+ void WriteEmptyEntry(NpadInternalState* npad);
+
+ NpadControllerData& GetControllerFromHandle(
+ u64 aruid, const Core::HID::VibrationDeviceHandle& device_handle);
+ const NpadControllerData& GetControllerFromHandle(
+ u64 aruid, const Core::HID::VibrationDeviceHandle& device_handle) const;
+ NpadControllerData& GetControllerFromHandle(
+ u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle);
+ const NpadControllerData& GetControllerFromHandle(
+ u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle) const;
+ NpadControllerData& GetControllerFromNpadIdType(u64 aruid, Core::HID::NpadIdType npad_id);
+ const NpadControllerData& GetControllerFromNpadIdType(u64 aruid,
+ Core::HID::NpadIdType npad_id) const;
+
+ Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
+ u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle);
+ const Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
+ u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle) const;
+
+ Core::HID::HIDCore& hid_core;
+ KernelHelpers::ServiceContext& service_context;
+
+ s32 ref_counter{};
+ mutable std::mutex mutex;
+ NPadResource npad_resource;
+ AppletResourceHolder applet_resource_holder{};
+ Kernel::KEvent* input_event{nullptr};
+ std::mutex* input_mutex{nullptr};
+
+ std::atomic<u64> press_state{};
+ bool permit_vibration_session_enabled;
+ std::array<std::array<NpadControllerData, MaxSupportedNpadIdTypes>, AruidIndexMax>
+ controller_data{};
+};
+} // namespace Service::HID
diff --git a/src/hid_core/resources/npad/npad_data.cpp b/src/hid_core/resources/npad/npad_data.cpp
new file mode 100644
index 000000000..c7e9760cb
--- /dev/null
+++ b/src/hid_core/resources/npad/npad_data.cpp
@@ -0,0 +1,228 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "hid_core/hid_util.h"
+#include "hid_core/resources/npad/npad_data.h"
+
+namespace Service::HID {
+
+NPadData::NPadData() {
+ ClearNpadSystemCommonPolicy();
+}
+
+NPadData::~NPadData() = default;
+
+NpadStatus NPadData::GetNpadStatus() const {
+ return status;
+}
+
+void NPadData::SetNpadAnalogStickUseCenterClamp(bool is_enabled) {
+ status.use_center_clamp.Assign(is_enabled);
+}
+
+bool NPadData::GetNpadAnalogStickUseCenterClamp() const {
+ return status.use_center_clamp.As<bool>();
+}
+
+void NPadData::SetNpadSystemExtStateEnabled(bool is_enabled) {
+ status.system_ext_state.Assign(is_enabled);
+}
+
+bool NPadData::GetNpadSystemExtState() const {
+ return status.system_ext_state.As<bool>();
+}
+
+Result NPadData::SetSupportedNpadIdType(std::span<const Core::HID::NpadIdType> list) {
+ // Note: Real limit is 11. But array size is 10. N's bug?
+ if (list.size() > MaxSupportedNpadIdTypes) {
+ return ResultInvalidArraySize;
+ }
+
+ supported_npad_id_types_count = list.size();
+ memcpy(supported_npad_id_types.data(), list.data(),
+ list.size() * sizeof(Core::HID::NpadIdType));
+
+ return ResultSuccess;
+}
+
+std::size_t NPadData::GetSupportedNpadIdType(std::span<Core::HID::NpadIdType> out_list) const {
+ std::size_t out_size = std::min(supported_npad_id_types_count, out_list.size());
+
+ memcpy(out_list.data(), supported_npad_id_types.data(),
+ out_size * sizeof(Core::HID::NpadIdType));
+
+ return out_size;
+}
+
+bool NPadData::IsNpadIdTypeSupported(Core::HID::NpadIdType npad_id) const {
+ for (std::size_t i = 0; i < supported_npad_id_types_count; i++) {
+ if (supported_npad_id_types[i] == npad_id) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void NPadData::SetNpadSystemCommonPolicy(bool is_full_policy) {
+ supported_npad_style_set = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::JoyDual |
+ Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
+ handheld_activation_mode = NpadHandheldActivationMode::Dual;
+
+ status.is_supported_styleset_set.Assign(true);
+ status.is_hold_type_set.Assign(true);
+ status.lr_assignment_mode.Assign(false);
+ status.is_policy.Assign(true);
+ if (is_full_policy) {
+ status.is_full_policy.Assign(true);
+ }
+
+ supported_npad_id_types_count = 10;
+ supported_npad_id_types[0] = Core::HID::NpadIdType::Player1;
+ supported_npad_id_types[1] = Core::HID::NpadIdType::Player2;
+ supported_npad_id_types[2] = Core::HID::NpadIdType::Player3;
+ supported_npad_id_types[3] = Core::HID::NpadIdType::Player4;
+ supported_npad_id_types[4] = Core::HID::NpadIdType::Player5;
+ supported_npad_id_types[5] = Core::HID::NpadIdType::Player6;
+ supported_npad_id_types[6] = Core::HID::NpadIdType::Player7;
+ supported_npad_id_types[7] = Core::HID::NpadIdType::Player8;
+ supported_npad_id_types[8] = Core::HID::NpadIdType::Other;
+ supported_npad_id_types[9] = Core::HID::NpadIdType::Handheld;
+
+ for (auto& input_protection : is_unintended_home_button_input_protection) {
+ input_protection = true;
+ }
+}
+
+void NPadData::ClearNpadSystemCommonPolicy() {
+ status.raw = 0;
+ supported_npad_style_set = Core::HID::NpadStyleSet::All;
+ npad_hold_type = NpadJoyHoldType::Vertical;
+ handheld_activation_mode = NpadHandheldActivationMode::Dual;
+
+ for (auto& button_assignment : npad_button_assignment) {
+ button_assignment = Core::HID::NpadButton::None;
+ }
+
+ supported_npad_id_types_count = 10;
+ supported_npad_id_types[0] = Core::HID::NpadIdType::Player1;
+ supported_npad_id_types[1] = Core::HID::NpadIdType::Player2;
+ supported_npad_id_types[2] = Core::HID::NpadIdType::Player3;
+ supported_npad_id_types[3] = Core::HID::NpadIdType::Player4;
+ supported_npad_id_types[4] = Core::HID::NpadIdType::Player5;
+ supported_npad_id_types[5] = Core::HID::NpadIdType::Player6;
+ supported_npad_id_types[6] = Core::HID::NpadIdType::Player7;
+ supported_npad_id_types[7] = Core::HID::NpadIdType::Player8;
+ supported_npad_id_types[8] = Core::HID::NpadIdType::Other;
+ supported_npad_id_types[9] = Core::HID::NpadIdType::Handheld;
+
+ for (auto& input_protection : is_unintended_home_button_input_protection) {
+ input_protection = true;
+ }
+}
+
+void NPadData::SetNpadJoyHoldType(NpadJoyHoldType hold_type) {
+ npad_hold_type = hold_type;
+ status.is_hold_type_set.Assign(true);
+}
+
+NpadJoyHoldType NPadData::GetNpadJoyHoldType() const {
+ return npad_hold_type;
+}
+
+void NPadData::SetHandheldActivationMode(NpadHandheldActivationMode activation_mode) {
+ handheld_activation_mode = activation_mode;
+}
+
+NpadHandheldActivationMode NPadData::GetHandheldActivationMode() const {
+ return handheld_activation_mode;
+}
+
+void NPadData::SetSupportedNpadStyleSet(Core::HID::NpadStyleSet style_set) {
+ supported_npad_style_set = style_set;
+ status.is_supported_styleset_set.Assign(true);
+ status.is_hold_type_set.Assign(true);
+}
+
+Core::HID::NpadStyleSet NPadData::GetSupportedNpadStyleSet() const {
+ return supported_npad_style_set;
+}
+
+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:
+ return style.fullkey.As<bool>();
+ case Core::HID::NpadStyleIndex::Handheld:
+ return style.handheld.As<bool>();
+ case Core::HID::NpadStyleIndex::JoyconDual:
+ return style.joycon_dual.As<bool>();
+ case Core::HID::NpadStyleIndex::JoyconLeft:
+ return style.joycon_left.As<bool>();
+ case Core::HID::NpadStyleIndex::JoyconRight:
+ return style.joycon_right.As<bool>();
+ case Core::HID::NpadStyleIndex::GameCube:
+ return style.gamecube.As<bool>();
+ case Core::HID::NpadStyleIndex::Pokeball:
+ return style.palma.As<bool>();
+ case Core::HID::NpadStyleIndex::NES:
+ return style.lark.As<bool>();
+ case Core::HID::NpadStyleIndex::SNES:
+ return style.lucia.As<bool>();
+ case Core::HID::NpadStyleIndex::N64:
+ return style.lagoon.As<bool>();
+ case Core::HID::NpadStyleIndex::SegaGenesis:
+ return style.lager.As<bool>();
+ default:
+ return false;
+ }
+}
+
+void NPadData::SetLrAssignmentMode(bool is_enabled) {
+ status.lr_assignment_mode.Assign(is_enabled);
+}
+
+bool NPadData::GetLrAssignmentMode() const {
+ return status.lr_assignment_mode.As<bool>();
+}
+
+void NPadData::SetAssigningSingleOnSlSrPress(bool is_enabled) {
+ status.assigning_single_on_sl_sr_press.Assign(is_enabled);
+}
+
+bool NPadData::GetAssigningSingleOnSlSrPress() const {
+ return status.assigning_single_on_sl_sr_press.As<bool>();
+}
+
+void NPadData::SetHomeProtectionEnabled(bool is_enabled, Core::HID::NpadIdType npad_id) {
+ is_unintended_home_button_input_protection[NpadIdTypeToIndex(npad_id)] = is_enabled;
+}
+
+bool NPadData::GetHomeProtectionEnabled(Core::HID::NpadIdType npad_id) const {
+ return is_unintended_home_button_input_protection[NpadIdTypeToIndex(npad_id)];
+}
+
+void NPadData::SetCaptureButtonAssignment(Core::HID::NpadButton button_assignment,
+ std::size_t style_index) {
+ npad_button_assignment[style_index] = button_assignment;
+}
+
+Core::HID::NpadButton NPadData::GetCaptureButtonAssignment(std::size_t style_index) const {
+ return npad_button_assignment[style_index];
+}
+
+std::size_t NPadData::GetNpadCaptureButtonAssignmentList(
+ std::span<Core::HID::NpadButton> out_list) const {
+ for (std::size_t i = 0; i < out_list.size(); i++) {
+ Core::HID::NpadStyleSet style_set = GetStylesetByIndex(i);
+ if ((style_set & supported_npad_style_set) == Core::HID::NpadStyleSet::None ||
+ npad_button_assignment[i] == Core::HID::NpadButton::None) {
+ return i;
+ }
+ out_list[i] = npad_button_assignment[i];
+ }
+
+ return out_list.size();
+}
+
+} // namespace Service::HID
diff --git a/src/hid_core/resources/npad/npad_data.h b/src/hid_core/resources/npad/npad_data.h
new file mode 100644
index 000000000..86bd3b81c
--- /dev/null
+++ b/src/hid_core/resources/npad/npad_data.h
@@ -0,0 +1,88 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include <array>
+#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 NpadStatus {
+ union {
+ u32 raw{};
+
+ BitField<0, 1, u32> is_supported_styleset_set;
+ BitField<1, 1, u32> is_hold_type_set;
+ BitField<2, 1, u32> lr_assignment_mode;
+ BitField<3, 1, u32> assigning_single_on_sl_sr_press;
+ BitField<4, 1, u32> is_full_policy;
+ BitField<5, 1, u32> is_policy;
+ BitField<6, 1, u32> use_center_clamp;
+ BitField<7, 1, u32> system_ext_state;
+ };
+};
+static_assert(sizeof(NpadStatus) == 4, "NpadStatus is an invalid size");
+
+/// Handles Npad request from HID interfaces
+class NPadData final {
+public:
+ explicit NPadData();
+ ~NPadData();
+
+ NpadStatus GetNpadStatus() const;
+
+ void SetNpadAnalogStickUseCenterClamp(bool is_enabled);
+ bool GetNpadAnalogStickUseCenterClamp() const;
+
+ void SetNpadSystemExtStateEnabled(bool is_enabled);
+ bool GetNpadSystemExtState() const;
+
+ Result SetSupportedNpadIdType(std::span<const Core::HID::NpadIdType> list);
+ std::size_t GetSupportedNpadIdType(std::span<Core::HID::NpadIdType> out_list) const;
+ bool IsNpadIdTypeSupported(Core::HID::NpadIdType npad_id) const;
+
+ void SetNpadSystemCommonPolicy(bool is_full_policy);
+ void ClearNpadSystemCommonPolicy();
+
+ void SetNpadJoyHoldType(NpadJoyHoldType hold_type);
+ NpadJoyHoldType GetNpadJoyHoldType() const;
+
+ void SetHandheldActivationMode(NpadHandheldActivationMode activation_mode);
+ NpadHandheldActivationMode GetHandheldActivationMode() const;
+
+ void SetSupportedNpadStyleSet(Core::HID::NpadStyleSet style_set);
+ Core::HID::NpadStyleSet GetSupportedNpadStyleSet() const;
+ bool IsNpadStyleIndexSupported(Core::HID::NpadStyleIndex style_index) const;
+
+ void SetLrAssignmentMode(bool is_enabled);
+ bool GetLrAssignmentMode() const;
+
+ void SetAssigningSingleOnSlSrPress(bool is_enabled);
+ bool GetAssigningSingleOnSlSrPress() const;
+
+ void SetHomeProtectionEnabled(bool is_enabled, Core::HID::NpadIdType npad_id);
+ bool GetHomeProtectionEnabled(Core::HID::NpadIdType npad_id) const;
+
+ void SetCaptureButtonAssignment(Core::HID::NpadButton button_assignment,
+ std::size_t style_index);
+ Core::HID::NpadButton GetCaptureButtonAssignment(std::size_t style_index) const;
+ std::size_t GetNpadCaptureButtonAssignmentList(std::span<Core::HID::NpadButton> out_list) const;
+
+private:
+ NpadStatus status{};
+ Core::HID::NpadStyleSet supported_npad_style_set{Core::HID::NpadStyleSet::All};
+ NpadJoyHoldType npad_hold_type{NpadJoyHoldType::Vertical};
+ NpadHandheldActivationMode handheld_activation_mode{};
+ std::array<Core::HID::NpadIdType, MaxSupportedNpadIdTypes> supported_npad_id_types{};
+ std::array<Core::HID::NpadButton, StyleIndexCount> npad_button_assignment{};
+ std::size_t supported_npad_id_types_count{};
+ std::array<bool, MaxSupportedNpadIdTypes> is_unintended_home_button_input_protection{};
+};
+
+} // namespace Service::HID
diff --git a/src/hid_core/resources/npad/npad_resource.cpp b/src/hid_core/resources/npad/npad_resource.cpp
new file mode 100644
index 000000000..ea9fc14ed
--- /dev/null
+++ b/src/hid_core/resources/npad/npad_resource.cpp
@@ -0,0 +1,687 @@
+// SPDX-FileCopyrightText: Copyright 2023 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/hid_util.h"
+#include "hid_core/resources/npad/npad_resource.h"
+#include "hid_core/resources/npad/npad_types.h"
+
+namespace Service::HID {
+
+NPadResource::NPadResource(KernelHelpers::ServiceContext& context) : service_context{context} {}
+
+NPadResource::~NPadResource() = default;
+
+Result NPadResource::RegisterAppletResourceUserId(u64 aruid) {
+ const auto aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index < AruidIndexMax) {
+ return ResultAruidAlreadyRegistered;
+ }
+
+ std::size_t data_index = AruidIndexMax;
+ for (std::size_t i = 0; i < AruidIndexMax; i++) {
+ if (!state[i].flag.is_initialized) {
+ data_index = i;
+ break;
+ }
+ }
+
+ if (data_index == AruidIndexMax) {
+ return ResultAruidNoAvailableEntries;
+ }
+
+ auto& aruid_data = state[data_index];
+
+ aruid_data.aruid = aruid;
+ aruid_data.flag.is_initialized.Assign(true);
+
+ data_index = AruidIndexMax;
+ for (std::size_t i = 0; i < AruidIndexMax; i++) {
+ if (registration_list.flag[i] == RegistrationStatus::Initialized) {
+ if (registration_list.aruid[i] != aruid) {
+ continue;
+ }
+ data_index = i;
+ break;
+ }
+ // TODO: Don't Handle pending delete here
+ if (registration_list.flag[i] == RegistrationStatus::None ||
+ registration_list.flag[i] == RegistrationStatus::PendingDelete) {
+ data_index = i;
+ break;
+ }
+ }
+
+ if (data_index == AruidIndexMax) {
+ return ResultSuccess;
+ }
+
+ registration_list.flag[data_index] = RegistrationStatus::Initialized;
+ registration_list.aruid[data_index] = aruid;
+
+ return ResultSuccess;
+}
+
+void NPadResource::UnregisterAppletResourceUserId(u64 aruid) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+
+ DestroyStyleSetUpdateEvents(aruid);
+ if (aruid_index < AruidIndexMax) {
+ state[aruid_index] = {};
+ registration_list.flag[aruid_index] = RegistrationStatus::PendingDelete;
+ }
+}
+
+void NPadResource::DestroyStyleSetUpdateEvents(u64 aruid) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+
+ if (aruid_index >= AruidIndexMax) {
+ return;
+ }
+
+ for (auto& controller_state : state[aruid_index].controller_state) {
+ if (!controller_state.is_styleset_update_event_initialized) {
+ continue;
+ }
+ service_context.CloseEvent(controller_state.style_set_update_event);
+ controller_state.is_styleset_update_event_initialized = false;
+ }
+}
+
+Result NPadResource::Activate(u64 aruid) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+
+ if (aruid_index >= AruidIndexMax) {
+ return ResultSuccess;
+ }
+
+ auto& state_data = state[aruid_index];
+
+ if (state_data.flag.is_assigned) {
+ return ResultAruidAlreadyRegistered;
+ }
+
+ state_data.flag.is_assigned.Assign(true);
+ state_data.data.ClearNpadSystemCommonPolicy();
+ state_data.npad_revision = NpadRevision::Revision0;
+ state_data.button_config = {};
+
+ if (active_data_aruid == aruid) {
+ default_hold_type = active_data.GetNpadJoyHoldType();
+ active_data.SetNpadJoyHoldType(default_hold_type);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::Activate() {
+ if (ref_counter == std::numeric_limits<s32>::max() - 1) {
+ return ResultAppletResourceOverflow;
+ }
+ if (ref_counter == 0) {
+ RegisterAppletResourceUserId(SystemAruid);
+ Activate(SystemAruid);
+ }
+ ref_counter++;
+ return ResultSuccess;
+}
+
+Result NPadResource::Deactivate() {
+ if (ref_counter == 0) {
+ return ResultAppletResourceNotInitialized;
+ }
+
+ UnregisterAppletResourceUserId(SystemAruid);
+ ref_counter--;
+ return ResultSuccess;
+}
+
+NPadData* NPadResource::GetActiveData() {
+ return &active_data;
+}
+
+u64 NPadResource::GetActiveDataAruid() {
+ return active_data_aruid;
+}
+
+void NPadResource::SetAppletResourceUserId(u64 aruid) {
+ if (active_data_aruid == aruid) {
+ return;
+ }
+
+ active_data_aruid = aruid;
+ default_hold_type = active_data.GetNpadJoyHoldType();
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+
+ if (aruid_index >= AruidIndexMax) {
+ return;
+ }
+
+ auto& data = state[aruid_index].data;
+ if (data.GetNpadStatus().is_policy || data.GetNpadStatus().is_full_policy) {
+ data.SetNpadJoyHoldType(default_hold_type);
+ }
+
+ active_data = data;
+ if (data.GetNpadStatus().is_hold_type_set) {
+ active_data.SetNpadJoyHoldType(default_hold_type);
+ }
+}
+
+std::size_t NPadResource::GetIndexFromAruid(u64 aruid) const {
+ for (std::size_t i = 0; i < AruidIndexMax; i++) {
+ if (registration_list.flag[i] == RegistrationStatus::Initialized &&
+ registration_list.aruid[i] == aruid) {
+ return i;
+ }
+ }
+ return AruidIndexMax;
+}
+
+Result NPadResource::ApplyNpadSystemCommonPolicy(u64 aruid, bool is_full_policy) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ auto& data = state[aruid_index].data;
+ data.SetNpadSystemCommonPolicy(is_full_policy);
+ data.SetNpadJoyHoldType(default_hold_type);
+ if (active_data_aruid == aruid) {
+ active_data.SetNpadSystemCommonPolicy(is_full_policy);
+ active_data.SetNpadJoyHoldType(default_hold_type);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::ClearNpadSystemCommonPolicy(u64 aruid) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.ClearNpadSystemCommonPolicy();
+ if (active_data_aruid == aruid) {
+ active_data.ClearNpadSystemCommonPolicy();
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet style_set) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ auto& data = state[aruid_index].data;
+ data.SetSupportedNpadStyleSet(style_set);
+ if (active_data_aruid == aruid) {
+ active_data.SetSupportedNpadStyleSet(style_set);
+ active_data.SetNpadJoyHoldType(data.GetNpadJoyHoldType());
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::GetSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_Set,
+ u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ auto& data = state[aruid_index].data;
+ if (!data.GetNpadStatus().is_supported_styleset_set) {
+ return ResultUndefinedStyleset;
+ }
+
+ out_style_Set = data.GetSupportedNpadStyleSet();
+ return ResultSuccess;
+}
+
+Result NPadResource::GetMaskedSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_set,
+ u64 aruid) const {
+ if (aruid == SystemAruid) {
+ out_style_set = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Palma |
+ Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
+ return ResultSuccess;
+ }
+
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ auto& data = state[aruid_index].data;
+ if (!data.GetNpadStatus().is_supported_styleset_set) {
+ return ResultUndefinedStyleset;
+ }
+
+ Core::HID::NpadStyleSet mask{Core::HID::NpadStyleSet::None};
+ out_style_set = data.GetSupportedNpadStyleSet();
+
+ switch (state[aruid_index].npad_revision) {
+ case NpadRevision::Revision1:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
+ Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::SystemExt |
+ Core::HID::NpadStyleSet::System;
+ break;
+ case NpadRevision::Revision2:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
+ Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
+ Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
+ break;
+ case NpadRevision::Revision3:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
+ Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
+ Core::HID::NpadStyleSet::HandheldLark | Core::HID::NpadStyleSet::Lucia |
+ Core::HID::NpadStyleSet::Lagoon | Core::HID::NpadStyleSet::Lager |
+ Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
+ break;
+ default:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::SystemExt |
+ Core::HID::NpadStyleSet::System;
+ break;
+ }
+
+ out_style_set = out_style_set & mask;
+ return ResultSuccess;
+}
+
+Result NPadResource::GetAvailableStyleset(Core::HID::NpadStyleSet& out_style_set, u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ auto& data = state[aruid_index].data;
+ if (!data.GetNpadStatus().is_supported_styleset_set) {
+ return ResultUndefinedStyleset;
+ }
+
+ Core::HID::NpadStyleSet mask{Core::HID::NpadStyleSet::None};
+ out_style_set = data.GetSupportedNpadStyleSet();
+
+ switch (state[aruid_index].npad_revision) {
+ case NpadRevision::Revision1:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
+ Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::SystemExt |
+ Core::HID::NpadStyleSet::System;
+ break;
+ case NpadRevision::Revision2:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
+ Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
+ Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
+ break;
+ case NpadRevision::Revision3:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
+ Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
+ Core::HID::NpadStyleSet::HandheldLark | Core::HID::NpadStyleSet::Lucia |
+ Core::HID::NpadStyleSet::Lagoon | Core::HID::NpadStyleSet::Lager |
+ Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
+ break;
+ default:
+ mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
+ Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
+ Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::SystemExt |
+ Core::HID::NpadStyleSet::System;
+ break;
+ }
+
+ out_style_set = out_style_set & mask;
+ return ResultSuccess;
+}
+
+NpadRevision NPadResource::GetNpadRevision(u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return NpadRevision::Revision0;
+ }
+
+ return state[aruid_index].npad_revision;
+}
+
+Result NPadResource::IsSupportedNpadStyleSet(bool& is_set, u64 aruid) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ is_set = state[aruid_index].data.GetNpadStatus().is_supported_styleset_set.Value() != 0;
+ return ResultSuccess;
+}
+
+Result NPadResource::SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.SetNpadJoyHoldType(hold_type);
+ if (active_data_aruid == aruid) {
+ active_data.SetNpadJoyHoldType(hold_type);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::GetNpadJoyHoldType(NpadJoyHoldType& hold_type, u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ auto& data = state[aruid_index].data;
+ if (data.GetNpadStatus().is_policy || data.GetNpadStatus().is_full_policy) {
+ hold_type = active_data.GetNpadJoyHoldType();
+ return ResultSuccess;
+ }
+ hold_type = data.GetNpadJoyHoldType();
+ return ResultSuccess;
+}
+
+Result NPadResource::SetNpadHandheldActivationMode(u64 aruid,
+ NpadHandheldActivationMode activation_mode) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.SetHandheldActivationMode(activation_mode);
+ if (active_data_aruid == aruid) {
+ active_data.SetHandheldActivationMode(activation_mode);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::GetNpadHandheldActivationMode(NpadHandheldActivationMode& activation_mode,
+ u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ activation_mode = state[aruid_index].data.GetHandheldActivationMode();
+ return ResultSuccess;
+}
+
+Result NPadResource::SetSupportedNpadIdType(
+ u64 aruid, std::span<const Core::HID::NpadIdType> supported_npad_list) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+ if (supported_npad_list.size() > MaxSupportedNpadIdTypes) {
+ return ResultInvalidArraySize;
+ }
+
+ Result result = state[aruid_index].data.SetSupportedNpadIdType(supported_npad_list);
+ if (result.IsSuccess() && active_data_aruid == aruid) {
+ result = active_data.SetSupportedNpadIdType(supported_npad_list);
+ }
+
+ return result;
+}
+
+bool NPadResource::IsControllerSupported(u64 aruid, Core::HID::NpadStyleIndex style_index) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return false;
+ }
+ return state[aruid_index].data.IsNpadStyleIndexSupported(style_index);
+}
+
+Result NPadResource::SetLrAssignmentMode(u64 aruid, bool is_enabled) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.SetLrAssignmentMode(is_enabled);
+ if (active_data_aruid == aruid) {
+ active_data.SetLrAssignmentMode(is_enabled);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::GetLrAssignmentMode(bool& is_enabled, u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ is_enabled = state[aruid_index].data.GetLrAssignmentMode();
+ return ResultSuccess;
+}
+
+Result NPadResource::SetAssigningSingleOnSlSrPress(u64 aruid, bool is_enabled) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.SetAssigningSingleOnSlSrPress(is_enabled);
+ if (active_data_aruid == aruid) {
+ active_data.SetAssigningSingleOnSlSrPress(is_enabled);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::IsAssigningSingleOnSlSrPressEnabled(bool& is_enabled, u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ is_enabled = state[aruid_index].data.GetAssigningSingleOnSlSrPress();
+ return ResultSuccess;
+}
+
+Result NPadResource::AcquireNpadStyleSetUpdateEventHandle(u64 aruid,
+ Kernel::KReadableEvent** out_event,
+ Core::HID::NpadIdType npad_id) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ auto& controller_state = state[aruid_index].controller_state[NpadIdTypeToIndex(npad_id)];
+ if (!controller_state.is_styleset_update_event_initialized) {
+ // Auto clear = true
+ controller_state.style_set_update_event =
+ service_context.CreateEvent("NpadResource:StylesetUpdateEvent");
+
+ // Assume creating the event succeeds otherwise crash the system here
+ controller_state.is_styleset_update_event_initialized = true;
+ }
+
+ *out_event = &controller_state.style_set_update_event->GetReadableEvent();
+
+ if (controller_state.is_styleset_update_event_initialized) {
+ controller_state.style_set_update_event->Signal();
+ }
+
+ return ResultSuccess;
+}
+
+Result NPadResource::SignalStyleSetUpdateEvent(u64 aruid, Core::HID::NpadIdType npad_id) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+ auto controller = state[aruid_index].controller_state[NpadIdTypeToIndex(npad_id)];
+ if (controller.is_styleset_update_event_initialized) {
+ controller.style_set_update_event->Signal();
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::GetHomeProtectionEnabled(bool& is_enabled, u64 aruid,
+ Core::HID::NpadIdType npad_id) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ is_enabled = state[aruid_index].data.GetHomeProtectionEnabled(npad_id);
+ return ResultSuccess;
+}
+
+Result NPadResource::SetHomeProtectionEnabled(u64 aruid, Core::HID::NpadIdType npad_id,
+ bool is_enabled) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.SetHomeProtectionEnabled(is_enabled, npad_id);
+ if (active_data_aruid == aruid) {
+ active_data.SetHomeProtectionEnabled(is_enabled, npad_id);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.SetNpadAnalogStickUseCenterClamp(is_enabled);
+ if (active_data_aruid == aruid) {
+ active_data.SetNpadAnalogStickUseCenterClamp(is_enabled);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::SetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id, std::size_t index,
+ Core::HID::NpadButton button_config) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].button_config[NpadIdTypeToIndex(npad_id)][index] = button_config;
+ return ResultSuccess;
+}
+
+Core::HID::NpadButton NPadResource::GetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id,
+ std::size_t index, Core::HID::NpadButton mask,
+ bool is_enabled) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return Core::HID::NpadButton::None;
+ }
+
+ auto& button_config = state[aruid_index].button_config[NpadIdTypeToIndex(npad_id)][index];
+ if (is_enabled) {
+ button_config = button_config | mask;
+ return button_config;
+ }
+
+ button_config = Core::HID::NpadButton::None;
+ return Core::HID::NpadButton::None;
+}
+
+void NPadResource::ResetButtonConfig() {
+ for (auto& selected_state : state) {
+ selected_state.button_config = {};
+ }
+}
+
+Result NPadResource::SetNpadCaptureButtonAssignment(u64 aruid,
+ Core::HID::NpadStyleSet npad_style_set,
+ Core::HID::NpadButton button_assignment) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ // Must be a power of two
+ const auto raw_styleset = static_cast<u32>(npad_style_set);
+ if (raw_styleset == 0 && (raw_styleset & (raw_styleset - 1)) != 0) {
+ return ResultMultipleStyleSetSelected;
+ }
+
+ std::size_t style_index{};
+ Core::HID::NpadStyleSet style_selected{};
+ for (style_index = 0; style_index < StyleIndexCount; ++style_index) {
+ style_selected = GetStylesetByIndex(style_index);
+ if (npad_style_set == style_selected) {
+ break;
+ }
+ }
+
+ if (style_selected == Core::HID::NpadStyleSet::None) {
+ return ResultMultipleStyleSetSelected;
+ }
+
+ state[aruid_index].data.SetCaptureButtonAssignment(button_assignment, style_index);
+ if (active_data_aruid == aruid) {
+ active_data.SetCaptureButtonAssignment(button_assignment, style_index);
+ }
+ return ResultSuccess;
+}
+
+Result NPadResource::ClearNpadCaptureButtonAssignment(u64 aruid) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ for (std::size_t i = 0; i < StyleIndexCount; i++) {
+ state[aruid_index].data.SetCaptureButtonAssignment(Core::HID::NpadButton::None, i);
+ if (active_data_aruid == aruid) {
+ active_data.SetCaptureButtonAssignment(Core::HID::NpadButton::None, i);
+ }
+ }
+ return ResultSuccess;
+}
+
+std::size_t NPadResource::GetNpadCaptureButtonAssignment(std::span<Core::HID::NpadButton> out_list,
+ u64 aruid) const {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return 0;
+ }
+ return state[aruid_index].data.GetNpadCaptureButtonAssignmentList(out_list);
+}
+
+void NPadResource::SetNpadRevision(u64 aruid, NpadRevision revision) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return;
+ }
+
+ state[aruid_index].npad_revision = revision;
+}
+
+Result NPadResource::SetNpadSystemExtStateEnabled(u64 aruid, bool is_enabled) {
+ const u64 aruid_index = GetIndexFromAruid(aruid);
+ if (aruid_index >= AruidIndexMax) {
+ return ResultNpadNotConnected;
+ }
+
+ state[aruid_index].data.SetNpadAnalogStickUseCenterClamp(is_enabled);
+ if (active_data_aruid == aruid) {
+ active_data.SetNpadAnalogStickUseCenterClamp(is_enabled);
+ }
+ return ResultSuccess;
+}
+
+} // namespace Service::HID
diff --git a/src/hid_core/resources/npad/npad_resource.h b/src/hid_core/resources/npad/npad_resource.h
new file mode 100644
index 000000000..aed89eec6
--- /dev/null
+++ b/src/hid_core/resources/npad/npad_resource.h
@@ -0,0 +1,132 @@
+// SPDX-FileCopyrightText: Copyright 2023 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 "core/hle/service/kernel_helpers.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/npad/npad_data.h"
+#include "hid_core/resources/npad/npad_types.h"
+
+namespace Core {
+class System;
+}
+
+namespace Kernel {
+class KReadableEvent;
+}
+
+namespace Service::HID {
+struct DataStatusFlag;
+
+struct NpadControllerState {
+ bool is_styleset_update_event_initialized{};
+ INSERT_PADDING_BYTES(0x7);
+ Kernel::KEvent* style_set_update_event{nullptr};
+ INSERT_PADDING_BYTES(0x27);
+};
+
+struct NpadState {
+ DataStatusFlag flag{};
+ u64 aruid{};
+ NPadData data{};
+ std::array<std::array<Core::HID::NpadButton, StyleIndexCount>, MaxSupportedNpadIdTypes>
+ button_config;
+ std::array<NpadControllerState, MaxSupportedNpadIdTypes> controller_state;
+ NpadRevision npad_revision;
+};
+
+/// Handles Npad request from HID interfaces
+class NPadResource final {
+public:
+ explicit NPadResource(KernelHelpers::ServiceContext& context);
+ ~NPadResource();
+
+ NPadData* GetActiveData();
+ u64 GetActiveDataAruid();
+
+ Result RegisterAppletResourceUserId(u64 aruid);
+ void UnregisterAppletResourceUserId(u64 aruid);
+
+ void DestroyStyleSetUpdateEvents(u64 aruid);
+
+ Result Activate(u64 aruid);
+ Result Activate();
+ Result Deactivate();
+
+ void SetAppletResourceUserId(u64 aruid);
+ std::size_t GetIndexFromAruid(u64 aruid) const;
+
+ Result ApplyNpadSystemCommonPolicy(u64 aruid, bool is_full_policy);
+ Result ClearNpadSystemCommonPolicy(u64 aruid);
+
+ Result SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet style_set);
+ Result GetSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_Set, u64 aruid) const;
+ Result GetMaskedSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_set, u64 aruid) const;
+ Result GetAvailableStyleset(Core::HID::NpadStyleSet& out_style_set, u64 aruid) const;
+
+ NpadRevision GetNpadRevision(u64 aruid) const;
+ void SetNpadRevision(u64 aruid, NpadRevision revision);
+
+ Result IsSupportedNpadStyleSet(bool& is_set, u64 aruid);
+
+ Result SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type);
+ Result GetNpadJoyHoldType(NpadJoyHoldType& hold_type, u64 aruid) const;
+
+ Result SetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode activation_mode);
+ Result GetNpadHandheldActivationMode(NpadHandheldActivationMode& activation_mode,
+ u64 aruid) const;
+
+ Result SetSupportedNpadIdType(u64 aruid,
+ std::span<const Core::HID::NpadIdType> supported_npad_list);
+ bool IsControllerSupported(u64 aruid, Core::HID::NpadStyleIndex style_index) const;
+
+ Result SetLrAssignmentMode(u64 aruid, bool is_enabled);
+ Result GetLrAssignmentMode(bool& is_enabled, u64 aruid) const;
+
+ Result SetAssigningSingleOnSlSrPress(u64 aruid, bool is_enabled);
+ Result IsAssigningSingleOnSlSrPressEnabled(bool& is_enabled, u64 aruid) const;
+
+ Result AcquireNpadStyleSetUpdateEventHandle(u64 aruid, Kernel::KReadableEvent** out_event,
+ Core::HID::NpadIdType npad_id);
+ Result SignalStyleSetUpdateEvent(u64 aruid, Core::HID::NpadIdType npad_id);
+
+ Result GetHomeProtectionEnabled(bool& is_enabled, u64 aruid,
+ Core::HID::NpadIdType npad_id) const;
+ Result SetHomeProtectionEnabled(u64 aruid, Core::HID::NpadIdType npad_id, bool is_enabled);
+
+ Result SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled);
+
+ Result SetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id, std::size_t index,
+ Core::HID::NpadButton button_config);
+ Core::HID::NpadButton GetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id,
+ std::size_t index, Core::HID::NpadButton mask,
+ bool is_enabled);
+ void ResetButtonConfig();
+
+ Result SetNpadCaptureButtonAssignment(u64 aruid, Core::HID::NpadStyleSet npad_style_set,
+ Core::HID::NpadButton button_assignment);
+ Result ClearNpadCaptureButtonAssignment(u64 aruid);
+ std::size_t GetNpadCaptureButtonAssignment(std::span<Core::HID::NpadButton> out_list,
+ u64 aruid) const;
+
+ Result SetNpadSystemExtStateEnabled(u64 aruid, bool is_enabled);
+
+private:
+ NPadData active_data{};
+ AruidRegisterList registration_list{};
+ std::array<NpadState, AruidIndexMax> state{};
+ u64 active_data_aruid{};
+ NpadJoyHoldType default_hold_type{};
+ s32 ref_counter{};
+
+ KernelHelpers::ServiceContext& service_context;
+};
+} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/types/npad_types.h b/src/hid_core/resources/npad/npad_types.h
index a5ce2562b..a02f9cf16 100644
--- a/src/core/hle/service/hid/controllers/types/npad_types.h
+++ b/src/hid_core/resources/npad/npad_types.h
@@ -6,10 +6,11 @@
#include "common/bit_field.h"
#include "common/common_funcs.h"
#include "common/common_types.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
namespace Service::HID {
-static constexpr std::size_t NpadCount = 10;
+static constexpr std::size_t MaxSupportedNpadIdTypes = 10;
+static constexpr std::size_t StyleIndexCount = 7;
// This is nn::hid::NpadJoyHoldType
enum class NpadJoyHoldType : u64 {
diff --git a/src/core/hle/service/hid/controllers/palma.cpp b/src/hid_core/resources/palma/palma.cpp
index aa0454b5e..ea4a291fd 100644
--- a/src/core/hle/service/hid/controllers/palma.cpp
+++ b/src/hid_core/resources/palma/palma.cpp
@@ -2,13 +2,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h"
-#include "core/hle/service/hid/controllers/palma.h"
#include "core/hle/service/kernel_helpers.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/palma/palma.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/palma.h b/src/hid_core/resources/palma/palma.h
index 73884230d..60259c3d8 100644
--- a/src/core/hle/service/hid/controllers/palma.h
+++ b/src/hid_core/resources/palma/palma.h
@@ -6,8 +6,9 @@
#include <array>
#include "common/common_funcs.h"
#include "common/typed_address.h"
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/errors.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/controller_base.h"
namespace Kernel {
class KEvent;
diff --git a/src/core/hle/service/hid/ring_lifo.h b/src/hid_core/resources/ring_lifo.h
index 0816784e0..0816784e0 100644
--- a/src/core/hle/service/hid/ring_lifo.h
+++ b/src/hid_core/resources/ring_lifo.h
diff --git a/src/core/hle/service/hid/controllers/types/shared_memory_format.h b/src/hid_core/resources/shared_memory_format.h
index 2986c113e..2ae0004ba 100644
--- a/src/core/hle/service/hid/controllers/types/shared_memory_format.h
+++ b/src/hid_core/resources/shared_memory_format.h
@@ -6,13 +6,13 @@
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/vector_math.h"
-#include "core/hid/hid_types.h"
-#include "core/hle/service/hid//controllers/types/debug_pad_types.h"
-#include "core/hle/service/hid//controllers/types/keyboard_types.h"
-#include "core/hle/service/hid//controllers/types/mouse_types.h"
-#include "core/hle/service/hid//controllers/types/npad_types.h"
-#include "core/hle/service/hid//controllers/types/touch_types.h"
-#include "core/hle/service/hid/ring_lifo.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/debug_pad/debug_pad_types.h"
+#include "hid_core/resources/keyboard/keyboard_types.h"
+#include "hid_core/resources/mouse/mouse_types.h"
+#include "hid_core/resources/npad/npad_types.h"
+#include "hid_core/resources/ring_lifo.h"
+#include "hid_core/resources/touch_screen/touch_types.h"
namespace Service::HID {
static const std::size_t HidEntryCount = 17;
@@ -171,7 +171,7 @@ static_assert(sizeof(NpadSharedMemoryEntry) == 0x5000, "NpadSharedMemoryEntry is
// This is nn::hid::detail::NpadSharedMemoryFormat
struct NpadSharedMemoryFormat {
- std::array<NpadSharedMemoryEntry, NpadCount> npad_entry;
+ std::array<NpadSharedMemoryEntry, MaxSupportedNpadIdTypes> npad_entry;
};
static_assert(sizeof(NpadSharedMemoryFormat) == 0x32000,
"NpadSharedMemoryFormat is an invalid size");
diff --git a/src/core/hle/service/hid/controllers/shared_memory_holder.cpp b/src/hid_core/resources/shared_memory_holder.cpp
index 0bc5169c6..ada593d8b 100644
--- a/src/core/hle/service/hid/controllers/shared_memory_holder.cpp
+++ b/src/hid_core/resources/shared_memory_holder.cpp
@@ -3,10 +3,10 @@
#include "core/core.h"
#include "core/hle/kernel/k_shared_memory.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/shared_memory_holder.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
-#include "core/hle/service/hid/errors.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/shared_memory_holder.h"
namespace Service::HID {
SharedMemoryHolder::SharedMemoryHolder() {}
diff --git a/src/core/hle/service/hid/controllers/shared_memory_holder.h b/src/hid_core/resources/shared_memory_holder.h
index 943407c00..943407c00 100644
--- a/src/core/hle/service/hid/controllers/shared_memory_holder.h
+++ b/src/hid_core/resources/shared_memory_holder.h
diff --git a/src/core/hle/service/hid/controllers/console_six_axis.cpp b/src/hid_core/resources/six_axis/console_six_axis.cpp
index 8eba2c292..4f733cc76 100644
--- a/src/core/hle/service/hid/controllers/console_six_axis.cpp
+++ b/src/hid_core/resources/six_axis/console_six_axis.cpp
@@ -2,10 +2,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
-#include "core/hid/emulated_console.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/console_six_axis.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/frontend/emulated_console.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/six_axis/console_six_axis.h"
namespace Service::HID {
@@ -20,10 +20,11 @@ void ConsoleSixAxis::OnInit() {}
void ConsoleSixAxis::OnRelease() {}
void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/console_six_axis.h b/src/hid_core/resources/six_axis/console_six_axis.h
index e3351f83c..013b2e93b 100644
--- a/src/core/hle/service/hid/controllers/console_six_axis.h
+++ b/src/hid_core/resources/six_axis/console_six_axis.h
@@ -3,7 +3,7 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/resources/controller_base.h"
namespace Core::HID {
class EmulatedConsole;
diff --git a/src/core/hle/service/hid/controllers/seven_six_axis.cpp b/src/hid_core/resources/six_axis/seven_six_axis.cpp
index 495568484..d84ef31e1 100644
--- a/src/core/hle/service/hid/controllers/seven_six_axis.cpp
+++ b/src/hid_core/resources/six_axis/seven_six_axis.cpp
@@ -6,11 +6,11 @@
#include "core/core.h"
#include "core/core_timing.h"
#include "core/frontend/emu_window.h"
-#include "core/hid/emulated_console.h"
-#include "core/hid/emulated_devices.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/seven_six_axis.h"
#include "core/memory.h"
+#include "hid_core/frontend/emulated_console.h"
+#include "hid_core/frontend/emulated_devices.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/six_axis/seven_six_axis.h"
namespace Service::HID {
SevenSixAxis::SevenSixAxis(Core::System& system_)
diff --git a/src/core/hle/service/hid/controllers/seven_six_axis.h b/src/hid_core/resources/six_axis/seven_six_axis.h
index 40e3f5d12..0a26c77c9 100644
--- a/src/core/hle/service/hid/controllers/seven_six_axis.h
+++ b/src/hid_core/resources/six_axis/seven_six_axis.h
@@ -6,8 +6,8 @@
#include "common/common_types.h"
#include "common/quaternion.h"
#include "common/typed_address.h"
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/ring_lifo.h"
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/ring_lifo.h"
namespace Core {
class System;
diff --git a/src/core/hle/service/hid/controllers/six_axis.cpp b/src/hid_core/resources/six_axis/six_axis.cpp
index a5a67dea6..8a9677c50 100644
--- a/src/core/hle/service/hid/controllers/six_axis.cpp
+++ b/src/hid_core/resources/six_axis/six_axis.cpp
@@ -3,13 +3,13 @@
#include "common/common_types.h"
#include "core/core_timing.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/npad.h"
-#include "core/hle/service/hid/controllers/six_axis.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
-#include "core/hle/service/hid/errors.h"
-#include "core/hle/service/hid/hid_util.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_result.h"
+#include "hid_core/hid_util.h"
+#include "hid_core/resources/npad/npad.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/six_axis/six_axis.h"
namespace Service::HID {
@@ -27,10 +27,11 @@ void SixAxis::OnInit() {}
void SixAxis::OnRelease() {}
void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/six_axis.h b/src/hid_core/resources/six_axis/six_axis.h
index 4c4f5dc7b..1054e1b27 100644
--- a/src/core/hle/service/hid/controllers/six_axis.h
+++ b/src/hid_core/resources/six_axis/six_axis.h
@@ -4,9 +4,9 @@
#pragma once
#include "common/common_types.h"
-#include "core/hid/hid_types.h"
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/ring_lifo.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/ring_lifo.h"
namespace Core::HID {
class EmulatedController;
diff --git a/src/core/hle/service/hid/controllers/capture_button.cpp b/src/hid_core/resources/system_buttons/capture_button.cpp
index 8b486fcb5..70973ae25 100644
--- a/src/core/hle/service/hid/controllers/capture_button.cpp
+++ b/src/hid_core/resources/system_buttons/capture_button.cpp
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/capture_button.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/system_buttons/capture_button.h"
namespace Service::HID {
@@ -21,10 +21,11 @@ void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return;
}
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/capture_button.h b/src/hid_core/resources/system_buttons/capture_button.h
index dcc4715c5..ad95d7cad 100644
--- a/src/core/hle/service/hid/controllers/capture_button.h
+++ b/src/hid_core/resources/system_buttons/capture_button.h
@@ -3,7 +3,7 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/resources/controller_base.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/home_button.cpp b/src/hid_core/resources/system_buttons/home_button.cpp
index 71dd9bc08..f9c1f44b5 100644
--- a/src/core/hle/service/hid/controllers/home_button.cpp
+++ b/src/hid_core/resources/system_buttons/home_button.cpp
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/home_button.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/system_buttons/home_button.h"
namespace Service::HID {
@@ -21,10 +21,11 @@ void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return;
}
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/home_button.h b/src/hid_core/resources/system_buttons/home_button.h
index e91c2aa5d..ecf8327f4 100644
--- a/src/core/hle/service/hid/controllers/home_button.h
+++ b/src/hid_core/resources/system_buttons/home_button.h
@@ -3,7 +3,7 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/resources/controller_base.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/sleep_button.cpp b/src/hid_core/resources/system_buttons/sleep_button.cpp
index 978dc4c1f..22adf501f 100644
--- a/src/core/hle/service/hid/controllers/sleep_button.cpp
+++ b/src/hid_core/resources/system_buttons/sleep_button.cpp
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/sleep_button.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/system_buttons/sleep_button.h"
namespace Service::HID {
@@ -21,10 +21,11 @@ void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return;
}
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/sleep_button.h b/src/hid_core/resources/system_buttons/sleep_button.h
index 59964bf63..f9ed38c33 100644
--- a/src/core/hle/service/hid/controllers/sleep_button.h
+++ b/src/hid_core/resources/system_buttons/sleep_button.h
@@ -3,7 +3,7 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/resources/controller_base.h"
namespace Service::HID {
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/hid_core/resources/touch_screen/gesture.cpp
index 6e686fe65..0ecc0941f 100644
--- a/src/core/hle/service/hid/controllers/gesture.cpp
+++ b/src/hid_core/resources/touch_screen/gesture.cpp
@@ -4,11 +4,11 @@
#include "common/math_util.h"
#include "common/settings.h"
#include "core/frontend/emu_window.h"
-#include "core/hid/emulated_console.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/gesture.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/frontend/emulated_console.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/touch_screen/gesture.h"
namespace Service::HID {
// HW is around 700, value is set to 400 to make it easier to trigger with mouse
@@ -28,10 +28,11 @@ Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) {
Gesture::~Gesture() = default;
void Gesture::OnInit() {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
@@ -44,10 +45,11 @@ void Gesture::OnInit() {
void Gesture::OnRelease() {}
void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/hid_core/resources/touch_screen/gesture.h
index 78da1552a..32e9a8690 100644
--- a/src/core/hle/service/hid/controllers/gesture.h
+++ b/src/hid_core/resources/touch_screen/gesture.h
@@ -6,8 +6,8 @@
#include <array>
#include "common/common_types.h"
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/controllers/types/touch_types.h"
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/touch_screen/touch_types.h"
namespace Core::HID {
class EmulatedConsole;
diff --git a/src/core/hle/service/hid/controllers/types/gesture_types.h b/src/hid_core/resources/touch_screen/gesture_types.h
index b4f034cd3..b4f034cd3 100644
--- a/src/core/hle/service/hid/controllers/types/gesture_types.h
+++ b/src/hid_core/resources/touch_screen/gesture_types.h
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/hid_core/resources/touch_screen/touch_screen.cpp
index 291dc707e..48d956c51 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.cpp
+++ b/src/hid_core/resources/touch_screen/touch_screen.cpp
@@ -6,11 +6,11 @@
#include "common/settings.h"
#include "core/core_timing.h"
#include "core/frontend/emu_window.h"
-#include "core/hid/emulated_console.h"
-#include "core/hid/hid_core.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/touchscreen.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
+#include "hid_core/frontend/emulated_console.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/touch_screen/touch_screen.h"
namespace Service::HID {
@@ -30,7 +30,7 @@ void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/hid_core/resources/touch_screen/touch_screen.h
index 945d359be..4b3824742 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.h
+++ b/src/hid_core/resources/touch_screen/touch_screen.h
@@ -5,9 +5,9 @@
#include <array>
-#include "core/hid/hid_types.h"
-#include "core/hle/service/hid/controllers/controller_base.h"
-#include "core/hle/service/hid/controllers/types/touch_types.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/touch_screen/touch_types.h"
namespace Core::HID {
class EmulatedConsole;
diff --git a/src/core/hle/service/hid/controllers/types/touch_types.h b/src/hid_core/resources/touch_screen/touch_types.h
index efeaa796d..97ee847da 100644
--- a/src/core/hle/service/hid/controllers/types/touch_types.h
+++ b/src/hid_core/resources/touch_screen/touch_types.h
@@ -10,7 +10,7 @@
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/point.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
namespace Service::HID {
static constexpr std::size_t MAX_FINGERS = 16;
diff --git a/src/core/hle/service/hid/controllers/unique_pad.cpp b/src/hid_core/resources/unique_pad/unique_pad.cpp
index 8230501a5..892bbe3c9 100644
--- a/src/core/hle/service/hid/controllers/unique_pad.cpp
+++ b/src/hid_core/resources/unique_pad/unique_pad.cpp
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
-#include "core/hle/service/hid/controllers/applet_resource.h"
-#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
-#include "core/hle/service/hid/controllers/unique_pad.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/shared_memory_format.h"
+#include "hid_core/resources/unique_pad/unique_pad.h"
namespace Service::HID {
@@ -24,7 +24,7 @@ void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
- if (data == nullptr) {
+ if (data == nullptr || !data->flag.is_assigned) {
return;
}
diff --git a/src/core/hle/service/hid/controllers/unique_pad.h b/src/hid_core/resources/unique_pad/unique_pad.h
index 966368264..674ad1691 100644
--- a/src/core/hle/service/hid/controllers/unique_pad.h
+++ b/src/hid_core/resources/unique_pad/unique_pad.h
@@ -3,7 +3,7 @@
#pragma once
-#include "core/hle/service/hid/controllers/controller_base.h"
+#include "hid_core/resources/controller_base.h"
namespace Service::HID {
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt
index 5c127c8ef..d2fbea488 100644
--- a/src/input_common/CMakeLists.txt
+++ b/src/input_common/CMakeLists.txt
@@ -87,7 +87,7 @@ if (ENABLE_LIBUSB)
endif()
create_target_directory_groups(input_common)
-target_link_libraries(input_common PUBLIC core PRIVATE common Boost::headers)
+target_link_libraries(input_common PUBLIC hid_core PRIVATE common Boost::headers)
if (YUZU_USE_PRECOMPILED_HEADERS)
target_precompile_headers(input_common PRIVATE precompiled_headers.h)
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
index 6e940bd5a..ad39f44c3 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
@@ -449,7 +449,7 @@ void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& inde
}
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
- std::string_view coords, std::string_view offset, std::string_view lod,
+ std::string_view coords, const IR::Value& offset, std::string_view lod,
std::string_view ms) {
const auto info{inst.Flags<IR::TextureInstInfo>()};
if (info.has_bias) {
@@ -470,9 +470,9 @@ void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
const auto int_coords{CoordsCastToInt(coords, info)};
if (!ms.empty()) {
ctx.Add("{}=texelFetch({},{},int({}));", texel, texture, int_coords, ms);
- } else if (!offset.empty()) {
+ } else if (!offset.IsEmpty()) {
ctx.Add("{}=texelFetchOffset({},{},int({}),{});", texel, texture, int_coords, lod,
- CoordsCastToInt(offset, info));
+ GetOffsetVec(ctx, offset));
} else {
if (info.type == TextureType::Buffer) {
ctx.Add("{}=texelFetch({},int({}));", texel, texture, coords);
@@ -485,10 +485,10 @@ void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
if (!ms.empty()) {
throw NotImplementedException("EmitImageFetch Sparse MSAA samples");
}
- if (!offset.empty()) {
+ if (!offset.IsEmpty()) {
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchOffsetARB({},{},int({}),{},{}));",
- *sparse_inst, texture, CastToIntVec(coords, info), lod,
- CastToIntVec(offset, info), texel);
+ *sparse_inst, texture, CastToIntVec(coords, info), lod, GetOffsetVec(ctx, offset),
+ texel);
} else {
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchARB({},{},int({}),{}));",
*sparse_inst, texture, CastToIntVec(coords, info), lod, texel);
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
index 8d0a65047..acebaa785 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
@@ -651,7 +651,7 @@ void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& inde
std::string_view coords, const IR::Value& offset, const IR::Value& offset2,
std::string_view dref);
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
- std::string_view coords, std::string_view offset, std::string_view lod,
+ std::string_view coords, const IR::Value& offset, std::string_view lod,
std::string_view ms);
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
std::string_view lod, const IR::Value& skip_mips);
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp
index 89ebab08e..0442adc83 100644
--- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp
+++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp
@@ -1440,7 +1440,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
if (profile.support_vertex_instance_id) {
instance_id = DefineInput(*this, U32[1], true, spv::BuiltIn::InstanceId);
if (loads[IR::Attribute::BaseInstance]) {
- base_instance = DefineInput(*this, U32[1], true, spv::BuiltIn::BaseVertex);
+ base_instance = DefineInput(*this, U32[1], true, spv::BuiltIn::BaseInstance);
}
} else {
instance_index = DefineInput(*this, U32[1], true, spv::BuiltIn::InstanceIndex);
diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp
index 993438a27..9be1b0805 100644
--- a/src/video_core/renderer_opengl/gl_device.cpp
+++ b/src/video_core/renderer_opengl/gl_device.cpp
@@ -195,9 +195,9 @@ Device::Device(Core::Frontend::EmuWindow& emu_window) {
has_texture_shadow_lod = HasExtension(extensions, "GL_EXT_texture_shadow_lod");
has_astc = !has_slow_software_astc && IsASTCSupported();
has_variable_aoffi = TestVariableAoffi();
- has_component_indexing_bug = is_amd;
+ has_component_indexing_bug = false;
has_precise_bug = TestPreciseBug();
- has_broken_texture_view_formats = is_amd || (!is_linux && is_intel);
+ has_broken_texture_view_formats = (!is_linux && is_intel);
has_nv_viewport_array2 = GLAD_GL_NV_viewport_array2;
has_derivative_control = GLAD_GL_ARB_derivative_control;
has_vertex_buffer_unified_memory = GLAD_GL_NV_vertex_buffer_unified_memory;
@@ -238,10 +238,11 @@ Device::Device(Core::Frontend::EmuWindow& emu_window) {
has_lmem_perf_bug = is_nvidia;
strict_context_required = emu_window.StrictContextRequired();
- // Blocks AMD and Intel OpenGL drivers on Windows from using asynchronous shader compilation.
+ // Blocks Intel OpenGL drivers on Windows from using asynchronous shader compilation.
// Blocks EGL on Wayland from using asynchronous shader compilation.
- use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue() &&
- !(is_amd || (is_intel && !is_linux)) && !strict_context_required;
+ const bool blacklist_async_shaders = (is_intel && !is_linux) || strict_context_required;
+ use_asynchronous_shaders =
+ Settings::values.use_asynchronous_shaders.GetValue() && !blacklist_async_shaders;
use_driver_cache = is_nvidia;
supports_conditional_barriers = !is_intel;
diff --git a/src/yuzu/applets/qt_controller.cpp b/src/yuzu/applets/qt_controller.cpp
index 9e5319716..8b340ee6c 100644
--- a/src/yuzu/applets/qt_controller.cpp
+++ b/src/yuzu/applets/qt_controller.cpp
@@ -9,11 +9,11 @@
#include "common/settings_enums.h"
#include "common/string_util.h"
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
-#include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/sm/sm.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/npad/npad.h"
#include "ui_qt_controller.h"
#include "yuzu/applets/qt_controller.h"
#include "yuzu/configuration/configure_input.h"
diff --git a/src/yuzu/applets/qt_software_keyboard.cpp b/src/yuzu/applets/qt_software_keyboard.cpp
index 4ae49506d..bbe17c35e 100644
--- a/src/yuzu/applets/qt_software_keyboard.cpp
+++ b/src/yuzu/applets/qt_software_keyboard.cpp
@@ -9,10 +9,10 @@
#include "common/settings.h"
#include "common/string_util.h"
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
-#include "core/hid/input_interpreter.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/frontend/input_interpreter.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
#include "ui_qt_software_keyboard.h"
#include "yuzu/applets/qt_software_keyboard.h"
#include "yuzu/main.h"
diff --git a/src/yuzu/applets/qt_web_browser.cpp b/src/yuzu/applets/qt_web_browser.cpp
index 28acc0ff8..34c5fd3be 100644
--- a/src/yuzu/applets/qt_web_browser.cpp
+++ b/src/yuzu/applets/qt_web_browser.cpp
@@ -13,7 +13,7 @@
#include <QWebEngineSettings>
#include <QWebEngineUrlScheme>
-#include "core/hid/input_interpreter.h"
+#include "hid_core/frontend/input_interpreter.h"
#include "yuzu/applets/qt_web_browser_scripts.h"
#endif
diff --git a/src/yuzu/configuration/configure_debug_controller.cpp b/src/yuzu/configuration/configure_debug_controller.cpp
index 42abe9119..74208d1cc 100644
--- a/src/yuzu/configuration/configure_debug_controller.cpp
+++ b/src/yuzu/configuration/configure_debug_controller.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include "core/hid/hid_core.h"
+#include "hid_core/hid_core.h"
#include "ui_configure_debug_controller.h"
#include "yuzu/configuration/configure_debug_controller.h"
#include "yuzu/configuration/configure_input_player.h"
diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp
index 76fc33e49..3d18670ce 100644
--- a/src/yuzu/configuration/configure_hotkeys.cpp
+++ b/src/yuzu/configuration/configure_hotkeys.cpp
@@ -6,8 +6,8 @@
#include <QStandardItemModel>
#include <QTimer>
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "frontend_common/config.h"
#include "ui_configure_hotkeys.h"
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index 02e23cce6..49ec52546 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -7,12 +7,12 @@
#include "common/settings.h"
#include "common/settings_enums.h"
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applet_ae.h"
#include "core/hle/service/am/applet_oe.h"
#include "core/hle/service/sm/sm.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "ui_configure_input.h"
#include "ui_configure_input_advanced.h"
#include "ui_configure_input_player.h"
diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp
index 441cea3f6..d6c4e09ec 100644
--- a/src/yuzu/configuration/configure_input_advanced.cpp
+++ b/src/yuzu/configuration/configure_input_advanced.cpp
@@ -4,8 +4,8 @@
#include <QColorDialog>
#include "common/settings.h"
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "ui_configure_input_advanced.h"
#include "yuzu/configuration/configure_input_advanced.h"
diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp
index 8d9f65a05..eea7ec369 100644
--- a/src/yuzu/configuration/configure_input_per_game.cpp
+++ b/src/yuzu/configuration/configure_input_per_game.cpp
@@ -3,9 +3,9 @@
#include "common/settings.h"
#include "core/core.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
#include "frontend_common/config.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "ui_configure_input_per_game.h"
#include "yuzu/configuration/configure_input_per_game.h"
#include "yuzu/configuration/input_profiles.h"
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 0f7b3714e..f3552191a 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -13,10 +13,10 @@
#include "common/assert.h"
#include "common/param_package.h"
#include "configuration/qt_config.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
#include "frontend_common/config.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
#include "input_common/drivers/keyboard.h"
#include "input_common/drivers/mouse.h"
#include "input_common/main.h"
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index 550cff9a0..19fdca7d3 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -6,7 +6,7 @@
#include <QPainter>
#include <QTimer>
-#include "core/hid/emulated_controller.h"
+#include "hid_core/frontend/emulated_controller.h"
#include "yuzu/configuration/configure_input_player_widget.h"
PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) {
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h
index a16943c3c..76340912d 100644
--- a/src/yuzu/configuration/configure_input_player_widget.h
+++ b/src/yuzu/configuration/configure_input_player_widget.h
@@ -10,8 +10,8 @@
#include "common/input.h"
#include "common/settings_input.h"
#include "common/vector_math.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_types.h"
class QLabel;
diff --git a/src/yuzu/configuration/configure_ringcon.cpp b/src/yuzu/configuration/configure_ringcon.cpp
index 9572ff43c..3a7f6101d 100644
--- a/src/yuzu/configuration/configure_ringcon.cpp
+++ b/src/yuzu/configuration/configure_ringcon.cpp
@@ -9,8 +9,8 @@
#include <fmt/format.h>
#include "configuration/qt_config.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "input_common/drivers/keyboard.h"
#include "input_common/drivers/mouse.h"
#include "input_common/main.h"
diff --git a/src/yuzu/configuration/configure_vibration.cpp b/src/yuzu/configuration/configure_vibration.cpp
index 68c28b320..d898d8acc 100644
--- a/src/yuzu/configuration/configure_vibration.cpp
+++ b/src/yuzu/configuration/configure_vibration.cpp
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
-#include "core/hid/hid_types.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
#include "ui_configure_vibration.h"
#include "yuzu/configuration/configure_vibration.h"
diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp
index 7e908924c..922eb1b1a 100644
--- a/src/yuzu/configuration/shared_translation.cpp
+++ b/src/yuzu/configuration/shared_translation.cpp
@@ -228,7 +228,7 @@ std::unique_ptr<ComboboxTranslationMap> ComboboxEnumeration(QWidget* parent) {
{
PAIR(ShaderBackend, Glsl, tr("GLSL")),
PAIR(ShaderBackend, Glasm, tr("GLASM (Assembly Shaders, NVIDIA Only)")),
- PAIR(ShaderBackend, SpirV, tr("SPIR-V (Experimental, Mesa Only)")),
+ PAIR(ShaderBackend, SpirV, tr("SPIR-V (Experimental, AMD/Mesa Only)")),
}});
translations->insert({Settings::EnumMetadata<Settings::GpuAccuracy>::Index(),
{
diff --git a/src/yuzu/debugger/controller.cpp b/src/yuzu/debugger/controller.cpp
index e2f55ebae..216d2974d 100644
--- a/src/yuzu/debugger/controller.cpp
+++ b/src/yuzu/debugger/controller.cpp
@@ -5,8 +5,8 @@
#include <QLayout>
#include <QString>
#include "common/settings.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "input_common/drivers/tas_input.h"
#include "input_common/main.h"
#include "yuzu/configuration/configure_input_player_widget.h"
diff --git a/src/yuzu/hotkeys.cpp b/src/yuzu/hotkeys.cpp
index eebfbf155..b7693ad0d 100644
--- a/src/yuzu/hotkeys.cpp
+++ b/src/yuzu/hotkeys.cpp
@@ -6,7 +6,7 @@
#include <QTreeWidgetItem>
#include <QtGlobal>
-#include "core/hid/emulated_controller.h"
+#include "hid_core/frontend/emulated_controller.h"
#include "yuzu/hotkeys.h"
#include "yuzu/uisettings.h"
diff --git a/src/yuzu/hotkeys.h b/src/yuzu/hotkeys.h
index e11332d2e..bdc081649 100644
--- a/src/yuzu/hotkeys.h
+++ b/src/yuzu/hotkeys.h
@@ -7,7 +7,7 @@
#include <QKeySequence>
#include <QString>
#include <QWidget>
-#include "core/hid/hid_types.h"
+#include "hid_core/hid_types.h"
class QDialog;
class QSettings;
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index c789c1e59..2a83486f9 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -42,13 +42,13 @@
#include "core/frontend/applets/general_frontend.h"
#include "core/frontend/applets/mii_edit.h"
#include "core/frontend/applets/software_keyboard.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/am/applet_ae.h"
#include "core/hle/service/am/applet_oe.h"
#include "core/hle/service/am/applets/applets.h"
#include "core/hle/service/set/set_sys.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "yuzu/multiplayer/state.h"
#include "yuzu/util/controller_navigation.h"
diff --git a/src/yuzu/util/controller_navigation.cpp b/src/yuzu/util/controller_navigation.cpp
index d49ae67cd..2690b075d 100644
--- a/src/yuzu/util/controller_navigation.cpp
+++ b/src/yuzu/util/controller_navigation.cpp
@@ -2,8 +2,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings_input.h"
-#include "core/hid/emulated_controller.h"
-#include "core/hid/hid_core.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
#include "yuzu/util/controller_navigation.h"
ControllerNavigation::ControllerNavigation(Core::HID::HIDCore& hid_core, QWidget* parent) {
diff --git a/src/yuzu/util/overlay_dialog.cpp b/src/yuzu/util/overlay_dialog.cpp
index ee35a3e15..466bbe7b2 100644
--- a/src/yuzu/util/overlay_dialog.cpp
+++ b/src/yuzu/util/overlay_dialog.cpp
@@ -6,8 +6,8 @@
#include <QWindow>
#include "core/core.h"
-#include "core/hid/hid_types.h"
-#include "core/hid/input_interpreter.h"
+#include "hid_core/frontend/input_interpreter.h"
+#include "hid_core/hid_types.h"
#include "ui_overlay_dialog.h"
#include "yuzu/util/overlay_dialog.h"
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index 1a35d471c..eae614f9d 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -7,8 +7,8 @@
#include "common/scm_rev.h"
#include "common/settings.h"
#include "core/core.h"
-#include "core/hid/hid_core.h"
#include "core/perf_stats.h"
+#include "hid_core/hid_core.h"
#include "input_common/drivers/keyboard.h"
#include "input_common/drivers/mouse.h"
#include "input_common/drivers/touch_screen.h"