Compare commits
106 Commits
android-15
...
android-16
Author | SHA1 | Date | |
---|---|---|---|
a801fe49b3 | |||
a54ce2571c | |||
426d4e4df5 | |||
3d268b8480 | |||
ad7445d4cc | |||
3a30271219 | |||
bb5196aaae | |||
d3070cafa7 | |||
5cd3b6f58c | |||
bedc758fe7 | |||
76701185ad | |||
f1cb14eb54 | |||
f4f4a469a9 | |||
9e5b4052ed | |||
234867b84d | |||
4b60aec190 | |||
ecfba79d98 | |||
310834aea2 | |||
6a1fa9bb17 | |||
1bb76201e6 | |||
372bca5945 | |||
93c19a40bf | |||
345ec25532 | |||
a94721fde0 | |||
816c7a8d1f | |||
efe52db690 | |||
d61df0f400 | |||
b14547b8b6 | |||
97ad3e7530 | |||
0589a32f75 | |||
617dc0f822 | |||
fcfa8b680b | |||
94244437de | |||
53956a2990 | |||
a7731abb72 | |||
50fd029eaa | |||
a2b567dfd6 | |||
b770f6a985 | |||
797e8fdbc3 | |||
b8c5027686 | |||
65e646eeba | |||
fba3fa705d | |||
09e8fb75ce | |||
6ca530a721 | |||
e01c535178 | |||
7239547ead | |||
7fc06260d1 | |||
e357896674 | |||
225f4f40cb | |||
927be75616 | |||
00965e6c34 | |||
4bf1f217ae | |||
fcc85abe27 | |||
6851e93296 | |||
67660972c9 | |||
ffbba74c91 | |||
2b0cf73bf0 | |||
a093f3d47a | |||
4f600f746a | |||
360418f1a1 | |||
3bc7575c47 | |||
fde8dc1652 | |||
b8f83aa4bf | |||
85b1e17df6 | |||
4144c517a5 | |||
8ad5f2c506 | |||
2a3f84aaf2 | |||
030e6b3980 | |||
e8ad603cd9 | |||
b560ade663 | |||
d10464de30 | |||
64f68e9635 | |||
462ba1b360 | |||
4a86a55174 | |||
86d26914a2 | |||
6ae4177b25 | |||
f6bf8b3ed3 | |||
345fb6b226 | |||
87a9dc9489 | |||
6c6e8b8de0 | |||
5acffe75df | |||
ac222ceba2 | |||
f9d4827102 | |||
7ea7c72dde | |||
809230f634 | |||
698c854d5b | |||
ca5b135ddf | |||
dbddc627d4 | |||
62fc386bb4 | |||
f2eb3c579f | |||
2fce812026 | |||
e975f3cde9 | |||
6b5fb2063f | |||
70c3d36536 | |||
d590cfb9d0 | |||
ded419ef2b | |||
4c3f898789 | |||
46c259bb20 | |||
adc3079613 | |||
15bebf1695 | |||
5c840334b8 | |||
a05c242429 | |||
bd59934350 | |||
abfebe5cc4 | |||
a22a025c5b | |||
d5de9402ee |
3
.github/workflows/verify.yml
vendored
3
.github/workflows/verify.yml
vendored
@ -79,7 +79,8 @@ jobs:
|
||||
fetch-depth: 0
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
brew install autoconf automake boost@1.83 ccache ffmpeg fmt glslang hidapi libtool libusb lz4 ninja nlohmann-json openssl pkg-config qt@5 sdl2 speexdsp zlib zlib zstd
|
||||
# workaround for https://github.com/actions/setup-python/issues/577
|
||||
brew install autoconf automake boost@1.83 ccache ffmpeg fmt glslang hidapi libtool libusb lz4 ninja nlohmann-json openssl pkg-config qt@5 sdl2 speexdsp zlib zlib zstd || brew link --overwrite python@3.12
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir build
|
||||
|
@ -142,6 +142,9 @@ if (YUZU_USE_BUNDLED_VCPKG)
|
||||
if (ENABLE_WEB_SERVICE)
|
||||
list(APPEND VCPKG_MANIFEST_FEATURES "web-service")
|
||||
endif()
|
||||
if (ANDROID)
|
||||
list(APPEND VCPKG_MANIFEST_FEATURES "android")
|
||||
endif()
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/externals/vcpkg/scripts/buildsystems/vcpkg.cmake)
|
||||
elseif(NOT "$ENV{VCPKG_TOOLCHAIN_FILE}" STREQUAL "")
|
||||
@ -302,7 +305,7 @@ find_package(ZLIB 1.2 REQUIRED)
|
||||
find_package(zstd 1.5 REQUIRED)
|
||||
|
||||
if (NOT YUZU_USE_EXTERNAL_VULKAN_HEADERS)
|
||||
find_package(Vulkan 1.3.256 REQUIRED)
|
||||
find_package(Vulkan 1.3.274 REQUIRED)
|
||||
endif()
|
||||
|
||||
if (ENABLE_LIBUSB)
|
||||
|
@ -1,6 +1,7 @@
|
||||
| Pull Request | Commit | Title | Author | Merged? |
|
||||
|----|----|----|----|----|
|
||||
| [12335](https://github.com/yuzu-emu/yuzu//pull/12335) | [`edcd6d547`](https://github.com/yuzu-emu/yuzu//pull/12335/files) | android: Game Properties | [t895](https://github.com/t895/) | Yes |
|
||||
| [12410](https://github.com/yuzu-emu/yuzu//pull/12410) | [`d0a75580d`](https://github.com/yuzu-emu/yuzu//pull/12410/files) | renderer_vulkan: don't pass null view when nullDescriptor is not supported | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||
| [12432](https://github.com/yuzu-emu/yuzu//pull/12432) | [`9e9aed41b`](https://github.com/yuzu-emu/yuzu//pull/12432/files) | shader_recompiler: use float image operations on load/store when required | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||
|
||||
|
||||
End of merge log. You can find the original README.md below the break.
|
||||
|
2
externals/Vulkan-Headers
vendored
2
externals/Vulkan-Headers
vendored
Submodule externals/Vulkan-Headers updated: df60f03168...80207f9da8
2
externals/vcpkg
vendored
2
externals/vcpkg
vendored
Submodule externals/vcpkg updated: ef2eef1734...a42af01b72
@ -174,7 +174,8 @@ android {
|
||||
"-DANDROID_ARM_NEON=true", // cryptopp requires Neon to work
|
||||
"-DYUZU_USE_BUNDLED_VCPKG=ON",
|
||||
"-DYUZU_USE_BUNDLED_FFMPEG=ON",
|
||||
"-DYUZU_ENABLE_LTO=ON"
|
||||
"-DYUZU_ENABLE_LTO=ON",
|
||||
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
|
||||
)
|
||||
|
||||
abiFilters("arm64-v8a", "x86_64")
|
||||
|
@ -14,7 +14,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.launch
|
||||
import org.yuzu.yuzu_emu.databinding.CardInstallableBinding
|
||||
import org.yuzu.yuzu_emu.databinding.CardInstallableIconBinding
|
||||
import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding
|
||||
import org.yuzu.yuzu_emu.model.GameProperty
|
||||
import org.yuzu.yuzu_emu.model.InstallableProperty
|
||||
@ -42,7 +42,7 @@ class GamePropertiesAdapter(
|
||||
}
|
||||
|
||||
else -> InstallablePropertyViewHolder(
|
||||
CardInstallableBinding.inflate(
|
||||
CardInstallableIconBinding.inflate(
|
||||
inflater,
|
||||
parent,
|
||||
false
|
||||
@ -107,13 +107,20 @@ class GamePropertiesAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
inner class InstallablePropertyViewHolder(val binding: CardInstallableBinding) :
|
||||
inner class InstallablePropertyViewHolder(val binding: CardInstallableIconBinding) :
|
||||
GamePropertyViewHolder(binding.root) {
|
||||
override fun bind(property: GameProperty) {
|
||||
val installableProperty = property as InstallableProperty
|
||||
|
||||
binding.title.setText(installableProperty.titleId)
|
||||
binding.description.setText(installableProperty.descriptionId)
|
||||
binding.icon.setImageDrawable(
|
||||
ResourcesCompat.getDrawable(
|
||||
binding.icon.context.resources,
|
||||
installableProperty.iconId,
|
||||
binding.icon.context.theme
|
||||
)
|
||||
)
|
||||
|
||||
if (installableProperty.install != null) {
|
||||
binding.buttonInstall.visibility = View.VISIBLE
|
||||
|
@ -22,6 +22,9 @@ interface AbstractSetting {
|
||||
get() = NativeConfig.usingGlobal(key)
|
||||
set(value) = NativeConfig.setGlobal(key, value)
|
||||
|
||||
val isSaveable: Boolean
|
||||
get() = NativeConfig.getIsSaveable(key)
|
||||
|
||||
fun getValueAsString(needsGlobal: Boolean = false): String
|
||||
|
||||
fun reset()
|
||||
|
@ -32,8 +32,7 @@ enum class BooleanSetting(override val key: String) : AbstractBooleanSetting {
|
||||
|
||||
override val defaultValue: Boolean by lazy { NativeConfig.getDefaultToString(key).toBoolean() }
|
||||
|
||||
override fun getValueAsString(needsGlobal: Boolean): String =
|
||||
if (getBoolean(needsGlobal)) "1" else "0"
|
||||
override fun getValueAsString(needsGlobal: Boolean): String = getBoolean(needsGlobal).toString()
|
||||
|
||||
override fun reset() = NativeConfig.setBoolean(key, defaultValue)
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ abstract class SettingsItem(
|
||||
|
||||
val isEditable: Boolean
|
||||
get() {
|
||||
// Can't edit settings that aren't saveable in per-game config even if they are switchable
|
||||
if (NativeConfig.isPerGameConfigLoaded() && !setting.isSaveable) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!NativeLibrary.isRunning()) return true
|
||||
|
||||
// Prevent editing settings that were modified in per-game config while editing global
|
||||
@ -37,6 +42,7 @@ abstract class SettingsItem(
|
||||
if (!NativeConfig.isPerGameConfigLoaded() && !setting.global) {
|
||||
return false
|
||||
}
|
||||
|
||||
return setting.isRuntimeModifiable
|
||||
}
|
||||
|
||||
@ -59,6 +65,7 @@ abstract class SettingsItem(
|
||||
val emptySetting = object : AbstractSetting {
|
||||
override val key: String = ""
|
||||
override val defaultValue: Any = false
|
||||
override val isSaveable = true
|
||||
override fun getValueAsString(needsGlobal: Boolean): String = ""
|
||||
override fun reset() {}
|
||||
}
|
||||
@ -303,6 +310,8 @@ abstract class SettingsItem(
|
||||
BooleanSetting.FASTMEM_EXCLUSIVES.global = value
|
||||
}
|
||||
|
||||
override val isSaveable = true
|
||||
|
||||
override fun getValueAsString(needsGlobal: Boolean): String =
|
||||
getBoolean().toString()
|
||||
|
||||
|
@ -128,8 +128,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
return
|
||||
}
|
||||
|
||||
if (args.custom) {
|
||||
SettingsFile.loadCustomConfig(args.game!!)
|
||||
// Always load custom settings when launching a game from an intent
|
||||
if (args.custom || intentGame != null) {
|
||||
SettingsFile.loadCustomConfig(game)
|
||||
NativeConfig.unloadPerGameConfig()
|
||||
} else {
|
||||
NativeConfig.reloadGlobalConfig()
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
package org.yuzu.yuzu_emu.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
@ -73,6 +74,8 @@ class GamePropertiesFragment : Fragment() {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
// This is using the correct scope, lint is just acting up
|
||||
@SuppressLint("UnsafeRepeatOnLifecycleDetector")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
homeViewModel.setNavigationVisibility(visible = false, animated = true)
|
||||
@ -99,12 +102,24 @@ class GamePropertiesFragment : Fragment() {
|
||||
|
||||
reloadList()
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
homeViewModel.openImportSaves.collect {
|
||||
if (it) {
|
||||
importSaves.launch(arrayOf("application/zip"))
|
||||
homeViewModel.setOpenImportSaves(false)
|
||||
viewLifecycleOwner.lifecycleScope.apply {
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
homeViewModel.openImportSaves.collect {
|
||||
if (it) {
|
||||
importSaves.launch(arrayOf("application/zip"))
|
||||
homeViewModel.setOpenImportSaves(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
homeViewModel.reloadPropertiesList.collect {
|
||||
if (it) {
|
||||
reloadList()
|
||||
homeViewModel.reloadPropertiesList(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -179,6 +194,7 @@ class GamePropertiesFragment : Fragment() {
|
||||
InstallableProperty(
|
||||
R.string.save_data,
|
||||
R.string.save_data_description,
|
||||
R.drawable.ic_save,
|
||||
{
|
||||
MessageDialogFragment.newInstance(
|
||||
requireActivity(),
|
||||
@ -214,7 +230,7 @@ class GamePropertiesFragment : Fragment() {
|
||||
R.string.save_data_deleted_successfully,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
reloadList()
|
||||
homeViewModel.reloadPropertiesList(true)
|
||||
}
|
||||
).show(parentFragmentManager, MessageDialogFragment.TAG)
|
||||
}
|
||||
@ -242,13 +258,20 @@ class GamePropertiesFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
) {
|
||||
shaderCacheDir.deleteRecursively()
|
||||
Toast.makeText(
|
||||
YuzuApplication.appContext,
|
||||
R.string.cleared_shaders_successfully,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
reloadList()
|
||||
MessageDialogFragment.newInstance(
|
||||
requireActivity(),
|
||||
titleId = R.string.clear_shader_cache,
|
||||
descriptionId = R.string.clear_shader_cache_warning_description,
|
||||
positiveAction = {
|
||||
shaderCacheDir.deleteRecursively()
|
||||
Toast.makeText(
|
||||
YuzuApplication.appContext,
|
||||
R.string.cleared_shaders_successfully,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
homeViewModel.reloadPropertiesList(true)
|
||||
}
|
||||
).show(parentFragmentManager, MessageDialogFragment.TAG)
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -388,7 +411,7 @@ class GamePropertiesFragment : Fragment() {
|
||||
getString(R.string.save_file_imported_success),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
reloadList()
|
||||
homeViewModel.reloadPropertiesList(true)
|
||||
}
|
||||
|
||||
cacheSaveDir.deleteRecursively()
|
||||
|
@ -15,7 +15,7 @@ import org.yuzu.yuzu_emu.model.Game
|
||||
import org.yuzu.yuzu_emu.utils.SerializableHelper.parcelable
|
||||
|
||||
class LaunchGameDialogFragment : DialogFragment() {
|
||||
private var selectedItem = 0
|
||||
private var selectedItem = 1
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val game = requireArguments().parcelable<Game>(GAME)
|
||||
@ -32,7 +32,7 @@ class LaunchGameDialogFragment : DialogFragment() {
|
||||
.actionGlobalEmulationActivity(game, selectedItem != 0)
|
||||
requireParentFragment().findNavController().navigate(action)
|
||||
}
|
||||
.setSingleChoiceItems(launchOptions, 0) { _: DialogInterface, i: Int ->
|
||||
.setSingleChoiceItems(launchOptions, 1) { _: DialogInterface, i: Int ->
|
||||
selectedItem = i
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
|
@ -10,17 +10,18 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
interface GameProperty {
|
||||
@get:StringRes
|
||||
val titleId: Int
|
||||
get() = -1
|
||||
|
||||
@get:StringRes
|
||||
val descriptionId: Int
|
||||
get() = -1
|
||||
|
||||
@get:DrawableRes
|
||||
val iconId: Int
|
||||
}
|
||||
|
||||
data class SubmenuProperty(
|
||||
override val titleId: Int,
|
||||
override val descriptionId: Int,
|
||||
@DrawableRes val iconId: Int,
|
||||
override val iconId: Int,
|
||||
val details: (() -> String)? = null,
|
||||
val detailsFlow: StateFlow<String>? = null,
|
||||
val action: () -> Unit
|
||||
@ -29,6 +30,7 @@ data class SubmenuProperty(
|
||||
data class InstallableProperty(
|
||||
override val titleId: Int,
|
||||
override val descriptionId: Int,
|
||||
override val iconId: Int,
|
||||
val install: (() -> Unit)? = null,
|
||||
val export: (() -> Unit)? = null
|
||||
) : GameProperty
|
||||
|
@ -28,6 +28,9 @@ class HomeViewModel : ViewModel() {
|
||||
private val _contentToInstall = MutableStateFlow<List<Uri>?>(null)
|
||||
val contentToInstall get() = _contentToInstall.asStateFlow()
|
||||
|
||||
private val _reloadPropertiesList = MutableStateFlow(false)
|
||||
val reloadPropertiesList get() = _reloadPropertiesList.asStateFlow()
|
||||
|
||||
var navigatedToSetup = false
|
||||
|
||||
fun setNavigationVisibility(visible: Boolean, animated: Boolean) {
|
||||
@ -59,4 +62,8 @@ class HomeViewModel : ViewModel() {
|
||||
fun setContentToInstall(documents: List<Uri>?) {
|
||||
_contentToInstall.value = documents
|
||||
}
|
||||
|
||||
fun reloadPropertiesList(reload: Boolean) {
|
||||
_reloadPropertiesList.value = reload
|
||||
}
|
||||
}
|
||||
|
@ -91,18 +91,20 @@ class GamesFragment : Fragment() {
|
||||
viewLifecycleOwner.lifecycleScope.apply {
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
gamesViewModel.isReloading.collect { binding.swipeRefresh.isRefreshing = it }
|
||||
gamesViewModel.isReloading.collect {
|
||||
binding.swipeRefresh.isRefreshing = it
|
||||
if (gamesViewModel.games.value.isEmpty() && !it) {
|
||||
binding.noticeText.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.noticeText.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
gamesViewModel.games.collectLatest {
|
||||
(binding.gridGames.adapter as GameAdapter).submitList(it)
|
||||
if (it.isEmpty()) {
|
||||
binding.noticeText.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.noticeText.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +110,8 @@ object NativeConfig {
|
||||
@Synchronized
|
||||
external fun setGlobal(key: String, global: Boolean)
|
||||
|
||||
external fun getIsSaveable(key: String): Boolean
|
||||
|
||||
external fun getDefaultToString(key: String): String
|
||||
|
||||
/**
|
||||
|
@ -89,13 +89,13 @@ jboolean Java_org_yuzu_yuzu_1emu_utils_GameMetadata_getIsValid(JNIEnv* env, jobj
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto fileType = loader->GetFileType();
|
||||
if (fileType == Loader::FileType::Unknown || fileType == Loader::FileType::Error) {
|
||||
const auto file_type = loader->GetFileType();
|
||||
if (file_type == Loader::FileType::Unknown || file_type == Loader::FileType::Error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
u64 programId = 0;
|
||||
Loader::ResultStatus res = loader->ReadProgramId(programId);
|
||||
u64 program_id = 0;
|
||||
Loader::ResultStatus res = loader->ReadProgramId(program_id);
|
||||
if (res != Loader::ResultStatus::Success) {
|
||||
return false;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ Core::System& EmulationSession::System() {
|
||||
return m_system;
|
||||
}
|
||||
|
||||
FileSys::ManualContentProvider* EmulationSession::ContentProvider() {
|
||||
FileSys::ManualContentProvider* EmulationSession::GetContentProvider() {
|
||||
return m_manual_provider.get();
|
||||
}
|
||||
|
||||
@ -296,9 +296,6 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string
|
||||
// Initialize filesystem.
|
||||
ConfigureFilesystemProvider(filepath);
|
||||
|
||||
// Initialize account manager
|
||||
m_profile_manager = std::make_unique<Service::Account::ProfileManager>();
|
||||
|
||||
// Load the ROM.
|
||||
m_load_result = m_system.Load(EmulationSession::GetInstance().Window(), filepath);
|
||||
if (m_load_result != Core::SystemResultStatus::Success) {
|
||||
@ -463,15 +460,13 @@ void EmulationSession::OnEmulationStopped(Core::SystemResultStatus result) {
|
||||
static_cast<jint>(result));
|
||||
}
|
||||
|
||||
u64 EmulationSession::getProgramId(JNIEnv* env, jstring jprogramId) {
|
||||
u64 program_id;
|
||||
u64 EmulationSession::GetProgramId(JNIEnv* env, jstring jprogramId) {
|
||||
auto program_id_string = GetJString(env, jprogramId);
|
||||
if (program_id_string.empty()) {
|
||||
program_id = 0;
|
||||
} else {
|
||||
program_id = std::stoull(program_id_string);
|
||||
try {
|
||||
return std::stoull(program_id_string);
|
||||
} catch (...) {
|
||||
return 0;
|
||||
}
|
||||
return program_id;
|
||||
}
|
||||
|
||||
static Core::SystemResultStatus RunEmulation(const std::string& filepath) {
|
||||
@ -526,16 +521,16 @@ int Java_org_yuzu_yuzu_1emu_NativeLibrary_installFileToNand(JNIEnv* env, jobject
|
||||
jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_doesUpdateMatchProgram(JNIEnv* env, jobject jobj,
|
||||
jstring jprogramId,
|
||||
jstring jupdatePath) {
|
||||
u64 programId = EmulationSession::getProgramId(env, jprogramId);
|
||||
u64 program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||
std::string updatePath = GetJString(env, jupdatePath);
|
||||
std::shared_ptr<FileSys::NSP> nsp = std::make_shared<FileSys::NSP>(
|
||||
EmulationSession::GetInstance().System().GetFilesystem()->OpenFile(updatePath,
|
||||
FileSys::Mode::Read));
|
||||
for (const auto& item : nsp->GetNCAs()) {
|
||||
for (const auto& ncaDetails : item.second) {
|
||||
if (ncaDetails.second->GetName().ends_with(".cnmt.nca")) {
|
||||
auto updateId = ncaDetails.second->GetTitleId() & ~0xFFFULL;
|
||||
if (updateId == programId) {
|
||||
for (const auto& nca_details : item.second) {
|
||||
if (nca_details.second->GetName().ends_with(".cnmt.nca")) {
|
||||
auto update_id = nca_details.second->GetTitleId() & ~0xFFFULL;
|
||||
if (update_id == program_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -770,8 +765,8 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_initializeEmptyUserDirectory(JNIEnv*
|
||||
auto vfs_nand_dir = EmulationSession::GetInstance().System().GetFilesystem()->OpenDirectory(
|
||||
Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read);
|
||||
|
||||
Service::Account::ProfileManager manager;
|
||||
const auto user_id = manager.GetUser(static_cast<std::size_t>(0));
|
||||
const auto user_id = EmulationSession::GetInstance().System().GetProfileManager().GetUser(
|
||||
static_cast<std::size_t>(0));
|
||||
ASSERT(user_id);
|
||||
|
||||
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||
@ -840,8 +835,8 @@ jobjectArray Java_org_yuzu_yuzu_1emu_NativeLibrary_getAddonsForFile(JNIEnv* env,
|
||||
}
|
||||
|
||||
auto& system = EmulationSession::GetInstance().System();
|
||||
auto programId = EmulationSession::getProgramId(env, jprogramId);
|
||||
const FileSys::PatchManager pm{programId, system.GetFileSystemController(),
|
||||
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||
const FileSys::PatchManager pm{program_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto loader = Loader::GetLoader(system, vFile);
|
||||
|
||||
@ -849,11 +844,11 @@ jobjectArray Java_org_yuzu_yuzu_1emu_NativeLibrary_getAddonsForFile(JNIEnv* env,
|
||||
loader->ReadUpdateRaw(update_raw);
|
||||
|
||||
auto addons = pm.GetPatchVersionNames(update_raw);
|
||||
auto emptyString = ToJString(env, "");
|
||||
auto emptyStringPair = env->NewObject(IDCache::GetPairClass(), IDCache::GetPairConstructor(),
|
||||
emptyString, emptyString);
|
||||
auto jemptyString = ToJString(env, "");
|
||||
auto jemptyStringPair = env->NewObject(IDCache::GetPairClass(), IDCache::GetPairConstructor(),
|
||||
jemptyString, jemptyString);
|
||||
jobjectArray jaddonsArray =
|
||||
env->NewObjectArray(addons.size(), IDCache::GetPairClass(), emptyStringPair);
|
||||
env->NewObjectArray(addons.size(), IDCache::GetPairClass(), jemptyStringPair);
|
||||
int i = 0;
|
||||
for (const auto& addon : addons) {
|
||||
jobject jaddon = env->NewObject(IDCache::GetPairClass(), IDCache::GetPairConstructor(),
|
||||
@ -866,7 +861,7 @@ jobjectArray Java_org_yuzu_yuzu_1emu_NativeLibrary_getAddonsForFile(JNIEnv* env,
|
||||
|
||||
jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getSavePath(JNIEnv* env, jobject jobj,
|
||||
jstring jprogramId) {
|
||||
auto programId = EmulationSession::getProgramId(env, jprogramId);
|
||||
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||
|
||||
auto& system = EmulationSession::GetInstance().System();
|
||||
|
||||
@ -881,7 +876,7 @@ jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getSavePath(JNIEnv* env, jobject j
|
||||
|
||||
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||
system, vfsNandDir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
|
||||
programId, user_id->AsU128(), 0);
|
||||
program_id, user_id->AsU128(), 0);
|
||||
return ToJString(env, user_save_data_path);
|
||||
}
|
||||
|
||||
@ -891,7 +886,7 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_addFileToFilesystemProvider(JNIEnv* e
|
||||
}
|
||||
|
||||
void Java_org_yuzu_yuzu_1emu_NativeLibrary_clearFilesystemProvider(JNIEnv* env, jobject jobj) {
|
||||
EmulationSession::GetInstance().ContentProvider()->ClearAllEntries();
|
||||
EmulationSession::GetInstance().GetContentProvider()->ClearAllEntries();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
static EmulationSession& GetInstance();
|
||||
const Core::System& System() const;
|
||||
Core::System& System();
|
||||
FileSys::ManualContentProvider* ContentProvider();
|
||||
FileSys::ManualContentProvider* GetContentProvider();
|
||||
|
||||
const EmuWindow_Android& Window() const;
|
||||
EmuWindow_Android& Window();
|
||||
@ -55,7 +55,7 @@ public:
|
||||
|
||||
static void OnEmulationStarted();
|
||||
|
||||
static u64 getProgramId(JNIEnv* env, jstring jprogramId);
|
||||
static u64 GetProgramId(JNIEnv* env, jstring jprogramId);
|
||||
|
||||
private:
|
||||
static void LoadDiskCacheProgress(VideoCore::LoadCallbackStage stage, int progress, int max);
|
||||
@ -76,7 +76,6 @@ private:
|
||||
std::atomic<bool> m_is_running = false;
|
||||
std::atomic<bool> m_is_paused = false;
|
||||
SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{};
|
||||
std::unique_ptr<Service::Account::ProfileManager> m_profile_manager;
|
||||
std::unique_ptr<FileSys::ManualContentProvider> m_manual_provider;
|
||||
|
||||
// GPU driver parameters
|
||||
|
@ -21,13 +21,13 @@ std::unique_ptr<AndroidConfig> per_game_config;
|
||||
template <typename T>
|
||||
Settings::Setting<T>* getSetting(JNIEnv* env, jstring jkey) {
|
||||
auto key = GetJString(env, jkey);
|
||||
auto basicSetting = Settings::values.linkage.by_key[key];
|
||||
if (basicSetting != 0) {
|
||||
return static_cast<Settings::Setting<T>*>(basicSetting);
|
||||
auto basic_setting = Settings::values.linkage.by_key[key];
|
||||
if (basic_setting != 0) {
|
||||
return static_cast<Settings::Setting<T>*>(basic_setting);
|
||||
}
|
||||
auto basicAndroidSetting = AndroidSettings::values.linkage.by_key[key];
|
||||
if (basicAndroidSetting != 0) {
|
||||
return static_cast<Settings::Setting<T>*>(basicAndroidSetting);
|
||||
auto basic_android_setting = AndroidSettings::values.linkage.by_key[key];
|
||||
if (basic_android_setting != 0) {
|
||||
return static_cast<Settings::Setting<T>*>(basic_android_setting);
|
||||
}
|
||||
LOG_ERROR(Frontend, "[Android Native] Could not find setting - {}", key);
|
||||
return nullptr;
|
||||
@ -54,7 +54,7 @@ void Java_org_yuzu_yuzu_1emu_utils_NativeConfig_saveGlobalConfig(JNIEnv* env, jo
|
||||
void Java_org_yuzu_yuzu_1emu_utils_NativeConfig_initializePerGameConfig(JNIEnv* env, jobject obj,
|
||||
jstring jprogramId,
|
||||
jstring jfileName) {
|
||||
auto program_id = EmulationSession::getProgramId(env, jprogramId);
|
||||
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||
auto file_name = GetJString(env, jfileName);
|
||||
const auto config_file_name = program_id == 0 ? file_name : fmt::format("{:016X}", program_id);
|
||||
per_game_config =
|
||||
@ -249,6 +249,15 @@ void Java_org_yuzu_yuzu_1emu_utils_NativeConfig_setGlobal(JNIEnv* env, jobject o
|
||||
}
|
||||
}
|
||||
|
||||
jboolean Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getIsSaveable(JNIEnv* env, jobject obj,
|
||||
jstring jkey) {
|
||||
auto setting = getSetting<std::string>(env, jkey);
|
||||
if (setting != nullptr) {
|
||||
return setting->Save();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
jstring Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getDefaultToString(JNIEnv* env, jobject obj,
|
||||
jstring jkey) {
|
||||
auto setting = getSetting<std::string>(env, jkey);
|
||||
@ -311,7 +320,7 @@ void Java_org_yuzu_yuzu_1emu_utils_NativeConfig_addGameDir(JNIEnv* env, jobject
|
||||
|
||||
jobjectArray Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getDisabledAddons(JNIEnv* env, jobject obj,
|
||||
jstring jprogramId) {
|
||||
auto program_id = EmulationSession::getProgramId(env, jprogramId);
|
||||
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||
auto& disabledAddons = Settings::values.disabled_addons[program_id];
|
||||
jobjectArray jdisabledAddonsArray =
|
||||
env->NewObjectArray(disabledAddons.size(), IDCache::GetStringClass(), ToJString(env, ""));
|
||||
@ -324,7 +333,7 @@ jobjectArray Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getDisabledAddons(JNIEnv
|
||||
void Java_org_yuzu_yuzu_1emu_utils_NativeConfig_setDisabledAddons(JNIEnv* env, jobject obj,
|
||||
jstring jprogramId,
|
||||
jobjectArray jdisabledAddons) {
|
||||
auto program_id = EmulationSession::getProgramId(env, jprogramId);
|
||||
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||
Settings::values.disabled_addons[program_id].clear();
|
||||
std::vector<std::string> disabled_addons;
|
||||
const int size = env->GetArrayLength(jdisabledAddons);
|
||||
|
@ -1,10 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L647,120Q663,120 677.5,126Q692,132 703,143L817,257Q828,268 834,282.5Q840,297 840,313L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM760,314L646,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760L760,760Q760,760 760,760Q760,760 760,760L760,314ZM480,720Q530,720 565,685Q600,650 600,600Q600,550 565,515Q530,480 480,480Q430,480 395,515Q360,550 360,600Q360,650 395,685Q430,720 480,720ZM280,400L560,400Q577,400 588.5,388.5Q600,377 600,360L600,280Q600,263 588.5,251.5Q577,240 560,240L280,240Q263,240 251.5,251.5Q240,263 240,280L240,360Q240,377 251.5,388.5Q263,400 280,400ZM200,314L200,760Q200,760 200,760Q200,760 200,760L200,760Q200,760 200,760Q200,760 200,760L200,200Q200,200 200,200Q200,200 200,200L200,200L200,314Z"/>
|
||||
android:fillColor="?attr/colorControlNormal"
|
||||
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z" />
|
||||
</vector>
|
||||
|
@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="?attr/materialCardViewOutlinedStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginVertical="12dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:tint="?attr/colorOnSurface"
|
||||
tools:src="@drawable/ic_settings" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/title"
|
||||
style="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/user_data"
|
||||
android:textAlignment="viewStart" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/description"
|
||||
style="@style/TextAppearance.Material3.BodyMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/user_data_description"
|
||||
android:textAlignment="viewStart" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_export"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:contentDescription="@string/export"
|
||||
android:tooltipText="@string/export"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_export"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_install"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="12dp"
|
||||
android:contentDescription="@string/string_import"
|
||||
android:tooltipText="@string/string_import"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_import"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="?attr/materialCardViewOutlinedStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginVertical="12dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:tint="?attr/colorOnSurface"
|
||||
tools:src="@drawable/ic_settings" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/title"
|
||||
style="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/user_data"
|
||||
android:textAlignment="viewStart" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/description"
|
||||
style="@style/TextAppearance.Material3.BodyMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/user_data_description"
|
||||
android:textAlignment="viewStart" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_install"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:contentDescription="@string/string_import"
|
||||
android:tooltipText="@string/string_import"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_import"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_export"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="8dp"
|
||||
android:contentDescription="@string/export"
|
||||
android:tooltipText="@string/export"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_export"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
@ -256,11 +256,13 @@
|
||||
|
||||
<string-array name="outputEngineEntries">
|
||||
<item>@string/auto</item>
|
||||
<item>@string/oboe</item>
|
||||
<item>@string/cubeb</item>
|
||||
<item>@string/string_null</item>
|
||||
</string-array>
|
||||
<integer-array name="outputEngineValues">
|
||||
<item>0</item>
|
||||
<item>4</item>
|
||||
<item>1</item>
|
||||
<item>3</item>
|
||||
</integer-array>
|
||||
|
@ -314,6 +314,7 @@
|
||||
<string name="add_ons_description">Toggle mods, updates and DLC</string>
|
||||
<string name="clear_shader_cache">Clear shader cache</string>
|
||||
<string name="clear_shader_cache_description">Removes all shaders built while playing this game</string>
|
||||
<string name="clear_shader_cache_warning_description">You will experience more stuttering as the shader cache regenerates</string>
|
||||
<string name="cleared_shaders_successfully">Cleared shaders successfully</string>
|
||||
<string name="addons_game">Addons: %1$s</string>
|
||||
<string name="save_data">Save data</string>
|
||||
@ -334,7 +335,7 @@
|
||||
<string name="addon_installed_successfully">Addon installed successfully</string>
|
||||
<string name="verifying_content">Verifying content…</string>
|
||||
<string name="content_install_notice">Content install notice</string>
|
||||
<string name="content_install_notice_description">The content that you selected does not match this game.\nInstall anyways?</string>
|
||||
<string name="content_install_notice_description">The content that you selected does not match this game.\nInstall anyway?</string>
|
||||
|
||||
<!-- ROM loading errors -->
|
||||
<string name="loader_error_encrypted">Your ROM is encrypted</string>
|
||||
@ -502,6 +503,7 @@
|
||||
<string name="theme_mode_dark">Dark</string>
|
||||
|
||||
<!-- Audio output engines -->
|
||||
<string name="oboe">oboe</string>
|
||||
<string name="cubeb">cubeb</string>
|
||||
|
||||
<!-- Black backgrounds theme -->
|
||||
|
@ -253,6 +253,17 @@ if (ENABLE_SDL2)
|
||||
target_compile_definitions(audio_core PRIVATE HAVE_SDL2)
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
target_sources(audio_core PRIVATE
|
||||
sink/oboe_sink.cpp
|
||||
sink/oboe_sink.h
|
||||
)
|
||||
|
||||
# FIXME: this port seems broken, it cannot be imported with find_package(oboe REQUIRED)
|
||||
target_link_libraries(audio_core PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/liboboe.a")
|
||||
target_compile_definitions(audio_core PRIVATE HAVE_OBOE)
|
||||
endif()
|
||||
|
||||
if (YUZU_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(audio_core PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
@ -253,8 +253,9 @@ CubebSink::~CubebSink() {
|
||||
#endif
|
||||
}
|
||||
|
||||
SinkStream* CubebSink::AcquireSinkStream(Core::System& system, u32 system_channels,
|
||||
SinkStream* CubebSink::AcquireSinkStream(Core::System& system, u32 system_channels_,
|
||||
const std::string& name, StreamType type) {
|
||||
system_channels = system_channels_;
|
||||
SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<CubebSinkStream>(
|
||||
ctx, device_channels, system_channels, output_device, input_device, name, type, system));
|
||||
|
||||
|
223
src/audio_core/sink/oboe_sink.cpp
Normal file
223
src/audio_core/sink/oboe_sink.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
#include <oboe/Oboe.h>
|
||||
|
||||
#include "audio_core/common/common.h"
|
||||
#include "audio_core/sink/oboe_sink.h"
|
||||
#include "audio_core/sink/sink_stream.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/scope_exit.h"
|
||||
#include "core/core.h"
|
||||
|
||||
namespace AudioCore::Sink {
|
||||
|
||||
class OboeSinkStream final : public SinkStream,
|
||||
public oboe::AudioStreamDataCallback,
|
||||
public oboe::AudioStreamErrorCallback {
|
||||
public:
|
||||
explicit OboeSinkStream(Core::System& system_, StreamType type_, const std::string& name_,
|
||||
u32 system_channels_)
|
||||
: SinkStream(system_, type_) {
|
||||
name = name_;
|
||||
system_channels = system_channels_;
|
||||
|
||||
this->OpenStream();
|
||||
}
|
||||
|
||||
~OboeSinkStream() override {
|
||||
LOG_INFO(Audio_Sink, "Destroyed Oboe stream");
|
||||
}
|
||||
|
||||
void Finalize() override {
|
||||
this->Stop();
|
||||
m_stream.reset();
|
||||
}
|
||||
|
||||
void Start(bool resume = false) override {
|
||||
if (!m_stream || !paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
paused = false;
|
||||
|
||||
if (m_stream->start() != oboe::Result::OK) {
|
||||
LOG_CRITICAL(Audio_Sink, "Error starting Oboe stream");
|
||||
}
|
||||
}
|
||||
|
||||
void Stop() override {
|
||||
if (!m_stream || paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->SignalPause();
|
||||
|
||||
if (m_stream->stop() != oboe::Result::OK) {
|
||||
LOG_CRITICAL(Audio_Sink, "Error stopping Oboe stream");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static s32 QueryChannelCount(oboe::Direction direction) {
|
||||
std::shared_ptr<oboe::AudioStream> temp_stream;
|
||||
oboe::AudioStreamBuilder builder;
|
||||
|
||||
const auto result = ConfigureBuilder(builder, direction)->openStream(temp_stream);
|
||||
ASSERT(result == oboe::Result::OK);
|
||||
|
||||
return temp_stream->getChannelCount() >= 6 ? 6 : 2;
|
||||
}
|
||||
|
||||
protected:
|
||||
oboe::DataCallbackResult onAudioReady(oboe::AudioStream*, void* audio_data,
|
||||
s32 num_buffer_frames) override {
|
||||
const size_t num_channels = this->GetDeviceChannels();
|
||||
const size_t frame_size = num_channels;
|
||||
const size_t num_frames = static_cast<size_t>(num_buffer_frames);
|
||||
|
||||
if (type == StreamType::In) {
|
||||
std::span<const s16> input_buffer{reinterpret_cast<const s16*>(audio_data),
|
||||
num_frames * frame_size};
|
||||
this->ProcessAudioIn(input_buffer, num_frames);
|
||||
} else {
|
||||
std::span<s16> output_buffer{reinterpret_cast<s16*>(audio_data),
|
||||
num_frames * frame_size};
|
||||
this->ProcessAudioOutAndRender(output_buffer, num_frames);
|
||||
}
|
||||
|
||||
return oboe::DataCallbackResult::Continue;
|
||||
}
|
||||
|
||||
void onErrorAfterClose(oboe::AudioStream*, oboe::Result) override {
|
||||
LOG_INFO(Audio_Sink, "Audio stream closed, reinitializing");
|
||||
|
||||
if (this->OpenStream()) {
|
||||
m_stream->start();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static oboe::AudioStreamBuilder* ConfigureBuilder(oboe::AudioStreamBuilder& builder,
|
||||
oboe::Direction direction) {
|
||||
// TODO: investigate callback delay issues when using AAudio
|
||||
return builder.setPerformanceMode(oboe::PerformanceMode::LowLatency)
|
||||
->setAudioApi(oboe::AudioApi::OpenSLES)
|
||||
->setDirection(direction)
|
||||
->setSampleRate(TargetSampleRate)
|
||||
->setSampleRateConversionQuality(oboe::SampleRateConversionQuality::High)
|
||||
->setFormat(oboe::AudioFormat::I16)
|
||||
->setFormatConversionAllowed(true)
|
||||
->setUsage(oboe::Usage::Game)
|
||||
->setBufferCapacityInFrames(TargetSampleCount * 2);
|
||||
}
|
||||
|
||||
bool OpenStream() {
|
||||
const auto direction = [&]() {
|
||||
switch (type) {
|
||||
case StreamType::In:
|
||||
return oboe::Direction::Input;
|
||||
case StreamType::Out:
|
||||
case StreamType::Render:
|
||||
return oboe::Direction::Output;
|
||||
default:
|
||||
ASSERT(false);
|
||||
return oboe::Direction::Output;
|
||||
}
|
||||
}();
|
||||
|
||||
const auto expected_channels = QueryChannelCount(direction);
|
||||
const auto expected_mask = [&]() {
|
||||
switch (expected_channels) {
|
||||
case 1:
|
||||
return oboe::ChannelMask::Mono;
|
||||
case 2:
|
||||
return oboe::ChannelMask::Stereo;
|
||||
case 6:
|
||||
return oboe::ChannelMask::CM5Point1;
|
||||
default:
|
||||
ASSERT(false);
|
||||
return oboe::ChannelMask::Unspecified;
|
||||
}
|
||||
}();
|
||||
|
||||
oboe::AudioStreamBuilder builder;
|
||||
const auto result = ConfigureBuilder(builder, direction)
|
||||
->setChannelCount(expected_channels)
|
||||
->setChannelMask(expected_mask)
|
||||
->setChannelConversionAllowed(true)
|
||||
->setDataCallback(this)
|
||||
->setErrorCallback(this)
|
||||
->openStream(m_stream);
|
||||
ASSERT(result == oboe::Result::OK);
|
||||
return result == oboe::Result::OK && this->SetStreamProperties();
|
||||
}
|
||||
|
||||
bool SetStreamProperties() {
|
||||
ASSERT(m_stream);
|
||||
|
||||
m_stream->setBufferSizeInFrames(TargetSampleCount * 2);
|
||||
device_channels = m_stream->getChannelCount();
|
||||
|
||||
const auto sample_rate = m_stream->getSampleRate();
|
||||
const auto buffer_capacity = m_stream->getBufferCapacityInFrames();
|
||||
const auto stream_backend =
|
||||
m_stream->getAudioApi() == oboe::AudioApi::AAudio ? "AAudio" : "OpenSLES";
|
||||
|
||||
LOG_INFO(Audio_Sink, "Opened Oboe {} stream with {} channels sample rate {} capacity {}",
|
||||
stream_backend, device_channels, sample_rate, buffer_capacity);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<oboe::AudioStream> m_stream{};
|
||||
};
|
||||
|
||||
OboeSink::OboeSink() {
|
||||
// TODO: This is not generally knowable
|
||||
// The channel count is distinct based on direction and can change
|
||||
device_channels = OboeSinkStream::QueryChannelCount(oboe::Direction::Output);
|
||||
}
|
||||
|
||||
OboeSink::~OboeSink() = default;
|
||||
|
||||
SinkStream* OboeSink::AcquireSinkStream(Core::System& system, u32 system_channels,
|
||||
const std::string& name, StreamType type) {
|
||||
SinkStreamPtr& stream = sink_streams.emplace_back(
|
||||
std::make_unique<OboeSinkStream>(system, type, name, system_channels));
|
||||
|
||||
return stream.get();
|
||||
}
|
||||
|
||||
void OboeSink::CloseStream(SinkStream* to_remove) {
|
||||
sink_streams.remove_if([&](auto& stream) { return stream.get() == to_remove; });
|
||||
}
|
||||
|
||||
void OboeSink::CloseStreams() {
|
||||
sink_streams.clear();
|
||||
}
|
||||
|
||||
f32 OboeSink::GetDeviceVolume() const {
|
||||
if (sink_streams.empty()) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return sink_streams.front()->GetDeviceVolume();
|
||||
}
|
||||
|
||||
void OboeSink::SetDeviceVolume(f32 volume) {
|
||||
for (auto& stream : sink_streams) {
|
||||
stream->SetDeviceVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
void OboeSink::SetSystemVolume(f32 volume) {
|
||||
for (auto& stream : sink_streams) {
|
||||
stream->SetSystemVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AudioCore::Sink
|
75
src/audio_core/sink/oboe_sink.h
Normal file
75
src/audio_core/sink/oboe_sink.h
Normal file
@ -0,0 +1,75 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "audio_core/sink/sink.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace AudioCore::Sink {
|
||||
class SinkStream;
|
||||
|
||||
class OboeSink final : public Sink {
|
||||
public:
|
||||
explicit OboeSink();
|
||||
~OboeSink() override;
|
||||
|
||||
/**
|
||||
* Create a new sink stream.
|
||||
*
|
||||
* @param system - Core system.
|
||||
* @param system_channels - Number of channels the audio system expects.
|
||||
* May differ from the device's channel count.
|
||||
* @param name - Name of this stream.
|
||||
* @param type - Type of this stream, render/in/out.
|
||||
*
|
||||
* @return A pointer to the created SinkStream
|
||||
*/
|
||||
SinkStream* AcquireSinkStream(Core::System& system, u32 system_channels,
|
||||
const std::string& name, StreamType type) override;
|
||||
|
||||
/**
|
||||
* Close a given stream.
|
||||
*
|
||||
* @param stream - The stream to close.
|
||||
*/
|
||||
void CloseStream(SinkStream* stream) override;
|
||||
|
||||
/**
|
||||
* Close all streams.
|
||||
*/
|
||||
void CloseStreams() override;
|
||||
|
||||
/**
|
||||
* Get the device volume. Set from calls to the IAudioDevice service.
|
||||
*
|
||||
* @return Volume of the device.
|
||||
*/
|
||||
f32 GetDeviceVolume() const override;
|
||||
|
||||
/**
|
||||
* Set the device volume. Set from calls to the IAudioDevice service.
|
||||
*
|
||||
* @param volume - New volume of the device.
|
||||
*/
|
||||
void SetDeviceVolume(f32 volume) override;
|
||||
|
||||
/**
|
||||
* Set the system volume. Comes from the audio system using this stream.
|
||||
*
|
||||
* @param volume - New volume of the system.
|
||||
*/
|
||||
void SetSystemVolume(f32 volume) override;
|
||||
|
||||
private:
|
||||
/// List of streams managed by this sink
|
||||
std::list<SinkStreamPtr> sink_streams{};
|
||||
};
|
||||
|
||||
} // namespace AudioCore::Sink
|
@ -168,8 +168,9 @@ SDLSink::SDLSink(std::string_view target_device_name) {
|
||||
|
||||
SDLSink::~SDLSink() = default;
|
||||
|
||||
SinkStream* SDLSink::AcquireSinkStream(Core::System& system, u32 system_channels,
|
||||
SinkStream* SDLSink::AcquireSinkStream(Core::System& system, u32 system_channels_,
|
||||
const std::string&, StreamType type) {
|
||||
system_channels = system_channels_;
|
||||
SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<SDLSinkStream>(
|
||||
device_channels, system_channels, output_device, input_device, type, system));
|
||||
return stream.get();
|
||||
|
@ -85,9 +85,21 @@ public:
|
||||
*/
|
||||
virtual void SetSystemVolume(f32 volume) = 0;
|
||||
|
||||
/**
|
||||
* Get the number of channels the game has set, can be different to the host hardware's support.
|
||||
* Either 2 or 6.
|
||||
*
|
||||
* @return Number of device channels.
|
||||
*/
|
||||
u32 GetSystemChannels() const {
|
||||
return system_channels;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Number of device channels supported by the hardware
|
||||
u32 device_channels{2};
|
||||
/// Number of channels the game is sending
|
||||
u32 system_channels{2};
|
||||
};
|
||||
|
||||
using SinkPtr = std::unique_ptr<Sink>;
|
||||
|
@ -7,6 +7,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "audio_core/sink/sink_details.h"
|
||||
#ifdef HAVE_OBOE
|
||||
#include "audio_core/sink/oboe_sink.h"
|
||||
#endif
|
||||
#ifdef HAVE_CUBEB
|
||||
#include "audio_core/sink/cubeb_sink.h"
|
||||
#endif
|
||||
@ -36,6 +39,16 @@ struct SinkDetails {
|
||||
|
||||
// sink_details is ordered in terms of desirability, with the best choice at the top.
|
||||
constexpr SinkDetails sink_details[] = {
|
||||
#ifdef HAVE_OBOE
|
||||
SinkDetails{
|
||||
Settings::AudioEngine::Oboe,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Sink> {
|
||||
return std::make_unique<OboeSink>();
|
||||
},
|
||||
[](bool capture) { return std::vector<std::string>{"Default"}; },
|
||||
[]() { return true; },
|
||||
},
|
||||
#endif
|
||||
#ifdef HAVE_CUBEB
|
||||
SinkDetails{
|
||||
Settings::AudioEngine::Cubeb,
|
||||
|
@ -40,29 +40,36 @@ void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
|
||||
|
||||
if (system_channels == 6 && device_channels == 2) {
|
||||
// We're given 6 channels, but our device only outputs 2, so downmix.
|
||||
static constexpr std::array<f32, 4> down_mix_coeff{1.0f, 0.707f, 0.251f, 0.707f};
|
||||
// Front = 1.0
|
||||
// Center = 0.596
|
||||
// LFE = 0.354
|
||||
// Back = 0.707
|
||||
static constexpr std::array<f32, 4> down_mix_coeff{1.0, 0.596f, 0.354f, 0.707f};
|
||||
|
||||
for (u32 read_index = 0, write_index = 0; read_index < samples.size();
|
||||
read_index += system_channels, write_index += device_channels) {
|
||||
const auto fl =
|
||||
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::FrontLeft)]);
|
||||
const auto fr =
|
||||
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::FrontRight)]);
|
||||
const auto c =
|
||||
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::Center)]);
|
||||
const auto lfe =
|
||||
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::LFE)]);
|
||||
const auto bl =
|
||||
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::BackLeft)]);
|
||||
const auto br =
|
||||
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::BackRight)]);
|
||||
|
||||
const auto left_sample{
|
||||
((Common::FixedPoint<49, 15>(
|
||||
samples[read_index + static_cast<u32>(Channels::FrontLeft)]) *
|
||||
down_mix_coeff[0] +
|
||||
samples[read_index + static_cast<u32>(Channels::Center)] * down_mix_coeff[1] +
|
||||
samples[read_index + static_cast<u32>(Channels::LFE)] * down_mix_coeff[2] +
|
||||
samples[read_index + static_cast<u32>(Channels::BackLeft)] * down_mix_coeff[3]) *
|
||||
volume)
|
||||
.to_int()};
|
||||
static_cast<s32>((fl * down_mix_coeff[0] + c * down_mix_coeff[1] +
|
||||
lfe * down_mix_coeff[2] + bl * down_mix_coeff[3]) *
|
||||
volume)};
|
||||
|
||||
const auto right_sample{
|
||||
((Common::FixedPoint<49, 15>(
|
||||
samples[read_index + static_cast<u32>(Channels::FrontRight)]) *
|
||||
down_mix_coeff[0] +
|
||||
samples[read_index + static_cast<u32>(Channels::Center)] * down_mix_coeff[1] +
|
||||
samples[read_index + static_cast<u32>(Channels::LFE)] * down_mix_coeff[2] +
|
||||
samples[read_index + static_cast<u32>(Channels::BackRight)] * down_mix_coeff[3]) *
|
||||
volume)
|
||||
.to_int()};
|
||||
static_cast<s32>((fr * down_mix_coeff[0] + c * down_mix_coeff[1] +
|
||||
lfe * down_mix_coeff[2] + br * down_mix_coeff[3]) *
|
||||
volume)};
|
||||
|
||||
samples[write_index + static_cast<u32>(Channels::FrontLeft)] =
|
||||
static_cast<s16>(std::clamp(left_sample, min, max));
|
||||
|
@ -123,6 +123,12 @@ namespace Common {
|
||||
return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr u64 MakeMagic(char a, char b, char c, char d, char e, char f, char g,
|
||||
char h) {
|
||||
return u64(a) << 0 | u64(b) << 8 | u64(c) << 16 | u64(d) << 24 | u64(e) << 32 | u64(f) << 40 |
|
||||
u64(g) << 48 | u64(h) << 56;
|
||||
}
|
||||
|
||||
// std::size() does not support zero-size C arrays. We're fixing that.
|
||||
template <class C>
|
||||
constexpr auto Size(const C& c) -> decltype(c.size()) {
|
||||
|
@ -354,18 +354,36 @@ std::string_view RemoveTrailingSlash(std::string_view path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
std::vector<std::string> SplitPathComponents(std::string_view filename) {
|
||||
std::string copy(filename);
|
||||
std::replace(copy.begin(), copy.end(), '\\', '/');
|
||||
std::vector<std::string> out;
|
||||
|
||||
std::stringstream stream(copy);
|
||||
std::string item;
|
||||
while (std::getline(stream, item, '/')) {
|
||||
out.push_back(std::move(item));
|
||||
template <typename F>
|
||||
static void ForEachPathComponent(std::string_view filename, F&& cb) {
|
||||
const char* component_begin = filename.data();
|
||||
const char* const end = component_begin + filename.size();
|
||||
for (const char* it = component_begin; it != end; ++it) {
|
||||
const char c = *it;
|
||||
if (c == '\\' || c == '/') {
|
||||
if (component_begin != it) {
|
||||
cb(std::string_view{component_begin, it});
|
||||
}
|
||||
component_begin = it + 1;
|
||||
}
|
||||
}
|
||||
if (component_begin != end) {
|
||||
cb(std::string_view{component_begin, end});
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
std::vector<std::string_view> SplitPathComponents(std::string_view filename) {
|
||||
std::vector<std::string_view> components;
|
||||
ForEachPathComponent(filename, [&](auto component) { components.emplace_back(component); });
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
std::vector<std::string> SplitPathComponentsCopy(std::string_view filename) {
|
||||
std::vector<std::string> components;
|
||||
ForEachPathComponent(filename, [&](auto component) { components.emplace_back(component); });
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
std::string SanitizePath(std::string_view path_, DirectorySeparator directory_separator) {
|
||||
@ -400,9 +418,9 @@ std::string SanitizePath(std::string_view path_, DirectorySeparator directory_se
|
||||
return std::string(RemoveTrailingSlash(path));
|
||||
}
|
||||
|
||||
std::string_view GetParentPath(std::string_view path) {
|
||||
std::string GetParentPath(std::string_view path) {
|
||||
if (path.empty()) {
|
||||
return path;
|
||||
return std::string(path);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
@ -421,7 +439,7 @@ std::string_view GetParentPath(std::string_view path) {
|
||||
name_index = std::max(name_bck_index, name_fwd_index);
|
||||
}
|
||||
|
||||
return path.substr(0, name_index);
|
||||
return std::string(path.substr(0, name_index));
|
||||
}
|
||||
|
||||
std::string_view GetPathWithoutTop(std::string_view path) {
|
||||
|
@ -289,7 +289,11 @@ enum class DirectorySeparator {
|
||||
|
||||
// Splits the path on '/' or '\' and put the components into a vector
|
||||
// i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" }
|
||||
[[nodiscard]] std::vector<std::string> SplitPathComponents(std::string_view filename);
|
||||
[[nodiscard]] std::vector<std::string_view> SplitPathComponents(std::string_view filename);
|
||||
|
||||
// Splits the path on '/' or '\' and put the components into a vector
|
||||
// i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" }
|
||||
[[nodiscard]] std::vector<std::string> SplitPathComponentsCopy(std::string_view filename);
|
||||
|
||||
// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\'
|
||||
// depending if directory_separator is BackwardSlash or PlatformDefault and running on windows
|
||||
@ -298,7 +302,7 @@ enum class DirectorySeparator {
|
||||
DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash);
|
||||
|
||||
// Gets all of the text up to the last '/' or '\' in the path.
|
||||
[[nodiscard]] std::string_view GetParentPath(std::string_view path);
|
||||
[[nodiscard]] std::string GetParentPath(std::string_view path);
|
||||
|
||||
// Gets all of the text after the first '/' or '\' in the path.
|
||||
[[nodiscard]] std::string_view GetPathWithoutTop(std::string_view path);
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
#elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/sharedmem.h>
|
||||
#endif
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
@ -193,6 +189,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
||||
// TODO: This does not seem to be possible on Windows.
|
||||
return false;
|
||||
}
|
||||
|
||||
void EnableDirectMappedAddress() {
|
||||
// TODO
|
||||
UNREACHABLE();
|
||||
@ -442,9 +443,7 @@ public:
|
||||
}
|
||||
|
||||
// Backing memory initialization
|
||||
#ifdef ANDROID
|
||||
fd = ASharedMemory_create("HostMemory", backing_size);
|
||||
#elif defined(__FreeBSD__) && __FreeBSD__ < 13
|
||||
#if defined(__FreeBSD__) && __FreeBSD__ < 13
|
||||
// XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30
|
||||
fd = shm_open(SHM_ANON, O_RDWR, 0600);
|
||||
#else
|
||||
@ -455,7 +454,6 @@ public:
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
|
||||
#ifndef ANDROID
|
||||
// Defined to extend the file with zeros
|
||||
int ret = ftruncate(fd, backing_size);
|
||||
if (ret != 0) {
|
||||
@ -463,7 +461,6 @@ public:
|
||||
strerror(errno));
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
#endif
|
||||
|
||||
backing_base = static_cast<u8*>(
|
||||
mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
||||
@ -552,6 +549,19 @@ public:
|
||||
ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno));
|
||||
}
|
||||
|
||||
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
||||
#ifdef __linux__
|
||||
// Set MADV_REMOVE on backing map to destroy it instantly.
|
||||
// This also deletes the area from the backing file.
|
||||
int ret = madvise(backing_base + physical_offset, length, MADV_REMOVE);
|
||||
ASSERT_MSG(ret == 0, "madvise failed: {}", strerror(errno));
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void EnableDirectMappedAddress() {
|
||||
virtual_base = nullptr;
|
||||
}
|
||||
@ -623,6 +633,10 @@ public:
|
||||
|
||||
void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {}
|
||||
|
||||
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void EnableDirectMappedAddress() {}
|
||||
|
||||
u8* backing_base{nullptr};
|
||||
@ -698,6 +712,12 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, bool read, bool w
|
||||
impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute);
|
||||
}
|
||||
|
||||
void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) {
|
||||
if (!impl || fill_value != 0 || !impl->ClearBackingRegion(physical_offset, length)) {
|
||||
std::memset(backing_base + physical_offset, fill_value, length);
|
||||
}
|
||||
}
|
||||
|
||||
void HostMemory::EnableDirectMappedAddress() {
|
||||
if (impl) {
|
||||
impl->EnableDirectMappedAddress();
|
||||
|
@ -48,6 +48,8 @@ public:
|
||||
|
||||
void EnableDirectMappedAddress();
|
||||
|
||||
void ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value);
|
||||
|
||||
[[nodiscard]] u8* BackingBasePointer() noexcept {
|
||||
return backing_base;
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ struct Values {
|
||||
AstcDecodeMode::CpuAsynchronous,
|
||||
"accelerate_astc",
|
||||
Category::Renderer};
|
||||
Setting<VSyncMode, true> vsync_mode{
|
||||
SwitchableSetting<VSyncMode, true> vsync_mode{
|
||||
linkage, VSyncMode::Fifo, VSyncMode::Immediate, VSyncMode::FifoRelaxed,
|
||||
"use_vsync", Category::Renderer, Specialization::RuntimeList, true,
|
||||
true};
|
||||
|
@ -82,16 +82,15 @@ enum class AudioEngine : u32 {
|
||||
Cubeb,
|
||||
Sdl2,
|
||||
Null,
|
||||
Oboe,
|
||||
};
|
||||
|
||||
template <>
|
||||
inline std::vector<std::pair<std::string, AudioEngine>>
|
||||
EnumMetadata<AudioEngine>::Canonicalizations() {
|
||||
return {
|
||||
{"auto", AudioEngine::Auto},
|
||||
{"cubeb", AudioEngine::Cubeb},
|
||||
{"sdl2", AudioEngine::Sdl2},
|
||||
{"null", AudioEngine::Null},
|
||||
{"auto", AudioEngine::Auto}, {"cubeb", AudioEngine::Cubeb}, {"sdl2", AudioEngine::Sdl2},
|
||||
{"null", AudioEngine::Null}, {"oboe", AudioEngine::Oboe},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -549,6 +549,11 @@ add_library(core STATIC
|
||||
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/touch_types.h
|
||||
hle/service/hid/controllers/applet_resource.cpp
|
||||
hle/service/hid/controllers/applet_resource.h
|
||||
hle/service/hid/controllers/console_six_axis.cpp
|
||||
@ -569,14 +574,15 @@ add_library(core STATIC
|
||||
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_format.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/stubbed.cpp
|
||||
hle/service/hid/controllers/stubbed.h
|
||||
hle/service/hid/controllers/touchscreen.cpp
|
||||
hle/service/hid/controllers/touchscreen.h
|
||||
hle/service/hid/controllers/xpad.cpp
|
||||
hle/service/hid/controllers/xpad.h
|
||||
hle/service/hid/hidbus/hidbus_base.cpp
|
||||
hle/service/hid/hidbus/hidbus_base.h
|
||||
hle/service/hid/hidbus/ringcon.cpp
|
||||
@ -784,6 +790,12 @@ add_library(core STATIC
|
||||
hle/service/service.h
|
||||
hle/service/set/set.cpp
|
||||
hle/service/set/set.h
|
||||
hle/service/set/appln_settings.cpp
|
||||
hle/service/set/appln_settings.h
|
||||
hle/service/set/device_settings.cpp
|
||||
hle/service/set/device_settings.h
|
||||
hle/service/set/private_settings.cpp
|
||||
hle/service/set/private_settings.h
|
||||
hle/service/set/set_cal.cpp
|
||||
hle/service/set/set_cal.h
|
||||
hle/service/set/set_fd.cpp
|
||||
@ -792,6 +804,8 @@ add_library(core STATIC
|
||||
hle/service/set/set_sys.h
|
||||
hle/service/set/settings.cpp
|
||||
hle/service/set/settings.h
|
||||
hle/service/set/system_settings.cpp
|
||||
hle/service/set/system_settings.h
|
||||
hle/service/sm/sm.cpp
|
||||
hle/service/sm/sm.h
|
||||
hle/service/sm/sm_controller.cpp
|
||||
@ -947,15 +961,19 @@ if (HAS_NCE)
|
||||
set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp")
|
||||
|
||||
target_sources(core PRIVATE
|
||||
arm/nce/arm_nce_asm_definitions.h
|
||||
arm/nce/arm_nce.cpp
|
||||
arm/nce/arm_nce.h
|
||||
arm/nce/arm_nce.s
|
||||
arm/nce/guest_context.h
|
||||
arm/nce/instructions.h
|
||||
arm/nce/interpreter_visitor.cpp
|
||||
arm/nce/interpreter_visitor.h
|
||||
arm/nce/patcher.cpp
|
||||
arm/nce/patcher.h
|
||||
arm/nce/instructions.h
|
||||
arm/nce/visitor_base.h
|
||||
)
|
||||
target_link_libraries(core PRIVATE merry::oaknut)
|
||||
target_link_libraries(core PRIVATE merry::mcl merry::oaknut)
|
||||
endif()
|
||||
|
||||
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "common/signal_chain.h"
|
||||
#include "core/arm/nce/arm_nce.h"
|
||||
#include "core/arm/nce/guest_context.h"
|
||||
#include "core/arm/nce/interpreter_visitor.h"
|
||||
#include "core/arm/nce/patcher.h"
|
||||
#include "core/core.h"
|
||||
#include "core/memory.h"
|
||||
@ -21,7 +21,8 @@ namespace Core {
|
||||
|
||||
namespace {
|
||||
|
||||
struct sigaction g_orig_action;
|
||||
struct sigaction g_orig_bus_action;
|
||||
struct sigaction g_orig_segv_action;
|
||||
|
||||
// Verify assembly offsets.
|
||||
using NativeExecutionParameters = Kernel::KThread::NativeExecutionParameters;
|
||||
@ -37,6 +38,9 @@ fpsimd_context* GetFloatingPointState(mcontext_t& host_ctx) {
|
||||
return reinterpret_cast<fpsimd_context*>(header);
|
||||
}
|
||||
|
||||
using namespace Common::Literals;
|
||||
constexpr u32 StackSize = 128_KiB;
|
||||
|
||||
} // namespace
|
||||
|
||||
void* ArmNce::RestoreGuestContext(void* raw_context) {
|
||||
@ -104,19 +108,10 @@ void ArmNce::SaveGuestContext(GuestContext* guest_ctx, void* raw_context) {
|
||||
host_ctx.regs[0] = guest_ctx->esr_el1.exchange(0);
|
||||
}
|
||||
|
||||
bool ArmNce::HandleGuestFault(GuestContext* guest_ctx, void* raw_info, void* raw_context) {
|
||||
bool ArmNce::HandleFailedGuestFault(GuestContext* guest_ctx, void* raw_info, void* raw_context) {
|
||||
auto& host_ctx = static_cast<ucontext_t*>(raw_context)->uc_mcontext;
|
||||
auto* info = static_cast<siginfo_t*>(raw_info);
|
||||
|
||||
// Try to handle an invalid access.
|
||||
// TODO: handle accesses which split a page?
|
||||
const Common::ProcessAddress addr =
|
||||
(reinterpret_cast<u64>(info->si_addr) & ~Memory::YUZU_PAGEMASK);
|
||||
if (guest_ctx->system->ApplicationMemory().InvalidateNCE(addr, Memory::YUZU_PAGESIZE)) {
|
||||
// We handled the access successfully and are returning to guest code.
|
||||
return true;
|
||||
}
|
||||
|
||||
// We can't handle the access, so determine why we crashed.
|
||||
const bool is_prefetch_abort = host_ctx.pc == reinterpret_cast<u64>(info->si_addr);
|
||||
|
||||
@ -143,8 +138,44 @@ bool ArmNce::HandleGuestFault(GuestContext* guest_ctx, void* raw_info, void* raw
|
||||
return false;
|
||||
}
|
||||
|
||||
void ArmNce::HandleHostFault(int sig, void* raw_info, void* raw_context) {
|
||||
return g_orig_action.sa_sigaction(sig, static_cast<siginfo_t*>(raw_info), raw_context);
|
||||
bool ArmNce::HandleGuestAlignmentFault(GuestContext* guest_ctx, void* raw_info, void* raw_context) {
|
||||
auto& host_ctx = static_cast<ucontext_t*>(raw_context)->uc_mcontext;
|
||||
auto* fpctx = GetFloatingPointState(host_ctx);
|
||||
auto& memory = guest_ctx->system->ApplicationMemory();
|
||||
|
||||
// Match and execute an instruction.
|
||||
auto next_pc = MatchAndExecuteOneInstruction(memory, &host_ctx, fpctx);
|
||||
if (next_pc) {
|
||||
host_ctx.pc = *next_pc;
|
||||
return true;
|
||||
}
|
||||
|
||||
// We couldn't handle the access.
|
||||
return HandleFailedGuestFault(guest_ctx, raw_info, raw_context);
|
||||
}
|
||||
|
||||
bool ArmNce::HandleGuestAccessFault(GuestContext* guest_ctx, void* raw_info, void* raw_context) {
|
||||
auto* info = static_cast<siginfo_t*>(raw_info);
|
||||
|
||||
// Try to handle an invalid access.
|
||||
// TODO: handle accesses which split a page?
|
||||
const Common::ProcessAddress addr =
|
||||
(reinterpret_cast<u64>(info->si_addr) & ~Memory::YUZU_PAGEMASK);
|
||||
if (guest_ctx->system->ApplicationMemory().InvalidateNCE(addr, Memory::YUZU_PAGESIZE)) {
|
||||
// We handled the access successfully and are returning to guest code.
|
||||
return true;
|
||||
}
|
||||
|
||||
// We couldn't handle the access.
|
||||
return HandleFailedGuestFault(guest_ctx, raw_info, raw_context);
|
||||
}
|
||||
|
||||
void ArmNce::HandleHostAlignmentFault(int sig, void* raw_info, void* raw_context) {
|
||||
return g_orig_bus_action.sa_sigaction(sig, static_cast<siginfo_t*>(raw_info), raw_context);
|
||||
}
|
||||
|
||||
void ArmNce::HandleHostAccessFault(int sig, void* raw_info, void* raw_context) {
|
||||
return g_orig_segv_action.sa_sigaction(sig, static_cast<siginfo_t*>(raw_info), raw_context);
|
||||
}
|
||||
|
||||
void ArmNce::LockThread(Kernel::KThread* thread) {
|
||||
@ -225,18 +256,31 @@ ArmNce::ArmNce(System& system, bool uses_wall_clock, std::size_t core_index)
|
||||
ArmNce::~ArmNce() = default;
|
||||
|
||||
void ArmNce::Initialize() {
|
||||
m_thread_id = gettid();
|
||||
if (m_thread_id == -1) {
|
||||
m_thread_id = gettid();
|
||||
}
|
||||
|
||||
// Setup our signals
|
||||
static std::once_flag signals;
|
||||
std::call_once(signals, [] {
|
||||
// Configure signal stack.
|
||||
if (!m_stack) {
|
||||
m_stack = std::make_unique<u8[]>(StackSize);
|
||||
|
||||
stack_t ss{};
|
||||
ss.ss_sp = m_stack.get();
|
||||
ss.ss_size = StackSize;
|
||||
sigaltstack(&ss, nullptr);
|
||||
}
|
||||
|
||||
// Set up signals.
|
||||
static std::once_flag flag;
|
||||
std::call_once(flag, [] {
|
||||
using HandlerType = decltype(sigaction::sa_sigaction);
|
||||
|
||||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
sigaddset(&signal_mask, ReturnToRunCodeByExceptionLevelChangeSignal);
|
||||
sigaddset(&signal_mask, BreakFromRunCodeSignal);
|
||||
sigaddset(&signal_mask, GuestFaultSignal);
|
||||
sigaddset(&signal_mask, GuestAlignmentFaultSignal);
|
||||
sigaddset(&signal_mask, GuestAccessFaultSignal);
|
||||
|
||||
struct sigaction return_to_run_code_action {};
|
||||
return_to_run_code_action.sa_flags = SA_SIGINFO | SA_ONSTACK;
|
||||
@ -253,18 +297,19 @@ void ArmNce::Initialize() {
|
||||
break_from_run_code_action.sa_mask = signal_mask;
|
||||
Common::SigAction(BreakFromRunCodeSignal, &break_from_run_code_action, nullptr);
|
||||
|
||||
struct sigaction fault_action {};
|
||||
fault_action.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
|
||||
fault_action.sa_sigaction = reinterpret_cast<HandlerType>(&ArmNce::GuestFaultSignalHandler);
|
||||
fault_action.sa_mask = signal_mask;
|
||||
Common::SigAction(GuestFaultSignal, &fault_action, &g_orig_action);
|
||||
struct sigaction alignment_fault_action {};
|
||||
alignment_fault_action.sa_flags = SA_SIGINFO | SA_ONSTACK;
|
||||
alignment_fault_action.sa_sigaction =
|
||||
reinterpret_cast<HandlerType>(&ArmNce::GuestAlignmentFaultSignalHandler);
|
||||
alignment_fault_action.sa_mask = signal_mask;
|
||||
Common::SigAction(GuestAlignmentFaultSignal, &alignment_fault_action, nullptr);
|
||||
|
||||
// Simplify call for g_orig_action.
|
||||
// These fields occupy the same space in memory, so this should be a no-op in practice.
|
||||
if (!(g_orig_action.sa_flags & SA_SIGINFO)) {
|
||||
g_orig_action.sa_sigaction =
|
||||
reinterpret_cast<decltype(g_orig_action.sa_sigaction)>(g_orig_action.sa_handler);
|
||||
}
|
||||
struct sigaction access_fault_action {};
|
||||
access_fault_action.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
|
||||
access_fault_action.sa_sigaction =
|
||||
reinterpret_cast<HandlerType>(&ArmNce::GuestAccessFaultSignalHandler);
|
||||
access_fault_action.sa_mask = signal_mask;
|
||||
Common::SigAction(GuestAccessFaultSignal, &access_fault_action, &g_orig_segv_action);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,8 @@ private:
|
||||
static void ReturnToRunCodeByExceptionLevelChangeSignalHandler(int sig, void* info,
|
||||
void* raw_context);
|
||||
static void BreakFromRunCodeSignalHandler(int sig, void* info, void* raw_context);
|
||||
static void GuestFaultSignalHandler(int sig, void* info, void* raw_context);
|
||||
static void GuestAlignmentFaultSignalHandler(int sig, void* info, void* raw_context);
|
||||
static void GuestAccessFaultSignalHandler(int sig, void* info, void* raw_context);
|
||||
|
||||
static void LockThreadParameters(void* tpidr);
|
||||
static void UnlockThreadParameters(void* tpidr);
|
||||
@ -70,8 +71,11 @@ private:
|
||||
// C++ implementation functions for assembly definitions.
|
||||
static void* RestoreGuestContext(void* raw_context);
|
||||
static void SaveGuestContext(GuestContext* ctx, void* raw_context);
|
||||
static bool HandleGuestFault(GuestContext* ctx, void* info, void* raw_context);
|
||||
static void HandleHostFault(int sig, void* info, void* raw_context);
|
||||
static bool HandleFailedGuestFault(GuestContext* ctx, void* info, void* raw_context);
|
||||
static bool HandleGuestAlignmentFault(GuestContext* ctx, void* info, void* raw_context);
|
||||
static bool HandleGuestAccessFault(GuestContext* ctx, void* info, void* raw_context);
|
||||
static void HandleHostAlignmentFault(int sig, void* info, void* raw_context);
|
||||
static void HandleHostAccessFault(int sig, void* info, void* raw_context);
|
||||
|
||||
public:
|
||||
Core::System& m_system;
|
||||
@ -83,6 +87,9 @@ public:
|
||||
// Core context.
|
||||
GuestContext m_guest_ctx{};
|
||||
Kernel::KThread* m_running_thread{};
|
||||
|
||||
// Stack for signal processing.
|
||||
std::unique_ptr<u8[]> m_stack{};
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
@ -130,11 +130,11 @@ _ZN4Core6ArmNce29BreakFromRunCodeSignalHandlerEiPvS1_:
|
||||
ret
|
||||
|
||||
|
||||
/* static void Core::ArmNce::GuestFaultSignalHandler(int sig, void* info, void* raw_context) */
|
||||
.section .text._ZN4Core6ArmNce23GuestFaultSignalHandlerEiPvS1_, "ax", %progbits
|
||||
.global _ZN4Core6ArmNce23GuestFaultSignalHandlerEiPvS1_
|
||||
.type _ZN4Core6ArmNce23GuestFaultSignalHandlerEiPvS1_, %function
|
||||
_ZN4Core6ArmNce23GuestFaultSignalHandlerEiPvS1_:
|
||||
/* static void Core::ArmNce::GuestAlignmentFaultSignalHandler(int sig, void* info, void* raw_context) */
|
||||
.section .text._ZN4Core6ArmNce32GuestAlignmentFaultSignalHandlerEiPvS1_, "ax", %progbits
|
||||
.global _ZN4Core6ArmNce32GuestAlignmentFaultSignalHandlerEiPvS1_
|
||||
.type _ZN4Core6ArmNce32GuestAlignmentFaultSignalHandlerEiPvS1_, %function
|
||||
_ZN4Core6ArmNce32GuestAlignmentFaultSignalHandlerEiPvS1_:
|
||||
/* Check to see if we have the correct TLS magic. */
|
||||
mrs x8, tpidr_el0
|
||||
ldr w9, [x8, #(TpidrEl0TlsMagic)]
|
||||
@ -146,7 +146,7 @@ _ZN4Core6ArmNce23GuestFaultSignalHandlerEiPvS1_:
|
||||
|
||||
/* Incorrect TLS magic, so this is a host fault. */
|
||||
/* Tail call the handler. */
|
||||
b _ZN4Core6ArmNce15HandleHostFaultEiPvS1_
|
||||
b _ZN4Core6ArmNce24HandleHostAlignmentFaultEiPvS1_
|
||||
|
||||
1:
|
||||
/* Correct TLS magic, so this is a guest fault. */
|
||||
@ -163,7 +163,53 @@ _ZN4Core6ArmNce23GuestFaultSignalHandlerEiPvS1_:
|
||||
msr tpidr_el0, x3
|
||||
|
||||
/* Call the handler. */
|
||||
bl _ZN4Core6ArmNce16HandleGuestFaultEPNS_12GuestContextEPvS3_
|
||||
bl _ZN4Core6ArmNce25HandleGuestAlignmentFaultEPNS_12GuestContextEPvS3_
|
||||
|
||||
/* If the handler returned false, we want to preserve the host tpidr_el0. */
|
||||
cbz x0, 2f
|
||||
|
||||
/* Otherwise, restore guest tpidr_el0. */
|
||||
msr tpidr_el0, x19
|
||||
|
||||
2:
|
||||
ldr x19, [sp, #0x10]
|
||||
ldp x29, x30, [sp], #0x20
|
||||
ret
|
||||
|
||||
/* static void Core::ArmNce::GuestAccessFaultSignalHandler(int sig, void* info, void* raw_context) */
|
||||
.section .text._ZN4Core6ArmNce29GuestAccessFaultSignalHandlerEiPvS1_, "ax", %progbits
|
||||
.global _ZN4Core6ArmNce29GuestAccessFaultSignalHandlerEiPvS1_
|
||||
.type _ZN4Core6ArmNce29GuestAccessFaultSignalHandlerEiPvS1_, %function
|
||||
_ZN4Core6ArmNce29GuestAccessFaultSignalHandlerEiPvS1_:
|
||||
/* Check to see if we have the correct TLS magic. */
|
||||
mrs x8, tpidr_el0
|
||||
ldr w9, [x8, #(TpidrEl0TlsMagic)]
|
||||
|
||||
LOAD_IMMEDIATE_32(w10, TlsMagic)
|
||||
|
||||
cmp w9, w10
|
||||
b.eq 1f
|
||||
|
||||
/* Incorrect TLS magic, so this is a host fault. */
|
||||
/* Tail call the handler. */
|
||||
b _ZN4Core6ArmNce21HandleHostAccessFaultEiPvS1_
|
||||
|
||||
1:
|
||||
/* Correct TLS magic, so this is a guest fault. */
|
||||
stp x29, x30, [sp, #-0x20]!
|
||||
str x19, [sp, #0x10]
|
||||
mov x29, sp
|
||||
|
||||
/* Save the old tpidr_el0. */
|
||||
mov x19, x8
|
||||
|
||||
/* Restore host tpidr_el0. */
|
||||
ldr x0, [x8, #(TpidrEl0NativeContext)]
|
||||
ldr x3, [x0, #(GuestContextHostContext + HostContextTpidrEl0)]
|
||||
msr tpidr_el0, x3
|
||||
|
||||
/* Call the handler. */
|
||||
bl _ZN4Core6ArmNce22HandleGuestAccessFaultEPNS_12GuestContextEPvS3_
|
||||
|
||||
/* If the handler returned false, we want to preserve the host tpidr_el0. */
|
||||
cbz x0, 2f
|
||||
|
@ -10,7 +10,8 @@
|
||||
|
||||
#define ReturnToRunCodeByExceptionLevelChangeSignal SIGUSR2
|
||||
#define BreakFromRunCodeSignal SIGURG
|
||||
#define GuestFaultSignal SIGSEGV
|
||||
#define GuestAccessFaultSignal SIGSEGV
|
||||
#define GuestAlignmentFaultSignal SIGBUS
|
||||
|
||||
#define GuestContextSp 0xF8
|
||||
#define GuestContextHostContext 0x320
|
||||
|
824
src/core/arm/nce/interpreter_visitor.cpp
Normal file
824
src/core/arm/nce/interpreter_visitor.cpp
Normal file
@ -0,0 +1,824 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2023 merryhime <https://mary.rs>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/bit_cast.h"
|
||||
#include "core/arm/nce/interpreter_visitor.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
template <u32 BitSize>
|
||||
u64 SignExtendToLong(u64 value) {
|
||||
u64 mask = 1ULL << (BitSize - 1);
|
||||
value &= (1ULL << BitSize) - 1;
|
||||
return (value ^ mask) - mask;
|
||||
}
|
||||
|
||||
static u64 SignExtendToLong(u64 value, u64 bitsize) {
|
||||
switch (bitsize) {
|
||||
case 8:
|
||||
return SignExtendToLong<8>(value);
|
||||
case 16:
|
||||
return SignExtendToLong<16>(value);
|
||||
case 32:
|
||||
return SignExtendToLong<32>(value);
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
template <u64 BitSize>
|
||||
u32 SignExtendToWord(u32 value) {
|
||||
u32 mask = 1ULL << (BitSize - 1);
|
||||
value &= (1ULL << BitSize) - 1;
|
||||
return (value ^ mask) - mask;
|
||||
}
|
||||
|
||||
static u32 SignExtendToWord(u32 value, u64 bitsize) {
|
||||
switch (bitsize) {
|
||||
case 8:
|
||||
return SignExtendToWord<8>(value);
|
||||
case 16:
|
||||
return SignExtendToWord<16>(value);
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
static u64 SignExtend(u64 value, u64 bitsize, u64 regsize) {
|
||||
if (regsize == 64) {
|
||||
return SignExtendToLong(value, bitsize);
|
||||
} else {
|
||||
return SignExtendToWord(static_cast<u32>(value), bitsize);
|
||||
}
|
||||
}
|
||||
|
||||
static u128 VectorGetElement(u128 value, u64 bitsize) {
|
||||
switch (bitsize) {
|
||||
case 8:
|
||||
return {value[0] & ((1ULL << 8) - 1), 0};
|
||||
case 16:
|
||||
return {value[0] & ((1ULL << 16) - 1), 0};
|
||||
case 32:
|
||||
return {value[0] & ((1ULL << 32) - 1), 0};
|
||||
case 64:
|
||||
return {value[0], 0};
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
u64 InterpreterVisitor::ExtendReg(size_t bitsize, Reg reg, Imm<3> option, u8 shift) {
|
||||
ASSERT(shift <= 4);
|
||||
ASSERT(bitsize == 32 || bitsize == 64);
|
||||
u64 val = this->GetReg(reg);
|
||||
size_t len;
|
||||
u64 extended;
|
||||
bool signed_extend;
|
||||
|
||||
switch (option.ZeroExtend()) {
|
||||
case 0b000: { // UXTB
|
||||
val &= ((1ULL << 8) - 1);
|
||||
len = 8;
|
||||
signed_extend = false;
|
||||
break;
|
||||
}
|
||||
case 0b001: { // UXTH
|
||||
val &= ((1ULL << 16) - 1);
|
||||
len = 16;
|
||||
signed_extend = false;
|
||||
break;
|
||||
}
|
||||
case 0b010: { // UXTW
|
||||
val &= ((1ULL << 32) - 1);
|
||||
len = 32;
|
||||
signed_extend = false;
|
||||
break;
|
||||
}
|
||||
case 0b011: { // UXTX
|
||||
len = 64;
|
||||
signed_extend = false;
|
||||
break;
|
||||
}
|
||||
case 0b100: { // SXTB
|
||||
val &= ((1ULL << 8) - 1);
|
||||
len = 8;
|
||||
signed_extend = true;
|
||||
break;
|
||||
}
|
||||
case 0b101: { // SXTH
|
||||
val &= ((1ULL << 16) - 1);
|
||||
len = 16;
|
||||
signed_extend = true;
|
||||
break;
|
||||
}
|
||||
case 0b110: { // SXTW
|
||||
val &= ((1ULL << 32) - 1);
|
||||
len = 32;
|
||||
signed_extend = true;
|
||||
break;
|
||||
}
|
||||
case 0b111: { // SXTX
|
||||
len = 64;
|
||||
signed_extend = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (len < bitsize && signed_extend) {
|
||||
extended = SignExtend(val, len, bitsize);
|
||||
} else {
|
||||
extended = val;
|
||||
}
|
||||
|
||||
return extended << shift;
|
||||
}
|
||||
|
||||
u128 InterpreterVisitor::GetVec(Vec v) {
|
||||
return m_fpsimd_regs[static_cast<u32>(v)];
|
||||
}
|
||||
|
||||
u64 InterpreterVisitor::GetReg(Reg r) {
|
||||
return m_regs[static_cast<u32>(r)];
|
||||
}
|
||||
|
||||
u64 InterpreterVisitor::GetSp() {
|
||||
return m_sp;
|
||||
}
|
||||
|
||||
u64 InterpreterVisitor::GetPc() {
|
||||
return m_pc;
|
||||
}
|
||||
|
||||
void InterpreterVisitor::SetVec(Vec v, u128 value) {
|
||||
m_fpsimd_regs[static_cast<u32>(v)] = value;
|
||||
}
|
||||
|
||||
void InterpreterVisitor::SetReg(Reg r, u64 value) {
|
||||
m_regs[static_cast<u32>(r)] = value;
|
||||
}
|
||||
|
||||
void InterpreterVisitor::SetSp(u64 value) {
|
||||
m_sp = value;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::Ordered(size_t size, bool L, bool o0, Reg Rn, Reg Rt) {
|
||||
const auto memop = L ? MemOp::Load : MemOp::Store;
|
||||
const size_t elsize = 8 << size;
|
||||
const size_t datasize = elsize;
|
||||
|
||||
// Operation
|
||||
const size_t dbytes = datasize / 8;
|
||||
|
||||
u64 address;
|
||||
if (Rn == Reg::SP) {
|
||||
address = this->GetSp();
|
||||
} else {
|
||||
address = this->GetReg(Rn);
|
||||
}
|
||||
|
||||
switch (memop) {
|
||||
case MemOp::Store: {
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
u64 value = this->GetReg(Rt);
|
||||
m_memory.WriteBlock(address, &value, dbytes);
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
break;
|
||||
}
|
||||
case MemOp::Load: {
|
||||
u64 value = 0;
|
||||
m_memory.ReadBlock(address, &value, dbytes);
|
||||
this->SetReg(Rt, value);
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STLLR(Imm<2> sz, Reg Rn, Reg Rt) {
|
||||
const size_t size = sz.ZeroExtend<size_t>();
|
||||
const bool L = 0;
|
||||
const bool o0 = 0;
|
||||
return this->Ordered(size, L, o0, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STLR(Imm<2> sz, Reg Rn, Reg Rt) {
|
||||
const size_t size = sz.ZeroExtend<size_t>();
|
||||
const bool L = 0;
|
||||
const bool o0 = 1;
|
||||
return this->Ordered(size, L, o0, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDLAR(Imm<2> sz, Reg Rn, Reg Rt) {
|
||||
const size_t size = sz.ZeroExtend<size_t>();
|
||||
const bool L = 1;
|
||||
const bool o0 = 0;
|
||||
return this->Ordered(size, L, o0, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDAR(Imm<2> sz, Reg Rn, Reg Rt) {
|
||||
const size_t size = sz.ZeroExtend<size_t>();
|
||||
const bool L = 1;
|
||||
const bool o0 = 1;
|
||||
return this->Ordered(size, L, o0, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDR_lit_gen(bool opc_0, Imm<19> imm19, Reg Rt) {
|
||||
const size_t size = opc_0 == 0 ? 4 : 8;
|
||||
const s64 offset = Dynarmic::concatenate(imm19, Imm<2>{0}).SignExtend<s64>();
|
||||
const u64 address = this->GetPc() + offset;
|
||||
|
||||
u64 data = 0;
|
||||
m_memory.ReadBlock(address, &data, size);
|
||||
|
||||
this->SetReg(Rt, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDR_lit_fpsimd(Imm<2> opc, Imm<19> imm19, Vec Vt) {
|
||||
if (opc == 0b11) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
// Size in bytes
|
||||
const u64 size = 4 << opc.ZeroExtend();
|
||||
const u64 offset = imm19.SignExtend<u64>() << 2;
|
||||
const u64 address = this->GetPc() + offset;
|
||||
|
||||
u128 data{};
|
||||
m_memory.ReadBlock(address, &data, size);
|
||||
this->SetVec(Vt, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STP_LDP_gen(Imm<2> opc, bool not_postindex, bool wback, Imm<1> L,
|
||||
Imm<7> imm7, Reg Rt2, Reg Rn, Reg Rt) {
|
||||
if ((L == 0 && opc.Bit<0>() == 1) || opc == 0b11) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto memop = L == 1 ? MemOp::Load : MemOp::Store;
|
||||
if (memop == MemOp::Load && wback && (Rt == Rn || Rt2 == Rn) && Rn != Reg::R31) {
|
||||
// Unpredictable instruction
|
||||
return false;
|
||||
}
|
||||
if (memop == MemOp::Store && wback && (Rt == Rn || Rt2 == Rn) && Rn != Reg::R31) {
|
||||
// Unpredictable instruction
|
||||
return false;
|
||||
}
|
||||
if (memop == MemOp::Load && Rt == Rt2) {
|
||||
// Unpredictable instruction
|
||||
return false;
|
||||
}
|
||||
|
||||
u64 address;
|
||||
if (Rn == Reg::SP) {
|
||||
address = this->GetSp();
|
||||
} else {
|
||||
address = this->GetReg(Rn);
|
||||
}
|
||||
|
||||
const bool postindex = !not_postindex;
|
||||
const bool signed_ = opc.Bit<0>() != 0;
|
||||
const size_t scale = 2 + opc.Bit<1>();
|
||||
const size_t datasize = 8 << scale;
|
||||
const u64 offset = imm7.SignExtend<u64>() << scale;
|
||||
|
||||
if (!postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
const size_t dbytes = datasize / 8;
|
||||
switch (memop) {
|
||||
case MemOp::Store: {
|
||||
u64 data1 = this->GetReg(Rt);
|
||||
u64 data2 = this->GetReg(Rt2);
|
||||
m_memory.WriteBlock(address, &data1, dbytes);
|
||||
m_memory.WriteBlock(address + dbytes, &data2, dbytes);
|
||||
break;
|
||||
}
|
||||
case MemOp::Load: {
|
||||
u64 data1 = 0, data2 = 0;
|
||||
m_memory.ReadBlock(address, &data1, dbytes);
|
||||
m_memory.ReadBlock(address + dbytes, &data2, dbytes);
|
||||
if (signed_) {
|
||||
this->SetReg(Rt, SignExtend(data1, datasize, 64));
|
||||
this->SetReg(Rt2, SignExtend(data2, datasize, 64));
|
||||
} else {
|
||||
this->SetReg(Rt, data1);
|
||||
this->SetReg(Rt2, data2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (wback) {
|
||||
if (postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
if (Rn == Reg::SP) {
|
||||
this->SetSp(address);
|
||||
} else {
|
||||
this->SetReg(Rn, address);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STP_LDP_fpsimd(Imm<2> opc, bool not_postindex, bool wback, Imm<1> L,
|
||||
Imm<7> imm7, Vec Vt2, Reg Rn, Vec Vt) {
|
||||
if (opc == 0b11) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto memop = L == 1 ? MemOp::Load : MemOp::Store;
|
||||
if (memop == MemOp::Load && Vt == Vt2) {
|
||||
// Unpredictable instruction
|
||||
return false;
|
||||
}
|
||||
|
||||
u64 address;
|
||||
if (Rn == Reg::SP) {
|
||||
address = this->GetSp();
|
||||
} else {
|
||||
address = this->GetReg(Rn);
|
||||
}
|
||||
|
||||
const bool postindex = !not_postindex;
|
||||
const size_t scale = 2 + opc.ZeroExtend<size_t>();
|
||||
const size_t datasize = 8 << scale;
|
||||
const u64 offset = imm7.SignExtend<u64>() << scale;
|
||||
const size_t dbytes = datasize / 8;
|
||||
|
||||
if (!postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
switch (memop) {
|
||||
case MemOp::Store: {
|
||||
u128 data1 = VectorGetElement(this->GetVec(Vt), datasize);
|
||||
u128 data2 = VectorGetElement(this->GetVec(Vt2), datasize);
|
||||
m_memory.WriteBlock(address, &data1, dbytes);
|
||||
m_memory.WriteBlock(address + dbytes, &data2, dbytes);
|
||||
break;
|
||||
}
|
||||
case MemOp::Load: {
|
||||
u128 data1{}, data2{};
|
||||
m_memory.ReadBlock(address, &data1, dbytes);
|
||||
m_memory.ReadBlock(address + dbytes, &data2, dbytes);
|
||||
this->SetVec(Vt, data1);
|
||||
this->SetVec(Vt2, data2);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (wback) {
|
||||
if (postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
if (Rn == Reg::SP) {
|
||||
this->SetSp(address);
|
||||
} else {
|
||||
this->SetReg(Rn, address);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::RegisterImmediate(bool wback, bool postindex, size_t scale, u64 offset,
|
||||
Imm<2> size, Imm<2> opc, Reg Rn, Reg Rt) {
|
||||
MemOp memop;
|
||||
bool signed_ = false;
|
||||
size_t regsize = 0;
|
||||
|
||||
if (opc.Bit<1>() == 0) {
|
||||
memop = opc.Bit<0>() ? MemOp::Load : MemOp::Store;
|
||||
regsize = size == 0b11 ? 64 : 32;
|
||||
signed_ = false;
|
||||
} else if (size == 0b11) {
|
||||
memop = MemOp::Prefetch;
|
||||
ASSERT(!opc.Bit<0>());
|
||||
} else {
|
||||
memop = MemOp::Load;
|
||||
ASSERT(!(size == 0b10 && opc.Bit<0>() == 1));
|
||||
regsize = opc.Bit<0>() ? 32 : 64;
|
||||
signed_ = true;
|
||||
}
|
||||
|
||||
if (memop == MemOp::Load && wback && Rn == Rt && Rn != Reg::R31) {
|
||||
// Unpredictable instruction
|
||||
return false;
|
||||
}
|
||||
if (memop == MemOp::Store && wback && Rn == Rt && Rn != Reg::R31) {
|
||||
// Unpredictable instruction
|
||||
return false;
|
||||
}
|
||||
|
||||
u64 address;
|
||||
if (Rn == Reg::SP) {
|
||||
address = this->GetSp();
|
||||
} else {
|
||||
address = this->GetReg(Rn);
|
||||
}
|
||||
if (!postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
const size_t datasize = 8 << scale;
|
||||
switch (memop) {
|
||||
case MemOp::Store: {
|
||||
u64 data = this->GetReg(Rt);
|
||||
m_memory.WriteBlock(address, &data, datasize / 8);
|
||||
break;
|
||||
}
|
||||
case MemOp::Load: {
|
||||
u64 data = 0;
|
||||
m_memory.ReadBlock(address, &data, datasize / 8);
|
||||
if (signed_) {
|
||||
this->SetReg(Rt, SignExtend(data, datasize, regsize));
|
||||
} else {
|
||||
this->SetReg(Rt, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MemOp::Prefetch:
|
||||
// this->Prefetch(address, Rt)
|
||||
break;
|
||||
}
|
||||
|
||||
if (wback) {
|
||||
if (postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
if (Rn == Reg::SP) {
|
||||
this->SetSp(address);
|
||||
} else {
|
||||
this->SetReg(Rn, address);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STRx_LDRx_imm_1(Imm<2> size, Imm<2> opc, Imm<9> imm9, bool not_postindex,
|
||||
Reg Rn, Reg Rt) {
|
||||
const bool wback = true;
|
||||
const bool postindex = !not_postindex;
|
||||
const size_t scale = size.ZeroExtend<size_t>();
|
||||
const u64 offset = imm9.SignExtend<u64>();
|
||||
|
||||
return this->RegisterImmediate(wback, postindex, scale, offset, size, opc, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STRx_LDRx_imm_2(Imm<2> size, Imm<2> opc, Imm<12> imm12, Reg Rn, Reg Rt) {
|
||||
const bool wback = false;
|
||||
const bool postindex = false;
|
||||
const size_t scale = size.ZeroExtend<size_t>();
|
||||
const u64 offset = imm12.ZeroExtend<u64>() << scale;
|
||||
|
||||
return this->RegisterImmediate(wback, postindex, scale, offset, size, opc, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STURx_LDURx(Imm<2> size, Imm<2> opc, Imm<9> imm9, Reg Rn, Reg Rt) {
|
||||
const bool wback = false;
|
||||
const bool postindex = false;
|
||||
const size_t scale = size.ZeroExtend<size_t>();
|
||||
const u64 offset = imm9.SignExtend<u64>();
|
||||
|
||||
return this->RegisterImmediate(wback, postindex, scale, offset, size, opc, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::SIMDImmediate(bool wback, bool postindex, size_t scale, u64 offset,
|
||||
MemOp memop, Reg Rn, Vec Vt) {
|
||||
const size_t datasize = 8 << scale;
|
||||
|
||||
u64 address;
|
||||
if (Rn == Reg::SP) {
|
||||
address = this->GetSp();
|
||||
} else {
|
||||
address = this->GetReg(Rn);
|
||||
}
|
||||
|
||||
if (!postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
switch (memop) {
|
||||
case MemOp::Store: {
|
||||
u128 data = VectorGetElement(this->GetVec(Vt), datasize);
|
||||
m_memory.WriteBlock(address, &data, datasize / 8);
|
||||
break;
|
||||
}
|
||||
case MemOp::Load: {
|
||||
u128 data{};
|
||||
m_memory.ReadBlock(address, &data, datasize / 8);
|
||||
this->SetVec(Vt, data);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (wback) {
|
||||
if (postindex) {
|
||||
address += offset;
|
||||
}
|
||||
|
||||
if (Rn == Reg::SP) {
|
||||
this->SetSp(address);
|
||||
} else {
|
||||
this->SetReg(Rn, address);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STR_imm_fpsimd_1(Imm<2> size, Imm<1> opc_1, Imm<9> imm9,
|
||||
bool not_postindex, Reg Rn, Vec Vt) {
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool wback = true;
|
||||
const bool postindex = !not_postindex;
|
||||
const u64 offset = imm9.SignExtend<u64>();
|
||||
|
||||
return this->SIMDImmediate(wback, postindex, scale, offset, MemOp::Store, Rn, Vt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STR_imm_fpsimd_2(Imm<2> size, Imm<1> opc_1, Imm<12> imm12, Reg Rn,
|
||||
Vec Vt) {
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool wback = false;
|
||||
const bool postindex = false;
|
||||
const u64 offset = imm12.ZeroExtend<u64>() << scale;
|
||||
|
||||
return this->SIMDImmediate(wback, postindex, scale, offset, MemOp::Store, Rn, Vt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDR_imm_fpsimd_1(Imm<2> size, Imm<1> opc_1, Imm<9> imm9,
|
||||
bool not_postindex, Reg Rn, Vec Vt) {
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool wback = true;
|
||||
const bool postindex = !not_postindex;
|
||||
const u64 offset = imm9.SignExtend<u64>();
|
||||
|
||||
return this->SIMDImmediate(wback, postindex, scale, offset, MemOp::Load, Rn, Vt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDR_imm_fpsimd_2(Imm<2> size, Imm<1> opc_1, Imm<12> imm12, Reg Rn,
|
||||
Vec Vt) {
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool wback = false;
|
||||
const bool postindex = false;
|
||||
const u64 offset = imm12.ZeroExtend<u64>() << scale;
|
||||
|
||||
return this->SIMDImmediate(wback, postindex, scale, offset, MemOp::Load, Rn, Vt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STUR_fpsimd(Imm<2> size, Imm<1> opc_1, Imm<9> imm9, Reg Rn, Vec Vt) {
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool wback = false;
|
||||
const bool postindex = false;
|
||||
const u64 offset = imm9.SignExtend<u64>();
|
||||
|
||||
return this->SIMDImmediate(wback, postindex, scale, offset, MemOp::Store, Rn, Vt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDUR_fpsimd(Imm<2> size, Imm<1> opc_1, Imm<9> imm9, Reg Rn, Vec Vt) {
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool wback = false;
|
||||
const bool postindex = false;
|
||||
const u64 offset = imm9.SignExtend<u64>();
|
||||
|
||||
return this->SIMDImmediate(wback, postindex, scale, offset, MemOp::Load, Rn, Vt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::RegisterOffset(size_t scale, u8 shift, Imm<2> size, Imm<1> opc_1,
|
||||
Imm<1> opc_0, Reg Rm, Imm<3> option, Reg Rn, Reg Rt) {
|
||||
MemOp memop;
|
||||
size_t regsize = 64;
|
||||
bool signed_ = false;
|
||||
|
||||
if (opc_1 == 0) {
|
||||
memop = opc_0 == 1 ? MemOp::Load : MemOp::Store;
|
||||
regsize = size == 0b11 ? 64 : 32;
|
||||
signed_ = false;
|
||||
} else if (size == 0b11) {
|
||||
memop = MemOp::Prefetch;
|
||||
if (opc_0 == 1) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
memop = MemOp::Load;
|
||||
if (size == 0b10 && opc_0 == 1) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
regsize = opc_0 == 1 ? 32 : 64;
|
||||
signed_ = true;
|
||||
}
|
||||
|
||||
const size_t datasize = 8 << scale;
|
||||
|
||||
// Operation
|
||||
const u64 offset = this->ExtendReg(64, Rm, option, shift);
|
||||
|
||||
u64 address;
|
||||
if (Rn == Reg::SP) {
|
||||
address = this->GetSp();
|
||||
} else {
|
||||
address = this->GetReg(Rn);
|
||||
}
|
||||
address += offset;
|
||||
|
||||
switch (memop) {
|
||||
case MemOp::Store: {
|
||||
u64 data = this->GetReg(Rt);
|
||||
m_memory.WriteBlock(address, &data, datasize / 8);
|
||||
break;
|
||||
}
|
||||
case MemOp::Load: {
|
||||
u64 data = 0;
|
||||
m_memory.ReadBlock(address, &data, datasize / 8);
|
||||
if (signed_) {
|
||||
this->SetReg(Rt, SignExtend(data, datasize, regsize));
|
||||
} else {
|
||||
this->SetReg(Rt, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MemOp::Prefetch:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STRx_reg(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S, Reg Rn,
|
||||
Reg Rt) {
|
||||
const Imm<1> opc_0{0};
|
||||
const size_t scale = size.ZeroExtend<size_t>();
|
||||
const u8 shift = S ? static_cast<u8>(scale) : 0;
|
||||
if (!option.Bit<1>()) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
return this->RegisterOffset(scale, shift, size, opc_1, opc_0, Rm, option, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDRx_reg(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S, Reg Rn,
|
||||
Reg Rt) {
|
||||
const Imm<1> opc_0{1};
|
||||
const size_t scale = size.ZeroExtend<size_t>();
|
||||
const u8 shift = S ? static_cast<u8>(scale) : 0;
|
||||
if (!option.Bit<1>()) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
return this->RegisterOffset(scale, shift, size, opc_1, opc_0, Rm, option, Rn, Rt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::SIMDOffset(size_t scale, u8 shift, Imm<1> opc_0, Reg Rm, Imm<3> option,
|
||||
Reg Rn, Vec Vt) {
|
||||
const auto memop = opc_0 == 1 ? MemOp::Load : MemOp::Store;
|
||||
const size_t datasize = 8 << scale;
|
||||
|
||||
// Operation
|
||||
const u64 offset = this->ExtendReg(64, Rm, option, shift);
|
||||
|
||||
u64 address;
|
||||
if (Rn == Reg::SP) {
|
||||
address = this->GetSp();
|
||||
} else {
|
||||
address = this->GetReg(Rn);
|
||||
}
|
||||
address += offset;
|
||||
|
||||
switch (memop) {
|
||||
case MemOp::Store: {
|
||||
u128 data = VectorGetElement(this->GetVec(Vt), datasize);
|
||||
m_memory.WriteBlock(address, &data, datasize / 8);
|
||||
break;
|
||||
}
|
||||
case MemOp::Load: {
|
||||
u128 data{};
|
||||
m_memory.ReadBlock(address, &data, datasize / 8);
|
||||
this->SetVec(Vt, data);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::STR_reg_fpsimd(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S,
|
||||
Reg Rn, Vec Vt) {
|
||||
const Imm<1> opc_0{0};
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
const u8 shift = S ? static_cast<u8>(scale) : 0;
|
||||
if (!option.Bit<1>()) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
return this->SIMDOffset(scale, shift, opc_0, Rm, option, Rn, Vt);
|
||||
}
|
||||
|
||||
bool InterpreterVisitor::LDR_reg_fpsimd(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S,
|
||||
Reg Rn, Vec Vt) {
|
||||
const Imm<1> opc_0{1};
|
||||
const size_t scale = Dynarmic::concatenate(opc_1, size).ZeroExtend<size_t>();
|
||||
if (scale > 4) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
const u8 shift = S ? static_cast<u8>(scale) : 0;
|
||||
if (!option.Bit<1>()) {
|
||||
// Unallocated encoding
|
||||
return false;
|
||||
}
|
||||
return this->SIMDOffset(scale, shift, opc_0, Rm, option, Rn, Vt);
|
||||
}
|
||||
|
||||
std::optional<u64> MatchAndExecuteOneInstruction(Core::Memory::Memory& memory, mcontext_t* context,
|
||||
fpsimd_context* fpsimd_context) {
|
||||
// Construct the interpreter.
|
||||
std::span<u64, 31> regs(reinterpret_cast<u64*>(context->regs), 31);
|
||||
std::span<u128, 32> vregs(reinterpret_cast<u128*>(fpsimd_context->vregs), 32);
|
||||
u64& sp = *reinterpret_cast<u64*>(&context->sp);
|
||||
const u64& pc = *reinterpret_cast<u64*>(&context->pc);
|
||||
|
||||
InterpreterVisitor visitor(memory, regs, vregs, sp, pc);
|
||||
|
||||
// Read the instruction at the program counter.
|
||||
u32 instruction = memory.Read32(pc);
|
||||
bool was_executed = false;
|
||||
|
||||
// Interpret the instruction.
|
||||
if (auto decoder = Dynarmic::A64::Decode<VisitorBase>(instruction)) {
|
||||
was_executed = decoder->get().call(visitor, instruction);
|
||||
} else {
|
||||
LOG_ERROR(Core_ARM, "Unallocated encoding: {:#x}", instruction);
|
||||
}
|
||||
|
||||
if (was_executed) {
|
||||
return pc + 4;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace Core
|
103
src/core/arm/nce/interpreter_visitor.h
Normal file
103
src/core/arm/nce/interpreter_visitor.h
Normal file
@ -0,0 +1,103 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2023 merryhime <https://mary.rs>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "core/arm/nce/visitor_base.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
namespace Memory {
|
||||
class Memory;
|
||||
}
|
||||
|
||||
class InterpreterVisitor final : public VisitorBase {
|
||||
public:
|
||||
explicit InterpreterVisitor(Core::Memory::Memory& memory, std::span<u64, 31> regs,
|
||||
std::span<u128, 32> fpsimd_regs, u64& sp, const u64& pc)
|
||||
: m_memory(memory), m_regs(regs), m_fpsimd_regs(fpsimd_regs), m_sp(sp), m_pc(pc) {}
|
||||
~InterpreterVisitor() override = default;
|
||||
|
||||
enum class MemOp {
|
||||
Load,
|
||||
Store,
|
||||
Prefetch,
|
||||
};
|
||||
|
||||
u128 GetVec(Vec v);
|
||||
u64 GetReg(Reg r);
|
||||
u64 GetSp();
|
||||
u64 GetPc();
|
||||
|
||||
void SetVec(Vec v, u128 value);
|
||||
void SetReg(Reg r, u64 value);
|
||||
void SetSp(u64 value);
|
||||
|
||||
u64 ExtendReg(size_t bitsize, Reg reg, Imm<3> option, u8 shift);
|
||||
|
||||
// Loads and stores - Load/Store Exclusive
|
||||
bool Ordered(size_t size, bool L, bool o0, Reg Rn, Reg Rt);
|
||||
bool STLLR(Imm<2> size, Reg Rn, Reg Rt) override;
|
||||
bool STLR(Imm<2> size, Reg Rn, Reg Rt) override;
|
||||
bool LDLAR(Imm<2> size, Reg Rn, Reg Rt) override;
|
||||
bool LDAR(Imm<2> size, Reg Rn, Reg Rt) override;
|
||||
|
||||
// Loads and stores - Load register (literal)
|
||||
bool LDR_lit_gen(bool opc_0, Imm<19> imm19, Reg Rt) override;
|
||||
bool LDR_lit_fpsimd(Imm<2> opc, Imm<19> imm19, Vec Vt) override;
|
||||
|
||||
// Loads and stores - Load/Store register pair
|
||||
bool STP_LDP_gen(Imm<2> opc, bool not_postindex, bool wback, Imm<1> L, Imm<7> imm7, Reg Rt2,
|
||||
Reg Rn, Reg Rt) override;
|
||||
bool STP_LDP_fpsimd(Imm<2> opc, bool not_postindex, bool wback, Imm<1> L, Imm<7> imm7, Vec Vt2,
|
||||
Reg Rn, Vec Vt) override;
|
||||
|
||||
// Loads and stores - Load/Store register (immediate)
|
||||
bool RegisterImmediate(bool wback, bool postindex, size_t scale, u64 offset, Imm<2> size,
|
||||
Imm<2> opc, Reg Rn, Reg Rt);
|
||||
bool STRx_LDRx_imm_1(Imm<2> size, Imm<2> opc, Imm<9> imm9, bool not_postindex, Reg Rn,
|
||||
Reg Rt) override;
|
||||
bool STRx_LDRx_imm_2(Imm<2> size, Imm<2> opc, Imm<12> imm12, Reg Rn, Reg Rt) override;
|
||||
bool STURx_LDURx(Imm<2> size, Imm<2> opc, Imm<9> imm9, Reg Rn, Reg Rt) override;
|
||||
|
||||
bool SIMDImmediate(bool wback, bool postindex, size_t scale, u64 offset, MemOp memop, Reg Rn,
|
||||
Vec Vt);
|
||||
bool STR_imm_fpsimd_1(Imm<2> size, Imm<1> opc_1, Imm<9> imm9, bool not_postindex, Reg Rn,
|
||||
Vec Vt) override;
|
||||
bool STR_imm_fpsimd_2(Imm<2> size, Imm<1> opc_1, Imm<12> imm12, Reg Rn, Vec Vt) override;
|
||||
bool LDR_imm_fpsimd_1(Imm<2> size, Imm<1> opc_1, Imm<9> imm9, bool not_postindex, Reg Rn,
|
||||
Vec Vt) override;
|
||||
bool LDR_imm_fpsimd_2(Imm<2> size, Imm<1> opc_1, Imm<12> imm12, Reg Rn, Vec Vt) override;
|
||||
bool STUR_fpsimd(Imm<2> size, Imm<1> opc_1, Imm<9> imm9, Reg Rn, Vec Vt) override;
|
||||
bool LDUR_fpsimd(Imm<2> size, Imm<1> opc_1, Imm<9> imm9, Reg Rn, Vec Vt) override;
|
||||
|
||||
// Loads and stores - Load/Store register (register offset)
|
||||
bool RegisterOffset(size_t scale, u8 shift, Imm<2> size, Imm<1> opc_1, Imm<1> opc_0, Reg Rm,
|
||||
Imm<3> option, Reg Rn, Reg Rt);
|
||||
bool STRx_reg(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S, Reg Rn,
|
||||
Reg Rt) override;
|
||||
bool LDRx_reg(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S, Reg Rn,
|
||||
Reg Rt) override;
|
||||
|
||||
bool SIMDOffset(size_t scale, u8 shift, Imm<1> opc_0, Reg Rm, Imm<3> option, Reg Rn, Vec Vt);
|
||||
bool STR_reg_fpsimd(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S, Reg Rn,
|
||||
Vec Vt) override;
|
||||
bool LDR_reg_fpsimd(Imm<2> size, Imm<1> opc_1, Reg Rm, Imm<3> option, bool S, Reg Rn,
|
||||
Vec Vt) override;
|
||||
|
||||
private:
|
||||
Core::Memory::Memory& m_memory;
|
||||
std::span<u64, 31> m_regs;
|
||||
std::span<u128, 32> m_fpsimd_regs;
|
||||
u64& m_sp;
|
||||
const u64& m_pc;
|
||||
};
|
||||
|
||||
std::optional<u64> MatchAndExecuteOneInstruction(Core::Memory::Memory& memory, mcontext_t* context,
|
||||
fpsimd_context* fpsimd_context);
|
||||
|
||||
} // namespace Core
|
2783
src/core/arm/nce/visitor_base.h
Normal file
2783
src/core/arm/nce/visitor_base.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -36,6 +36,7 @@
|
||||
#include "core/hle/kernel/k_scheduler.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/physical_core.h"
|
||||
#include "core/hle/service/acc/profile_manager.h"
|
||||
#include "core/hle/service/am/applets/applets.h"
|
||||
#include "core/hle/service/apm/apm_controller.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
@ -130,8 +131,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
||||
struct System::Impl {
|
||||
explicit Impl(System& system)
|
||||
: kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{},
|
||||
cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system},
|
||||
gpu_dirty_memory_write_manager{} {
|
||||
cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{},
|
||||
time_manager{system}, gpu_dirty_memory_write_manager{} {
|
||||
memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager);
|
||||
}
|
||||
|
||||
@ -532,6 +533,7 @@ struct System::Impl {
|
||||
|
||||
/// Service State
|
||||
Service::Glue::ARPManager arp_manager;
|
||||
Service::Account::ProfileManager profile_manager;
|
||||
Service::Time::TimeManager time_manager;
|
||||
|
||||
/// Service manager
|
||||
@ -921,6 +923,14 @@ const Service::APM::Controller& System::GetAPMController() const {
|
||||
return impl->apm_controller;
|
||||
}
|
||||
|
||||
Service::Account::ProfileManager& System::GetProfileManager() {
|
||||
return impl->profile_manager;
|
||||
}
|
||||
|
||||
const Service::Account::ProfileManager& System::GetProfileManager() const {
|
||||
return impl->profile_manager;
|
||||
}
|
||||
|
||||
Service::Time::TimeManager& System::GetTimeManager() {
|
||||
return impl->time_manager;
|
||||
}
|
||||
|
@ -45,6 +45,10 @@ class Memory;
|
||||
|
||||
namespace Service {
|
||||
|
||||
namespace Account {
|
||||
class ProfileManager;
|
||||
} // namespace Account
|
||||
|
||||
namespace AM::Applets {
|
||||
struct AppletFrontendSet;
|
||||
class AppletManager;
|
||||
@ -383,6 +387,9 @@ public:
|
||||
[[nodiscard]] Service::APM::Controller& GetAPMController();
|
||||
[[nodiscard]] const Service::APM::Controller& GetAPMController() const;
|
||||
|
||||
[[nodiscard]] Service::Account::ProfileManager& GetProfileManager();
|
||||
[[nodiscard]] const Service::Account::ProfileManager& GetProfileManager() const;
|
||||
|
||||
[[nodiscard]] Service::Time::TimeManager& GetTimeManager();
|
||||
[[nodiscard]] const Service::Time::TimeManager& GetTimeManager() const;
|
||||
|
||||
|
@ -201,8 +201,6 @@ std::string VfsFile::GetFullPath() const {
|
||||
|
||||
VirtualFile VfsDirectory::GetFileRelative(std::string_view path) const {
|
||||
auto vec = Common::FS::SplitPathComponents(path);
|
||||
vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||
vec.end());
|
||||
if (vec.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -237,8 +235,6 @@ VirtualFile VfsDirectory::GetFileAbsolute(std::string_view path) const {
|
||||
|
||||
VirtualDir VfsDirectory::GetDirectoryRelative(std::string_view path) const {
|
||||
auto vec = Common::FS::SplitPathComponents(path);
|
||||
vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||
vec.end());
|
||||
if (vec.empty()) {
|
||||
// TODO(DarkLordZach): Return this directory if path is '/' or similar. Can't currently
|
||||
// because of const-ness
|
||||
@ -303,8 +299,6 @@ std::size_t VfsDirectory::GetSize() const {
|
||||
|
||||
VirtualFile VfsDirectory::CreateFileRelative(std::string_view path) {
|
||||
auto vec = Common::FS::SplitPathComponents(path);
|
||||
vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||
vec.end());
|
||||
if (vec.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -334,8 +328,6 @@ VirtualFile VfsDirectory::CreateFileAbsolute(std::string_view path) {
|
||||
|
||||
VirtualDir VfsDirectory::CreateDirectoryRelative(std::string_view path) {
|
||||
auto vec = Common::FS::SplitPathComponents(path);
|
||||
vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||
vec.end());
|
||||
if (vec.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ void RealVfsFilesystem::RemoveReferenceFromListLocked(FileReference& reference)
|
||||
RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::unique_ptr<FileReference> reference_,
|
||||
const std::string& path_, Mode perms_, std::optional<u64> size_)
|
||||
: base(base_), reference(std::move(reference_)), path(path_),
|
||||
parent_path(FS::GetParentPath(path_)), path_components(FS::SplitPathComponents(path_)),
|
||||
parent_path(FS::GetParentPath(path_)), path_components(FS::SplitPathComponentsCopy(path_)),
|
||||
size(size_), perms(perms_) {}
|
||||
|
||||
RealVfsFile::~RealVfsFile() {
|
||||
@ -276,7 +276,7 @@ RealVfsFile::~RealVfsFile() {
|
||||
}
|
||||
|
||||
std::string RealVfsFile::GetName() const {
|
||||
return path_components.back();
|
||||
return path_components.empty() ? "" : std::string(path_components.back());
|
||||
}
|
||||
|
||||
std::size_t RealVfsFile::GetSize() const {
|
||||
@ -375,7 +375,7 @@ std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDi
|
||||
|
||||
RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_, Mode perms_)
|
||||
: base(base_), path(FS::RemoveTrailingSlash(path_)), parent_path(FS::GetParentPath(path)),
|
||||
path_components(FS::SplitPathComponents(path)), perms(perms_) {
|
||||
path_components(FS::SplitPathComponentsCopy(path)), perms(perms_) {
|
||||
if (!FS::Exists(path) && True(perms & Mode::Write)) {
|
||||
void(FS::CreateDirs(path));
|
||||
}
|
||||
@ -464,7 +464,7 @@ bool RealVfsDirectory::IsReadable() const {
|
||||
}
|
||||
|
||||
std::string RealVfsDirectory::GetName() const {
|
||||
return path_components.back();
|
||||
return path_components.empty() ? "" : std::string(path_components.back());
|
||||
}
|
||||
|
||||
VirtualDir RealVfsDirectory::GetParentDirectory() const {
|
||||
|
@ -20,6 +20,9 @@ InputInterpreter::InputInterpreter(Core::System& system)
|
||||
InputInterpreter::~InputInterpreter() = default;
|
||||
|
||||
void InputInterpreter::PollInput() {
|
||||
if (npad == nullptr) {
|
||||
return;
|
||||
}
|
||||
const auto button_state = npad->GetAndResetPressState();
|
||||
|
||||
previous_index = current_index;
|
||||
|
@ -421,8 +421,9 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
|
||||
} else {
|
||||
// Set all the allocated memory.
|
||||
for (const auto& block : *out) {
|
||||
std::memset(m_system.DeviceMemory().GetPointer<void>(block.GetAddress()), fill_pattern,
|
||||
block.GetSize());
|
||||
m_system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(block.GetAddress()) -
|
||||
Core::DramMemoryMap::Base,
|
||||
block.GetSize(), fill_pattern);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,11 @@ void InvalidateInstructionCache(KernelCore& kernel, AddressType addr, u64 size)
|
||||
}
|
||||
}
|
||||
|
||||
void ClearBackingRegion(Core::System& system, KPhysicalAddress addr, u64 size, u32 fill_value) {
|
||||
system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(addr) - Core::DramMemoryMap::Base,
|
||||
size, fill_value);
|
||||
}
|
||||
|
||||
template <typename AddressType>
|
||||
Result InvalidateDataCache(AddressType addr, u64 size) {
|
||||
R_SUCCEED();
|
||||
@ -1363,8 +1368,7 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
|
||||
|
||||
// Clear all the newly allocated pages.
|
||||
for (const auto& it : pg) {
|
||||
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()),
|
||||
static_cast<u32>(m_heap_fill_value), it.GetSize());
|
||||
ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
|
||||
}
|
||||
|
||||
// Lock the table.
|
||||
@ -1570,8 +1574,7 @@ Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList* page_list, KProce
|
||||
|
||||
// Clear all pages.
|
||||
for (const auto& it : pg) {
|
||||
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()),
|
||||
static_cast<u32>(m_heap_fill_value), it.GetSize());
|
||||
ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
|
||||
}
|
||||
|
||||
// Map the pages.
|
||||
@ -2159,8 +2162,7 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
|
||||
|
||||
// Clear all the newly allocated pages.
|
||||
for (const auto& it : pg) {
|
||||
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), m_heap_fill_value,
|
||||
it.GetSize());
|
||||
ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
|
||||
}
|
||||
|
||||
// Map the pages.
|
||||
|
@ -135,7 +135,6 @@ struct KernelCore::Impl {
|
||||
obj = nullptr;
|
||||
}
|
||||
};
|
||||
CleanupObject(hid_shared_mem);
|
||||
CleanupObject(font_shared_mem);
|
||||
CleanupObject(irs_shared_mem);
|
||||
CleanupObject(time_shared_mem);
|
||||
@ -744,22 +743,16 @@ struct KernelCore::Impl {
|
||||
void InitializeHackSharedMemory(KernelCore& kernel) {
|
||||
// Setup memory regions for emulated processes
|
||||
// TODO(bunnei): These should not be hardcoded regions initialized within the kernel
|
||||
constexpr std::size_t hid_size{0x40000};
|
||||
constexpr std::size_t font_size{0x1100000};
|
||||
constexpr std::size_t irs_size{0x8000};
|
||||
constexpr std::size_t time_size{0x1000};
|
||||
constexpr std::size_t hidbus_size{0x1000};
|
||||
|
||||
hid_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||
font_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||
irs_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||
time_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||
hidbus_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||
|
||||
hid_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
Svc::MemoryPermission::Read, hid_size);
|
||||
KSharedMemory::Register(kernel, hid_shared_mem);
|
||||
|
||||
font_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
Svc::MemoryPermission::Read, font_size);
|
||||
KSharedMemory::Register(kernel, font_shared_mem);
|
||||
@ -1190,14 +1183,6 @@ const KSystemResource& KernelCore::GetSystemSystemResource() const {
|
||||
return *impl->sys_system_resource;
|
||||
}
|
||||
|
||||
Kernel::KSharedMemory& KernelCore::GetHidSharedMem() {
|
||||
return *impl->hid_shared_mem;
|
||||
}
|
||||
|
||||
const Kernel::KSharedMemory& KernelCore::GetHidSharedMem() const {
|
||||
return *impl->hid_shared_mem;
|
||||
}
|
||||
|
||||
Kernel::KSharedMemory& KernelCore::GetFontSharedMem() {
|
||||
return *impl->font_shared_mem;
|
||||
}
|
||||
|
@ -239,12 +239,6 @@ public:
|
||||
/// Gets the system resource manager.
|
||||
const KSystemResource& GetSystemSystemResource() const;
|
||||
|
||||
/// Gets the shared memory object for HID services.
|
||||
Kernel::KSharedMemory& GetHidSharedMem();
|
||||
|
||||
/// Gets the shared memory object for HID services.
|
||||
const Kernel::KSharedMemory& GetHidSharedMem() const;
|
||||
|
||||
/// Gets the shared memory object for font services.
|
||||
Kernel::KSharedMemory& GetFontSharedMem();
|
||||
|
||||
|
@ -359,7 +359,7 @@ private:
|
||||
|
||||
void GetActiveChannelCount(HLERequestContext& ctx) {
|
||||
const auto& sink{system.AudioCore().GetOutputSink()};
|
||||
u32 channel_count{sink.GetDeviceChannels()};
|
||||
u32 channel_count{sink.GetSystemChannels()};
|
||||
|
||||
LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", channel_count);
|
||||
|
||||
|
@ -104,11 +104,7 @@ Result VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) con
|
||||
const auto components = Common::FS::SplitPathComponents(path);
|
||||
std::string relative_path;
|
||||
for (const auto& component : components) {
|
||||
// Skip empty path components
|
||||
if (component.empty()) {
|
||||
continue;
|
||||
}
|
||||
relative_path = Common::FS::SanitizePath(relative_path + '/' + component);
|
||||
relative_path = Common::FS::SanitizePath(fmt::format("{}/{}", relative_path, component));
|
||||
auto new_dir = backing->CreateSubdirectory(relative_path);
|
||||
if (new_dir == nullptr) {
|
||||
// TODO(DarkLordZach): Find a better error code for this
|
||||
|
@ -54,6 +54,13 @@ enum class ImageDirectoryId : u32 {
|
||||
SdCard,
|
||||
};
|
||||
|
||||
enum class OpenDirectoryMode : u64 {
|
||||
Directory = (1 << 0),
|
||||
File = (1 << 1),
|
||||
All = Directory | File
|
||||
};
|
||||
DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode);
|
||||
|
||||
class FileSystemController {
|
||||
public:
|
||||
explicit FileSystemController(Core::System& system_);
|
||||
|
@ -259,7 +259,7 @@ static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vec
|
||||
|
||||
class IDirectory final : public ServiceFramework<IDirectory> {
|
||||
public:
|
||||
explicit IDirectory(Core::System& system_, FileSys::VirtualDir backend_)
|
||||
explicit IDirectory(Core::System& system_, FileSys::VirtualDir backend_, OpenDirectoryMode mode)
|
||||
: ServiceFramework{system_, "IDirectory"}, backend(std::move(backend_)) {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &IDirectory::Read, "Read"},
|
||||
@ -269,8 +269,12 @@ public:
|
||||
|
||||
// TODO(DarkLordZach): Verify that this is the correct behavior.
|
||||
// Build entry index now to save time later.
|
||||
BuildEntryIndex(entries, backend->GetFiles(), FileSys::EntryType::File);
|
||||
BuildEntryIndex(entries, backend->GetSubdirectories(), FileSys::EntryType::Directory);
|
||||
if (True(mode & OpenDirectoryMode::Directory)) {
|
||||
BuildEntryIndex(entries, backend->GetSubdirectories(), FileSys::EntryType::Directory);
|
||||
}
|
||||
if (True(mode & OpenDirectoryMode::File)) {
|
||||
BuildEntryIndex(entries, backend->GetFiles(), FileSys::EntryType::File);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@ -446,11 +450,9 @@ public:
|
||||
|
||||
const auto file_buffer = ctx.ReadBuffer();
|
||||
const std::string name = Common::StringFromBuffer(file_buffer);
|
||||
const auto mode = rp.PopRaw<OpenDirectoryMode>();
|
||||
|
||||
// TODO(Subv): Implement this filter.
|
||||
const u32 filter_flags = rp.Pop<u32>();
|
||||
|
||||
LOG_DEBUG(Service_FS, "called. directory={}, filter={}", name, filter_flags);
|
||||
LOG_DEBUG(Service_FS, "called. directory={}, mode={}", name, mode);
|
||||
|
||||
FileSys::VirtualDir vfs_dir{};
|
||||
auto result = backend.OpenDirectory(&vfs_dir, name);
|
||||
@ -460,7 +462,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
auto directory = std::make_shared<IDirectory>(system, vfs_dir);
|
||||
auto directory = std::make_shared<IDirectory>(system, vfs_dir, mode);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||
rb.Push(ResultSuccess);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#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_format.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
@ -23,11 +24,24 @@ Result AppletResource::CreateAppletResource(u64 aruid) {
|
||||
return ResultAruidAlreadyRegistered;
|
||||
}
|
||||
|
||||
// TODO: Here shared memory is created for the process we don't quite emulate this part so
|
||||
// obtain this pointer from system
|
||||
auto& shared_memory = system.Kernel().GetHidSharedMem();
|
||||
auto& shared_memory = shared_memory_holder[index];
|
||||
if (!shared_memory.IsMapped()) {
|
||||
const Result result = shared_memory.Initialize(system);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
if (shared_memory.GetAddress() == nullptr) {
|
||||
shared_memory.Finalize();
|
||||
return ResultSharedMemoryNotInitialized;
|
||||
}
|
||||
}
|
||||
|
||||
data[index].shared_memory_handle = &shared_memory;
|
||||
auto* shared_memory_format = shared_memory.GetAddress();
|
||||
if (shared_memory_format != nullptr) {
|
||||
shared_memory_format->Initialize();
|
||||
}
|
||||
|
||||
data[index].shared_memory_format = shared_memory_format;
|
||||
data[index].flag.is_assigned.Assign(true);
|
||||
// TODO: InitializeSixAxisControllerConfig(false);
|
||||
active_aruid = aruid;
|
||||
@ -94,7 +108,7 @@ void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
|
||||
|
||||
if (index < AruidIndexMax) {
|
||||
if (data[index].flag.is_assigned) {
|
||||
data[index].shared_memory_handle = nullptr;
|
||||
data[index].shared_memory_format = nullptr;
|
||||
data[index].flag.is_assigned.Assign(false);
|
||||
}
|
||||
}
|
||||
@ -112,6 +126,19 @@ void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
|
||||
}
|
||||
}
|
||||
|
||||
void AppletResource::FreeAppletResourceId(u64 aruid) {
|
||||
u64 index = GetIndexFromAruid(aruid);
|
||||
if (index >= AruidIndexMax) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& aruid_data = data[index];
|
||||
if (aruid_data.flag.is_assigned) {
|
||||
aruid_data.shared_memory_format = nullptr;
|
||||
aruid_data.flag.is_assigned.Assign(false);
|
||||
}
|
||||
}
|
||||
|
||||
u64 AppletResource::GetActiveAruid() {
|
||||
return active_aruid;
|
||||
}
|
||||
@ -122,7 +149,18 @@ Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle,
|
||||
return ResultAruidNotRegistered;
|
||||
}
|
||||
|
||||
*out_handle = data[index].shared_memory_handle;
|
||||
*out_handle = shared_memory_holder[index].GetHandle();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format,
|
||||
u64 aruid) {
|
||||
u64 index = GetIndexFromAruid(aruid);
|
||||
if (index >= AruidIndexMax) {
|
||||
return ResultAruidNotRegistered;
|
||||
}
|
||||
|
||||
*out_shared_memory_format = data[index].shared_memory_format;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
@ -196,4 +234,80 @@ void AppletResource::EnablePalmaBoostMode(u64 aruid, bool is_enabled) {
|
||||
data[index].flag.enable_palma_boost_mode.Assign(is_enabled);
|
||||
}
|
||||
|
||||
Result AppletResource::RegisterCoreAppletResource() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultAppletResourceOverflow;
|
||||
}
|
||||
if (ref_counter == 0) {
|
||||
const u64 index = GetIndexFromAruid(0);
|
||||
if (index < AruidIndexMax) {
|
||||
return ResultAruidAlreadyRegistered;
|
||||
}
|
||||
|
||||
std::size_t data_index = AruidIndexMax;
|
||||
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||
if (!data[i].flag.is_initialized) {
|
||||
data_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (data_index == AruidIndexMax) {
|
||||
return ResultAruidNoAvailableEntries;
|
||||
}
|
||||
|
||||
AruidData& aruid_data = data[data_index];
|
||||
|
||||
aruid_data.aruid = 0;
|
||||
aruid_data.flag.is_initialized.Assign(true);
|
||||
aruid_data.flag.enable_pad_input.Assign(true);
|
||||
aruid_data.flag.enable_six_axis_sensor.Assign(true);
|
||||
aruid_data.flag.bit_18.Assign(true);
|
||||
aruid_data.flag.enable_touchscreen.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] != 0) {
|
||||
continue;
|
||||
}
|
||||
data_index = i;
|
||||
break;
|
||||
}
|
||||
if (registration_list.flag[i] == RegistrationStatus::None) {
|
||||
data_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Result result = ResultSuccess;
|
||||
|
||||
if (data_index == AruidIndexMax) {
|
||||
result = CreateAppletResource(0);
|
||||
} else {
|
||||
registration_list.flag[data_index] = RegistrationStatus::Initialized;
|
||||
registration_list.aruid[data_index] = 0;
|
||||
}
|
||||
|
||||
if (result.IsError()) {
|
||||
UnregisterAppletResourceUserId(0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result AppletResource::UnregisterCoreAppletResource() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultAppletResourceNotInitialized;
|
||||
}
|
||||
|
||||
if (--ref_counter == 0) {
|
||||
UnregisterAppletResourceUserId(0);
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -8,6 +8,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"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
@ -18,6 +19,8 @@ class KSharedMemory;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct SharedMemoryFormat;
|
||||
|
||||
class AppletResource {
|
||||
public:
|
||||
explicit AppletResource(Core::System& system_);
|
||||
@ -28,8 +31,11 @@ public:
|
||||
Result RegisterAppletResourceUserId(u64 aruid, bool enable_input);
|
||||
void UnregisterAppletResourceUserId(u64 aruid);
|
||||
|
||||
void FreeAppletResourceId(u64 aruid);
|
||||
|
||||
u64 GetActiveAruid();
|
||||
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
|
||||
Result GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format, u64 aruid);
|
||||
|
||||
u64 GetIndexFromAruid(u64 aruid);
|
||||
|
||||
@ -42,6 +48,9 @@ public:
|
||||
void SetIsPalmaConnectable(u64 aruid, bool is_connectable);
|
||||
void EnablePalmaBoostMode(u64 aruid, bool is_enabled);
|
||||
|
||||
Result RegisterCoreAppletResource();
|
||||
Result UnregisterCoreAppletResource();
|
||||
|
||||
private:
|
||||
static constexpr std::size_t AruidIndexMax = 0x20;
|
||||
|
||||
@ -75,12 +84,14 @@ private:
|
||||
struct AruidData {
|
||||
DataStatusFlag flag{};
|
||||
u64 aruid{};
|
||||
Kernel::KSharedMemory* shared_memory_handle{nullptr};
|
||||
SharedMemoryFormat* shared_memory_format{nullptr};
|
||||
};
|
||||
|
||||
u64 active_aruid{};
|
||||
AruidRegisterList registration_list{};
|
||||
std::array<AruidData, AruidIndexMax> data{};
|
||||
std::array<SharedMemoryHolder, AruidIndexMax> shared_memory_holder{};
|
||||
s32 ref_counter{};
|
||||
|
||||
Core::System& system;
|
||||
};
|
||||
|
@ -1,23 +1,18 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/core.h"
|
||||
#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/memory.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200;
|
||||
|
||||
ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_)
|
||||
: ControllerBase{hid_core_} {
|
||||
ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_,
|
||||
ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory)
|
||||
: ControllerBase{hid_core_}, shared_memory{console_shared_memory} {
|
||||
console = hid_core.GetEmulatedConsole();
|
||||
static_assert(SHARED_MEMORY_OFFSET + sizeof(ConsoleSharedMemory) < shared_memory_size,
|
||||
"ConsoleSharedMemory is bigger than the shared memory");
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<ConsoleSharedMemory*>(raw_shared_memory_ + SHARED_MEMORY_OFFSET));
|
||||
}
|
||||
|
||||
ConsoleSixAxis::~ConsoleSixAxis() = default;
|
||||
@ -33,10 +28,10 @@ void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
|
||||
const auto motion_status = console->GetMotion();
|
||||
|
||||
shared_memory->sampling_number++;
|
||||
shared_memory->is_seven_six_axis_sensor_at_rest = motion_status.is_at_rest;
|
||||
shared_memory->verticalization_error = motion_status.verticalization_error;
|
||||
shared_memory->gyro_bias = motion_status.gyro_bias;
|
||||
shared_memory.sampling_number++;
|
||||
shared_memory.is_seven_six_axis_sensor_at_rest = motion_status.is_at_rest;
|
||||
shared_memory.verticalization_error = motion_status.verticalization_error;
|
||||
shared_memory.gyro_bias = motion_status.gyro_bias;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/vector_math.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
|
||||
namespace Core::HID {
|
||||
@ -11,9 +10,12 @@ class EmulatedConsole;
|
||||
} // namespace Core::HID
|
||||
|
||||
namespace Service::HID {
|
||||
struct ConsoleSixAxisSensorSharedMemoryFormat;
|
||||
|
||||
class ConsoleSixAxis final : public ControllerBase {
|
||||
public:
|
||||
explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_,
|
||||
ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory);
|
||||
~ConsoleSixAxis() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
@ -26,18 +28,7 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
// This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat
|
||||
struct ConsoleSharedMemory {
|
||||
u64 sampling_number{};
|
||||
bool is_seven_six_axis_sensor_at_rest{};
|
||||
INSERT_PADDING_BYTES(3); // padding
|
||||
f32 verticalization_error{};
|
||||
Common::Vec3f gyro_bias{};
|
||||
INSERT_PADDING_BYTES(4); // padding
|
||||
};
|
||||
static_assert(sizeof(ConsoleSharedMemory) == 0x20, "ConsoleSharedMemory is an invalid size");
|
||||
|
||||
ConsoleSharedMemory* shared_memory = nullptr;
|
||||
ConsoleSixAxisSensorSharedMemoryFormat& shared_memory;
|
||||
Core::HID::EmulatedConsole* console = nullptr;
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
@ -39,9 +39,6 @@ public:
|
||||
|
||||
bool IsControllerActivated() const;
|
||||
|
||||
static const std::size_t hid_entry_count = 17;
|
||||
static const std::size_t shared_memory_size = 0x40000;
|
||||
|
||||
protected:
|
||||
bool is_activated{false};
|
||||
|
||||
|
@ -1,24 +1,19 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include "common/common_types.h"
|
||||
#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/debug_pad.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x00000;
|
||||
|
||||
DebugPad::DebugPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_)
|
||||
: ControllerBase{hid_core_} {
|
||||
static_assert(SHARED_MEMORY_OFFSET + sizeof(DebugPadSharedMemory) < shared_memory_size,
|
||||
"DebugPadSharedMemory is bigger than the shared memory");
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<DebugPadSharedMemory*>(raw_shared_memory_ + SHARED_MEMORY_OFFSET));
|
||||
DebugPad::DebugPad(Core::HID::HIDCore& hid_core_,
|
||||
DebugPadSharedMemoryFormat& debug_pad_shared_memory)
|
||||
: ControllerBase{hid_core_}, shared_memory{debug_pad_shared_memory} {
|
||||
controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other);
|
||||
}
|
||||
|
||||
@ -30,12 +25,12 @@ void DebugPad::OnRelease() {}
|
||||
|
||||
void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory->debug_pad_lifo.buffer_count = 0;
|
||||
shared_memory->debug_pad_lifo.buffer_tail = 0;
|
||||
shared_memory.debug_pad_lifo.buffer_count = 0;
|
||||
shared_memory.debug_pad_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& last_entry = shared_memory->debug_pad_lifo.ReadCurrentEntry().state;
|
||||
const auto& last_entry = shared_memory.debug_pad_lifo.ReadCurrentEntry().state;
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
|
||||
if (Settings::values.debug_pad_enabled) {
|
||||
@ -49,7 +44,7 @@ void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
next_state.r_stick = stick_state.right;
|
||||
}
|
||||
|
||||
shared_memory->debug_pad_lifo.WriteNextEntry(next_state);
|
||||
shared_memory.debug_pad_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -3,21 +3,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
#include "core/hle/service/hid/ring_lifo.h"
|
||||
#include "core/hle/service/hid/controllers/types/debug_pad_types.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedController;
|
||||
struct DebugPadButton;
|
||||
struct AnalogStickState;
|
||||
} // namespace Core::HID
|
||||
class HIDCore;
|
||||
}
|
||||
|
||||
namespace Core::Timing {
|
||||
class CoreTiming;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct DebugPadSharedMemoryFormat;
|
||||
|
||||
class DebugPad final : public ControllerBase {
|
||||
public:
|
||||
explicit DebugPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
explicit DebugPad(Core::HID::HIDCore& hid_core_,
|
||||
DebugPadSharedMemoryFormat& debug_pad_shared_memory);
|
||||
~DebugPad() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
@ -30,35 +33,8 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
// This is nn::hid::DebugPadAttribute
|
||||
struct DebugPadAttribute {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, u32> connected;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(DebugPadAttribute) == 0x4, "DebugPadAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::DebugPadState
|
||||
struct DebugPadState {
|
||||
s64 sampling_number{};
|
||||
DebugPadAttribute attribute{};
|
||||
Core::HID::DebugPadButton pad_state{};
|
||||
Core::HID::AnalogStickState r_stick{};
|
||||
Core::HID::AnalogStickState l_stick{};
|
||||
};
|
||||
static_assert(sizeof(DebugPadState) == 0x20, "DebugPadState is an invalid state");
|
||||
|
||||
struct DebugPadSharedMemory {
|
||||
// This is nn::hid::detail::DebugPadLifo
|
||||
Lifo<DebugPadState, hid_entry_count> debug_pad_lifo{};
|
||||
static_assert(sizeof(debug_pad_lifo) == 0x2C8, "debug_pad_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x4E);
|
||||
};
|
||||
static_assert(sizeof(DebugPadSharedMemory) == 0x400, "DebugPadSharedMemory is an invalid size");
|
||||
|
||||
DebugPadState next_state{};
|
||||
DebugPadSharedMemory* shared_memory = nullptr;
|
||||
DebugPadSharedMemoryFormat& shared_memory;
|
||||
Core::HID::EmulatedController* controller = nullptr;
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
@ -1,17 +1,15 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "common/math_util.h"
|
||||
#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/gesture.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00;
|
||||
|
||||
// HW is around 700, value is set to 400 to make it easier to trigger with mouse
|
||||
constexpr f32 swipe_threshold = 400.0f; // Threshold in pixels/s
|
||||
constexpr f32 angle_threshold = 0.015f; // Threshold in radians
|
||||
@ -23,19 +21,15 @@ constexpr f32 Square(s32 num) {
|
||||
return static_cast<f32>(num * num);
|
||||
}
|
||||
|
||||
Gesture::Gesture(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_)
|
||||
: ControllerBase(hid_core_) {
|
||||
static_assert(SHARED_MEMORY_OFFSET + sizeof(GestureSharedMemory) < shared_memory_size,
|
||||
"GestureSharedMemory is bigger than the shared memory");
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<GestureSharedMemory*>(raw_shared_memory_ + SHARED_MEMORY_OFFSET));
|
||||
Gesture::Gesture(Core::HID::HIDCore& hid_core_, GestureSharedMemoryFormat& gesture_shared_memory)
|
||||
: ControllerBase(hid_core_), shared_memory{gesture_shared_memory} {
|
||||
console = hid_core.GetEmulatedConsole();
|
||||
}
|
||||
Gesture::~Gesture() = default;
|
||||
|
||||
void Gesture::OnInit() {
|
||||
shared_memory->gesture_lifo.buffer_count = 0;
|
||||
shared_memory->gesture_lifo.buffer_tail = 0;
|
||||
shared_memory.gesture_lifo.buffer_count = 0;
|
||||
shared_memory.gesture_lifo.buffer_tail = 0;
|
||||
force_update = true;
|
||||
}
|
||||
|
||||
@ -43,8 +37,8 @@ void Gesture::OnRelease() {}
|
||||
|
||||
void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory->gesture_lifo.buffer_count = 0;
|
||||
shared_memory->gesture_lifo.buffer_tail = 0;
|
||||
shared_memory.gesture_lifo.buffer_count = 0;
|
||||
shared_memory.gesture_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,7 +46,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
|
||||
GestureProperties gesture = GetGestureProperties();
|
||||
f32 time_difference =
|
||||
static_cast<f32>(shared_memory->gesture_lifo.timestamp - last_update_timestamp) /
|
||||
static_cast<f32>(shared_memory.gesture_lifo.timestamp - last_update_timestamp) /
|
||||
(1000 * 1000 * 1000);
|
||||
|
||||
// Only update if necessary
|
||||
@ -60,7 +54,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
last_update_timestamp = shared_memory->gesture_lifo.timestamp;
|
||||
last_update_timestamp = shared_memory.gesture_lifo.timestamp;
|
||||
UpdateGestureSharedMemory(gesture, time_difference);
|
||||
}
|
||||
|
||||
@ -103,7 +97,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif
|
||||
GestureType type = GestureType::Idle;
|
||||
GestureAttribute attributes{};
|
||||
|
||||
const auto& last_entry = shared_memory->gesture_lifo.ReadCurrentEntry().state;
|
||||
const auto& last_entry = shared_memory.gesture_lifo.ReadCurrentEntry().state;
|
||||
|
||||
// Reset next state to default
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
@ -133,7 +127,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif
|
||||
next_state.points = gesture.points;
|
||||
last_gesture = gesture;
|
||||
|
||||
shared_memory->gesture_lifo.WriteNextEntry(next_state);
|
||||
shared_memory.gesture_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
void Gesture::NewGesture(GestureProperties& gesture, GestureType& type,
|
||||
@ -305,11 +299,11 @@ void Gesture::SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_
|
||||
next_state.direction = GestureDirection::Up;
|
||||
}
|
||||
|
||||
const Gesture::GestureState& Gesture::GetLastGestureEntry() const {
|
||||
return shared_memory->gesture_lifo.ReadCurrentEntry().state;
|
||||
const GestureState& Gesture::GetLastGestureEntry() const {
|
||||
return shared_memory.gesture_lifo.ReadCurrentEntry().state;
|
||||
}
|
||||
|
||||
Gesture::GestureProperties Gesture::GetGestureProperties() {
|
||||
GestureProperties Gesture::GetGestureProperties() {
|
||||
GestureProperties gesture;
|
||||
std::array<Core::HID::TouchFinger, MAX_POINTS> active_fingers;
|
||||
const auto end_iter = std::copy_if(fingers.begin(), fingers.end(), active_fingers.begin(),
|
||||
|
@ -4,17 +4,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include "common/bit_field.h"
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/point.h"
|
||||
#include "core/hid/emulated_console.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
#include "core/hle/service/hid/ring_lifo.h"
|
||||
#include "core/hle/service/hid/controllers/types/touch_types.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedConsole;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct GestureSharedMemoryFormat;
|
||||
|
||||
class Gesture final : public ControllerBase {
|
||||
public:
|
||||
explicit Gesture(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
explicit Gesture(Core::HID::HIDCore& hid_core_,
|
||||
GestureSharedMemoryFormat& gesture_shared_memory);
|
||||
~Gesture() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
@ -27,79 +32,6 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
static constexpr size_t MAX_FINGERS = 16;
|
||||
static constexpr size_t MAX_POINTS = 4;
|
||||
|
||||
// This is nn::hid::GestureType
|
||||
enum class GestureType : u32 {
|
||||
Idle, // Nothing touching the screen
|
||||
Complete, // Set at the end of a touch event
|
||||
Cancel, // Set when the number of fingers change
|
||||
Touch, // A finger just touched the screen
|
||||
Press, // Set if last type is touch and the finger hasn't moved
|
||||
Tap, // Fast press then release
|
||||
Pan, // All points moving together across the screen
|
||||
Swipe, // Fast press movement and release of a single point
|
||||
Pinch, // All points moving away/closer to the midpoint
|
||||
Rotate, // All points rotating from the midpoint
|
||||
};
|
||||
|
||||
// This is nn::hid::GestureDirection
|
||||
enum class GestureDirection : u32 {
|
||||
None,
|
||||
Left,
|
||||
Up,
|
||||
Right,
|
||||
Down,
|
||||
};
|
||||
|
||||
// This is nn::hid::GestureAttribute
|
||||
struct GestureAttribute {
|
||||
union {
|
||||
u32 raw{};
|
||||
|
||||
BitField<4, 1, u32> is_new_touch;
|
||||
BitField<8, 1, u32> is_double_tap;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(GestureAttribute) == 4, "GestureAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::GestureState
|
||||
struct GestureState {
|
||||
s64 sampling_number{};
|
||||
s64 detection_count{};
|
||||
GestureType type{GestureType::Idle};
|
||||
GestureDirection direction{GestureDirection::None};
|
||||
Common::Point<s32> pos{};
|
||||
Common::Point<s32> delta{};
|
||||
f32 vel_x{};
|
||||
f32 vel_y{};
|
||||
GestureAttribute attributes{};
|
||||
f32 scale{};
|
||||
f32 rotation_angle{};
|
||||
s32 point_count{};
|
||||
std::array<Common::Point<s32>, 4> points{};
|
||||
};
|
||||
static_assert(sizeof(GestureState) == 0x60, "GestureState is an invalid size");
|
||||
|
||||
struct GestureProperties {
|
||||
std::array<Common::Point<s32>, MAX_POINTS> points{};
|
||||
std::size_t active_points{};
|
||||
Common::Point<s32> mid_point{};
|
||||
s64 detection_count{};
|
||||
u64 delta_time{};
|
||||
f32 average_distance{};
|
||||
f32 angle{};
|
||||
};
|
||||
|
||||
struct GestureSharedMemory {
|
||||
// This is nn::hid::detail::GestureLifo
|
||||
Lifo<GestureState, hid_entry_count> gesture_lifo{};
|
||||
static_assert(sizeof(gesture_lifo) == 0x708, "gesture_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x3E);
|
||||
};
|
||||
static_assert(sizeof(GestureSharedMemory) == 0x800, "GestureSharedMemory is an invalid size");
|
||||
|
||||
// Reads input from all available input engines
|
||||
void ReadTouchInput();
|
||||
|
||||
@ -142,7 +74,7 @@ private:
|
||||
GestureProperties GetGestureProperties();
|
||||
|
||||
GestureState next_state{};
|
||||
GestureSharedMemory* shared_memory = nullptr;
|
||||
GestureSharedMemoryFormat& shared_memory;
|
||||
Core::HID::EmulatedConsole* console = nullptr;
|
||||
|
||||
std::array<Core::HID::TouchFinger, MAX_POINTS> fingers{};
|
||||
|
@ -1,23 +1,18 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include "common/common_types.h"
|
||||
#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/keyboard.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800;
|
||||
|
||||
Keyboard::Keyboard(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_)
|
||||
: ControllerBase{hid_core_} {
|
||||
static_assert(SHARED_MEMORY_OFFSET + sizeof(KeyboardSharedMemory) < shared_memory_size,
|
||||
"KeyboardSharedMemory is bigger than the shared memory");
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<KeyboardSharedMemory*>(raw_shared_memory_ + SHARED_MEMORY_OFFSET));
|
||||
Keyboard::Keyboard(Core::HID::HIDCore& hid_core_,
|
||||
KeyboardSharedMemoryFormat& keyboard_shared_memory)
|
||||
: ControllerBase{hid_core_}, shared_memory{keyboard_shared_memory} {
|
||||
emulated_devices = hid_core.GetEmulatedDevices();
|
||||
}
|
||||
|
||||
@ -29,12 +24,12 @@ void Keyboard::OnRelease() {}
|
||||
|
||||
void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory->keyboard_lifo.buffer_count = 0;
|
||||
shared_memory->keyboard_lifo.buffer_tail = 0;
|
||||
shared_memory.keyboard_lifo.buffer_count = 0;
|
||||
shared_memory.keyboard_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& last_entry = shared_memory->keyboard_lifo.ReadCurrentEntry().state;
|
||||
const auto& last_entry = shared_memory.keyboard_lifo.ReadCurrentEntry().state;
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
|
||||
if (Settings::values.keyboard_enabled) {
|
||||
@ -46,7 +41,7 @@ void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
next_state.attribute.is_connected.Assign(1);
|
||||
}
|
||||
|
||||
shared_memory->keyboard_lifo.WriteNextEntry(next_state);
|
||||
shared_memory.keyboard_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -3,20 +3,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
#include "core/hle/service/hid/ring_lifo.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedDevices;
|
||||
struct KeyboardModifier;
|
||||
struct KeyboardKey;
|
||||
} // namespace Core::HID
|
||||
#include "core/hle/service/hid/controllers/types/keyboard_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct KeyboardSharedMemoryFormat;
|
||||
|
||||
class Keyboard final : public ControllerBase {
|
||||
public:
|
||||
explicit Keyboard(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
explicit Keyboard(Core::HID::HIDCore& hid_core_,
|
||||
KeyboardSharedMemoryFormat& keyboard_shared_memory);
|
||||
~Keyboard() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
@ -29,25 +25,8 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
// This is nn::hid::detail::KeyboardState
|
||||
struct KeyboardState {
|
||||
s64 sampling_number{};
|
||||
Core::HID::KeyboardModifier modifier{};
|
||||
Core::HID::KeyboardAttribute attribute{};
|
||||
Core::HID::KeyboardKey key{};
|
||||
};
|
||||
static_assert(sizeof(KeyboardState) == 0x30, "KeyboardState is an invalid size");
|
||||
|
||||
struct KeyboardSharedMemory {
|
||||
// This is nn::hid::detail::KeyboardLifo
|
||||
Lifo<KeyboardState, hid_entry_count> keyboard_lifo{};
|
||||
static_assert(sizeof(keyboard_lifo) == 0x3D8, "keyboard_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0xA);
|
||||
};
|
||||
static_assert(sizeof(KeyboardSharedMemory) == 0x400, "KeyboardSharedMemory is an invalid size");
|
||||
|
||||
KeyboardState next_state{};
|
||||
KeyboardSharedMemory* shared_memory = nullptr;
|
||||
KeyboardSharedMemoryFormat& shared_memory;
|
||||
Core::HID::EmulatedDevices* emulated_devices = nullptr;
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
@ -1,22 +1,17 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include "common/common_types.h"
|
||||
#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/mouse.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400;
|
||||
|
||||
Mouse::Mouse(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase{hid_core_} {
|
||||
static_assert(SHARED_MEMORY_OFFSET + sizeof(MouseSharedMemory) < shared_memory_size,
|
||||
"MouseSharedMemory is bigger than the shared memory");
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<MouseSharedMemory*>(raw_shared_memory_ + SHARED_MEMORY_OFFSET));
|
||||
Mouse::Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory)
|
||||
: ControllerBase{hid_core_}, shared_memory{mouse_shared_memory} {
|
||||
emulated_devices = hid_core.GetEmulatedDevices();
|
||||
}
|
||||
|
||||
@ -27,14 +22,14 @@ void Mouse::OnRelease() {}
|
||||
|
||||
void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory->mouse_lifo.buffer_count = 0;
|
||||
shared_memory->mouse_lifo.buffer_tail = 0;
|
||||
shared_memory.mouse_lifo.buffer_count = 0;
|
||||
shared_memory.mouse_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
next_state = {};
|
||||
|
||||
const auto& last_entry = shared_memory->mouse_lifo.ReadCurrentEntry().state;
|
||||
const auto& last_entry = shared_memory.mouse_lifo.ReadCurrentEntry().state;
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
|
||||
if (Settings::values.mouse_enabled) {
|
||||
@ -53,7 +48,7 @@ void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
next_state.button = mouse_button_state;
|
||||
}
|
||||
|
||||
shared_memory->mouse_lifo.WriteNextEntry(next_state);
|
||||
shared_memory.mouse_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
#include "core/hle/service/hid/ring_lifo.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedDevices;
|
||||
@ -14,9 +12,11 @@ struct AnalogStickState;
|
||||
} // namespace Core::HID
|
||||
|
||||
namespace Service::HID {
|
||||
struct MouseSharedMemoryFormat;
|
||||
|
||||
class Mouse final : public ControllerBase {
|
||||
public:
|
||||
explicit Mouse(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
explicit Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory);
|
||||
~Mouse() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
@ -29,17 +29,9 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
struct MouseSharedMemory {
|
||||
// This is nn::hid::detail::MouseLifo
|
||||
Lifo<Core::HID::MouseState, hid_entry_count> mouse_lifo{};
|
||||
static_assert(sizeof(mouse_lifo) == 0x350, "mouse_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x2C);
|
||||
};
|
||||
static_assert(sizeof(MouseSharedMemory) == 0x400, "MouseSharedMemory is an invalid size");
|
||||
|
||||
Core::HID::MouseState next_state{};
|
||||
Core::HID::AnalogStickState last_mouse_wheel_state{};
|
||||
MouseSharedMemory* shared_memory = nullptr;
|
||||
MouseSharedMemoryFormat& shared_memory;
|
||||
Core::HID::EmulatedDevices* emulated_devices = nullptr;
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
@ -17,12 +17,12 @@
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
#include "core/hle/kernel/k_readable_event.h"
|
||||
#include "core/hle/service/hid/controllers/npad.h"
|
||||
#include "core/hle/service/hid/controllers/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"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t NPAD_OFFSET = 0x9A00;
|
||||
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,
|
||||
@ -30,14 +30,12 @@ constexpr std::array<Core::HID::NpadIdType, 10> npad_id_list{
|
||||
Core::HID::NpadIdType::Handheld,
|
||||
};
|
||||
|
||||
NPad::NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_,
|
||||
NPad::NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format,
|
||||
KernelHelpers::ServiceContext& service_context_)
|
||||
: ControllerBase{hid_core_}, service_context{service_context_} {
|
||||
static_assert(NPAD_OFFSET + (NPAD_COUNT * sizeof(NpadInternalState)) < shared_memory_size);
|
||||
for (std::size_t i = 0; i < controller_data.size(); ++i) {
|
||||
auto& controller = controller_data[i];
|
||||
controller.shared_memory = std::construct_at(reinterpret_cast<NpadInternalState*>(
|
||||
raw_shared_memory_ + NPAD_OFFSET + (i * sizeof(NpadInternalState))));
|
||||
controller.shared_memory = &npad_shared_memory_format.npad_entry[i].internal_state;
|
||||
controller.device = hid_core.GetEmulatedControllerByIndex(i);
|
||||
controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value =
|
||||
Core::HID::DEFAULT_VIBRATION_VALUE;
|
||||
@ -617,7 +615,7 @@ void NPad::SetHoldType(NpadJoyHoldType joy_hold_type) {
|
||||
hold_type = joy_hold_type;
|
||||
}
|
||||
|
||||
NPad::NpadJoyHoldType NPad::GetHoldType() const {
|
||||
NpadJoyHoldType NPad::GetHoldType() const {
|
||||
return hold_type;
|
||||
}
|
||||
|
||||
@ -630,7 +628,7 @@ void NPad::SetNpadHandheldActivationMode(NpadHandheldActivationMode activation_m
|
||||
handheld_activation_mode = activation_mode;
|
||||
}
|
||||
|
||||
NPad::NpadHandheldActivationMode NPad::GetNpadHandheldActivationMode() const {
|
||||
NpadHandheldActivationMode NPad::GetNpadHandheldActivationMode() const {
|
||||
return handheld_activation_mode;
|
||||
}
|
||||
|
||||
@ -638,7 +636,7 @@ void NPad::SetNpadCommunicationMode(NpadCommunicationMode communication_mode_) {
|
||||
communication_mode = communication_mode_;
|
||||
}
|
||||
|
||||
NPad::NpadCommunicationMode NPad::GetNpadCommunicationMode() const {
|
||||
NpadCommunicationMode NPad::GetNpadCommunicationMode() const {
|
||||
return communication_mode;
|
||||
}
|
||||
|
||||
@ -978,27 +976,27 @@ Result NPad::ResetIsSixAxisSensorDeviceNewlyAssigned(
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
NPad::SixAxisLifo& NPad::GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id) {
|
||||
NpadSixAxisSensorLifo& NPad::GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id) {
|
||||
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_fullkey_lifo;
|
||||
}
|
||||
|
||||
NPad::SixAxisLifo& NPad::GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id) {
|
||||
NpadSixAxisSensorLifo& NPad::GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id) {
|
||||
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_handheld_lifo;
|
||||
}
|
||||
|
||||
NPad::SixAxisLifo& NPad::GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id) {
|
||||
NpadSixAxisSensorLifo& NPad::GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id) {
|
||||
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_left_lifo;
|
||||
}
|
||||
|
||||
NPad::SixAxisLifo& NPad::GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id) {
|
||||
NpadSixAxisSensorLifo& NPad::GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id) {
|
||||
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_right_lifo;
|
||||
}
|
||||
|
||||
NPad::SixAxisLifo& NPad::GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id) {
|
||||
NpadSixAxisSensorLifo& NPad::GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id) {
|
||||
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_left_lifo;
|
||||
}
|
||||
|
||||
NPad::SixAxisLifo& NPad::GetSixAxisRightLifo(Core::HID::NpadIdType npad_id) {
|
||||
NpadSixAxisSensorLifo& NPad::GetSixAxisRightLifo(Core::HID::NpadIdType npad_id) {
|
||||
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_right_lifo;
|
||||
}
|
||||
|
||||
@ -1343,7 +1341,7 @@ const Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties(
|
||||
}
|
||||
}
|
||||
|
||||
NPad::AppletDetailedUiType NPad::GetAppletDetailedUiType(Core::HID::NpadIdType npad_id) {
|
||||
AppletDetailedUiType NPad::GetAppletDetailedUiType(Core::HID::NpadIdType npad_id) {
|
||||
const auto& shared_memory = GetControllerFromNpadIdType(npad_id).shared_memory;
|
||||
|
||||
return {
|
||||
|
@ -8,12 +8,10 @@
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#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 "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedController;
|
||||
@ -32,10 +30,13 @@ class ServiceContext;
|
||||
union Result;
|
||||
|
||||
namespace Service::HID {
|
||||
struct NpadInternalState;
|
||||
struct NpadSixAxisSensorLifo;
|
||||
struct NpadSharedMemoryFormat;
|
||||
|
||||
class NPad final : public ControllerBase {
|
||||
public:
|
||||
explicit NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_,
|
||||
explicit NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format,
|
||||
KernelHelpers::ServiceContext& service_context_);
|
||||
~NPad() override;
|
||||
|
||||
@ -48,89 +49,6 @@ public:
|
||||
// When the controller is requesting an update for the shared memory
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
// This is nn::hid::NpadJoyHoldType
|
||||
enum class NpadJoyHoldType : u64 {
|
||||
Vertical = 0,
|
||||
Horizontal = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadJoyAssignmentMode
|
||||
enum class NpadJoyAssignmentMode : u32 {
|
||||
Dual = 0,
|
||||
Single = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadJoyDeviceType
|
||||
enum class NpadJoyDeviceType : s64 {
|
||||
Left = 0,
|
||||
Right = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadHandheldActivationMode
|
||||
enum class NpadHandheldActivationMode : u64 {
|
||||
Dual = 0,
|
||||
Single = 1,
|
||||
None = 2,
|
||||
MaxActivationMode = 3,
|
||||
};
|
||||
|
||||
// This is nn::hid::system::AppletFooterUiAttributesSet
|
||||
struct AppletFooterUiAttributes {
|
||||
INSERT_PADDING_BYTES(0x4);
|
||||
};
|
||||
|
||||
// This is nn::hid::system::AppletFooterUiType
|
||||
enum class AppletFooterUiType : u8 {
|
||||
None = 0,
|
||||
HandheldNone = 1,
|
||||
HandheldJoyConLeftOnly = 2,
|
||||
HandheldJoyConRightOnly = 3,
|
||||
HandheldJoyConLeftJoyConRight = 4,
|
||||
JoyDual = 5,
|
||||
JoyDualLeftOnly = 6,
|
||||
JoyDualRightOnly = 7,
|
||||
JoyLeftHorizontal = 8,
|
||||
JoyLeftVertical = 9,
|
||||
JoyRightHorizontal = 10,
|
||||
JoyRightVertical = 11,
|
||||
SwitchProController = 12,
|
||||
CompatibleProController = 13,
|
||||
CompatibleJoyCon = 14,
|
||||
LarkHvc1 = 15,
|
||||
LarkHvc2 = 16,
|
||||
LarkNesLeft = 17,
|
||||
LarkNesRight = 18,
|
||||
Lucia = 19,
|
||||
Verification = 20,
|
||||
Lagon = 21,
|
||||
};
|
||||
|
||||
using AppletFooterUiVariant = u8;
|
||||
|
||||
// This is "nn::hid::system::AppletDetailedUiType".
|
||||
struct AppletDetailedUiType {
|
||||
AppletFooterUiVariant ui_variant;
|
||||
INSERT_PADDING_BYTES(0x2);
|
||||
AppletFooterUiType footer;
|
||||
};
|
||||
static_assert(sizeof(AppletDetailedUiType) == 0x4, "AppletDetailedUiType is an invalid size");
|
||||
// This is nn::hid::NpadCommunicationMode
|
||||
enum class NpadCommunicationMode : u64 {
|
||||
Mode_5ms = 0,
|
||||
Mode_10ms = 1,
|
||||
Mode_15ms = 2,
|
||||
Default = 3,
|
||||
};
|
||||
|
||||
enum class NpadRevision : u32 {
|
||||
Revision0 = 0,
|
||||
Revision1 = 1,
|
||||
Revision2 = 2,
|
||||
Revision3 = 3,
|
||||
};
|
||||
|
||||
using SixAxisLifo = Lifo<Core::HID::SixAxisSensorState, hid_entry_count>;
|
||||
|
||||
void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set);
|
||||
Core::HID::NpadStyleTag GetSupportedStyleSet() const;
|
||||
|
||||
@ -188,12 +106,12 @@ public:
|
||||
Result ResetIsSixAxisSensorDeviceNewlyAssigned(
|
||||
const Core::HID::SixAxisSensorHandle& sixaxis_handle);
|
||||
|
||||
SixAxisLifo& GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id);
|
||||
SixAxisLifo& GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id);
|
||||
SixAxisLifo& GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id);
|
||||
SixAxisLifo& GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id);
|
||||
SixAxisLifo& GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id);
|
||||
SixAxisLifo& GetSixAxisRightLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisRightLifo(Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
|
||||
Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
|
||||
@ -221,214 +139,6 @@ public:
|
||||
AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id);
|
||||
|
||||
private:
|
||||
static constexpr std::size_t NPAD_COUNT = 10;
|
||||
|
||||
// This is nn::hid::detail::ColorAttribute
|
||||
enum class ColorAttribute : u32 {
|
||||
Ok = 0,
|
||||
ReadError = 1,
|
||||
NoController = 2,
|
||||
};
|
||||
static_assert(sizeof(ColorAttribute) == 4, "ColorAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadFullKeyColorState
|
||||
struct NpadFullKeyColorState {
|
||||
ColorAttribute attribute{ColorAttribute::NoController};
|
||||
Core::HID::NpadControllerColor fullkey{};
|
||||
};
|
||||
static_assert(sizeof(NpadFullKeyColorState) == 0xC, "NpadFullKeyColorState is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadJoyColorState
|
||||
struct NpadJoyColorState {
|
||||
ColorAttribute attribute{ColorAttribute::NoController};
|
||||
Core::HID::NpadControllerColor left{};
|
||||
Core::HID::NpadControllerColor right{};
|
||||
};
|
||||
static_assert(sizeof(NpadJoyColorState) == 0x14, "NpadJoyColorState is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadAttribute
|
||||
struct NpadAttribute {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, u32> is_connected;
|
||||
BitField<1, 1, u32> is_wired;
|
||||
BitField<2, 1, u32> is_left_connected;
|
||||
BitField<3, 1, u32> is_left_wired;
|
||||
BitField<4, 1, u32> is_right_connected;
|
||||
BitField<5, 1, u32> is_right_wired;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(NpadAttribute) == 4, "NpadAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadFullKeyState
|
||||
// This is nn::hid::NpadHandheldState
|
||||
// This is nn::hid::NpadJoyDualState
|
||||
// This is nn::hid::NpadJoyLeftState
|
||||
// This is nn::hid::NpadJoyRightState
|
||||
// This is nn::hid::NpadPalmaState
|
||||
// This is nn::hid::NpadSystemExtState
|
||||
struct NPadGenericState {
|
||||
s64_le sampling_number{};
|
||||
Core::HID::NpadButtonState npad_buttons{};
|
||||
Core::HID::AnalogStickState l_stick{};
|
||||
Core::HID::AnalogStickState r_stick{};
|
||||
NpadAttribute connection_status{};
|
||||
INSERT_PADDING_BYTES(4); // Reserved
|
||||
};
|
||||
static_assert(sizeof(NPadGenericState) == 0x28, "NPadGenericState is an invalid size");
|
||||
|
||||
// This is nn::hid::server::NpadGcTriggerState
|
||||
struct NpadGcTriggerState {
|
||||
s64 sampling_number{};
|
||||
s32 l_analog{};
|
||||
s32 r_analog{};
|
||||
};
|
||||
static_assert(sizeof(NpadGcTriggerState) == 0x10, "NpadGcTriggerState is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadSystemProperties
|
||||
struct NPadSystemProperties {
|
||||
union {
|
||||
s64 raw{};
|
||||
BitField<0, 1, s64> is_charging_joy_dual;
|
||||
BitField<1, 1, s64> is_charging_joy_left;
|
||||
BitField<2, 1, s64> is_charging_joy_right;
|
||||
BitField<3, 1, s64> is_powered_joy_dual;
|
||||
BitField<4, 1, s64> is_powered_joy_left;
|
||||
BitField<5, 1, s64> is_powered_joy_right;
|
||||
BitField<9, 1, s64> is_system_unsupported_button;
|
||||
BitField<10, 1, s64> is_system_ext_unsupported_button;
|
||||
BitField<11, 1, s64> is_vertical;
|
||||
BitField<12, 1, s64> is_horizontal;
|
||||
BitField<13, 1, s64> use_plus;
|
||||
BitField<14, 1, s64> use_minus;
|
||||
BitField<15, 1, s64> use_directional_buttons;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(NPadSystemProperties) == 0x8, "NPadSystemProperties is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadSystemButtonProperties
|
||||
struct NpadSystemButtonProperties {
|
||||
union {
|
||||
s32 raw{};
|
||||
BitField<0, 1, s32> is_home_button_protection_enabled;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(NpadSystemButtonProperties) == 0x4,
|
||||
"NPadButtonProperties is an invalid size");
|
||||
|
||||
// This is nn::hid::system::DeviceType
|
||||
struct DeviceType {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, s32> fullkey;
|
||||
BitField<1, 1, s32> debug_pad;
|
||||
BitField<2, 1, s32> handheld_left;
|
||||
BitField<3, 1, s32> handheld_right;
|
||||
BitField<4, 1, s32> joycon_left;
|
||||
BitField<5, 1, s32> joycon_right;
|
||||
BitField<6, 1, s32> palma;
|
||||
BitField<7, 1, s32> lark_hvc_left;
|
||||
BitField<8, 1, s32> lark_hvc_right;
|
||||
BitField<9, 1, s32> lark_nes_left;
|
||||
BitField<10, 1, s32> lark_nes_right;
|
||||
BitField<11, 1, s32> handheld_lark_hvc_left;
|
||||
BitField<12, 1, s32> handheld_lark_hvc_right;
|
||||
BitField<13, 1, s32> handheld_lark_nes_left;
|
||||
BitField<14, 1, s32> handheld_lark_nes_right;
|
||||
BitField<15, 1, s32> lucia;
|
||||
BitField<16, 1, s32> lagon;
|
||||
BitField<17, 1, s32> lager;
|
||||
BitField<31, 1, s32> system;
|
||||
};
|
||||
};
|
||||
|
||||
// This is nn::hid::detail::NfcXcdDeviceHandleStateImpl
|
||||
struct NfcXcdDeviceHandleStateImpl {
|
||||
u64 handle{};
|
||||
bool is_available{};
|
||||
bool is_activated{};
|
||||
INSERT_PADDING_BYTES(0x6); // Reserved
|
||||
u64 sampling_number{};
|
||||
};
|
||||
static_assert(sizeof(NfcXcdDeviceHandleStateImpl) == 0x18,
|
||||
"NfcXcdDeviceHandleStateImpl is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadLarkType
|
||||
enum class NpadLarkType : u32 {
|
||||
Invalid,
|
||||
H1,
|
||||
H2,
|
||||
NL,
|
||||
NR,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLuciaType
|
||||
enum class NpadLuciaType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLagonType
|
||||
enum class NpadLagonType : u32 {
|
||||
Invalid,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLagerType
|
||||
enum class NpadLagerType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
};
|
||||
|
||||
// This is nn::hid::detail::NpadInternalState
|
||||
struct NpadInternalState {
|
||||
Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None};
|
||||
NpadJoyAssignmentMode assignment_mode{NpadJoyAssignmentMode::Dual};
|
||||
NpadFullKeyColorState fullkey_color{};
|
||||
NpadJoyColorState joycon_color{};
|
||||
Lifo<NPadGenericState, hid_entry_count> fullkey_lifo{};
|
||||
Lifo<NPadGenericState, hid_entry_count> handheld_lifo{};
|
||||
Lifo<NPadGenericState, hid_entry_count> joy_dual_lifo{};
|
||||
Lifo<NPadGenericState, hid_entry_count> joy_left_lifo{};
|
||||
Lifo<NPadGenericState, hid_entry_count> joy_right_lifo{};
|
||||
Lifo<NPadGenericState, hid_entry_count> palma_lifo{};
|
||||
Lifo<NPadGenericState, hid_entry_count> system_ext_lifo{};
|
||||
Lifo<Core::HID::SixAxisSensorState, hid_entry_count> sixaxis_fullkey_lifo{};
|
||||
Lifo<Core::HID::SixAxisSensorState, hid_entry_count> sixaxis_handheld_lifo{};
|
||||
Lifo<Core::HID::SixAxisSensorState, hid_entry_count> sixaxis_dual_left_lifo{};
|
||||
Lifo<Core::HID::SixAxisSensorState, hid_entry_count> sixaxis_dual_right_lifo{};
|
||||
Lifo<Core::HID::SixAxisSensorState, hid_entry_count> sixaxis_left_lifo{};
|
||||
Lifo<Core::HID::SixAxisSensorState, hid_entry_count> sixaxis_right_lifo{};
|
||||
DeviceType device_type{};
|
||||
INSERT_PADDING_BYTES(0x4); // Reserved
|
||||
NPadSystemProperties system_properties{};
|
||||
NpadSystemButtonProperties button_properties{};
|
||||
Core::HID::NpadBatteryLevel battery_level_dual{};
|
||||
Core::HID::NpadBatteryLevel battery_level_left{};
|
||||
Core::HID::NpadBatteryLevel battery_level_right{};
|
||||
AppletFooterUiAttributes applet_footer_attributes{};
|
||||
AppletFooterUiType applet_footer_type{AppletFooterUiType::None};
|
||||
INSERT_PADDING_BYTES(0x5B); // Reserved
|
||||
INSERT_PADDING_BYTES(0x20); // Unknown
|
||||
Lifo<NpadGcTriggerState, hid_entry_count> gc_trigger_lifo{};
|
||||
NpadLarkType lark_type_l_and_main{};
|
||||
NpadLarkType lark_type_r{};
|
||||
NpadLuciaType lucia_type{};
|
||||
NpadLagonType lagon_type{};
|
||||
NpadLagerType lager_type{};
|
||||
Core::HID::SixAxisSensorProperties sixaxis_fullkey_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_handheld_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_dual_left_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_dual_right_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_left_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_right_properties;
|
||||
INSERT_PADDING_BYTES(0xc06); // Unknown
|
||||
};
|
||||
static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size");
|
||||
|
||||
struct VibrationData {
|
||||
bool device_mounted{};
|
||||
Core::HID::VibrationValue latest_vibration_value{};
|
||||
@ -479,7 +189,7 @@ private:
|
||||
|
||||
std::atomic<u64> press_state{};
|
||||
|
||||
std::array<NpadControllerData, NPAD_COUNT> controller_data{};
|
||||
std::array<NpadControllerData, NpadCount> controller_data{};
|
||||
KernelHelpers::ServiceContext& service_context;
|
||||
std::mutex mutex;
|
||||
std::vector<Core::HID::NpadIdType> supported_npad_id_types{};
|
||||
|
@ -12,8 +12,7 @@
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
Palma::Palma(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_,
|
||||
KernelHelpers::ServiceContext& service_context_)
|
||||
Palma::Palma(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_)
|
||||
: ControllerBase{hid_core_}, service_context{service_context_} {
|
||||
controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other);
|
||||
operation_complete_event = service_context.CreateEvent("hid:PalmaOperationCompleteEvent");
|
||||
|
@ -97,8 +97,7 @@ public:
|
||||
static_assert(sizeof(PalmaConnectionHandle) == 0x8,
|
||||
"PalmaConnectionHandle has incorrect size.");
|
||||
|
||||
explicit Palma(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_,
|
||||
KernelHelpers::ServiceContext& service_context_);
|
||||
explicit Palma(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_);
|
||||
~Palma() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
|
240
src/core/hle/service/hid/controllers/shared_memory_format.h
Normal file
240
src/core/hle/service/hid/controllers/shared_memory_format.h
Normal file
@ -0,0 +1,240 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#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"
|
||||
|
||||
namespace Service::HID {
|
||||
static const std::size_t HidEntryCount = 17;
|
||||
|
||||
struct CommonHeader {
|
||||
s64 timestamp{};
|
||||
s64 total_entry_count{};
|
||||
s64 last_entry_index{};
|
||||
s64 entry_count{};
|
||||
};
|
||||
static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::DebugPadSharedMemoryFormat
|
||||
struct DebugPadSharedMemoryFormat {
|
||||
// This is nn::hid::detail::DebugPadLifo
|
||||
Lifo<DebugPadState, HidEntryCount> debug_pad_lifo{};
|
||||
static_assert(sizeof(debug_pad_lifo) == 0x2C8, "debug_pad_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x4E);
|
||||
};
|
||||
static_assert(sizeof(DebugPadSharedMemoryFormat) == 0x400,
|
||||
"DebugPadSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::TouchScreenSharedMemoryFormat
|
||||
struct TouchScreenSharedMemoryFormat {
|
||||
// This is nn::hid::detail::TouchScreenLifo
|
||||
Lifo<TouchScreenState, HidEntryCount> touch_screen_lifo{};
|
||||
static_assert(sizeof(touch_screen_lifo) == 0x2C38, "touch_screen_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0xF2);
|
||||
};
|
||||
static_assert(sizeof(TouchScreenSharedMemoryFormat) == 0x3000,
|
||||
"TouchScreenSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::MouseSharedMemoryFormat
|
||||
struct MouseSharedMemoryFormat {
|
||||
// This is nn::hid::detail::MouseLifo
|
||||
Lifo<Core::HID::MouseState, HidEntryCount> mouse_lifo{};
|
||||
static_assert(sizeof(mouse_lifo) == 0x350, "mouse_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x2C);
|
||||
};
|
||||
static_assert(sizeof(MouseSharedMemoryFormat) == 0x400,
|
||||
"MouseSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::KeyboardSharedMemoryFormat
|
||||
struct KeyboardSharedMemoryFormat {
|
||||
// This is nn::hid::detail::KeyboardLifo
|
||||
Lifo<KeyboardState, HidEntryCount> keyboard_lifo{};
|
||||
static_assert(sizeof(keyboard_lifo) == 0x3D8, "keyboard_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0xA);
|
||||
};
|
||||
static_assert(sizeof(KeyboardSharedMemoryFormat) == 0x400,
|
||||
"KeyboardSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::DigitizerSharedMemoryFormat
|
||||
struct DigitizerSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0xFE0);
|
||||
};
|
||||
static_assert(sizeof(DigitizerSharedMemoryFormat) == 0x1000,
|
||||
"DigitizerSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::HomeButtonSharedMemoryFormat
|
||||
struct HomeButtonSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x1E0);
|
||||
};
|
||||
static_assert(sizeof(HomeButtonSharedMemoryFormat) == 0x200,
|
||||
"HomeButtonSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::SleepButtonSharedMemoryFormat
|
||||
struct SleepButtonSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x1E0);
|
||||
};
|
||||
static_assert(sizeof(SleepButtonSharedMemoryFormat) == 0x200,
|
||||
"SleepButtonSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::CaptureButtonSharedMemoryFormat
|
||||
struct CaptureButtonSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x1E0);
|
||||
};
|
||||
static_assert(sizeof(CaptureButtonSharedMemoryFormat) == 0x200,
|
||||
"CaptureButtonSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::InputDetectorSharedMemoryFormat
|
||||
struct InputDetectorSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x7E0);
|
||||
};
|
||||
static_assert(sizeof(InputDetectorSharedMemoryFormat) == 0x800,
|
||||
"InputDetectorSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::UniquePadSharedMemoryFormat
|
||||
struct UniquePadSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x3FE0);
|
||||
};
|
||||
static_assert(sizeof(UniquePadSharedMemoryFormat) == 0x4000,
|
||||
"UniquePadSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadSixAxisSensorLifo
|
||||
struct NpadSixAxisSensorLifo {
|
||||
Lifo<Core::HID::SixAxisSensorState, HidEntryCount> lifo;
|
||||
};
|
||||
|
||||
// This is nn::hid::detail::NpadInternalState
|
||||
struct NpadInternalState {
|
||||
Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None};
|
||||
NpadJoyAssignmentMode assignment_mode{NpadJoyAssignmentMode::Dual};
|
||||
NpadFullKeyColorState fullkey_color{};
|
||||
NpadJoyColorState joycon_color{};
|
||||
Lifo<NPadGenericState, HidEntryCount> fullkey_lifo{};
|
||||
Lifo<NPadGenericState, HidEntryCount> handheld_lifo{};
|
||||
Lifo<NPadGenericState, HidEntryCount> joy_dual_lifo{};
|
||||
Lifo<NPadGenericState, HidEntryCount> joy_left_lifo{};
|
||||
Lifo<NPadGenericState, HidEntryCount> joy_right_lifo{};
|
||||
Lifo<NPadGenericState, HidEntryCount> palma_lifo{};
|
||||
Lifo<NPadGenericState, HidEntryCount> system_ext_lifo{};
|
||||
NpadSixAxisSensorLifo sixaxis_fullkey_lifo{};
|
||||
NpadSixAxisSensorLifo sixaxis_handheld_lifo{};
|
||||
NpadSixAxisSensorLifo sixaxis_dual_left_lifo{};
|
||||
NpadSixAxisSensorLifo sixaxis_dual_right_lifo{};
|
||||
NpadSixAxisSensorLifo sixaxis_left_lifo{};
|
||||
NpadSixAxisSensorLifo sixaxis_right_lifo{};
|
||||
DeviceType device_type{};
|
||||
INSERT_PADDING_BYTES(0x4); // Reserved
|
||||
NPadSystemProperties system_properties{};
|
||||
NpadSystemButtonProperties button_properties{};
|
||||
Core::HID::NpadBatteryLevel battery_level_dual{};
|
||||
Core::HID::NpadBatteryLevel battery_level_left{};
|
||||
Core::HID::NpadBatteryLevel battery_level_right{};
|
||||
AppletFooterUiAttributes applet_footer_attributes{};
|
||||
AppletFooterUiType applet_footer_type{AppletFooterUiType::None};
|
||||
INSERT_PADDING_BYTES(0x5B); // Reserved
|
||||
INSERT_PADDING_BYTES(0x20); // Unknown
|
||||
Lifo<NpadGcTriggerState, HidEntryCount> gc_trigger_lifo{};
|
||||
NpadLarkType lark_type_l_and_main{};
|
||||
NpadLarkType lark_type_r{};
|
||||
NpadLuciaType lucia_type{};
|
||||
NpadLagerType lager_type{};
|
||||
Core::HID::SixAxisSensorProperties sixaxis_fullkey_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_handheld_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_dual_left_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_dual_right_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_left_properties;
|
||||
Core::HID::SixAxisSensorProperties sixaxis_right_properties;
|
||||
};
|
||||
static_assert(sizeof(NpadInternalState) == 0x43F8, "NpadInternalState is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadSharedMemoryEntry
|
||||
struct NpadSharedMemoryEntry {
|
||||
NpadInternalState internal_state;
|
||||
INSERT_PADDING_BYTES(0xC08);
|
||||
};
|
||||
static_assert(sizeof(NpadSharedMemoryEntry) == 0x5000, "NpadSharedMemoryEntry is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadSharedMemoryFormat
|
||||
struct NpadSharedMemoryFormat {
|
||||
std::array<NpadSharedMemoryEntry, NpadCount> npad_entry;
|
||||
};
|
||||
static_assert(sizeof(NpadSharedMemoryFormat) == 0x32000,
|
||||
"NpadSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::GestureSharedMemoryFormat
|
||||
struct GestureSharedMemoryFormat {
|
||||
// This is nn::hid::detail::GestureLifo
|
||||
Lifo<GestureState, HidEntryCount> gesture_lifo{};
|
||||
static_assert(sizeof(gesture_lifo) == 0x708, "gesture_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x3E);
|
||||
};
|
||||
static_assert(sizeof(GestureSharedMemoryFormat) == 0x800,
|
||||
"GestureSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat
|
||||
struct ConsoleSixAxisSensorSharedMemoryFormat {
|
||||
u64 sampling_number{};
|
||||
bool is_seven_six_axis_sensor_at_rest{};
|
||||
INSERT_PADDING_BYTES(3); // padding
|
||||
f32 verticalization_error{};
|
||||
Common::Vec3f gyro_bias{};
|
||||
INSERT_PADDING_BYTES(4); // padding
|
||||
};
|
||||
static_assert(sizeof(ConsoleSixAxisSensorSharedMemoryFormat) == 0x20,
|
||||
"ConsoleSixAxisSensorSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::SharedMemoryFormat
|
||||
struct SharedMemoryFormat {
|
||||
void Initialize() {}
|
||||
|
||||
DebugPadSharedMemoryFormat debug_pad;
|
||||
TouchScreenSharedMemoryFormat touch_screen;
|
||||
MouseSharedMemoryFormat mouse;
|
||||
KeyboardSharedMemoryFormat keyboard;
|
||||
DigitizerSharedMemoryFormat digitizer;
|
||||
HomeButtonSharedMemoryFormat home_button;
|
||||
SleepButtonSharedMemoryFormat sleep_button;
|
||||
CaptureButtonSharedMemoryFormat capture_button;
|
||||
InputDetectorSharedMemoryFormat input_detector;
|
||||
UniquePadSharedMemoryFormat unique_pad;
|
||||
NpadSharedMemoryFormat npad;
|
||||
GestureSharedMemoryFormat gesture;
|
||||
ConsoleSixAxisSensorSharedMemoryFormat console;
|
||||
INSERT_PADDING_BYTES(0x19E0);
|
||||
MouseSharedMemoryFormat debug_mouse;
|
||||
INSERT_PADDING_BYTES(0x2000);
|
||||
};
|
||||
static_assert(offsetof(SharedMemoryFormat, debug_pad) == 0x0, "debug_pad has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, touch_screen) == 0x400, "touch_screen has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, mouse) == 0x3400, "mouse has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, keyboard) == 0x3800, "keyboard has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, digitizer) == 0x3C00, "digitizer has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, home_button) == 0x4C00, "home_button has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, sleep_button) == 0x4E00,
|
||||
"sleep_button has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, capture_button) == 0x5000,
|
||||
"capture_button has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, input_detector) == 0x5200,
|
||||
"input_detector has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, npad) == 0x9A00, "npad has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, gesture) == 0x3BA00, "gesture has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, console) == 0x3C200, "console has wrong offset");
|
||||
static_assert(offsetof(SharedMemoryFormat, debug_mouse) == 0x3DC00, "debug_mouse has wrong offset");
|
||||
static_assert(sizeof(SharedMemoryFormat) == 0x40000, "SharedMemoryFormat is an invalid size");
|
||||
|
||||
} // namespace Service::HID
|
@ -0,0 +1,53 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/k_shared_memory.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_holder.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
SharedMemoryHolder::SharedMemoryHolder() {}
|
||||
|
||||
SharedMemoryHolder::~SharedMemoryHolder() {
|
||||
Finalize();
|
||||
}
|
||||
|
||||
Result SharedMemoryHolder::Initialize(Core::System& system) {
|
||||
shared_memory = Kernel::KSharedMemory::Create(system.Kernel());
|
||||
const Result result = shared_memory->Initialize(
|
||||
system.DeviceMemory(), nullptr, Kernel::Svc::MemoryPermission::None,
|
||||
Kernel::Svc::MemoryPermission::Read, sizeof(SharedMemoryFormat));
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
Kernel::KSharedMemory::Register(system.Kernel(), shared_memory);
|
||||
|
||||
is_created = true;
|
||||
is_mapped = true;
|
||||
address = std::construct_at(reinterpret_cast<SharedMemoryFormat*>(shared_memory->GetPointer()));
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void SharedMemoryHolder::Finalize() {
|
||||
if (address != nullptr) {
|
||||
shared_memory->Close();
|
||||
}
|
||||
is_created = false;
|
||||
is_mapped = false;
|
||||
address = nullptr;
|
||||
}
|
||||
|
||||
bool SharedMemoryHolder::IsMapped() {
|
||||
return is_mapped;
|
||||
}
|
||||
|
||||
SharedMemoryFormat* SharedMemoryHolder::GetAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
Kernel::KSharedMemory* SharedMemoryHolder::GetHandle() {
|
||||
return shared_memory;
|
||||
}
|
||||
} // namespace Service::HID
|
44
src/core/hle/service/hid/controllers/shared_memory_holder.h
Normal file
44
src/core/hle/service/hid/controllers/shared_memory_holder.h
Normal file
@ -0,0 +1,44 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
class KSharedMemory;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct SharedMemoryFormat;
|
||||
|
||||
// This is nn::hid::detail::SharedMemoryHolder
|
||||
class SharedMemoryHolder {
|
||||
public:
|
||||
SharedMemoryHolder();
|
||||
~SharedMemoryHolder();
|
||||
|
||||
Result Initialize(Core::System& system);
|
||||
void Finalize();
|
||||
|
||||
bool IsMapped();
|
||||
SharedMemoryFormat* GetAddress();
|
||||
Kernel::KSharedMemory* GetHandle();
|
||||
|
||||
private:
|
||||
bool is_owner{};
|
||||
bool is_created{};
|
||||
bool is_mapped{};
|
||||
INSERT_PADDING_BYTES(0x5);
|
||||
Kernel::KSharedMemory* shared_memory;
|
||||
INSERT_PADDING_BYTES(0x38);
|
||||
SharedMemoryFormat* address = nullptr;
|
||||
};
|
||||
// Correct size is 0x50 bytes
|
||||
static_assert(sizeof(SharedMemoryHolder) == 0x50, "SharedMemoryHolder is an invalid size");
|
||||
|
||||
} // namespace Service::HID
|
@ -6,6 +6,7 @@
|
||||
#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/shared_memory_format.h"
|
||||
#include "core/hle/service/hid/controllers/six_axis.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
#include "core/hle/service/hid/hid_util.h"
|
||||
@ -132,30 +133,30 @@ void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
}
|
||||
|
||||
sixaxis_fullkey_state.sampling_number =
|
||||
sixaxis_fullkey_lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_fullkey_lifo.lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_handheld_state.sampling_number =
|
||||
sixaxis_handheld_lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_handheld_lifo.lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_dual_left_state.sampling_number =
|
||||
sixaxis_dual_left_lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_dual_left_lifo.lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_dual_right_state.sampling_number =
|
||||
sixaxis_dual_right_lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_dual_right_lifo.lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_left_lifo_state.sampling_number =
|
||||
sixaxis_left_lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_left_lifo.lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_right_lifo_state.sampling_number =
|
||||
sixaxis_right_lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
sixaxis_right_lifo.lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||
|
||||
if (IndexToNpadIdType(i) == Core::HID::NpadIdType::Handheld) {
|
||||
// This buffer only is updated on handheld on HW
|
||||
sixaxis_handheld_lifo.WriteNextEntry(sixaxis_handheld_state);
|
||||
sixaxis_handheld_lifo.lifo.WriteNextEntry(sixaxis_handheld_state);
|
||||
} else {
|
||||
// Handheld doesn't update this buffer on HW
|
||||
sixaxis_fullkey_lifo.WriteNextEntry(sixaxis_fullkey_state);
|
||||
sixaxis_fullkey_lifo.lifo.WriteNextEntry(sixaxis_fullkey_state);
|
||||
}
|
||||
|
||||
sixaxis_dual_left_lifo.WriteNextEntry(sixaxis_dual_left_state);
|
||||
sixaxis_dual_right_lifo.WriteNextEntry(sixaxis_dual_right_state);
|
||||
sixaxis_left_lifo.WriteNextEntry(sixaxis_left_lifo_state);
|
||||
sixaxis_right_lifo.WriteNextEntry(sixaxis_right_lifo_state);
|
||||
sixaxis_dual_left_lifo.lifo.WriteNextEntry(sixaxis_dual_left_state);
|
||||
sixaxis_dual_right_lifo.lifo.WriteNextEntry(sixaxis_dual_right_state);
|
||||
sixaxis_left_lifo.lifo.WriteNextEntry(sixaxis_left_lifo_state);
|
||||
sixaxis_right_lifo.lifo.WriteNextEntry(sixaxis_right_lifo_state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,15 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include "common/common_types.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hid/hid_core.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
#include "core/hle/service/hid/controllers/stubbed.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
Controller_Stubbed::Controller_Stubbed(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_)
|
||||
: ControllerBase{hid_core_} {
|
||||
raw_shared_memory = raw_shared_memory_;
|
||||
}
|
||||
Controller_Stubbed::Controller_Stubbed(Core::HID::HIDCore& hid_core_,
|
||||
CommonHeader& ring_lifo_header)
|
||||
: ControllerBase{hid_core_}, header{ring_lifo_header} {}
|
||||
|
||||
Controller_Stubbed::~Controller_Stubbed() = default;
|
||||
|
||||
@ -25,18 +22,10 @@ void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommonHeader header{};
|
||||
header.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
header.total_entry_count = 17;
|
||||
header.entry_count = 0;
|
||||
header.last_entry_index = 0;
|
||||
|
||||
std::memcpy(raw_shared_memory + common_offset, &header, sizeof(CommonHeader));
|
||||
}
|
||||
|
||||
void Controller_Stubbed::SetCommonHeaderOffset(std::size_t off) {
|
||||
common_offset = off;
|
||||
smart_update = true;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct CommonHeader;
|
||||
|
||||
class Controller_Stubbed final : public ControllerBase {
|
||||
public:
|
||||
explicit Controller_Stubbed(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
explicit Controller_Stubbed(Core::HID::HIDCore& hid_core_, CommonHeader& ring_lifo_header);
|
||||
~Controller_Stubbed() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
@ -21,19 +22,8 @@ public:
|
||||
// When the controller is requesting an update for the shared memory
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
void SetCommonHeaderOffset(std::size_t off);
|
||||
|
||||
private:
|
||||
struct CommonHeader {
|
||||
s64 timestamp{};
|
||||
s64 total_entry_count{};
|
||||
s64 last_entry_index{};
|
||||
s64 entry_count{};
|
||||
};
|
||||
static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size");
|
||||
|
||||
u8* raw_shared_memory = nullptr;
|
||||
CommonHeader& header;
|
||||
bool smart_update{};
|
||||
std::size_t common_offset{};
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
@ -2,26 +2,22 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "common/common_types.h"
|
||||
#include "common/settings.h"
|
||||
#include "core/core.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/shared_memory_format.h"
|
||||
#include "core/hle/service/hid/controllers/touchscreen.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400;
|
||||
|
||||
TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_)
|
||||
: ControllerBase{hid_core_}, touchscreen_width(Layout::ScreenUndocked::Width),
|
||||
TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_,
|
||||
TouchScreenSharedMemoryFormat& touch_shared_memory)
|
||||
: ControllerBase{hid_core_}, shared_memory{touch_shared_memory},
|
||||
touchscreen_width(Layout::ScreenUndocked::Width),
|
||||
touchscreen_height(Layout::ScreenUndocked::Height) {
|
||||
static_assert(SHARED_MEMORY_OFFSET + sizeof(TouchSharedMemory) < shared_memory_size,
|
||||
"TouchSharedMemory is bigger than the shared memory");
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<TouchSharedMemory*>(raw_shared_memory_ + SHARED_MEMORY_OFFSET));
|
||||
console = hid_core.GetEmulatedConsole();
|
||||
}
|
||||
|
||||
@ -32,11 +28,11 @@ void TouchScreen::OnInit() {}
|
||||
void TouchScreen::OnRelease() {}
|
||||
|
||||
void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
shared_memory->touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
shared_memory.touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory->touch_screen_lifo.buffer_count = 0;
|
||||
shared_memory->touch_screen_lifo.buffer_tail = 0;
|
||||
shared_memory.touch_screen_lifo.buffer_count = 0;
|
||||
shared_memory.touch_screen_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -86,7 +82,7 @@ void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
|
||||
|
||||
const u64 timestamp = static_cast<u64>(core_timing.GetGlobalTimeNs().count());
|
||||
const auto& last_entry = shared_memory->touch_screen_lifo.ReadCurrentEntry().state;
|
||||
const auto& last_entry = shared_memory.touch_screen_lifo.ReadCurrentEntry().state;
|
||||
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
next_state.entry_count = static_cast<s32>(active_fingers_count);
|
||||
@ -118,7 +114,7 @@ void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
}
|
||||
}
|
||||
|
||||
shared_memory->touch_screen_lifo.WriteNextEntry(next_state);
|
||||
shared_memory.touch_screen_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
void TouchScreen::SetTouchscreenDimensions(u32 width, u32 height) {
|
||||
|
@ -3,20 +3,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include <array>
|
||||
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
#include "core/hle/service/hid/ring_lifo.h"
|
||||
#include "core/hle/service/hid/controllers/types/touch_types.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedConsole;
|
||||
} // namespace Core::HID
|
||||
|
||||
namespace Service::HID {
|
||||
struct TouchScreenSharedMemoryFormat;
|
||||
|
||||
class TouchScreen final : public ControllerBase {
|
||||
public:
|
||||
explicit TouchScreen(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
explicit TouchScreen(Core::HID::HIDCore& hid_core_,
|
||||
TouchScreenSharedMemoryFormat& touch_shared_memory);
|
||||
~TouchScreen() override;
|
||||
|
||||
// Called when the controller is initialized
|
||||
@ -31,27 +34,8 @@ public:
|
||||
void SetTouchscreenDimensions(u32 width, u32 height);
|
||||
|
||||
private:
|
||||
static constexpr std::size_t MAX_FINGERS = 16;
|
||||
|
||||
// This is nn::hid::TouchScreenState
|
||||
struct TouchScreenState {
|
||||
s64 sampling_number{};
|
||||
s32 entry_count{};
|
||||
INSERT_PADDING_BYTES(4); // Reserved
|
||||
std::array<Core::HID::TouchState, MAX_FINGERS> states{};
|
||||
};
|
||||
static_assert(sizeof(TouchScreenState) == 0x290, "TouchScreenState is an invalid size");
|
||||
|
||||
struct TouchSharedMemory {
|
||||
// This is nn::hid::detail::TouchScreenLifo
|
||||
Lifo<TouchScreenState, hid_entry_count> touch_screen_lifo{};
|
||||
static_assert(sizeof(touch_screen_lifo) == 0x2C38, "touch_screen_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0xF2);
|
||||
};
|
||||
static_assert(sizeof(TouchSharedMemory) == 0x3000, "TouchSharedMemory is an invalid size");
|
||||
|
||||
TouchScreenState next_state{};
|
||||
TouchSharedMemory* shared_memory = nullptr;
|
||||
TouchScreenSharedMemoryFormat& shared_memory;
|
||||
Core::HID::EmulatedConsole* console = nullptr;
|
||||
|
||||
std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers{};
|
||||
|
31
src/core/hle/service/hid/controllers/types/debug_pad_types.h
Normal file
31
src/core/hle/service/hid/controllers/types/debug_pad_types.h
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
// This is nn::hid::DebugPadAttribute
|
||||
struct DebugPadAttribute {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, u32> connected;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(DebugPadAttribute) == 0x4, "DebugPadAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::DebugPadState
|
||||
struct DebugPadState {
|
||||
s64 sampling_number{};
|
||||
DebugPadAttribute attribute{};
|
||||
Core::HID::DebugPadButton pad_state{};
|
||||
Core::HID::AnalogStickState r_stick{};
|
||||
Core::HID::AnalogStickState l_stick{};
|
||||
};
|
||||
static_assert(sizeof(DebugPadState) == 0x20, "DebugPadState is an invalid state");
|
||||
|
||||
} // namespace Service::HID
|
77
src/core/hle/service/hid/controllers/types/gesture_types.h
Normal file
77
src/core/hle/service/hid/controllers/types/gesture_types.h
Normal file
@ -0,0 +1,77 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/point.h"
|
||||
|
||||
namespace Service::HID {
|
||||
static constexpr size_t MAX_FINGERS = 16;
|
||||
static constexpr size_t MAX_POINTS = 4;
|
||||
|
||||
// This is nn::hid::GestureType
|
||||
enum class GestureType : u32 {
|
||||
Idle, // Nothing touching the screen
|
||||
Complete, // Set at the end of a touch event
|
||||
Cancel, // Set when the number of fingers change
|
||||
Touch, // A finger just touched the screen
|
||||
Press, // Set if last type is touch and the finger hasn't moved
|
||||
Tap, // Fast press then release
|
||||
Pan, // All points moving together across the screen
|
||||
Swipe, // Fast press movement and release of a single point
|
||||
Pinch, // All points moving away/closer to the midpoint
|
||||
Rotate, // All points rotating from the midpoint
|
||||
};
|
||||
|
||||
// This is nn::hid::GestureDirection
|
||||
enum class GestureDirection : u32 {
|
||||
None,
|
||||
Left,
|
||||
Up,
|
||||
Right,
|
||||
Down,
|
||||
};
|
||||
|
||||
// This is nn::hid::GestureAttribute
|
||||
struct GestureAttribute {
|
||||
union {
|
||||
u32 raw{};
|
||||
|
||||
BitField<4, 1, u32> is_new_touch;
|
||||
BitField<8, 1, u32> is_double_tap;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(GestureAttribute) == 4, "GestureAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::GestureState
|
||||
struct GestureState {
|
||||
s64 sampling_number{};
|
||||
s64 detection_count{};
|
||||
GestureType type{GestureType::Idle};
|
||||
GestureDirection direction{GestureDirection::None};
|
||||
Common::Point<s32> pos{};
|
||||
Common::Point<s32> delta{};
|
||||
f32 vel_x{};
|
||||
f32 vel_y{};
|
||||
GestureAttribute attributes{};
|
||||
f32 scale{};
|
||||
f32 rotation_angle{};
|
||||
s32 point_count{};
|
||||
std::array<Common::Point<s32>, 4> points{};
|
||||
};
|
||||
static_assert(sizeof(GestureState) == 0x60, "GestureState is an invalid size");
|
||||
|
||||
struct GestureProperties {
|
||||
std::array<Common::Point<s32>, MAX_POINTS> points{};
|
||||
std::size_t active_points{};
|
||||
Common::Point<s32> mid_point{};
|
||||
s64 detection_count{};
|
||||
u64 delta_time{};
|
||||
f32 average_distance{};
|
||||
f32 angle{};
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
20
src/core/hle/service/hid/controllers/types/keyboard_types.h
Normal file
20
src/core/hle/service/hid/controllers/types/keyboard_types.h
Normal file
@ -0,0 +1,20 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
// This is nn::hid::detail::KeyboardState
|
||||
struct KeyboardState {
|
||||
s64 sampling_number{};
|
||||
Core::HID::KeyboardModifier modifier{};
|
||||
Core::HID::KeyboardAttribute attribute{};
|
||||
Core::HID::KeyboardKey key{};
|
||||
};
|
||||
static_assert(sizeof(KeyboardState) == 0x30, "KeyboardState is an invalid size");
|
||||
|
||||
} // namespace Service::HID
|
8
src/core/hle/service/hid/controllers/types/mouse_types.h
Normal file
8
src/core/hle/service/hid/controllers/types/mouse_types.h
Normal file
@ -0,0 +1,8 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Service::HID {} // namespace Service::HID
|
254
src/core/hle/service/hid/controllers/types/npad_types.h
Normal file
254
src/core/hle/service/hid/controllers/types/npad_types.h
Normal file
@ -0,0 +1,254 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
static constexpr std::size_t NpadCount = 10;
|
||||
|
||||
// This is nn::hid::NpadJoyHoldType
|
||||
enum class NpadJoyHoldType : u64 {
|
||||
Vertical = 0,
|
||||
Horizontal = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadJoyAssignmentMode
|
||||
enum class NpadJoyAssignmentMode : u32 {
|
||||
Dual = 0,
|
||||
Single = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadJoyDeviceType
|
||||
enum class NpadJoyDeviceType : s64 {
|
||||
Left = 0,
|
||||
Right = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadHandheldActivationMode
|
||||
enum class NpadHandheldActivationMode : u64 {
|
||||
Dual = 0,
|
||||
Single = 1,
|
||||
None = 2,
|
||||
MaxActivationMode = 3,
|
||||
};
|
||||
|
||||
// This is nn::hid::system::AppletFooterUiAttributesSet
|
||||
struct AppletFooterUiAttributes {
|
||||
INSERT_PADDING_BYTES(0x4);
|
||||
};
|
||||
|
||||
// This is nn::hid::system::AppletFooterUiType
|
||||
enum class AppletFooterUiType : u8 {
|
||||
None = 0,
|
||||
HandheldNone = 1,
|
||||
HandheldJoyConLeftOnly = 2,
|
||||
HandheldJoyConRightOnly = 3,
|
||||
HandheldJoyConLeftJoyConRight = 4,
|
||||
JoyDual = 5,
|
||||
JoyDualLeftOnly = 6,
|
||||
JoyDualRightOnly = 7,
|
||||
JoyLeftHorizontal = 8,
|
||||
JoyLeftVertical = 9,
|
||||
JoyRightHorizontal = 10,
|
||||
JoyRightVertical = 11,
|
||||
SwitchProController = 12,
|
||||
CompatibleProController = 13,
|
||||
CompatibleJoyCon = 14,
|
||||
LarkHvc1 = 15,
|
||||
LarkHvc2 = 16,
|
||||
LarkNesLeft = 17,
|
||||
LarkNesRight = 18,
|
||||
Lucia = 19,
|
||||
Verification = 20,
|
||||
Lagon = 21,
|
||||
};
|
||||
|
||||
using AppletFooterUiVariant = u8;
|
||||
|
||||
// This is "nn::hid::system::AppletDetailedUiType".
|
||||
struct AppletDetailedUiType {
|
||||
AppletFooterUiVariant ui_variant;
|
||||
INSERT_PADDING_BYTES(0x2);
|
||||
AppletFooterUiType footer;
|
||||
};
|
||||
static_assert(sizeof(AppletDetailedUiType) == 0x4, "AppletDetailedUiType is an invalid size");
|
||||
// This is nn::hid::NpadCommunicationMode
|
||||
enum class NpadCommunicationMode : u64 {
|
||||
Mode_5ms = 0,
|
||||
Mode_10ms = 1,
|
||||
Mode_15ms = 2,
|
||||
Default = 3,
|
||||
};
|
||||
|
||||
enum class NpadRevision : u32 {
|
||||
Revision0 = 0,
|
||||
Revision1 = 1,
|
||||
Revision2 = 2,
|
||||
Revision3 = 3,
|
||||
};
|
||||
|
||||
// This is nn::hid::detail::ColorAttribute
|
||||
enum class ColorAttribute : u32 {
|
||||
Ok = 0,
|
||||
ReadError = 1,
|
||||
NoController = 2,
|
||||
};
|
||||
static_assert(sizeof(ColorAttribute) == 4, "ColorAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadFullKeyColorState
|
||||
struct NpadFullKeyColorState {
|
||||
ColorAttribute attribute{ColorAttribute::NoController};
|
||||
Core::HID::NpadControllerColor fullkey{};
|
||||
};
|
||||
static_assert(sizeof(NpadFullKeyColorState) == 0xC, "NpadFullKeyColorState is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadJoyColorState
|
||||
struct NpadJoyColorState {
|
||||
ColorAttribute attribute{ColorAttribute::NoController};
|
||||
Core::HID::NpadControllerColor left{};
|
||||
Core::HID::NpadControllerColor right{};
|
||||
};
|
||||
static_assert(sizeof(NpadJoyColorState) == 0x14, "NpadJoyColorState is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadAttribute
|
||||
struct NpadAttribute {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, u32> is_connected;
|
||||
BitField<1, 1, u32> is_wired;
|
||||
BitField<2, 1, u32> is_left_connected;
|
||||
BitField<3, 1, u32> is_left_wired;
|
||||
BitField<4, 1, u32> is_right_connected;
|
||||
BitField<5, 1, u32> is_right_wired;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(NpadAttribute) == 4, "NpadAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadFullKeyState
|
||||
// This is nn::hid::NpadHandheldState
|
||||
// This is nn::hid::NpadJoyDualState
|
||||
// This is nn::hid::NpadJoyLeftState
|
||||
// This is nn::hid::NpadJoyRightState
|
||||
// This is nn::hid::NpadPalmaState
|
||||
// This is nn::hid::NpadSystemExtState
|
||||
struct NPadGenericState {
|
||||
s64_le sampling_number{};
|
||||
Core::HID::NpadButtonState npad_buttons{};
|
||||
Core::HID::AnalogStickState l_stick{};
|
||||
Core::HID::AnalogStickState r_stick{};
|
||||
NpadAttribute connection_status{};
|
||||
INSERT_PADDING_BYTES(4); // Reserved
|
||||
};
|
||||
static_assert(sizeof(NPadGenericState) == 0x28, "NPadGenericState is an invalid size");
|
||||
|
||||
// This is nn::hid::server::NpadGcTriggerState
|
||||
struct NpadGcTriggerState {
|
||||
s64 sampling_number{};
|
||||
s32 l_analog{};
|
||||
s32 r_analog{};
|
||||
};
|
||||
static_assert(sizeof(NpadGcTriggerState) == 0x10, "NpadGcTriggerState is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadSystemProperties
|
||||
struct NPadSystemProperties {
|
||||
union {
|
||||
s64 raw{};
|
||||
BitField<0, 1, s64> is_charging_joy_dual;
|
||||
BitField<1, 1, s64> is_charging_joy_left;
|
||||
BitField<2, 1, s64> is_charging_joy_right;
|
||||
BitField<3, 1, s64> is_powered_joy_dual;
|
||||
BitField<4, 1, s64> is_powered_joy_left;
|
||||
BitField<5, 1, s64> is_powered_joy_right;
|
||||
BitField<9, 1, s64> is_system_unsupported_button;
|
||||
BitField<10, 1, s64> is_system_ext_unsupported_button;
|
||||
BitField<11, 1, s64> is_vertical;
|
||||
BitField<12, 1, s64> is_horizontal;
|
||||
BitField<13, 1, s64> use_plus;
|
||||
BitField<14, 1, s64> use_minus;
|
||||
BitField<15, 1, s64> use_directional_buttons;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(NPadSystemProperties) == 0x8, "NPadSystemProperties is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadSystemButtonProperties
|
||||
struct NpadSystemButtonProperties {
|
||||
union {
|
||||
s32 raw{};
|
||||
BitField<0, 1, s32> is_home_button_protection_enabled;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(NpadSystemButtonProperties) == 0x4, "NPadButtonProperties is an invalid size");
|
||||
|
||||
// This is nn::hid::system::DeviceType
|
||||
struct DeviceType {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, s32> fullkey;
|
||||
BitField<1, 1, s32> debug_pad;
|
||||
BitField<2, 1, s32> handheld_left;
|
||||
BitField<3, 1, s32> handheld_right;
|
||||
BitField<4, 1, s32> joycon_left;
|
||||
BitField<5, 1, s32> joycon_right;
|
||||
BitField<6, 1, s32> palma;
|
||||
BitField<7, 1, s32> lark_hvc_left;
|
||||
BitField<8, 1, s32> lark_hvc_right;
|
||||
BitField<9, 1, s32> lark_nes_left;
|
||||
BitField<10, 1, s32> lark_nes_right;
|
||||
BitField<11, 1, s32> handheld_lark_hvc_left;
|
||||
BitField<12, 1, s32> handheld_lark_hvc_right;
|
||||
BitField<13, 1, s32> handheld_lark_nes_left;
|
||||
BitField<14, 1, s32> handheld_lark_nes_right;
|
||||
BitField<15, 1, s32> lucia;
|
||||
BitField<16, 1, s32> lagon;
|
||||
BitField<17, 1, s32> lager;
|
||||
BitField<31, 1, s32> system;
|
||||
};
|
||||
};
|
||||
|
||||
// This is nn::hid::detail::NfcXcdDeviceHandleStateImpl
|
||||
struct NfcXcdDeviceHandleStateImpl {
|
||||
u64 handle{};
|
||||
bool is_available{};
|
||||
bool is_activated{};
|
||||
INSERT_PADDING_BYTES(0x6); // Reserved
|
||||
u64 sampling_number{};
|
||||
};
|
||||
static_assert(sizeof(NfcXcdDeviceHandleStateImpl) == 0x18,
|
||||
"NfcXcdDeviceHandleStateImpl is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadLarkType
|
||||
enum class NpadLarkType : u32 {
|
||||
Invalid,
|
||||
H1,
|
||||
H2,
|
||||
NL,
|
||||
NR,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLuciaType
|
||||
enum class NpadLuciaType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLagonType
|
||||
enum class NpadLagonType : u32 {
|
||||
Invalid,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLagerType
|
||||
enum class NpadLagerType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
90
src/core/hle/service/hid/controllers/types/touch_types.h
Normal file
90
src/core/hle/service/hid/controllers/types/touch_types.h
Normal file
@ -0,0 +1,90 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <array>
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/point.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
static constexpr std::size_t MAX_FINGERS = 16;
|
||||
static constexpr size_t MAX_POINTS = 4;
|
||||
|
||||
// This is nn::hid::GestureType
|
||||
enum class GestureType : u32 {
|
||||
Idle, // Nothing touching the screen
|
||||
Complete, // Set at the end of a touch event
|
||||
Cancel, // Set when the number of fingers change
|
||||
Touch, // A finger just touched the screen
|
||||
Press, // Set if last type is touch and the finger hasn't moved
|
||||
Tap, // Fast press then release
|
||||
Pan, // All points moving together across the screen
|
||||
Swipe, // Fast press movement and release of a single point
|
||||
Pinch, // All points moving away/closer to the midpoint
|
||||
Rotate, // All points rotating from the midpoint
|
||||
};
|
||||
|
||||
// This is nn::hid::GestureDirection
|
||||
enum class GestureDirection : u32 {
|
||||
None,
|
||||
Left,
|
||||
Up,
|
||||
Right,
|
||||
Down,
|
||||
};
|
||||
|
||||
// This is nn::hid::GestureAttribute
|
||||
struct GestureAttribute {
|
||||
union {
|
||||
u32 raw{};
|
||||
|
||||
BitField<4, 1, u32> is_new_touch;
|
||||
BitField<8, 1, u32> is_double_tap;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(GestureAttribute) == 4, "GestureAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::GestureState
|
||||
struct GestureState {
|
||||
s64 sampling_number{};
|
||||
s64 detection_count{};
|
||||
GestureType type{GestureType::Idle};
|
||||
GestureDirection direction{GestureDirection::None};
|
||||
Common::Point<s32> pos{};
|
||||
Common::Point<s32> delta{};
|
||||
f32 vel_x{};
|
||||
f32 vel_y{};
|
||||
GestureAttribute attributes{};
|
||||
f32 scale{};
|
||||
f32 rotation_angle{};
|
||||
s32 point_count{};
|
||||
std::array<Common::Point<s32>, 4> points{};
|
||||
};
|
||||
static_assert(sizeof(GestureState) == 0x60, "GestureState is an invalid size");
|
||||
|
||||
struct GestureProperties {
|
||||
std::array<Common::Point<s32>, MAX_POINTS> points{};
|
||||
std::size_t active_points{};
|
||||
Common::Point<s32> mid_point{};
|
||||
s64 detection_count{};
|
||||
u64 delta_time{};
|
||||
f32 average_distance{};
|
||||
f32 angle{};
|
||||
};
|
||||
|
||||
// This is nn::hid::TouchScreenState
|
||||
struct TouchScreenState {
|
||||
s64 sampling_number{};
|
||||
s32 entry_count{};
|
||||
INSERT_PADDING_BYTES(4); // Reserved
|
||||
std::array<Core::HID::TouchState, MAX_FINGERS> states{};
|
||||
};
|
||||
static_assert(sizeof(TouchScreenState) == 0x290, "TouchScreenState is an invalid size");
|
||||
|
||||
} // namespace Service::HID
|
@ -1,39 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include "common/common_types.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hid/hid_core.h"
|
||||
#include "core/hle/service/hid/controllers/xpad.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00;
|
||||
|
||||
XPad::XPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase{hid_core_} {
|
||||
static_assert(SHARED_MEMORY_OFFSET + sizeof(XpadSharedMemory) < shared_memory_size,
|
||||
"XpadSharedMemory is bigger than the shared memory");
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<XpadSharedMemory*>(raw_shared_memory_ + SHARED_MEMORY_OFFSET));
|
||||
}
|
||||
XPad::~XPad() = default;
|
||||
|
||||
void XPad::OnInit() {}
|
||||
|
||||
void XPad::OnRelease() {}
|
||||
|
||||
void XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory->basic_xpad_lifo.buffer_count = 0;
|
||||
shared_memory->basic_xpad_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& last_entry = shared_memory->basic_xpad_lifo.ReadCurrentEntry().state;
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
// TODO(ogniK): Update xpad states
|
||||
|
||||
shared_memory->basic_xpad_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
@ -1,112 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#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"
|
||||
|
||||
namespace Service::HID {
|
||||
class XPad final : public ControllerBase {
|
||||
public:
|
||||
explicit XPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
|
||||
~XPad() 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;
|
||||
|
||||
private:
|
||||
// This is nn::hid::BasicXpadAttributeSet
|
||||
struct BasicXpadAttributeSet {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, u32> is_connected;
|
||||
BitField<1, 1, u32> is_wired;
|
||||
BitField<2, 1, u32> is_left_connected;
|
||||
BitField<3, 1, u32> is_left_wired;
|
||||
BitField<4, 1, u32> is_right_connected;
|
||||
BitField<5, 1, u32> is_right_wired;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(BasicXpadAttributeSet) == 4, "BasicXpadAttributeSet is an invalid size");
|
||||
|
||||
// This is nn::hid::BasicXpadButtonSet
|
||||
struct BasicXpadButtonSet {
|
||||
union {
|
||||
u32 raw{};
|
||||
// Button states
|
||||
BitField<0, 1, u32> a;
|
||||
BitField<1, 1, u32> b;
|
||||
BitField<2, 1, u32> x;
|
||||
BitField<3, 1, u32> y;
|
||||
BitField<4, 1, u32> l_stick;
|
||||
BitField<5, 1, u32> r_stick;
|
||||
BitField<6, 1, u32> l;
|
||||
BitField<7, 1, u32> r;
|
||||
BitField<8, 1, u32> zl;
|
||||
BitField<9, 1, u32> zr;
|
||||
BitField<10, 1, u32> plus;
|
||||
BitField<11, 1, u32> minus;
|
||||
|
||||
// D-Pad
|
||||
BitField<12, 1, u32> d_left;
|
||||
BitField<13, 1, u32> d_up;
|
||||
BitField<14, 1, u32> d_right;
|
||||
BitField<15, 1, u32> d_down;
|
||||
|
||||
// Left JoyStick
|
||||
BitField<16, 1, u32> l_stick_left;
|
||||
BitField<17, 1, u32> l_stick_up;
|
||||
BitField<18, 1, u32> l_stick_right;
|
||||
BitField<19, 1, u32> l_stick_down;
|
||||
|
||||
// Right JoyStick
|
||||
BitField<20, 1, u32> r_stick_left;
|
||||
BitField<21, 1, u32> r_stick_up;
|
||||
BitField<22, 1, u32> r_stick_right;
|
||||
BitField<23, 1, u32> r_stick_down;
|
||||
|
||||
// Not always active?
|
||||
BitField<24, 1, u32> left_sl;
|
||||
BitField<25, 1, u32> left_sr;
|
||||
|
||||
BitField<26, 1, u32> right_sl;
|
||||
BitField<27, 1, u32> right_sr;
|
||||
|
||||
BitField<28, 1, u32> palma;
|
||||
BitField<30, 1, u32> handheld_left_b;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(BasicXpadButtonSet) == 4, "BasicXpadButtonSet is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::BasicXpadState
|
||||
struct BasicXpadState {
|
||||
s64 sampling_number{};
|
||||
BasicXpadAttributeSet attributes{};
|
||||
BasicXpadButtonSet pad_states{};
|
||||
Core::HID::AnalogStickState l_stick{};
|
||||
Core::HID::AnalogStickState r_stick{};
|
||||
};
|
||||
static_assert(sizeof(BasicXpadState) == 0x20, "BasicXpadState is an invalid size");
|
||||
|
||||
struct XpadSharedMemory {
|
||||
// This is nn::hid::detail::BasicXpadLifo
|
||||
Lifo<BasicXpadState, hid_entry_count> basic_xpad_lifo{};
|
||||
static_assert(sizeof(basic_xpad_lifo) == 0x2C8, "basic_xpad_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x4E);
|
||||
};
|
||||
static_assert(sizeof(XpadSharedMemory) == 0x400, "XpadSharedMemory is an invalid size");
|
||||
|
||||
BasicXpadState next_state{};
|
||||
XpadSharedMemory* shared_memory = nullptr;
|
||||
};
|
||||
} // namespace Service::HID
|
@ -20,6 +20,9 @@ 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};
|
||||
|
@ -28,6 +28,7 @@
|
||||
#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"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
@ -50,7 +51,7 @@ private:
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()};
|
||||
|
||||
if (resource_manager != nullptr) {
|
||||
if (resource_manager != nullptr && resource_manager->GetNpad()) {
|
||||
resource_manager->GetNpad()->InitializeVibrationDevice(vibration_device_handle);
|
||||
}
|
||||
|
||||
@ -222,16 +223,14 @@ void IHidServer::CreateAppletResource(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
Result result = GetResourceManager()->CreateAppletResource(applet_resource_user_id);
|
||||
if (result.IsSuccess()) {
|
||||
result = GetResourceManager()->GetNpad()->Activate(applet_resource_user_id);
|
||||
}
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}",
|
||||
applet_resource_user_id, result.raw);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||
rb.Push(result);
|
||||
rb.PushIpcInterface<IAppletResource>(system, resource_manager);
|
||||
rb.PushIpcInterface<IAppletResource>(system, resource_manager, applet_resource_user_id);
|
||||
}
|
||||
|
||||
void IHidServer::ActivateDebugPad(HLERequestContext& ctx) {
|
||||
@ -1101,7 +1100,7 @@ void IHidServer::GetPlayerLedPattern(HLERequestContext& ctx) {
|
||||
void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
struct Parameters {
|
||||
NPad::NpadRevision revision;
|
||||
NpadRevision revision;
|
||||
INSERT_PADDING_WORDS_NOINIT(1);
|
||||
u64 applet_resource_user_id;
|
||||
};
|
||||
@ -1124,7 +1123,7 @@ void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) {
|
||||
void IHidServer::SetNpadJoyHoldType(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
const auto hold_type{rp.PopEnum<NPad::NpadJoyHoldType>()};
|
||||
const auto hold_type{rp.PopEnum<NpadJoyHoldType>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetHoldType(hold_type);
|
||||
|
||||
@ -1159,8 +1158,8 @@ void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx)
|
||||
|
||||
Core::HID::NpadIdType new_npad_id{};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
controller->SetNpadMode(new_npad_id, parameters.npad_id, NPad::NpadJoyDeviceType::Left,
|
||||
NPad::NpadJoyAssignmentMode::Single);
|
||||
controller->SetNpadMode(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);
|
||||
@ -1175,7 +1174,7 @@ void IHidServer::SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx) {
|
||||
Core::HID::NpadIdType npad_id;
|
||||
INSERT_PADDING_WORDS_NOINIT(1);
|
||||
u64 applet_resource_user_id;
|
||||
NPad::NpadJoyDeviceType npad_joy_device_type;
|
||||
NpadJoyDeviceType npad_joy_device_type;
|
||||
};
|
||||
static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
|
||||
|
||||
@ -1184,7 +1183,7 @@ 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,
|
||||
NPad::NpadJoyAssignmentMode::Single);
|
||||
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,
|
||||
@ -1207,7 +1206,7 @@ void IHidServer::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) {
|
||||
|
||||
Core::HID::NpadIdType new_npad_id{};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
controller->SetNpadMode(new_npad_id, parameters.npad_id, {}, NPad::NpadJoyAssignmentMode::Dual);
|
||||
controller->SetNpadMode(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
|
||||
@ -1259,7 +1258,7 @@ void IHidServer::StopLrAssignmentMode(HLERequestContext& ctx) {
|
||||
void IHidServer::SetNpadHandheldActivationMode(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
const auto activation_mode{rp.PopEnum<NPad::NpadHandheldActivationMode>()};
|
||||
const auto activation_mode{rp.PopEnum<NpadHandheldActivationMode>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetNpadHandheldActivationMode(activation_mode);
|
||||
|
||||
@ -1351,7 +1350,7 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext
|
||||
Core::HID::NpadIdType npad_id;
|
||||
INSERT_PADDING_WORDS_NOINIT(1);
|
||||
u64 applet_resource_user_id;
|
||||
NPad::NpadJoyDeviceType npad_joy_device_type;
|
||||
NpadJoyDeviceType npad_joy_device_type;
|
||||
};
|
||||
static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
|
||||
|
||||
@ -1361,7 +1360,7 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto is_reassigned =
|
||||
controller->SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type,
|
||||
NPad::NpadJoyAssignmentMode::Single);
|
||||
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,
|
||||
@ -2317,7 +2316,7 @@ void IHidServer::SetDisallowedPalmaConnection(HLERequestContext& ctx) {
|
||||
void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
const auto communication_mode{rp.PopEnum<NPad::NpadCommunicationMode>()};
|
||||
const auto communication_mode{rp.PopEnum<NpadCommunicationMode>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetNpadCommunicationMode(communication_mode);
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#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"
|
||||
@ -328,7 +329,7 @@ void IHidSystemServer::GetAppletDetailedUiType(HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
|
||||
const NPad::AppletDetailedUiType detailed_ui_type =
|
||||
const AppletDetailedUiType detailed_ui_type =
|
||||
GetResourceManager()->GetNpad()->GetAppletDetailedUiType(npad_id_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
|
@ -18,10 +18,10 @@
|
||||
#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/shared_memory_format.h"
|
||||
#include "core/hle/service/hid/controllers/six_axis.h"
|
||||
#include "core/hle/service/hid/controllers/stubbed.h"
|
||||
#include "core/hle/service/hid/controllers/touchscreen.h"
|
||||
#include "core/hle/service/hid/controllers/xpad.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
@ -45,40 +45,43 @@ void ResourceManager::Initialize() {
|
||||
return;
|
||||
}
|
||||
|
||||
u8* shared_memory = system.Kernel().GetHidSharedMem().GetPointer();
|
||||
debug_pad = std::make_shared<DebugPad>(system.HIDCore(), shared_memory);
|
||||
mouse = std::make_shared<Mouse>(system.HIDCore(), shared_memory);
|
||||
debug_mouse = std::make_shared<DebugMouse>(system.HIDCore(), shared_memory);
|
||||
keyboard = std::make_shared<Keyboard>(system.HIDCore(), shared_memory);
|
||||
unique_pad = std::make_shared<UniquePad>(system.HIDCore(), shared_memory);
|
||||
npad = std::make_shared<NPad>(system.HIDCore(), shared_memory, service_context);
|
||||
gesture = std::make_shared<Gesture>(system.HIDCore(), shared_memory);
|
||||
touch_screen = std::make_shared<TouchScreen>(system.HIDCore(), shared_memory);
|
||||
xpad = std::make_shared<XPad>(system.HIDCore(), shared_memory);
|
||||
system.HIDCore().ReloadInputDevices();
|
||||
is_initialized = true;
|
||||
}
|
||||
|
||||
palma = std::make_shared<Palma>(system.HIDCore(), shared_memory, service_context);
|
||||
void ResourceManager::InitializeController(u64 aruid) {
|
||||
SharedMemoryFormat* shared_memory = nullptr;
|
||||
const auto result = applet_resource->GetSharedMemoryFormat(&shared_memory, aruid);
|
||||
if (result.IsError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
home_button = std::make_shared<HomeButton>(system.HIDCore(), shared_memory);
|
||||
sleep_button = std::make_shared<SleepButton>(system.HIDCore(), shared_memory);
|
||||
capture_button = std::make_shared<CaptureButton>(system.HIDCore(), shared_memory);
|
||||
debug_pad = std::make_shared<DebugPad>(system.HIDCore(), shared_memory->debug_pad);
|
||||
mouse = std::make_shared<Mouse>(system.HIDCore(), shared_memory->mouse);
|
||||
debug_mouse = std::make_shared<DebugMouse>(system.HIDCore(), shared_memory->debug_mouse);
|
||||
keyboard = std::make_shared<Keyboard>(system.HIDCore(), shared_memory->keyboard);
|
||||
unique_pad = std::make_shared<UniquePad>(system.HIDCore(), shared_memory->unique_pad.header);
|
||||
npad = std::make_shared<NPad>(system.HIDCore(), shared_memory->npad, service_context);
|
||||
gesture = std::make_shared<Gesture>(system.HIDCore(), shared_memory->gesture);
|
||||
touch_screen = std::make_shared<TouchScreen>(system.HIDCore(), shared_memory->touch_screen);
|
||||
|
||||
palma = std::make_shared<Palma>(system.HIDCore(), service_context);
|
||||
|
||||
home_button = std::make_shared<HomeButton>(system.HIDCore(), shared_memory->home_button.header);
|
||||
sleep_button =
|
||||
std::make_shared<SleepButton>(system.HIDCore(), shared_memory->sleep_button.header);
|
||||
capture_button =
|
||||
std::make_shared<CaptureButton>(system.HIDCore(), shared_memory->capture_button.header);
|
||||
digitizer = std::make_shared<Digitizer>(system.HIDCore(), shared_memory->digitizer.header);
|
||||
|
||||
six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad);
|
||||
console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore(), shared_memory);
|
||||
console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore(), shared_memory->console);
|
||||
seven_six_axis = std::make_shared<SevenSixAxis>(system);
|
||||
|
||||
home_button->SetCommonHeaderOffset(0x4C00);
|
||||
sleep_button->SetCommonHeaderOffset(0x4E00);
|
||||
capture_button->SetCommonHeaderOffset(0x5000);
|
||||
unique_pad->SetCommonHeaderOffset(0x5A00);
|
||||
debug_mouse->SetCommonHeaderOffset(0x3DC00);
|
||||
|
||||
// Homebrew doesn't try to activate some controllers, so we activate them by default
|
||||
npad->Activate();
|
||||
six_axis->Activate();
|
||||
touch_screen->Activate();
|
||||
|
||||
system.HIDCore().ReloadInputDevices();
|
||||
is_initialized = true;
|
||||
}
|
||||
|
||||
std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const {
|
||||
@ -101,6 +104,10 @@ std::shared_ptr<DebugPad> ResourceManager::GetDebugPad() const {
|
||||
return debug_pad;
|
||||
}
|
||||
|
||||
std::shared_ptr<Digitizer> ResourceManager::GetDigitizer() const {
|
||||
return digitizer;
|
||||
}
|
||||
|
||||
std::shared_ptr<Gesture> ResourceManager::GetGesture() const {
|
||||
return gesture;
|
||||
}
|
||||
@ -146,8 +153,38 @@ std::shared_ptr<UniquePad> ResourceManager::GetUniquePad() const {
|
||||
}
|
||||
|
||||
Result ResourceManager::CreateAppletResource(u64 aruid) {
|
||||
if (aruid == 0) {
|
||||
const auto result = RegisterCoreAppletResource();
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
return GetNpad()->Activate();
|
||||
}
|
||||
|
||||
const auto result = CreateAppletResourceImpl(aruid);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
return GetNpad()->Activate(aruid);
|
||||
}
|
||||
|
||||
Result ResourceManager::CreateAppletResourceImpl(u64 aruid) {
|
||||
std::scoped_lock lock{shared_mutex};
|
||||
return applet_resource->CreateAppletResource(aruid);
|
||||
const auto result = applet_resource->CreateAppletResource(aruid);
|
||||
if (result.IsSuccess()) {
|
||||
InitializeController(aruid);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Result ResourceManager::RegisterCoreAppletResource() {
|
||||
std::scoped_lock lock{shared_mutex};
|
||||
return applet_resource->RegisterCoreAppletResource();
|
||||
}
|
||||
|
||||
Result ResourceManager::UnregisterCoreAppletResource() {
|
||||
std::scoped_lock lock{shared_mutex};
|
||||
return applet_resource->UnregisterCoreAppletResource();
|
||||
}
|
||||
|
||||
Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) {
|
||||
@ -165,6 +202,11 @@ Result ResourceManager::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle
|
||||
return applet_resource->GetSharedMemoryHandle(out_handle, aruid);
|
||||
}
|
||||
|
||||
void ResourceManager::FreeAppletResourceId(u64 aruid) {
|
||||
std::scoped_lock lock{shared_mutex};
|
||||
applet_resource->FreeAppletResourceId(aruid);
|
||||
}
|
||||
|
||||
void ResourceManager::EnableInput(u64 aruid, bool is_enabled) {
|
||||
std::scoped_lock lock{shared_mutex};
|
||||
applet_resource->EnableInput(aruid, is_enabled);
|
||||
@ -189,6 +231,7 @@ void ResourceManager::UpdateControllers(std::uintptr_t user_data,
|
||||
std::chrono::nanoseconds ns_late) {
|
||||
auto& core_timing = system.CoreTiming();
|
||||
debug_pad->OnUpdate(core_timing);
|
||||
digitizer->OnUpdate(core_timing);
|
||||
unique_pad->OnUpdate(core_timing);
|
||||
gesture->OnUpdate(core_timing);
|
||||
touch_screen->OnUpdate(core_timing);
|
||||
@ -196,7 +239,6 @@ void ResourceManager::UpdateControllers(std::uintptr_t user_data,
|
||||
home_button->OnUpdate(core_timing);
|
||||
sleep_button->OnUpdate(core_timing);
|
||||
capture_button->OnUpdate(core_timing);
|
||||
xpad->OnUpdate(core_timing);
|
||||
}
|
||||
|
||||
void ResourceManager::UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
|
||||
@ -219,8 +261,10 @@ void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose
|
||||
console_six_axis->OnUpdate(core_timing);
|
||||
}
|
||||
|
||||
IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource)
|
||||
: ServiceFramework{system_, "IAppletResource"}, resource_manager{resource} {
|
||||
IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
|
||||
u64 applet_resource_user_id)
|
||||
: ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id},
|
||||
resource_manager{resource} {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
||||
};
|
||||
@ -274,14 +318,14 @@ IAppletResource::~IAppletResource() {
|
||||
system.CoreTiming().UnscheduleEvent(default_update_event, 0);
|
||||
system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event, 0);
|
||||
system.CoreTiming().UnscheduleEvent(motion_update_event, 0);
|
||||
resource_manager->FreeAppletResourceId(aruid);
|
||||
}
|
||||
|
||||
void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_HID, "called");
|
||||
|
||||
Kernel::KSharedMemory* handle;
|
||||
const u64 applet_resource_user_id = resource_manager->GetAppletResource()->GetActiveAruid();
|
||||
const auto result = resource_manager->GetSharedMemoryHandle(&handle, applet_resource_user_id);
|
||||
const auto result = resource_manager->GetSharedMemoryHandle(&handle, aruid);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||
rb.Push(result);
|
||||
|
@ -31,10 +31,10 @@ class Palma;
|
||||
class SevenSixAxis;
|
||||
class SixAxis;
|
||||
class TouchScreen;
|
||||
class XPad;
|
||||
|
||||
using CaptureButton = Controller_Stubbed;
|
||||
using DebugMouse = Controller_Stubbed;
|
||||
using DebugMouse = Mouse;
|
||||
using Digitizer = Controller_Stubbed;
|
||||
using HomeButton = Controller_Stubbed;
|
||||
using SleepButton = Controller_Stubbed;
|
||||
using UniquePad = Controller_Stubbed;
|
||||
@ -46,12 +46,14 @@ public:
|
||||
~ResourceManager();
|
||||
|
||||
void Initialize();
|
||||
void InitializeController(u64 aruid);
|
||||
|
||||
std::shared_ptr<AppletResource> GetAppletResource() const;
|
||||
std::shared_ptr<CaptureButton> GetCaptureButton() const;
|
||||
std::shared_ptr<ConsoleSixAxis> GetConsoleSixAxis() const;
|
||||
std::shared_ptr<DebugMouse> GetDebugMouse() const;
|
||||
std::shared_ptr<DebugPad> GetDebugPad() const;
|
||||
std::shared_ptr<Digitizer> GetDigitizer() const;
|
||||
std::shared_ptr<Gesture> GetGesture() const;
|
||||
std::shared_ptr<HomeButton> GetHomeButton() const;
|
||||
std::shared_ptr<Keyboard> GetKeyboard() const;
|
||||
@ -66,10 +68,13 @@ public:
|
||||
|
||||
Result CreateAppletResource(u64 aruid);
|
||||
|
||||
Result RegisterCoreAppletResource();
|
||||
Result UnregisterCoreAppletResource();
|
||||
Result RegisterAppletResourceUserId(u64 aruid, bool bool_value);
|
||||
void UnregisterAppletResourceUserId(u64 aruid);
|
||||
|
||||
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
|
||||
void FreeAppletResourceId(u64 aruid);
|
||||
|
||||
void EnableInput(u64 aruid, bool is_enabled);
|
||||
void EnableSixAxisSensor(u64 aruid, bool is_enabled);
|
||||
@ -82,6 +87,8 @@ public:
|
||||
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||
|
||||
private:
|
||||
Result CreateAppletResourceImpl(u64 aruid);
|
||||
|
||||
bool is_initialized{false};
|
||||
|
||||
mutable std::mutex shared_mutex;
|
||||
@ -91,6 +98,7 @@ private:
|
||||
std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
|
||||
std::shared_ptr<DebugMouse> debug_mouse = nullptr;
|
||||
std::shared_ptr<DebugPad> debug_pad = nullptr;
|
||||
std::shared_ptr<Digitizer> digitizer = nullptr;
|
||||
std::shared_ptr<Gesture> gesture = nullptr;
|
||||
std::shared_ptr<HomeButton> home_button = nullptr;
|
||||
std::shared_ptr<Keyboard> keyboard = nullptr;
|
||||
@ -102,7 +110,6 @@ private:
|
||||
std::shared_ptr<SleepButton> sleep_button = nullptr;
|
||||
std::shared_ptr<TouchScreen> touch_screen = nullptr;
|
||||
std::shared_ptr<UniquePad> unique_pad = nullptr;
|
||||
std::shared_ptr<XPad> xpad = nullptr;
|
||||
|
||||
// TODO: Create these resources
|
||||
// std::shared_ptr<AudioControl> audio_control = nullptr;
|
||||
@ -121,7 +128,8 @@ private:
|
||||
|
||||
class IAppletResource final : public ServiceFramework<IAppletResource> {
|
||||
public:
|
||||
explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource);
|
||||
explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
|
||||
u64 applet_resource_user_id);
|
||||
~IAppletResource() override;
|
||||
|
||||
private:
|
||||
@ -132,6 +140,7 @@ private:
|
||||
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
|
||||
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
||||
|
||||
u64 aruid;
|
||||
std::shared_ptr<ResourceManager> resource_manager;
|
||||
};
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user