Compare commits
3 Commits
android-18
...
android-18
Author | SHA1 | Date | |
---|---|---|---|
4634c092d1 | |||
8b27dd4442 | |||
797970093f |
@ -3,32 +3,38 @@
|
|||||||
# SPDX-FileCopyrightText: 2019 yuzu Emulator Project
|
# SPDX-FileCopyrightText: 2019 yuzu Emulator Project
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
shopt -s nullglob globstar
|
if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop \
|
||||||
|
dist/*.svg dist/*.xml; then
|
||||||
if git grep -nrI '\s$' src **/*.yml **/*.txt **/*.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop dist/*.svg dist/*.xml; then
|
|
||||||
echo Trailing whitespace found, aborting
|
echo Trailing whitespace found, aborting
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Default clang-format points to default 3.5 version one
|
# Default clang-format points to default 3.5 version one
|
||||||
CLANG_FORMAT="${CLANG_FORMAT:-clang-format-15}"
|
CLANG_FORMAT=${CLANG_FORMAT:-clang-format-15}
|
||||||
"$CLANG_FORMAT" --version
|
$CLANG_FORMAT --version
|
||||||
|
|
||||||
|
if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
|
||||||
|
# Get list of every file modified in this pull request
|
||||||
|
files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' || true)"
|
||||||
|
else
|
||||||
|
# Check everything for branch pushes
|
||||||
|
files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
|
||||||
|
fi
|
||||||
|
|
||||||
# Turn off tracing for this because it's too verbose
|
# Turn off tracing for this because it's too verbose
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
# Check everything for branch pushes
|
for f in $files_to_lint; do
|
||||||
FILES_TO_LINT="$(find src/ -name '*.cpp' -or -name '*.h')"
|
d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true)
|
||||||
|
if ! [ -z "$d" ]; then
|
||||||
for f in $FILES_TO_LINT; do
|
echo "!!! $f not compliant to coding style, here is the fix:"
|
||||||
echo "$f"
|
echo "$d"
|
||||||
"$CLANG_FORMAT" -i "$f"
|
fail=1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
DIFF=$(git diff)
|
set -x
|
||||||
|
|
||||||
if [ ! -z "$DIFF" ]; then
|
if [ "$fail" = 1 ]; then
|
||||||
echo "!!! Not compliant to coding style, here is the fix:"
|
|
||||||
echo "$DIFF"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -9,7 +9,7 @@ chmod a+x ./.ci/scripts/linux/docker.sh
|
|||||||
sudo chown -R 1027 ./
|
sudo chown -R 1027 ./
|
||||||
|
|
||||||
# The environment variables listed below:
|
# The environment variables listed below:
|
||||||
# AZURECIREPO TITLEBARFORMATIDLE TITLEBARFORMATRUNNING DISPLAYVERSION
|
# AZURECIREPO TITLEBARFORMATIDLE TITLEBARFORMATRUNNING DISPLAYVERSION
|
||||||
# are requested in src/common/CMakeLists.txt and appear to be provided somewhere in Azure DevOps
|
# are requested in src/common/CMakeLists.txt and appear to be provided somewhere in Azure DevOps
|
||||||
|
|
||||||
docker run -e AZURECIREPO -e TITLEBARFORMATIDLE -e TITLEBARFORMATRUNNING -e DISPLAYVERSION -e ENABLE_COMPATIBILITY_REPORTING -e CCACHE_DIR=/yuzu/ccache -v "$(pwd):/yuzu" -w /yuzu yuzuemu/build-environments:linux-fresh /bin/bash /yuzu/.ci/scripts/linux/docker.sh "$1"
|
docker run -e AZURECIREPO -e TITLEBARFORMATIDLE -e TITLEBARFORMATRUNNING -e DISPLAYVERSION -e ENABLE_COMPATIBILITY_REPORTING -e CCACHE_DIR=/yuzu/ccache -v "$(pwd):/yuzu" -w /yuzu yuzuemu/build-environments:linux-fresh /bin/bash /yuzu/.ci/scripts/linux/docker.sh "$1"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>
|
Copyright (c) <year> <owner>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>.
|
Copyright (c) <year> <owner>.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ Mozilla Public License Version 2.0
|
|||||||
means any form of the work other than Source Code Form.
|
means any form of the work other than Source Code Form.
|
||||||
|
|
||||||
1.7. "Larger Work"
|
1.7. "Larger Work"
|
||||||
means a work that combines Covered Software with other material, in
|
means a work that combines Covered Software with other material, in
|
||||||
a separate file or files, that is not Covered Software.
|
a separate file or files, that is not Covered Software.
|
||||||
|
|
||||||
1.8. "License"
|
1.8. "License"
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
| Pull Request | Commit | Title | Author | Merged? |
|
| Pull Request | Commit | Title | Author | Merged? |
|
||||||
|----|----|----|----|----|
|
|----|----|----|----|----|
|
||||||
| [12579](https://github.com/yuzu-emu/yuzu-android//pull/12579) | [`66ae60a9e`](https://github.com/yuzu-emu/yuzu-android//pull/12579/files) | Core: Implement Device Mapping & GPU SMMU | [FernandoS27](https://github.com/FernandoS27/) | Yes |
|
| [12560](https://github.com/yuzu-emu/yuzu-android//pull/12560) | [`e5de3d5a7`](https://github.com/yuzu-emu/yuzu-android//pull/12560/files) | android: add basic support for google game dashboard | [GayPotatoEmma](https://github.com/GayPotatoEmma/) | Yes |
|
||||||
| [12610](https://github.com/yuzu-emu/yuzu-android//pull/12610) | [`200b371d1`](https://github.com/yuzu-emu/yuzu-android//pull/12610/files) | server_manager: respond to session close correctly | [liamwhite](https://github.com/liamwhite/) | Yes |
|
| [12576](https://github.com/yuzu-emu/yuzu-android//pull/12576) | [`53d4dbacf`](https://github.com/yuzu-emu/yuzu-android//pull/12576/files) | android: Re-add global save manager | [t895](https://github.com/t895/) | Yes |
|
||||||
| [12611](https://github.com/yuzu-emu/yuzu-android//pull/12611) | [`642a29923`](https://github.com/yuzu-emu/yuzu-android//pull/12611/files) | kernel: fix resource management issues | [liamwhite](https://github.com/liamwhite/) | Yes |
|
|
||||||
| [12612](https://github.com/yuzu-emu/yuzu-android//pull/12612) | [`417df3b6e`](https://github.com/yuzu-emu/yuzu-android//pull/12612/files) | fsp-srv: use program registry for SetCurrentProcess | [liamwhite](https://github.com/liamwhite/) | Yes |
|
|
||||||
| [12642](https://github.com/yuzu-emu/yuzu-android//pull/12642) | [`4037afea1`](https://github.com/yuzu-emu/yuzu-android//pull/12642/files) | android: Refactor list adapters | [t895](https://github.com/t895/) | Yes |
|
|
||||||
|
|
||||||
|
|
||||||
End of merge log. You can find the original README.md below the break.
|
End of merge log. You can find the original README.md below the break.
|
||||||
|
2
externals/ffmpeg/CMakeLists.txt
vendored
2
externals/ffmpeg/CMakeLists.txt
vendored
@ -138,7 +138,7 @@ if (NOT WIN32 AND NOT ANDROID)
|
|||||||
--cross-prefix=${TOOLCHAIN}/bin/aarch64-linux-android-
|
--cross-prefix=${TOOLCHAIN}/bin/aarch64-linux-android-
|
||||||
--sysroot=${SYSROOT}
|
--sysroot=${SYSROOT}
|
||||||
--target-os=android
|
--target-os=android
|
||||||
--extra-ldflags="--ld-path=${TOOLCHAIN}/bin/ld.lld"
|
--extra-ldflags="--ld-path=${TOOLCHAIN}/bin/ld.lld"
|
||||||
--extra-ldflags="-nostdlib"
|
--extra-ldflags="-nostdlib"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
2
externals/nx_tzdb/tzdb_to_nx
vendored
2
externals/nx_tzdb/tzdb_to_nx
vendored
Submodule externals/nx_tzdb/tzdb_to_nx updated: 404d390045...f6680093bc
@ -185,7 +185,6 @@ add_subdirectory(common)
|
|||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(audio_core)
|
add_subdirectory(audio_core)
|
||||||
add_subdirectory(video_core)
|
add_subdirectory(video_core)
|
||||||
add_subdirectory(hid_core)
|
|
||||||
add_subdirectory(network)
|
add_subdirectory(network)
|
||||||
add_subdirectory(input_common)
|
add_subdirectory(input_common)
|
||||||
add_subdirectory(frontend_common)
|
add_subdirectory(frontend_common)
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.yuzu.yuzu_emu.adapters
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic adapter that implements an [AsyncDifferConfig] and covers some of the basic boilerplate
|
|
||||||
* code used in every [RecyclerView].
|
|
||||||
* Type assigned to [Model] must inherit from [Object] in order to be compared properly.
|
|
||||||
*/
|
|
||||||
abstract class AbstractDiffAdapter<Model : Any, Holder : AbstractViewHolder<Model>> :
|
|
||||||
ListAdapter<Model, Holder>(AsyncDifferConfig.Builder(DiffCallback<Model>()).build()) {
|
|
||||||
override fun onBindViewHolder(holder: Holder, position: Int) =
|
|
||||||
holder.bind(currentList[position])
|
|
||||||
|
|
||||||
private class DiffCallback<Model> : DiffUtil.ItemCallback<Model>() {
|
|
||||||
override fun areItemsTheSame(oldItem: Model & Any, newItem: Model & Any): Boolean {
|
|
||||||
return oldItem === newItem
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("DiffUtilEquals")
|
|
||||||
override fun areContentsTheSame(oldItem: Model & Any, newItem: Model & Any): Boolean {
|
|
||||||
return oldItem == newItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.yuzu.yuzu_emu.adapters
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic list class meant to take care of basic lists
|
|
||||||
* @param currentList The list to show initially
|
|
||||||
*/
|
|
||||||
abstract class AbstractListAdapter<Model : Any, Holder : AbstractViewHolder<Model>>(
|
|
||||||
open var currentList: List<Model>
|
|
||||||
) : RecyclerView.Adapter<Holder>() {
|
|
||||||
override fun onBindViewHolder(holder: Holder, position: Int) =
|
|
||||||
holder.bind(currentList[position])
|
|
||||||
|
|
||||||
override fun getItemCount(): Int = currentList.size
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an item to [currentList] and notifies the underlying adapter of the change. If no parameter
|
|
||||||
* is passed in for position, [item] is added to the end of the list. Invokes [callback] last.
|
|
||||||
* @param item The item to add to the list
|
|
||||||
* @param position Index where [item] will be added
|
|
||||||
* @param callback Lambda that's called at the end of the list changes and has the added list
|
|
||||||
* position passed in as a parameter
|
|
||||||
*/
|
|
||||||
open fun addItem(item: Model, position: Int = -1, callback: ((position: Int) -> Unit)? = null) {
|
|
||||||
val newList = currentList.toMutableList()
|
|
||||||
val positionToUpdate: Int
|
|
||||||
if (position == -1) {
|
|
||||||
newList.add(item)
|
|
||||||
currentList = newList
|
|
||||||
positionToUpdate = currentList.size - 1
|
|
||||||
} else {
|
|
||||||
newList.add(position, item)
|
|
||||||
currentList = newList
|
|
||||||
positionToUpdate = position
|
|
||||||
}
|
|
||||||
onItemAdded(positionToUpdate, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun onItemAdded(position: Int, callback: ((Int) -> Unit)? = null) {
|
|
||||||
notifyItemInserted(position)
|
|
||||||
callback?.invoke(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the [item] at [position] in the [currentList] and notifies the underlying adapter
|
|
||||||
* of the change. Invokes [callback] last.
|
|
||||||
* @param item New list item
|
|
||||||
* @param position Index where [item] will replace the existing list item
|
|
||||||
* @param callback Lambda that's called at the end of the list changes and has the changed list
|
|
||||||
* position passed in as a parameter
|
|
||||||
*/
|
|
||||||
fun changeItem(item: Model, position: Int, callback: ((position: Int) -> Unit)? = null) {
|
|
||||||
val newList = currentList.toMutableList()
|
|
||||||
newList[position] = item
|
|
||||||
currentList = newList
|
|
||||||
onItemChanged(position, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun onItemChanged(position: Int, callback: ((Int) -> Unit)? = null) {
|
|
||||||
notifyItemChanged(position)
|
|
||||||
callback?.invoke(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the list item at [position] in [currentList] and notifies the underlying adapter
|
|
||||||
* of the change. Invokes [callback] last.
|
|
||||||
* @param position Index where the list item will be removed
|
|
||||||
* @param callback Lambda that's called at the end of the list changes and has the removed list
|
|
||||||
* position passed in as a parameter
|
|
||||||
*/
|
|
||||||
fun removeItem(position: Int, callback: ((position: Int) -> Unit)? = null) {
|
|
||||||
val newList = currentList.toMutableList()
|
|
||||||
newList.removeAt(position)
|
|
||||||
currentList = newList
|
|
||||||
onItemRemoved(position, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun onItemRemoved(position: Int, callback: ((Int) -> Unit)? = null) {
|
|
||||||
notifyItemRemoved(position)
|
|
||||||
callback?.invoke(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces [currentList] with [newList] and notifies the underlying adapter of the change.
|
|
||||||
* @param newList The new list to replace [currentList]
|
|
||||||
*/
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
|
||||||
open fun replaceList(newList: List<Model>) {
|
|
||||||
currentList = newList
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.yuzu.yuzu_emu.adapters
|
|
||||||
|
|
||||||
import org.yuzu.yuzu_emu.model.SelectableItem
|
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic list class meant to take care of single selection UI updates
|
|
||||||
* @param currentList The list to show initially
|
|
||||||
* @param defaultSelection The default selection to use if no list items are selected by
|
|
||||||
* [SelectableItem.selected] or if the currently selected item is removed from the list
|
|
||||||
*/
|
|
||||||
abstract class AbstractSingleSelectionList<
|
|
||||||
Model : SelectableItem,
|
|
||||||
Holder : AbstractViewHolder<Model>
|
|
||||||
>(
|
|
||||||
final override var currentList: List<Model>,
|
|
||||||
private val defaultSelection: DefaultSelection = DefaultSelection.Start
|
|
||||||
) : AbstractListAdapter<Model, Holder>(currentList) {
|
|
||||||
var selectedItem = getDefaultSelection()
|
|
||||||
|
|
||||||
init {
|
|
||||||
findSelectedItem()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the selection state of the [SelectableItem] that was selected and the previously selected
|
|
||||||
* item and notifies the underlying adapter of the change for those items. Invokes [callback] last.
|
|
||||||
* Does nothing if [position] is the same as the currently selected item.
|
|
||||||
* @param position Index of the item that was selected
|
|
||||||
* @param callback Lambda that's called at the end of the list changes and has the selected list
|
|
||||||
* position passed in as a parameter
|
|
||||||
*/
|
|
||||||
fun selectItem(position: Int, callback: ((position: Int) -> Unit)? = null) {
|
|
||||||
if (position == selectedItem) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val previouslySelectedItem = selectedItem
|
|
||||||
selectedItem = position
|
|
||||||
if (currentList.indices.contains(selectedItem)) {
|
|
||||||
currentList[selectedItem].onSelectionStateChanged(true)
|
|
||||||
}
|
|
||||||
if (currentList.indices.contains(previouslySelectedItem)) {
|
|
||||||
currentList[previouslySelectedItem].onSelectionStateChanged(false)
|
|
||||||
}
|
|
||||||
onItemChanged(previouslySelectedItem)
|
|
||||||
onItemChanged(selectedItem)
|
|
||||||
callback?.invoke(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a given item from the list and notifies the underlying adapter of the change. If the
|
|
||||||
* currently selected item was the item that was removed, the item at the position provided
|
|
||||||
* by [defaultSelection] will be made the new selection. Invokes [callback] last.
|
|
||||||
* @param position Index of the item that was removed
|
|
||||||
* @param callback Lambda that's called at the end of the list changes and has the removed and
|
|
||||||
* selected list positions passed in as parameters
|
|
||||||
*/
|
|
||||||
fun removeSelectableItem(
|
|
||||||
position: Int,
|
|
||||||
callback: ((removedPosition: Int, selectedPosition: Int) -> Unit)?
|
|
||||||
) {
|
|
||||||
removeItem(position)
|
|
||||||
if (position == selectedItem) {
|
|
||||||
selectedItem = getDefaultSelection()
|
|
||||||
currentList[selectedItem].onSelectionStateChanged(true)
|
|
||||||
onItemChanged(selectedItem)
|
|
||||||
} else if (position < selectedItem) {
|
|
||||||
selectedItem--
|
|
||||||
}
|
|
||||||
callback?.invoke(position, selectedItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun addItem(item: Model, position: Int, callback: ((Int) -> Unit)?) {
|
|
||||||
super.addItem(item, position, callback)
|
|
||||||
if (position <= selectedItem && position != -1) {
|
|
||||||
selectedItem++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun replaceList(newList: List<Model>) {
|
|
||||||
super.replaceList(newList)
|
|
||||||
findSelectedItem()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findSelectedItem() {
|
|
||||||
for (i in currentList.indices) {
|
|
||||||
if (currentList[i].selected) {
|
|
||||||
selectedItem = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDefaultSelection(): Int =
|
|
||||||
when (defaultSelection) {
|
|
||||||
DefaultSelection.Start -> currentList.indices.first
|
|
||||||
DefaultSelection.End -> currentList.indices.last
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class DefaultSelection { Start, End }
|
|
||||||
}
|
|
@ -5,28 +5,48 @@ package org.yuzu.yuzu_emu.adapters
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.yuzu.yuzu_emu.databinding.ListItemAddonBinding
|
import org.yuzu.yuzu_emu.databinding.ListItemAddonBinding
|
||||||
import org.yuzu.yuzu_emu.model.Addon
|
import org.yuzu.yuzu_emu.model.Addon
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class AddonAdapter : AbstractDiffAdapter<Addon, AddonAdapter.AddonViewHolder>() {
|
class AddonAdapter : ListAdapter<Addon, AddonAdapter.AddonViewHolder>(
|
||||||
|
AsyncDifferConfig.Builder(DiffCallback()).build()
|
||||||
|
) {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AddonViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AddonViewHolder {
|
||||||
ListItemAddonBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
ListItemAddonBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
.also { return AddonViewHolder(it) }
|
.also { return AddonViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = currentList.size
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: AddonViewHolder, position: Int) =
|
||||||
|
holder.bind(currentList[position])
|
||||||
|
|
||||||
inner class AddonViewHolder(val binding: ListItemAddonBinding) :
|
inner class AddonViewHolder(val binding: ListItemAddonBinding) :
|
||||||
AbstractViewHolder<Addon>(binding) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
override fun bind(model: Addon) {
|
fun bind(addon: Addon) {
|
||||||
binding.root.setOnClickListener {
|
binding.root.setOnClickListener {
|
||||||
binding.addonSwitch.isChecked = !binding.addonSwitch.isChecked
|
binding.addonSwitch.isChecked = !binding.addonSwitch.isChecked
|
||||||
}
|
}
|
||||||
binding.title.text = model.title
|
binding.title.text = addon.title
|
||||||
binding.version.text = model.version
|
binding.version.text = addon.version
|
||||||
binding.addonSwitch.setOnCheckedChangeListener { _, checked ->
|
binding.addonSwitch.setOnCheckedChangeListener { _, checked ->
|
||||||
model.enabled = checked
|
addon.enabled = checked
|
||||||
}
|
}
|
||||||
binding.addonSwitch.isChecked = model.enabled
|
binding.addonSwitch.isChecked = addon.enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DiffCallback : DiffUtil.ItemCallback<Addon>() {
|
||||||
|
override fun areItemsTheSame(oldItem: Addon, newItem: Addon): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: Addon, newItem: Addon): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
package org.yuzu.yuzu_emu.adapters
|
package org.yuzu.yuzu_emu.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
||||||
import org.yuzu.yuzu_emu.NativeLibrary
|
import org.yuzu.yuzu_emu.NativeLibrary
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
@ -17,58 +19,72 @@ import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding
|
|||||||
import org.yuzu.yuzu_emu.model.Applet
|
import org.yuzu.yuzu_emu.model.Applet
|
||||||
import org.yuzu.yuzu_emu.model.AppletInfo
|
import org.yuzu.yuzu_emu.model.AppletInfo
|
||||||
import org.yuzu.yuzu_emu.model.Game
|
import org.yuzu.yuzu_emu.model.Game
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class AppletAdapter(val activity: FragmentActivity, applets: List<Applet>) :
|
class AppletAdapter(val activity: FragmentActivity, var applets: List<Applet>) :
|
||||||
AbstractListAdapter<Applet, AppletAdapter.AppletViewHolder>(applets) {
|
RecyclerView.Adapter<AppletAdapter.AppletViewHolder>(),
|
||||||
|
View.OnClickListener {
|
||||||
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
): AppletAdapter.AppletViewHolder {
|
): AppletAdapter.AppletViewHolder {
|
||||||
CardSimpleOutlinedBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
CardSimpleOutlinedBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
.apply { root.setOnClickListener(this@AppletAdapter) }
|
||||||
.also { return AppletViewHolder(it) }
|
.also { return AppletViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: AppletViewHolder, position: Int) =
|
||||||
|
holder.bind(applets[position])
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = applets.size
|
||||||
|
|
||||||
|
override fun onClick(view: View) {
|
||||||
|
val applet = (view.tag as AppletViewHolder).applet
|
||||||
|
val appletPath = NativeLibrary.getAppletLaunchPath(applet.appletInfo.entryId)
|
||||||
|
if (appletPath.isEmpty()) {
|
||||||
|
Toast.makeText(
|
||||||
|
YuzuApplication.appContext,
|
||||||
|
R.string.applets_error_applet,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applet.appletInfo == AppletInfo.Cabinet) {
|
||||||
|
view.findNavController()
|
||||||
|
.navigate(R.id.action_appletLauncherFragment_to_cabinetLauncherDialogFragment)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeLibrary.setCurrentAppletId(applet.appletInfo.appletId)
|
||||||
|
val appletGame = Game(
|
||||||
|
title = YuzuApplication.appContext.getString(applet.titleId),
|
||||||
|
path = appletPath
|
||||||
|
)
|
||||||
|
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
||||||
|
view.findNavController().navigate(action)
|
||||||
|
}
|
||||||
|
|
||||||
inner class AppletViewHolder(val binding: CardSimpleOutlinedBinding) :
|
inner class AppletViewHolder(val binding: CardSimpleOutlinedBinding) :
|
||||||
AbstractViewHolder<Applet>(binding) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
override fun bind(model: Applet) {
|
lateinit var applet: Applet
|
||||||
binding.title.setText(model.titleId)
|
|
||||||
binding.description.setText(model.descriptionId)
|
init {
|
||||||
|
itemView.tag = this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(applet: Applet) {
|
||||||
|
this.applet = applet
|
||||||
|
|
||||||
|
binding.title.setText(applet.titleId)
|
||||||
|
binding.description.setText(applet.descriptionId)
|
||||||
binding.icon.setImageDrawable(
|
binding.icon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
binding.icon.context.resources,
|
binding.icon.context.resources,
|
||||||
model.iconId,
|
applet.iconId,
|
||||||
binding.icon.context.theme
|
binding.icon.context.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
binding.root.setOnClickListener { onClick(model) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onClick(applet: Applet) {
|
|
||||||
val appletPath = NativeLibrary.getAppletLaunchPath(applet.appletInfo.entryId)
|
|
||||||
if (appletPath.isEmpty()) {
|
|
||||||
Toast.makeText(
|
|
||||||
binding.root.context,
|
|
||||||
R.string.applets_error_applet,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (applet.appletInfo == AppletInfo.Cabinet) {
|
|
||||||
binding.root.findNavController()
|
|
||||||
.navigate(R.id.action_appletLauncherFragment_to_cabinetLauncherDialogFragment)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeLibrary.setCurrentAppletId(applet.appletInfo.appletId)
|
|
||||||
val appletGame = Game(
|
|
||||||
title = YuzuApplication.appContext.getString(applet.titleId),
|
|
||||||
path = appletPath
|
|
||||||
)
|
|
||||||
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
|
||||||
binding.root.findNavController().navigate(action)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
package org.yuzu.yuzu_emu.adapters
|
package org.yuzu.yuzu_emu.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
||||||
import org.yuzu.yuzu_emu.NativeLibrary
|
import org.yuzu.yuzu_emu.NativeLibrary
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
@ -17,43 +19,54 @@ import org.yuzu.yuzu_emu.model.CabinetMode
|
|||||||
import org.yuzu.yuzu_emu.adapters.CabinetLauncherDialogAdapter.CabinetModeViewHolder
|
import org.yuzu.yuzu_emu.adapters.CabinetLauncherDialogAdapter.CabinetModeViewHolder
|
||||||
import org.yuzu.yuzu_emu.model.AppletInfo
|
import org.yuzu.yuzu_emu.model.AppletInfo
|
||||||
import org.yuzu.yuzu_emu.model.Game
|
import org.yuzu.yuzu_emu.model.Game
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class CabinetLauncherDialogAdapter(val fragment: Fragment) :
|
class CabinetLauncherDialogAdapter(val fragment: Fragment) :
|
||||||
AbstractListAdapter<CabinetMode, CabinetModeViewHolder>(
|
RecyclerView.Adapter<CabinetModeViewHolder>(),
|
||||||
CabinetMode.values().copyOfRange(1, CabinetMode.entries.size).toList()
|
View.OnClickListener {
|
||||||
) {
|
private val cabinetModes = CabinetMode.values().copyOfRange(1, CabinetMode.values().size)
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CabinetModeViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CabinetModeViewHolder {
|
||||||
DialogListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
DialogListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
.apply { root.setOnClickListener(this@CabinetLauncherDialogAdapter) }
|
||||||
.also { return CabinetModeViewHolder(it) }
|
.also { return CabinetModeViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = cabinetModes.size
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: CabinetModeViewHolder, position: Int) =
|
||||||
|
holder.bind(cabinetModes[position])
|
||||||
|
|
||||||
|
override fun onClick(view: View) {
|
||||||
|
val mode = (view.tag as CabinetModeViewHolder).cabinetMode
|
||||||
|
val appletPath = NativeLibrary.getAppletLaunchPath(AppletInfo.Cabinet.entryId)
|
||||||
|
NativeLibrary.setCurrentAppletId(AppletInfo.Cabinet.appletId)
|
||||||
|
NativeLibrary.setCabinetMode(mode.id)
|
||||||
|
val appletGame = Game(
|
||||||
|
title = YuzuApplication.appContext.getString(R.string.cabinet_applet),
|
||||||
|
path = appletPath
|
||||||
|
)
|
||||||
|
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
||||||
|
fragment.findNavController().navigate(action)
|
||||||
|
}
|
||||||
|
|
||||||
inner class CabinetModeViewHolder(val binding: DialogListItemBinding) :
|
inner class CabinetModeViewHolder(val binding: DialogListItemBinding) :
|
||||||
AbstractViewHolder<CabinetMode>(binding) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
override fun bind(model: CabinetMode) {
|
lateinit var cabinetMode: CabinetMode
|
||||||
|
|
||||||
|
init {
|
||||||
|
itemView.tag = this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(cabinetMode: CabinetMode) {
|
||||||
|
this.cabinetMode = cabinetMode
|
||||||
binding.icon.setImageDrawable(
|
binding.icon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
binding.icon.context.resources,
|
binding.icon.context.resources,
|
||||||
model.iconId,
|
cabinetMode.iconId,
|
||||||
binding.icon.context.theme
|
binding.icon.context.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
binding.title.setText(model.titleId)
|
binding.title.setText(cabinetMode.titleId)
|
||||||
|
|
||||||
binding.root.setOnClickListener { onClick(model) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onClick(mode: CabinetMode) {
|
|
||||||
val appletPath = NativeLibrary.getAppletLaunchPath(AppletInfo.Cabinet.entryId)
|
|
||||||
NativeLibrary.setCurrentAppletId(AppletInfo.Cabinet.appletId)
|
|
||||||
NativeLibrary.setCabinetMode(mode.id)
|
|
||||||
val appletGame = Game(
|
|
||||||
title = YuzuApplication.appContext.getString(R.string.cabinet_applet),
|
|
||||||
path = appletPath
|
|
||||||
)
|
|
||||||
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
|
||||||
fragment.findNavController().navigate(action)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,39 +7,65 @@ import android.text.TextUtils
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding
|
import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding
|
||||||
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
|
||||||
import org.yuzu.yuzu_emu.model.Driver
|
|
||||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||||
|
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
||||||
|
|
||||||
class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
||||||
AbstractSingleSelectionList<Driver, DriverAdapter.DriverViewHolder>(
|
ListAdapter<Pair<String, GpuDriverMetadata>, DriverAdapter.DriverViewHolder>(
|
||||||
driverViewModel.driverList.value
|
AsyncDifferConfig.Builder(DiffCallback()).build()
|
||||||
) {
|
) {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DriverViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DriverViewHolder {
|
||||||
CardDriverOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding =
|
||||||
.also { return DriverViewHolder(it) }
|
CardDriverOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
return DriverViewHolder(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = currentList.size
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: DriverViewHolder, position: Int) =
|
||||||
|
holder.bind(currentList[position])
|
||||||
|
|
||||||
|
private fun onSelectDriver(position: Int) {
|
||||||
|
driverViewModel.setSelectedDriverIndex(position)
|
||||||
|
notifyItemChanged(driverViewModel.previouslySelectedDriver)
|
||||||
|
notifyItemChanged(driverViewModel.selectedDriver)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onDeleteDriver(driverData: Pair<String, GpuDriverMetadata>, position: Int) {
|
||||||
|
if (driverViewModel.selectedDriver > position) {
|
||||||
|
driverViewModel.setSelectedDriverIndex(driverViewModel.selectedDriver - 1)
|
||||||
|
}
|
||||||
|
if (GpuDriverHelper.customDriverSettingData == driverData.second) {
|
||||||
|
driverViewModel.setSelectedDriverIndex(0)
|
||||||
|
}
|
||||||
|
driverViewModel.driversToDelete.add(driverData.first)
|
||||||
|
driverViewModel.removeDriver(driverData)
|
||||||
|
notifyItemRemoved(position)
|
||||||
|
notifyItemChanged(driverViewModel.selectedDriver)
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class DriverViewHolder(val binding: CardDriverOptionBinding) :
|
inner class DriverViewHolder(val binding: CardDriverOptionBinding) :
|
||||||
AbstractViewHolder<Driver>(binding) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
override fun bind(model: Driver) {
|
private lateinit var driverData: Pair<String, GpuDriverMetadata>
|
||||||
|
|
||||||
|
fun bind(driverData: Pair<String, GpuDriverMetadata>) {
|
||||||
|
this.driverData = driverData
|
||||||
|
val driver = driverData.second
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
radioButton.isChecked = model.selected
|
radioButton.isChecked = driverViewModel.selectedDriver == bindingAdapterPosition
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
selectItem(bindingAdapterPosition) {
|
onSelectDriver(bindingAdapterPosition)
|
||||||
driverViewModel.onDriverSelected(it)
|
|
||||||
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buttonDelete.setOnClickListener {
|
buttonDelete.setOnClickListener {
|
||||||
removeSelectableItem(
|
onDeleteDriver(driverData, bindingAdapterPosition)
|
||||||
bindingAdapterPosition
|
|
||||||
) { removedPosition: Int, selectedPosition: Int ->
|
|
||||||
driverViewModel.onDriverRemoved(removedPosition, selectedPosition)
|
|
||||||
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delay marquee by 3s
|
// Delay marquee by 3s
|
||||||
@ -54,19 +80,38 @@ class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
|||||||
},
|
},
|
||||||
3000
|
3000
|
||||||
)
|
)
|
||||||
title.text = model.title
|
if (driver.name == null) {
|
||||||
version.text = model.version
|
title.setText(R.string.system_gpu_driver)
|
||||||
description.text = model.description
|
description.text = ""
|
||||||
if (model.description.isNotEmpty()) {
|
version.text = ""
|
||||||
version.visibility = View.VISIBLE
|
|
||||||
description.visibility = View.VISIBLE
|
|
||||||
buttonDelete.visibility = View.VISIBLE
|
|
||||||
} else {
|
|
||||||
version.visibility = View.GONE
|
version.visibility = View.GONE
|
||||||
description.visibility = View.GONE
|
description.visibility = View.GONE
|
||||||
buttonDelete.visibility = View.GONE
|
buttonDelete.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
title.text = driver.name
|
||||||
|
version.text = driver.version
|
||||||
|
description.text = driver.description
|
||||||
|
version.visibility = View.VISIBLE
|
||||||
|
description.visibility = View.VISIBLE
|
||||||
|
buttonDelete.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DiffCallback : DiffUtil.ItemCallback<Pair<String, GpuDriverMetadata>>() {
|
||||||
|
override fun areItemsTheSame(
|
||||||
|
oldItem: Pair<String, GpuDriverMetadata>,
|
||||||
|
newItem: Pair<String, GpuDriverMetadata>
|
||||||
|
): Boolean {
|
||||||
|
return oldItem.first == newItem.first
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(
|
||||||
|
oldItem: Pair<String, GpuDriverMetadata>,
|
||||||
|
newItem: Pair<String, GpuDriverMetadata>
|
||||||
|
): Boolean {
|
||||||
|
return oldItem.second == newItem.second
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,19 @@ import android.text.TextUtils
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.yuzu.yuzu_emu.databinding.CardFolderBinding
|
import org.yuzu.yuzu_emu.databinding.CardFolderBinding
|
||||||
import org.yuzu.yuzu_emu.fragments.GameFolderPropertiesDialogFragment
|
import org.yuzu.yuzu_emu.fragments.GameFolderPropertiesDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.GameDir
|
import org.yuzu.yuzu_emu.model.GameDir
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesViewModel) :
|
class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesViewModel) :
|
||||||
AbstractDiffAdapter<GameDir, FolderAdapter.FolderViewHolder>() {
|
ListAdapter<GameDir, FolderAdapter.FolderViewHolder>(
|
||||||
|
AsyncDifferConfig.Builder(DiffCallback()).build()
|
||||||
|
) {
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
@ -24,11 +29,18 @@ class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesVie
|
|||||||
.also { return FolderViewHolder(it) }
|
.also { return FolderViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: FolderAdapter.FolderViewHolder, position: Int) =
|
||||||
|
holder.bind(currentList[position])
|
||||||
|
|
||||||
inner class FolderViewHolder(val binding: CardFolderBinding) :
|
inner class FolderViewHolder(val binding: CardFolderBinding) :
|
||||||
AbstractViewHolder<GameDir>(binding) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
override fun bind(model: GameDir) {
|
private lateinit var gameDir: GameDir
|
||||||
|
|
||||||
|
fun bind(gameDir: GameDir) {
|
||||||
|
this.gameDir = gameDir
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
path.text = Uri.parse(model.uriString).path
|
path.text = Uri.parse(gameDir.uriString).path
|
||||||
path.postDelayed(
|
path.postDelayed(
|
||||||
{
|
{
|
||||||
path.isSelected = true
|
path.isSelected = true
|
||||||
@ -38,7 +50,7 @@ class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesVie
|
|||||||
)
|
)
|
||||||
|
|
||||||
buttonEdit.setOnClickListener {
|
buttonEdit.setOnClickListener {
|
||||||
GameFolderPropertiesDialogFragment.newInstance(model)
|
GameFolderPropertiesDialogFragment.newInstance(this@FolderViewHolder.gameDir)
|
||||||
.show(
|
.show(
|
||||||
activity.supportFragmentManager,
|
activity.supportFragmentManager,
|
||||||
GameFolderPropertiesDialogFragment.TAG
|
GameFolderPropertiesDialogFragment.TAG
|
||||||
@ -46,9 +58,19 @@ class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
buttonDelete.setOnClickListener {
|
buttonDelete.setOnClickListener {
|
||||||
gamesViewModel.removeFolder(model)
|
gamesViewModel.removeFolder(this@FolderViewHolder.gameDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DiffCallback : DiffUtil.ItemCallback<GameDir>() {
|
||||||
|
override fun areItemsTheSame(oldItem: GameDir, newItem: GameDir): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: GameDir, newItem: GameDir): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.graphics.drawable.LayerDrawable
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -24,6 +25,10 @@ import androidx.lifecycle.ViewModelProvider
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -31,26 +36,122 @@ import org.yuzu.yuzu_emu.HomeNavigationDirections
|
|||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.YuzuApplication
|
import org.yuzu.yuzu_emu.YuzuApplication
|
||||||
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
||||||
|
import org.yuzu.yuzu_emu.adapters.GameAdapter.GameViewHolder
|
||||||
import org.yuzu.yuzu_emu.databinding.CardGameBinding
|
import org.yuzu.yuzu_emu.databinding.CardGameBinding
|
||||||
import org.yuzu.yuzu_emu.model.Game
|
import org.yuzu.yuzu_emu.model.Game
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
import org.yuzu.yuzu_emu.utils.GameIconUtils
|
import org.yuzu.yuzu_emu.utils.GameIconUtils
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class GameAdapter(private val activity: AppCompatActivity) :
|
class GameAdapter(private val activity: AppCompatActivity) :
|
||||||
AbstractDiffAdapter<Game, GameAdapter.GameViewHolder>() {
|
ListAdapter<Game, GameViewHolder>(AsyncDifferConfig.Builder(DiffCallback()).build()),
|
||||||
|
View.OnClickListener,
|
||||||
|
View.OnLongClickListener {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameViewHolder {
|
||||||
CardGameBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
// Create a new view.
|
||||||
.also { return GameViewHolder(it) }
|
val binding = CardGameBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
binding.cardGame.setOnClickListener(this)
|
||||||
|
binding.cardGame.setOnLongClickListener(this)
|
||||||
|
|
||||||
|
// Use that view to create a ViewHolder.
|
||||||
|
return GameViewHolder(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: GameViewHolder, position: Int) =
|
||||||
|
holder.bind(currentList[position])
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = currentList.size
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launches the game that was clicked on.
|
||||||
|
*
|
||||||
|
* @param view The card representing the game the user wants to play.
|
||||||
|
*/
|
||||||
|
override fun onClick(view: View) {
|
||||||
|
val holder = view.tag as GameViewHolder
|
||||||
|
|
||||||
|
val gameExists = DocumentFile.fromSingleUri(
|
||||||
|
YuzuApplication.appContext,
|
||||||
|
Uri.parse(holder.game.path)
|
||||||
|
)?.exists() == true
|
||||||
|
if (!gameExists) {
|
||||||
|
Toast.makeText(
|
||||||
|
YuzuApplication.appContext,
|
||||||
|
R.string.loader_error_file_not_found,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
|
||||||
|
ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
||||||
|
preferences.edit()
|
||||||
|
.putLong(
|
||||||
|
holder.game.keyLastPlayedTime,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
val openIntent = Intent(YuzuApplication.appContext, EmulationActivity::class.java).apply {
|
||||||
|
action = Intent.ACTION_VIEW
|
||||||
|
data = Uri.parse(holder.game.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.lifecycleScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val layerDrawable = ResourcesCompat.getDrawable(
|
||||||
|
YuzuApplication.appContext.resources,
|
||||||
|
R.drawable.shortcut,
|
||||||
|
null
|
||||||
|
) as LayerDrawable
|
||||||
|
layerDrawable.setDrawableByLayerId(
|
||||||
|
R.id.shortcut_foreground,
|
||||||
|
GameIconUtils.getGameIcon(activity, holder.game)
|
||||||
|
.toDrawable(YuzuApplication.appContext.resources)
|
||||||
|
)
|
||||||
|
val inset = YuzuApplication.appContext.resources
|
||||||
|
.getDimensionPixelSize(R.dimen.icon_inset)
|
||||||
|
layerDrawable.setLayerInset(1, inset, inset, inset, inset)
|
||||||
|
val shortcut =
|
||||||
|
ShortcutInfoCompat.Builder(YuzuApplication.appContext, holder.game.path)
|
||||||
|
.setShortLabel(holder.game.title)
|
||||||
|
.setIcon(
|
||||||
|
IconCompat.createWithAdaptiveBitmap(
|
||||||
|
layerDrawable.toBitmap(config = Bitmap.Config.ARGB_8888)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setIntent(openIntent)
|
||||||
|
.build()
|
||||||
|
ShortcutManagerCompat.pushDynamicShortcut(YuzuApplication.appContext, shortcut)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val action = HomeNavigationDirections.actionGlobalEmulationActivity(holder.game, true)
|
||||||
|
view.findNavController().navigate(action)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLongClick(view: View): Boolean {
|
||||||
|
val holder = view.tag as GameViewHolder
|
||||||
|
val action = HomeNavigationDirections.actionGlobalPerGamePropertiesFragment(holder.game)
|
||||||
|
view.findNavController().navigate(action)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class GameViewHolder(val binding: CardGameBinding) :
|
inner class GameViewHolder(val binding: CardGameBinding) :
|
||||||
AbstractViewHolder<Game>(binding) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
override fun bind(model: Game) {
|
lateinit var game: Game
|
||||||
binding.imageGameScreen.scaleType = ImageView.ScaleType.CENTER_CROP
|
|
||||||
GameIconUtils.loadGameIcon(model, binding.imageGameScreen)
|
|
||||||
|
|
||||||
binding.textGameTitle.text = model.title.replace("[\\t\\n\\r]+".toRegex(), " ")
|
init {
|
||||||
|
binding.cardGame.tag = this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(game: Game) {
|
||||||
|
this.game = game
|
||||||
|
|
||||||
|
binding.imageGameScreen.scaleType = ImageView.ScaleType.CENTER_CROP
|
||||||
|
GameIconUtils.loadGameIcon(game, binding.imageGameScreen)
|
||||||
|
|
||||||
|
binding.textGameTitle.text = game.title.replace("[\\t\\n\\r]+".toRegex(), " ")
|
||||||
|
|
||||||
binding.textGameTitle.postDelayed(
|
binding.textGameTitle.postDelayed(
|
||||||
{
|
{
|
||||||
@ -59,79 +160,16 @@ class GameAdapter(private val activity: AppCompatActivity) :
|
|||||||
},
|
},
|
||||||
3000
|
3000
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
binding.cardGame.setOnClickListener { onClick(model) }
|
private class DiffCallback : DiffUtil.ItemCallback<Game>() {
|
||||||
binding.cardGame.setOnLongClickListener { onLongClick(model) }
|
override fun areItemsTheSame(oldItem: Game, newItem: Game): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onClick(game: Game) {
|
override fun areContentsTheSame(oldItem: Game, newItem: Game): Boolean {
|
||||||
val gameExists = DocumentFile.fromSingleUri(
|
return oldItem == newItem
|
||||||
YuzuApplication.appContext,
|
|
||||||
Uri.parse(game.path)
|
|
||||||
)?.exists() == true
|
|
||||||
if (!gameExists) {
|
|
||||||
Toast.makeText(
|
|
||||||
YuzuApplication.appContext,
|
|
||||||
R.string.loader_error_file_not_found,
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
|
|
||||||
ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val preferences =
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
|
||||||
preferences.edit()
|
|
||||||
.putLong(
|
|
||||||
game.keyLastPlayedTime,
|
|
||||||
System.currentTimeMillis()
|
|
||||||
)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
val openIntent =
|
|
||||||
Intent(YuzuApplication.appContext, EmulationActivity::class.java).apply {
|
|
||||||
action = Intent.ACTION_VIEW
|
|
||||||
data = Uri.parse(game.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
activity.lifecycleScope.launch {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
val layerDrawable = ResourcesCompat.getDrawable(
|
|
||||||
YuzuApplication.appContext.resources,
|
|
||||||
R.drawable.shortcut,
|
|
||||||
null
|
|
||||||
) as LayerDrawable
|
|
||||||
layerDrawable.setDrawableByLayerId(
|
|
||||||
R.id.shortcut_foreground,
|
|
||||||
GameIconUtils.getGameIcon(activity, game)
|
|
||||||
.toDrawable(YuzuApplication.appContext.resources)
|
|
||||||
)
|
|
||||||
val inset = YuzuApplication.appContext.resources
|
|
||||||
.getDimensionPixelSize(R.dimen.icon_inset)
|
|
||||||
layerDrawable.setLayerInset(1, inset, inset, inset, inset)
|
|
||||||
val shortcut =
|
|
||||||
ShortcutInfoCompat.Builder(YuzuApplication.appContext, game.path)
|
|
||||||
.setShortLabel(game.title)
|
|
||||||
.setIcon(
|
|
||||||
IconCompat.createWithAdaptiveBitmap(
|
|
||||||
layerDrawable.toBitmap(config = Bitmap.Config.ARGB_8888)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setIntent(openIntent)
|
|
||||||
.build()
|
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(YuzuApplication.appContext, shortcut)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val action = HomeNavigationDirections.actionGlobalEmulationActivity(game, true)
|
|
||||||
binding.root.findNavController().navigate(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onLongClick(game: Game): Boolean {
|
|
||||||
val action = HomeNavigationDirections.actionGlobalPerGamePropertiesFragment(game)
|
|
||||||
binding.root.findNavController().navigate(action)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,22 +12,23 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.yuzu.yuzu_emu.databinding.CardInstallableIconBinding
|
import org.yuzu.yuzu_emu.databinding.CardInstallableIconBinding
|
||||||
import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding
|
import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding
|
||||||
import org.yuzu.yuzu_emu.model.GameProperty
|
import org.yuzu.yuzu_emu.model.GameProperty
|
||||||
import org.yuzu.yuzu_emu.model.InstallableProperty
|
import org.yuzu.yuzu_emu.model.InstallableProperty
|
||||||
import org.yuzu.yuzu_emu.model.SubmenuProperty
|
import org.yuzu.yuzu_emu.model.SubmenuProperty
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class GamePropertiesAdapter(
|
class GamePropertiesAdapter(
|
||||||
private val viewLifecycle: LifecycleOwner,
|
private val viewLifecycle: LifecycleOwner,
|
||||||
private var properties: List<GameProperty>
|
private var properties: List<GameProperty>
|
||||||
) : AbstractListAdapter<GameProperty, AbstractViewHolder<GameProperty>>(properties) {
|
) :
|
||||||
|
RecyclerView.Adapter<GamePropertiesAdapter.GamePropertyViewHolder>() {
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
): AbstractViewHolder<GameProperty> {
|
): GamePropertyViewHolder {
|
||||||
val inflater = LayoutInflater.from(parent.context)
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
PropertyType.Submenu.ordinal -> {
|
PropertyType.Submenu.ordinal -> {
|
||||||
@ -50,6 +51,11 @@ class GamePropertiesAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = properties.size
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: GamePropertyViewHolder, position: Int) =
|
||||||
|
holder.bind(properties[position])
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return when (properties[position]) {
|
return when (properties[position]) {
|
||||||
is SubmenuProperty -> PropertyType.Submenu.ordinal
|
is SubmenuProperty -> PropertyType.Submenu.ordinal
|
||||||
@ -57,10 +63,14 @@ class GamePropertiesAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class GamePropertyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
|
abstract fun bind(property: GameProperty)
|
||||||
|
}
|
||||||
|
|
||||||
inner class SubmenuPropertyViewHolder(val binding: CardSimpleOutlinedBinding) :
|
inner class SubmenuPropertyViewHolder(val binding: CardSimpleOutlinedBinding) :
|
||||||
AbstractViewHolder<GameProperty>(binding) {
|
GamePropertyViewHolder(binding.root) {
|
||||||
override fun bind(model: GameProperty) {
|
override fun bind(property: GameProperty) {
|
||||||
val submenuProperty = model as SubmenuProperty
|
val submenuProperty = property as SubmenuProperty
|
||||||
|
|
||||||
binding.root.setOnClickListener {
|
binding.root.setOnClickListener {
|
||||||
submenuProperty.action.invoke()
|
submenuProperty.action.invoke()
|
||||||
@ -98,9 +108,9 @@ class GamePropertiesAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inner class InstallablePropertyViewHolder(val binding: CardInstallableIconBinding) :
|
inner class InstallablePropertyViewHolder(val binding: CardInstallableIconBinding) :
|
||||||
AbstractViewHolder<GameProperty>(binding) {
|
GamePropertyViewHolder(binding.root) {
|
||||||
override fun bind(model: GameProperty) {
|
override fun bind(property: GameProperty) {
|
||||||
val installableProperty = model as InstallableProperty
|
val installableProperty = property as InstallableProperty
|
||||||
|
|
||||||
binding.title.setText(installableProperty.titleId)
|
binding.title.setText(installableProperty.titleId)
|
||||||
binding.description.setText(installableProperty.descriptionId)
|
binding.description.setText(installableProperty.descriptionId)
|
||||||
|
@ -14,37 +14,69 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding
|
import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding
|
||||||
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.HomeSetting
|
import org.yuzu.yuzu_emu.model.HomeSetting
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class HomeSettingAdapter(
|
class HomeSettingAdapter(
|
||||||
private val activity: AppCompatActivity,
|
private val activity: AppCompatActivity,
|
||||||
private val viewLifecycle: LifecycleOwner,
|
private val viewLifecycle: LifecycleOwner,
|
||||||
options: List<HomeSetting>
|
var options: List<HomeSetting>
|
||||||
) : AbstractListAdapter<HomeSetting, HomeSettingAdapter.HomeOptionViewHolder>(options) {
|
) :
|
||||||
|
RecyclerView.Adapter<HomeSettingAdapter.HomeOptionViewHolder>(),
|
||||||
|
View.OnClickListener {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder {
|
||||||
CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding =
|
||||||
.also { return HomeOptionViewHolder(it) }
|
CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
binding.root.setOnClickListener(this)
|
||||||
|
return HomeOptionViewHolder(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return options.size
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: HomeOptionViewHolder, position: Int) {
|
||||||
|
holder.bind(options[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(view: View) {
|
||||||
|
val holder = view.tag as HomeOptionViewHolder
|
||||||
|
if (holder.option.isEnabled.invoke()) {
|
||||||
|
holder.option.onClick.invoke()
|
||||||
|
} else {
|
||||||
|
MessageDialogFragment.newInstance(
|
||||||
|
activity,
|
||||||
|
titleId = holder.option.disabledTitleId,
|
||||||
|
descriptionId = holder.option.disabledMessageId
|
||||||
|
).show(activity.supportFragmentManager, MessageDialogFragment.TAG)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) :
|
inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) :
|
||||||
AbstractViewHolder<HomeSetting>(binding) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
override fun bind(model: HomeSetting) {
|
lateinit var option: HomeSetting
|
||||||
binding.optionTitle.text = activity.resources.getString(model.titleId)
|
|
||||||
binding.optionDescription.text = activity.resources.getString(model.descriptionId)
|
init {
|
||||||
|
itemView.tag = this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(option: HomeSetting) {
|
||||||
|
this.option = option
|
||||||
|
binding.optionTitle.text = activity.resources.getString(option.titleId)
|
||||||
|
binding.optionDescription.text = activity.resources.getString(option.descriptionId)
|
||||||
binding.optionIcon.setImageDrawable(
|
binding.optionIcon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
activity.resources,
|
activity.resources,
|
||||||
model.iconId,
|
option.iconId,
|
||||||
activity.theme
|
activity.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
when (model.titleId) {
|
when (option.titleId) {
|
||||||
R.string.get_early_access ->
|
R.string.get_early_access ->
|
||||||
binding.optionLayout.background =
|
binding.optionLayout.background =
|
||||||
ContextCompat.getDrawable(
|
ContextCompat.getDrawable(
|
||||||
@ -53,7 +85,7 @@ class HomeSettingAdapter(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!model.isEnabled.invoke()) {
|
if (!option.isEnabled.invoke()) {
|
||||||
binding.optionTitle.alpha = 0.5f
|
binding.optionTitle.alpha = 0.5f
|
||||||
binding.optionDescription.alpha = 0.5f
|
binding.optionDescription.alpha = 0.5f
|
||||||
binding.optionIcon.alpha = 0.5f
|
binding.optionIcon.alpha = 0.5f
|
||||||
@ -61,7 +93,7 @@ class HomeSettingAdapter(
|
|||||||
|
|
||||||
viewLifecycle.lifecycleScope.launch {
|
viewLifecycle.lifecycleScope.launch {
|
||||||
viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
|
viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
model.details.collect { updateOptionDetails(it) }
|
option.details.collect { updateOptionDetails(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.optionDetail.postDelayed(
|
binding.optionDetail.postDelayed(
|
||||||
@ -71,20 +103,6 @@ class HomeSettingAdapter(
|
|||||||
},
|
},
|
||||||
3000
|
3000
|
||||||
)
|
)
|
||||||
|
|
||||||
binding.root.setOnClickListener { onClick(model) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onClick(model: HomeSetting) {
|
|
||||||
if (model.isEnabled.invoke()) {
|
|
||||||
model.onClick.invoke()
|
|
||||||
} else {
|
|
||||||
MessageDialogFragment.newInstance(
|
|
||||||
activity,
|
|
||||||
titleId = model.disabledTitleId,
|
|
||||||
descriptionId = model.disabledMessageId
|
|
||||||
).show(activity.supportFragmentManager, MessageDialogFragment.TAG)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateOptionDetails(detailString: String) {
|
private fun updateOptionDetails(detailString: String) {
|
||||||
|
@ -6,33 +6,43 @@ package org.yuzu.yuzu_emu.adapters
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.yuzu.yuzu_emu.databinding.CardInstallableBinding
|
import org.yuzu.yuzu_emu.databinding.CardInstallableBinding
|
||||||
import org.yuzu.yuzu_emu.model.Installable
|
import org.yuzu.yuzu_emu.model.Installable
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class InstallableAdapter(installables: List<Installable>) :
|
class InstallableAdapter(private val installables: List<Installable>) :
|
||||||
AbstractListAdapter<Installable, InstallableAdapter.InstallableViewHolder>(installables) {
|
RecyclerView.Adapter<InstallableAdapter.InstallableViewHolder>() {
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
): InstallableAdapter.InstallableViewHolder {
|
): InstallableAdapter.InstallableViewHolder {
|
||||||
CardInstallableBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding =
|
||||||
.also { return InstallableViewHolder(it) }
|
CardInstallableBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
return InstallableViewHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class InstallableViewHolder(val binding: CardInstallableBinding) :
|
override fun getItemCount(): Int = installables.size
|
||||||
AbstractViewHolder<Installable>(binding) {
|
|
||||||
override fun bind(model: Installable) {
|
|
||||||
binding.title.setText(model.titleId)
|
|
||||||
binding.description.setText(model.descriptionId)
|
|
||||||
|
|
||||||
if (model.install != null) {
|
override fun onBindViewHolder(holder: InstallableAdapter.InstallableViewHolder, position: Int) =
|
||||||
|
holder.bind(installables[position])
|
||||||
|
|
||||||
|
inner class InstallableViewHolder(val binding: CardInstallableBinding) :
|
||||||
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
lateinit var installable: Installable
|
||||||
|
|
||||||
|
fun bind(installable: Installable) {
|
||||||
|
this.installable = installable
|
||||||
|
|
||||||
|
binding.title.setText(installable.titleId)
|
||||||
|
binding.description.setText(installable.descriptionId)
|
||||||
|
|
||||||
|
if (installable.install != null) {
|
||||||
binding.buttonInstall.visibility = View.VISIBLE
|
binding.buttonInstall.visibility = View.VISIBLE
|
||||||
binding.buttonInstall.setOnClickListener { model.install.invoke() }
|
binding.buttonInstall.setOnClickListener { installable.install.invoke() }
|
||||||
}
|
}
|
||||||
if (model.export != null) {
|
if (installable.export != null) {
|
||||||
binding.buttonExport.visibility = View.VISIBLE
|
binding.buttonExport.visibility = View.VISIBLE
|
||||||
binding.buttonExport.setOnClickListener { model.export.invoke() }
|
binding.buttonExport.setOnClickListener { installable.export.invoke() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,33 +7,49 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||||
|
import org.yuzu.yuzu_emu.YuzuApplication
|
||||||
import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding
|
import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding
|
||||||
import org.yuzu.yuzu_emu.fragments.LicenseBottomSheetDialogFragment
|
import org.yuzu.yuzu_emu.fragments.LicenseBottomSheetDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.License
|
import org.yuzu.yuzu_emu.model.License
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class LicenseAdapter(private val activity: AppCompatActivity, licenses: List<License>) :
|
class LicenseAdapter(private val activity: AppCompatActivity, var licenses: List<License>) :
|
||||||
AbstractListAdapter<License, LicenseAdapter.LicenseViewHolder>(licenses) {
|
RecyclerView.Adapter<LicenseAdapter.LicenseViewHolder>(),
|
||||||
|
View.OnClickListener {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LicenseViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LicenseViewHolder {
|
||||||
ListItemSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding =
|
||||||
.also { return LicenseViewHolder(it) }
|
ListItemSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
binding.root.setOnClickListener(this)
|
||||||
|
return LicenseViewHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class LicenseViewHolder(val binding: ListItemSettingBinding) :
|
override fun getItemCount(): Int = licenses.size
|
||||||
AbstractViewHolder<License>(binding) {
|
|
||||||
override fun bind(model: License) {
|
|
||||||
binding.apply {
|
|
||||||
textSettingName.text = root.context.getString(model.titleId)
|
|
||||||
textSettingDescription.text = root.context.getString(model.descriptionId)
|
|
||||||
textSettingValue.visibility = View.GONE
|
|
||||||
|
|
||||||
root.setOnClickListener { onClick(model) }
|
override fun onBindViewHolder(holder: LicenseViewHolder, position: Int) {
|
||||||
}
|
holder.bind(licenses[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(view: View) {
|
||||||
|
val license = (view.tag as LicenseViewHolder).license
|
||||||
|
LicenseBottomSheetDialogFragment.newInstance(license)
|
||||||
|
.show(activity.supportFragmentManager, LicenseBottomSheetDialogFragment.TAG)
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class LicenseViewHolder(val binding: ListItemSettingBinding) : ViewHolder(binding.root) {
|
||||||
|
lateinit var license: License
|
||||||
|
|
||||||
|
init {
|
||||||
|
itemView.tag = this
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onClick(license: License) {
|
fun bind(license: License) {
|
||||||
LicenseBottomSheetDialogFragment.newInstance(license)
|
this.license = license
|
||||||
.show(activity.supportFragmentManager, LicenseBottomSheetDialogFragment.TAG)
|
|
||||||
|
val context = YuzuApplication.appContext
|
||||||
|
binding.textSettingName.text = context.getString(license.titleId)
|
||||||
|
binding.textSettingDescription.text = context.getString(license.descriptionId)
|
||||||
|
binding.textSettingValue.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import android.view.ViewGroup
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import org.yuzu.yuzu_emu.databinding.PageSetupBinding
|
import org.yuzu.yuzu_emu.databinding.PageSetupBinding
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
@ -17,19 +18,31 @@ import org.yuzu.yuzu_emu.model.SetupCallback
|
|||||||
import org.yuzu.yuzu_emu.model.SetupPage
|
import org.yuzu.yuzu_emu.model.SetupPage
|
||||||
import org.yuzu.yuzu_emu.model.StepState
|
import org.yuzu.yuzu_emu.model.StepState
|
||||||
import org.yuzu.yuzu_emu.utils.ViewUtils
|
import org.yuzu.yuzu_emu.utils.ViewUtils
|
||||||
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
||||||
|
|
||||||
class SetupAdapter(val activity: AppCompatActivity, pages: List<SetupPage>) :
|
class SetupAdapter(val activity: AppCompatActivity, val pages: List<SetupPage>) :
|
||||||
AbstractListAdapter<SetupPage, SetupAdapter.SetupPageViewHolder>(pages) {
|
RecyclerView.Adapter<SetupAdapter.SetupPageViewHolder>() {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SetupPageViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SetupPageViewHolder {
|
||||||
PageSetupBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding = PageSetupBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
.also { return SetupPageViewHolder(it) }
|
return SetupPageViewHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = pages.size
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: SetupPageViewHolder, position: Int) =
|
||||||
|
holder.bind(pages[position])
|
||||||
|
|
||||||
inner class SetupPageViewHolder(val binding: PageSetupBinding) :
|
inner class SetupPageViewHolder(val binding: PageSetupBinding) :
|
||||||
AbstractViewHolder<SetupPage>(binding), SetupCallback {
|
RecyclerView.ViewHolder(binding.root), SetupCallback {
|
||||||
override fun bind(model: SetupPage) {
|
lateinit var page: SetupPage
|
||||||
if (model.stepCompleted.invoke() == StepState.COMPLETE) {
|
|
||||||
|
init {
|
||||||
|
itemView.tag = this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(page: SetupPage) {
|
||||||
|
this.page = page
|
||||||
|
|
||||||
|
if (page.stepCompleted.invoke() == StepState.COMPLETE) {
|
||||||
binding.buttonAction.visibility = View.INVISIBLE
|
binding.buttonAction.visibility = View.INVISIBLE
|
||||||
binding.textConfirmation.visibility = View.VISIBLE
|
binding.textConfirmation.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
@ -37,31 +50,31 @@ class SetupAdapter(val activity: AppCompatActivity, pages: List<SetupPage>) :
|
|||||||
binding.icon.setImageDrawable(
|
binding.icon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
activity.resources,
|
activity.resources,
|
||||||
model.iconId,
|
page.iconId,
|
||||||
activity.theme
|
activity.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
binding.textTitle.text = activity.resources.getString(model.titleId)
|
binding.textTitle.text = activity.resources.getString(page.titleId)
|
||||||
binding.textDescription.text =
|
binding.textDescription.text =
|
||||||
Html.fromHtml(activity.resources.getString(model.descriptionId), 0)
|
Html.fromHtml(activity.resources.getString(page.descriptionId), 0)
|
||||||
|
|
||||||
binding.buttonAction.apply {
|
binding.buttonAction.apply {
|
||||||
text = activity.resources.getString(model.buttonTextId)
|
text = activity.resources.getString(page.buttonTextId)
|
||||||
if (model.buttonIconId != 0) {
|
if (page.buttonIconId != 0) {
|
||||||
icon = ResourcesCompat.getDrawable(
|
icon = ResourcesCompat.getDrawable(
|
||||||
activity.resources,
|
activity.resources,
|
||||||
model.buttonIconId,
|
page.buttonIconId,
|
||||||
activity.theme
|
activity.theme
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
iconGravity =
|
iconGravity =
|
||||||
if (model.leftAlignedIcon) {
|
if (page.leftAlignedIcon) {
|
||||||
MaterialButton.ICON_GRAVITY_START
|
MaterialButton.ICON_GRAVITY_START
|
||||||
} else {
|
} else {
|
||||||
MaterialButton.ICON_GRAVITY_END
|
MaterialButton.ICON_GRAVITY_END
|
||||||
}
|
}
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
model.buttonAction.invoke(this@SetupPageViewHolder)
|
page.buttonAction.invoke(this@SetupPageViewHolder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
package org.yuzu.yuzu_emu.fragments
|
package org.yuzu.yuzu_emu.fragments
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -14,26 +13,20 @@ import androidx.core.view.WindowInsetsCompat
|
|||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.fragment.navArgs
|
import androidx.navigation.fragment.navArgs
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.google.android.material.transition.MaterialSharedAxis
|
import com.google.android.material.transition.MaterialSharedAxis
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.adapters.DriverAdapter
|
import org.yuzu.yuzu_emu.adapters.DriverAdapter
|
||||||
import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding
|
import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding
|
||||||
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
|
||||||
import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver
|
|
||||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
import org.yuzu.yuzu_emu.utils.FileUtil
|
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||||
import org.yuzu.yuzu_emu.utils.NativeConfig
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@ -62,43 +55,12 @@ class DriverManagerFragment : Fragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is using the correct scope, lint is just acting up
|
|
||||||
@SuppressLint("UnsafeRepeatOnLifecycleDetector")
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
homeViewModel.setNavigationVisibility(visible = false, animated = true)
|
homeViewModel.setNavigationVisibility(visible = false, animated = true)
|
||||||
homeViewModel.setStatusBarShadeVisibility(visible = false)
|
homeViewModel.setStatusBarShadeVisibility(visible = false)
|
||||||
|
|
||||||
driverViewModel.onOpenDriverManager(args.game)
|
driverViewModel.onOpenDriverManager(args.game)
|
||||||
if (NativeConfig.isPerGameConfigLoaded()) {
|
|
||||||
binding.toolbarDrivers.inflateMenu(R.menu.menu_driver_manager)
|
|
||||||
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
|
||||||
binding.toolbarDrivers.setOnMenuItemClickListener {
|
|
||||||
when (it.itemId) {
|
|
||||||
R.id.menu_driver_clear -> {
|
|
||||||
StringSetting.DRIVER_PATH.global = true
|
|
||||||
driverViewModel.updateDriverList()
|
|
||||||
(binding.listDrivers.adapter as DriverAdapter)
|
|
||||||
.replaceList(driverViewModel.driverList.value)
|
|
||||||
driverViewModel.showClearButton(false)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
viewLifecycleOwner.lifecycleScope.apply {
|
|
||||||
launch {
|
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
||||||
driverViewModel.showClearButton.collect {
|
|
||||||
binding.toolbarDrivers.menu
|
|
||||||
.findItem(R.id.menu_driver_clear).isVisible = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!driverViewModel.isInteractionAllowed.value) {
|
if (!driverViewModel.isInteractionAllowed.value) {
|
||||||
DriversLoadingDialogFragment().show(
|
DriversLoadingDialogFragment().show(
|
||||||
@ -123,6 +85,25 @@ class DriverManagerFragment : Fragment() {
|
|||||||
adapter = DriverAdapter(driverViewModel)
|
adapter = DriverAdapter(driverViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewLifecycleOwner.lifecycleScope.apply {
|
||||||
|
launch {
|
||||||
|
driverViewModel.driverList.collectLatest {
|
||||||
|
(binding.listDrivers.adapter as DriverAdapter).submitList(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
launch {
|
||||||
|
driverViewModel.newDriverInstalled.collect {
|
||||||
|
if (_binding != null && it) {
|
||||||
|
(binding.listDrivers.adapter as DriverAdapter).apply {
|
||||||
|
notifyItemChanged(driverViewModel.previouslySelectedDriver)
|
||||||
|
notifyItemChanged(driverViewModel.selectedDriver)
|
||||||
|
driverViewModel.setNewDriverInstalled(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setInsets()
|
setInsets()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +160,7 @@ class DriverManagerFragment : Fragment() {
|
|||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
val driverPath =
|
val driverPath =
|
||||||
"${GpuDriverHelper.driverStoragePath}${FileUtil.getFilename(result)}"
|
"${GpuDriverHelper.driverStoragePath}/${FileUtil.getFilename(result)}"
|
||||||
val driverFile = File(driverPath)
|
val driverFile = File(driverPath)
|
||||||
|
|
||||||
// Ignore file exceptions when a user selects an invalid zip
|
// Ignore file exceptions when a user selects an invalid zip
|
||||||
@ -196,21 +177,12 @@ class DriverManagerFragment : Fragment() {
|
|||||||
|
|
||||||
val driverData = GpuDriverHelper.getMetadataFromZip(driverFile)
|
val driverData = GpuDriverHelper.getMetadataFromZip(driverFile)
|
||||||
val driverInList =
|
val driverInList =
|
||||||
driverViewModel.driverData.firstOrNull { it.second == driverData }
|
driverViewModel.driverList.value.firstOrNull { it.second == driverData }
|
||||||
if (driverInList != null) {
|
if (driverInList != null) {
|
||||||
return@newInstance getString(R.string.driver_already_installed)
|
return@newInstance getString(R.string.driver_already_installed)
|
||||||
} else {
|
} else {
|
||||||
driverViewModel.onDriverAdded(Pair(driverPath, driverData))
|
driverViewModel.addDriver(Pair(driverPath, driverData))
|
||||||
withContext(Dispatchers.Main) {
|
driverViewModel.setNewDriverInstalled(true)
|
||||||
if (_binding != null) {
|
|
||||||
val adapter = binding.listDrivers.adapter as DriverAdapter
|
|
||||||
adapter.addItem(driverData.toDriver())
|
|
||||||
adapter.selectItem(adapter.currentList.indices.last)
|
|
||||||
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
|
||||||
binding.listDrivers
|
|
||||||
.smoothScrollToPosition(adapter.currentList.indices.last)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return@newInstance Any()
|
return@newInstance Any()
|
||||||
}.show(childFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(childFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.yuzu.yuzu_emu.model
|
|
||||||
|
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
|
||||||
|
|
||||||
data class Driver(
|
|
||||||
override var selected: Boolean,
|
|
||||||
val title: String,
|
|
||||||
val version: String = "",
|
|
||||||
val description: String = ""
|
|
||||||
) : SelectableItem {
|
|
||||||
override fun onSelectionStateChanged(selected: Boolean) {
|
|
||||||
this.selected = selected
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun GpuDriverMetadata.toDriver(selected: Boolean = false): Driver =
|
|
||||||
Driver(
|
|
||||||
selected,
|
|
||||||
this.name ?: "",
|
|
||||||
this.version ?: "",
|
|
||||||
this.description ?: ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,7 +9,6 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -18,10 +17,11 @@ import org.yuzu.yuzu_emu.R
|
|||||||
import org.yuzu.yuzu_emu.YuzuApplication
|
import org.yuzu.yuzu_emu.YuzuApplication
|
||||||
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
||||||
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
||||||
import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver
|
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
||||||
import org.yuzu.yuzu_emu.utils.NativeConfig
|
import org.yuzu.yuzu_emu.utils.NativeConfig
|
||||||
|
import java.io.BufferedOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class DriverViewModel : ViewModel() {
|
class DriverViewModel : ViewModel() {
|
||||||
@ -38,81 +38,97 @@ class DriverViewModel : ViewModel() {
|
|||||||
!loading && ready && !deleting
|
!loading && ready && !deleting
|
||||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), initialValue = false)
|
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), initialValue = false)
|
||||||
|
|
||||||
var driverData = GpuDriverHelper.getDrivers()
|
private val _driverList = MutableStateFlow(GpuDriverHelper.getDrivers())
|
||||||
|
val driverList: StateFlow<MutableList<Pair<String, GpuDriverMetadata>>> get() = _driverList
|
||||||
|
|
||||||
private val _driverList = MutableStateFlow(emptyList<Driver>())
|
var previouslySelectedDriver = 0
|
||||||
val driverList: StateFlow<List<Driver>> get() = _driverList
|
var selectedDriver = -1
|
||||||
|
|
||||||
// Used for showing which driver is currently installed within the driver manager card
|
// Used for showing which driver is currently installed within the driver manager card
|
||||||
private val _selectedDriverTitle = MutableStateFlow("")
|
private val _selectedDriverTitle = MutableStateFlow("")
|
||||||
val selectedDriverTitle: StateFlow<String> get() = _selectedDriverTitle
|
val selectedDriverTitle: StateFlow<String> get() = _selectedDriverTitle
|
||||||
|
|
||||||
private val _showClearButton = MutableStateFlow(false)
|
private val _newDriverInstalled = MutableStateFlow(false)
|
||||||
val showClearButton = _showClearButton.asStateFlow()
|
val newDriverInstalled: StateFlow<Boolean> get() = _newDriverInstalled
|
||||||
|
|
||||||
private val driversToDelete = mutableListOf<String>()
|
val driversToDelete = mutableListOf<String>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
updateDriverList()
|
val currentDriverMetadata = GpuDriverHelper.installedCustomDriverData
|
||||||
|
findSelectedDriver(currentDriverMetadata)
|
||||||
|
|
||||||
|
// If a user had installed a driver before the manager was implemented, this zips
|
||||||
|
// the installed driver to UserData/gpu_drivers/CustomDriver.zip so that it can
|
||||||
|
// be indexed and exported as expected.
|
||||||
|
if (selectedDriver == -1) {
|
||||||
|
val driverToSave =
|
||||||
|
File(GpuDriverHelper.driverStoragePath, "CustomDriver.zip")
|
||||||
|
driverToSave.createNewFile()
|
||||||
|
FileUtil.zipFromInternalStorage(
|
||||||
|
File(GpuDriverHelper.driverInstallationPath!!),
|
||||||
|
GpuDriverHelper.driverInstallationPath!!,
|
||||||
|
BufferedOutputStream(driverToSave.outputStream())
|
||||||
|
)
|
||||||
|
_driverList.value.add(Pair(driverToSave.path, currentDriverMetadata))
|
||||||
|
setSelectedDriverIndex(_driverList.value.size - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a user had installed a driver before the config was reworked to be multiplatform,
|
||||||
|
// we have save the path of the previously selected driver to the new setting.
|
||||||
|
if (StringSetting.DRIVER_PATH.getString(true).isEmpty() && selectedDriver > 0 &&
|
||||||
|
StringSetting.DRIVER_PATH.global
|
||||||
|
) {
|
||||||
|
StringSetting.DRIVER_PATH.setString(_driverList.value[selectedDriver].first)
|
||||||
|
NativeConfig.saveGlobalConfig()
|
||||||
|
} else {
|
||||||
|
findSelectedDriver(GpuDriverHelper.customDriverSettingData)
|
||||||
|
}
|
||||||
updateDriverNameForGame(null)
|
updateDriverNameForGame(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reloadDriverData() {
|
fun setSelectedDriverIndex(value: Int) {
|
||||||
_areDriversLoading.value = true
|
if (selectedDriver != -1) {
|
||||||
driverData = GpuDriverHelper.getDrivers()
|
previouslySelectedDriver = selectedDriver
|
||||||
updateDriverList()
|
}
|
||||||
_areDriversLoading.value = false
|
selectedDriver = value
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateDriverList() {
|
fun setNewDriverInstalled(value: Boolean) {
|
||||||
val selectedDriver = GpuDriverHelper.customDriverSettingData
|
_newDriverInstalled.value = value
|
||||||
val newDriverList = mutableListOf(
|
}
|
||||||
Driver(
|
|
||||||
selectedDriver == GpuDriverMetadata(),
|
fun addDriver(driverData: Pair<String, GpuDriverMetadata>) {
|
||||||
YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
val driverIndex = _driverList.value.indexOfFirst { it == driverData }
|
||||||
)
|
if (driverIndex == -1) {
|
||||||
)
|
_driverList.value.add(driverData)
|
||||||
driverData.forEach {
|
setSelectedDriverIndex(_driverList.value.size - 1)
|
||||||
newDriverList.add(it.second.toDriver(it.second == selectedDriver))
|
_selectedDriverTitle.value = driverData.second.name
|
||||||
|
?: YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
||||||
|
} else {
|
||||||
|
setSelectedDriverIndex(driverIndex)
|
||||||
}
|
}
|
||||||
_driverList.value = newDriverList
|
}
|
||||||
|
|
||||||
|
fun removeDriver(driverData: Pair<String, GpuDriverMetadata>) {
|
||||||
|
_driverList.value.remove(driverData)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onOpenDriverManager(game: Game?) {
|
fun onOpenDriverManager(game: Game?) {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
SettingsFile.loadCustomConfig(game)
|
SettingsFile.loadCustomConfig(game)
|
||||||
}
|
}
|
||||||
updateDriverList()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showClearButton(value: Boolean) {
|
val driverPath = StringSetting.DRIVER_PATH.getString()
|
||||||
_showClearButton.value = value
|
if (driverPath.isEmpty()) {
|
||||||
}
|
setSelectedDriverIndex(0)
|
||||||
|
|
||||||
fun onDriverSelected(position: Int) {
|
|
||||||
if (position == 0) {
|
|
||||||
StringSetting.DRIVER_PATH.setString("")
|
|
||||||
} else {
|
} else {
|
||||||
StringSetting.DRIVER_PATH.setString(driverData[position - 1].first)
|
findSelectedDriver(GpuDriverHelper.getMetadataFromZip(File(driverPath)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDriverRemoved(removedPosition: Int, selectedPosition: Int) {
|
|
||||||
driversToDelete.add(driverData[removedPosition - 1].first)
|
|
||||||
driverData.removeAt(removedPosition - 1)
|
|
||||||
onDriverSelected(selectedPosition)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onDriverAdded(driver: Pair<String, GpuDriverMetadata>) {
|
|
||||||
if (driversToDelete.contains(driver.first)) {
|
|
||||||
driversToDelete.remove(driver.first)
|
|
||||||
}
|
|
||||||
driverData.add(driver)
|
|
||||||
onDriverSelected(driverData.size)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onCloseDriverManager(game: Game?) {
|
fun onCloseDriverManager(game: Game?) {
|
||||||
_isDeletingDrivers.value = true
|
_isDeletingDrivers.value = true
|
||||||
|
StringSetting.DRIVER_PATH.setString(driverList.value[selectedDriver].first)
|
||||||
updateDriverNameForGame(game)
|
updateDriverNameForGame(game)
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
NativeConfig.saveGlobalConfig()
|
NativeConfig.saveGlobalConfig()
|
||||||
@ -165,6 +181,20 @@ class DriverViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun findSelectedDriver(currentDriverMetadata: GpuDriverMetadata) {
|
||||||
|
if (driverList.value.size == 1) {
|
||||||
|
setSelectedDriverIndex(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
driverList.value.forEachIndexed { i: Int, driver: Pair<String, GpuDriverMetadata> ->
|
||||||
|
if (driver.second == currentDriverMetadata) {
|
||||||
|
setSelectedDriverIndex(i)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun updateDriverNameForGame(game: Game?) {
|
fun updateDriverNameForGame(game: Game?) {
|
||||||
if (!GpuDriverHelper.supportsCustomDriverLoading()) {
|
if (!GpuDriverHelper.supportsCustomDriverLoading()) {
|
||||||
return
|
return
|
||||||
@ -187,6 +217,7 @@ class DriverViewModel : ViewModel() {
|
|||||||
|
|
||||||
private fun setDriverReady() {
|
private fun setDriverReady() {
|
||||||
_isDriverReady.value = true
|
_isDriverReady.value = true
|
||||||
updateName()
|
_selectedDriverTitle.value = GpuDriverHelper.customDriverSettingData.name
|
||||||
|
?: YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.yuzu.yuzu_emu.model
|
|
||||||
|
|
||||||
interface SelectableItem {
|
|
||||||
var selected: Boolean
|
|
||||||
fun onSelectionStateChanged(selected: Boolean)
|
|
||||||
}
|
|
@ -41,7 +41,6 @@ import org.yuzu.yuzu_emu.fragments.AddGameFolderDialogFragment
|
|||||||
import org.yuzu.yuzu_emu.fragments.IndeterminateProgressDialogFragment
|
import org.yuzu.yuzu_emu.fragments.IndeterminateProgressDialogFragment
|
||||||
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.AddonViewModel
|
import org.yuzu.yuzu_emu.model.AddonViewModel
|
||||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
import org.yuzu.yuzu_emu.model.TaskState
|
import org.yuzu.yuzu_emu.model.TaskState
|
||||||
@ -59,7 +58,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
private val gamesViewModel: GamesViewModel by viewModels()
|
private val gamesViewModel: GamesViewModel by viewModels()
|
||||||
private val taskViewModel: TaskViewModel by viewModels()
|
private val taskViewModel: TaskViewModel by viewModels()
|
||||||
private val addonViewModel: AddonViewModel by viewModels()
|
private val addonViewModel: AddonViewModel by viewModels()
|
||||||
private val driverViewModel: DriverViewModel by viewModels()
|
|
||||||
|
|
||||||
override var themeId: Int = 0
|
override var themeId: Int = 0
|
||||||
|
|
||||||
@ -691,7 +689,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
NativeLibrary.initializeSystem(true)
|
NativeLibrary.initializeSystem(true)
|
||||||
NativeConfig.initializeGlobalConfig()
|
NativeConfig.initializeGlobalConfig()
|
||||||
gamesViewModel.reloadGames(false)
|
gamesViewModel.reloadGames(false)
|
||||||
driverViewModel.reloadDriverData()
|
|
||||||
|
|
||||||
return@newInstance getString(R.string.user_data_import_success)
|
return@newInstance getString(R.string.user_data_import_success)
|
||||||
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
||||||
|
@ -62,6 +62,9 @@ object GpuDriverHelper {
|
|||||||
?.sortedByDescending { it: Pair<String, GpuDriverMetadata> -> it.second.name }
|
?.sortedByDescending { it: Pair<String, GpuDriverMetadata> -> it.second.name }
|
||||||
?.distinct()
|
?.distinct()
|
||||||
?.toMutableList() ?: mutableListOf()
|
?.toMutableList() ?: mutableListOf()
|
||||||
|
|
||||||
|
// TODO: Get system driver information
|
||||||
|
drivers.add(0, Pair("", GpuDriverMetadata()))
|
||||||
return drivers
|
return drivers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.yuzu.yuzu_emu.viewholder
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import androidx.viewbinding.ViewBinding
|
|
||||||
import org.yuzu.yuzu_emu.adapters.AbstractDiffAdapter
|
|
||||||
import org.yuzu.yuzu_emu.adapters.AbstractListAdapter
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [RecyclerView.ViewHolder] meant to work together with a [AbstractDiffAdapter] or a
|
|
||||||
* [AbstractListAdapter] so we can run [bind] on each list item without needing a manual hookup.
|
|
||||||
*/
|
|
||||||
abstract class AbstractViewHolder<Model>(binding: ViewBinding) :
|
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
|
||||||
abstract fun bind(model: Model)
|
|
||||||
}
|
|
@ -45,15 +45,15 @@
|
|||||||
#include "core/frontend/applets/profile_select.h"
|
#include "core/frontend/applets/profile_select.h"
|
||||||
#include "core/frontend/applets/software_keyboard.h"
|
#include "core/frontend/applets/software_keyboard.h"
|
||||||
#include "core/frontend/applets/web_browser.h"
|
#include "core/frontend/applets/web_browser.h"
|
||||||
|
#include "core/hid/emulated_controller.h"
|
||||||
|
#include "core/hid/hid_core.h"
|
||||||
|
#include "core/hid/hid_types.h"
|
||||||
#include "core/hle/service/am/applet_ae.h"
|
#include "core/hle/service/am/applet_ae.h"
|
||||||
#include "core/hle/service/am/applet_oe.h"
|
#include "core/hle/service/am/applet_oe.h"
|
||||||
#include "core/hle/service/am/applets/applets.h"
|
#include "core/hle/service/am/applets/applets.h"
|
||||||
#include "core/hle/service/filesystem/filesystem.h"
|
#include "core/hle/service/filesystem/filesystem.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
#include "frontend_common/config.h"
|
#include "frontend_common/config.h"
|
||||||
#include "hid_core/frontend/emulated_controller.h"
|
|
||||||
#include "hid_core/hid_core.h"
|
|
||||||
#include "hid_core/hid_types.h"
|
|
||||||
#include "jni/android_common/android_common.h"
|
#include "jni/android_common/android_common.h"
|
||||||
#include "jni/id_cache.h"
|
#include "jni/id_cache.h"
|
||||||
#include "jni/native.h"
|
#include "jni/native.h"
|
||||||
@ -770,8 +770,8 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_initializeEmptyUserDirectory(JNIEnv*
|
|||||||
ASSERT(user_id);
|
ASSERT(user_id);
|
||||||
|
|
||||||
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||||
{}, vfs_nand_dir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, 1,
|
EmulationSession::GetInstance().System(), vfs_nand_dir, FileSys::SaveDataSpaceId::NandUser,
|
||||||
user_id->AsU128(), 0);
|
FileSys::SaveDataType::SaveData, 1, user_id->AsU128(), 0);
|
||||||
|
|
||||||
const auto full_path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path);
|
const auto full_path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path);
|
||||||
if (!Common::FS::CreateParentDirs(full_path)) {
|
if (!Common::FS::CreateParentDirs(full_path)) {
|
||||||
@ -878,7 +878,7 @@ jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getSavePath(JNIEnv* env, jobject j
|
|||||||
FileSys::Mode::Read);
|
FileSys::Mode::Read);
|
||||||
|
|
||||||
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||||
{}, vfsNandDir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
|
system, vfsNandDir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
|
||||||
program_id, user_id->AsU128(), 0);
|
program_id, user_id->AsU128(), 0);
|
||||||
return ToJString(env, user_save_data_path);
|
return ToJString(env, user_save_data_path);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_driver_clear"
|
|
||||||
android:icon="@drawable/ic_clear"
|
|
||||||
android:title="@string/clear"
|
|
||||||
app:showAsAction="always" />
|
|
||||||
|
|
||||||
</menu>
|
|
@ -8,7 +8,6 @@
|
|||||||
#include "audio_core/sink/sink_stream.h"
|
#include "audio_core/sink/sink_stream.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/guest_memory.h"
|
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "common/fixed_point.h"
|
#include "common/fixed_point.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/scratch_buffer.h"
|
#include "common/scratch_buffer.h"
|
||||||
#include "core/guest_memory.h"
|
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
namespace AudioCore::Renderer {
|
namespace AudioCore::Renderer {
|
||||||
|
@ -45,7 +45,6 @@ using f32 = float; ///< 32-bit floating point
|
|||||||
using f64 = double; ///< 64-bit floating point
|
using f64 = double; ///< 64-bit floating point
|
||||||
|
|
||||||
using VAddr = u64; ///< Represents a pointer in the userspace virtual address space.
|
using VAddr = u64; ///< Represents a pointer in the userspace virtual address space.
|
||||||
using DAddr = u64; ///< Represents a pointer in the device specific virtual address space.
|
|
||||||
using PAddr = u64; ///< Represents a pointer in the ARM11 physical address space.
|
using PAddr = u64; ///< Represents a pointer in the ARM11 physical address space.
|
||||||
using GPUVAddr = u64; ///< Represents a pointer in the GPU virtual address space.
|
using GPUVAddr = u64; ///< Represents a pointer in the GPU virtual address space.
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "common/page_table.h"
|
#include "common/page_table.h"
|
||||||
#include "common/scope_exit.h"
|
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
@ -12,10 +11,29 @@ PageTable::~PageTable() noexcept = default;
|
|||||||
|
|
||||||
bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context,
|
bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context,
|
||||||
Common::ProcessAddress address) const {
|
Common::ProcessAddress address) const {
|
||||||
out_context->next_offset = GetInteger(address);
|
// Setup invalid defaults.
|
||||||
out_context->next_page = address / page_size;
|
out_entry->phys_addr = 0;
|
||||||
|
out_entry->block_size = page_size;
|
||||||
|
out_context->next_page = 0;
|
||||||
|
|
||||||
return this->ContinueTraversal(out_entry, out_context);
|
// Validate that we can read the actual entry.
|
||||||
|
const auto page = address / page_size;
|
||||||
|
if (page >= backing_addr.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate that the entry is mapped.
|
||||||
|
const auto phys_addr = backing_addr[page];
|
||||||
|
if (phys_addr == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate the results.
|
||||||
|
out_entry->phys_addr = phys_addr + GetInteger(address);
|
||||||
|
out_context->next_page = page + 1;
|
||||||
|
out_context->next_offset = GetInteger(address) + page_size;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const {
|
bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const {
|
||||||
@ -23,12 +41,6 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
|
|||||||
out_entry->phys_addr = 0;
|
out_entry->phys_addr = 0;
|
||||||
out_entry->block_size = page_size;
|
out_entry->block_size = page_size;
|
||||||
|
|
||||||
// Regardless of whether the page was mapped, advance on exit.
|
|
||||||
SCOPE_EXIT({
|
|
||||||
context->next_page += 1;
|
|
||||||
context->next_offset += page_size;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Validate that we can read the actual entry.
|
// Validate that we can read the actual entry.
|
||||||
const auto page = context->next_page;
|
const auto page = context->next_page;
|
||||||
if (page >= backing_addr.size()) {
|
if (page >= backing_addr.size()) {
|
||||||
@ -43,6 +55,8 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
|
|||||||
|
|
||||||
// Populate the results.
|
// Populate the results.
|
||||||
out_entry->phys_addr = phys_addr + context->next_offset;
|
out_entry->phys_addr = phys_addr + context->next_offset;
|
||||||
|
context->next_page = page + 1;
|
||||||
|
context->next_offset += page_size;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ add_library(core STATIC
|
|||||||
debugger/gdbstub_arch.h
|
debugger/gdbstub_arch.h
|
||||||
debugger/gdbstub.cpp
|
debugger/gdbstub.cpp
|
||||||
debugger/gdbstub.h
|
debugger/gdbstub.h
|
||||||
device_memory_manager.h
|
|
||||||
device_memory_manager.inc
|
|
||||||
device_memory.cpp
|
device_memory.cpp
|
||||||
device_memory.h
|
device_memory.h
|
||||||
file_sys/fssystem/fs_i_storage.h
|
file_sys/fssystem/fs_i_storage.h
|
||||||
@ -185,6 +183,22 @@ add_library(core STATIC
|
|||||||
frontend/framebuffer_layout.cpp
|
frontend/framebuffer_layout.cpp
|
||||||
frontend/framebuffer_layout.h
|
frontend/framebuffer_layout.h
|
||||||
frontend/graphics_context.h
|
frontend/graphics_context.h
|
||||||
|
hid/emulated_console.cpp
|
||||||
|
hid/emulated_console.h
|
||||||
|
hid/emulated_controller.cpp
|
||||||
|
hid/emulated_controller.h
|
||||||
|
hid/emulated_devices.cpp
|
||||||
|
hid/emulated_devices.h
|
||||||
|
hid/hid_core.cpp
|
||||||
|
hid/hid_core.h
|
||||||
|
hid/hid_types.h
|
||||||
|
hid/input_converter.cpp
|
||||||
|
hid/input_converter.h
|
||||||
|
hid/input_interpreter.cpp
|
||||||
|
hid/input_interpreter.h
|
||||||
|
hid/irs_types.h
|
||||||
|
hid/motion_input.cpp
|
||||||
|
hid/motion_input.h
|
||||||
hle/api_version.h
|
hle/api_version.h
|
||||||
hle/ipc.h
|
hle/ipc.h
|
||||||
hle/kernel/board/nintendo/nx/k_memory_layout.cpp
|
hle/kernel/board/nintendo/nx/k_memory_layout.cpp
|
||||||
@ -492,10 +506,6 @@ add_library(core STATIC
|
|||||||
hle/service/filesystem/fsp_pr.h
|
hle/service/filesystem/fsp_pr.h
|
||||||
hle/service/filesystem/fsp_srv.cpp
|
hle/service/filesystem/fsp_srv.cpp
|
||||||
hle/service/filesystem/fsp_srv.h
|
hle/service/filesystem/fsp_srv.h
|
||||||
hle/service/filesystem/romfs_controller.cpp
|
|
||||||
hle/service/filesystem/romfs_controller.h
|
|
||||||
hle/service/filesystem/save_data_controller.cpp
|
|
||||||
hle/service/filesystem/save_data_controller.h
|
|
||||||
hle/service/fgm/fgm.cpp
|
hle/service/fgm/fgm.cpp
|
||||||
hle/service/fgm/fgm.h
|
hle/service/fgm/fgm.h
|
||||||
hle/service/friend/friend.cpp
|
hle/service/friend/friend.cpp
|
||||||
@ -521,16 +531,94 @@ add_library(core STATIC
|
|||||||
hle/service/hid/hid.h
|
hle/service/hid/hid.h
|
||||||
hle/service/hid/hid_debug_server.cpp
|
hle/service/hid/hid_debug_server.cpp
|
||||||
hle/service/hid/hid_debug_server.h
|
hle/service/hid/hid_debug_server.h
|
||||||
|
hle/service/hid/hid_firmware_settings.cpp
|
||||||
|
hle/service/hid/hid_firmware_settings.h
|
||||||
hle/service/hid/hid_server.cpp
|
hle/service/hid/hid_server.cpp
|
||||||
hle/service/hid/hid_server.h
|
hle/service/hid/hid_server.h
|
||||||
hle/service/hid/hid_system_server.cpp
|
hle/service/hid/hid_system_server.cpp
|
||||||
hle/service/hid/hid_system_server.h
|
hle/service/hid/hid_system_server.h
|
||||||
|
hle/service/hid/hid_util.h
|
||||||
hle/service/hid/hidbus.cpp
|
hle/service/hid/hidbus.cpp
|
||||||
hle/service/hid/hidbus.h
|
hle/service/hid/hidbus.h
|
||||||
hle/service/hid/irs.cpp
|
hle/service/hid/irs.cpp
|
||||||
hle/service/hid/irs.h
|
hle/service/hid/irs.h
|
||||||
|
hle/service/hid/irs_ring_lifo.h
|
||||||
|
hle/service/hid/resource_manager.cpp
|
||||||
|
hle/service/hid/resource_manager.h
|
||||||
|
hle/service/hid/ring_lifo.h
|
||||||
hle/service/hid/xcd.cpp
|
hle/service/hid/xcd.cpp
|
||||||
hle/service/hid/xcd.h
|
hle/service/hid/xcd.h
|
||||||
|
hle/service/hid/errors.h
|
||||||
|
hle/service/hid/controllers/npad/npad_data.cpp
|
||||||
|
hle/service/hid/controllers/npad/npad_data.h
|
||||||
|
hle/service/hid/controllers/npad/npad_resource.cpp
|
||||||
|
hle/service/hid/controllers/npad/npad_resource.h
|
||||||
|
hle/service/hid/controllers/types/debug_pad_types.h
|
||||||
|
hle/service/hid/controllers/types/keyboard_types.h
|
||||||
|
hle/service/hid/controllers/types/mouse_types.h
|
||||||
|
hle/service/hid/controllers/types/npad_types.h
|
||||||
|
hle/service/hid/controllers/types/shared_memory_format.h
|
||||||
|
hle/service/hid/controllers/types/touch_types.h
|
||||||
|
hle/service/hid/controllers/applet_resource.cpp
|
||||||
|
hle/service/hid/controllers/applet_resource.h
|
||||||
|
hle/service/hid/controllers/capture_button.cpp
|
||||||
|
hle/service/hid/controllers/capture_button.h
|
||||||
|
hle/service/hid/controllers/console_six_axis.cpp
|
||||||
|
hle/service/hid/controllers/console_six_axis.h
|
||||||
|
hle/service/hid/controllers/controller_base.cpp
|
||||||
|
hle/service/hid/controllers/controller_base.h
|
||||||
|
hle/service/hid/controllers/debug_mouse.cpp
|
||||||
|
hle/service/hid/controllers/debug_mouse.h
|
||||||
|
hle/service/hid/controllers/debug_pad.cpp
|
||||||
|
hle/service/hid/controllers/debug_pad.h
|
||||||
|
hle/service/hid/controllers/digitizer.cpp
|
||||||
|
hle/service/hid/controllers/digitizer.h
|
||||||
|
hle/service/hid/controllers/gesture.cpp
|
||||||
|
hle/service/hid/controllers/gesture.h
|
||||||
|
hle/service/hid/controllers/home_button.cpp
|
||||||
|
hle/service/hid/controllers/home_button.h
|
||||||
|
hle/service/hid/controllers/keyboard.cpp
|
||||||
|
hle/service/hid/controllers/keyboard.h
|
||||||
|
hle/service/hid/controllers/mouse.cpp
|
||||||
|
hle/service/hid/controllers/mouse.h
|
||||||
|
hle/service/hid/controllers/npad.cpp
|
||||||
|
hle/service/hid/controllers/npad.h
|
||||||
|
hle/service/hid/controllers/palma.cpp
|
||||||
|
hle/service/hid/controllers/palma.h
|
||||||
|
hle/service/hid/controllers/seven_six_axis.cpp
|
||||||
|
hle/service/hid/controllers/seven_six_axis.h
|
||||||
|
hle/service/hid/controllers/shared_memory_holder.cpp
|
||||||
|
hle/service/hid/controllers/shared_memory_holder.h
|
||||||
|
hle/service/hid/controllers/six_axis.cpp
|
||||||
|
hle/service/hid/controllers/six_axis.h
|
||||||
|
hle/service/hid/controllers/sleep_button.cpp
|
||||||
|
hle/service/hid/controllers/sleep_button.h
|
||||||
|
hle/service/hid/controllers/touchscreen.cpp
|
||||||
|
hle/service/hid/controllers/touchscreen.h
|
||||||
|
hle/service/hid/controllers/unique_pad.cpp
|
||||||
|
hle/service/hid/controllers/unique_pad.h
|
||||||
|
hle/service/hid/hidbus/hidbus_base.cpp
|
||||||
|
hle/service/hid/hidbus/hidbus_base.h
|
||||||
|
hle/service/hid/hidbus/ringcon.cpp
|
||||||
|
hle/service/hid/hidbus/ringcon.h
|
||||||
|
hle/service/hid/hidbus/starlink.cpp
|
||||||
|
hle/service/hid/hidbus/starlink.h
|
||||||
|
hle/service/hid/hidbus/stubbed.cpp
|
||||||
|
hle/service/hid/hidbus/stubbed.h
|
||||||
|
hle/service/hid/irsensor/clustering_processor.cpp
|
||||||
|
hle/service/hid/irsensor/clustering_processor.h
|
||||||
|
hle/service/hid/irsensor/image_transfer_processor.cpp
|
||||||
|
hle/service/hid/irsensor/image_transfer_processor.h
|
||||||
|
hle/service/hid/irsensor/ir_led_processor.cpp
|
||||||
|
hle/service/hid/irsensor/ir_led_processor.h
|
||||||
|
hle/service/hid/irsensor/moment_processor.cpp
|
||||||
|
hle/service/hid/irsensor/moment_processor.h
|
||||||
|
hle/service/hid/irsensor/pointing_processor.cpp
|
||||||
|
hle/service/hid/irsensor/pointing_processor.h
|
||||||
|
hle/service/hid/irsensor/processor_base.cpp
|
||||||
|
hle/service/hid/irsensor/processor_base.h
|
||||||
|
hle/service/hid/irsensor/tera_plugin_processor.cpp
|
||||||
|
hle/service/hid/irsensor/tera_plugin_processor.h
|
||||||
hle/service/lbl/lbl.cpp
|
hle/service/lbl/lbl.cpp
|
||||||
hle/service/lbl/lbl.h
|
hle/service/lbl/lbl.h
|
||||||
hle/service/ldn/lan_discovery.cpp
|
hle/service/ldn/lan_discovery.cpp
|
||||||
@ -611,8 +699,6 @@ add_library(core STATIC
|
|||||||
hle/service/ns/pdm_qry.h
|
hle/service/ns/pdm_qry.h
|
||||||
hle/service/nvdrv/core/container.cpp
|
hle/service/nvdrv/core/container.cpp
|
||||||
hle/service/nvdrv/core/container.h
|
hle/service/nvdrv/core/container.h
|
||||||
hle/service/nvdrv/core/heap_mapper.cpp
|
|
||||||
hle/service/nvdrv/core/heap_mapper.h
|
|
||||||
hle/service/nvdrv/core/nvmap.cpp
|
hle/service/nvdrv/core/nvmap.cpp
|
||||||
hle/service/nvdrv/core/nvmap.h
|
hle/service/nvdrv/core/nvmap.h
|
||||||
hle/service/nvdrv/core/syncpoint_manager.cpp
|
hle/service/nvdrv/core/syncpoint_manager.cpp
|
||||||
@ -716,24 +802,24 @@ add_library(core STATIC
|
|||||||
hle/service/server_manager.h
|
hle/service/server_manager.h
|
||||||
hle/service/service.cpp
|
hle/service/service.cpp
|
||||||
hle/service/service.h
|
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.cpp
|
||||||
hle/service/set/appln_settings.h
|
hle/service/set/appln_settings.h
|
||||||
hle/service/set/device_settings.cpp
|
hle/service/set/device_settings.cpp
|
||||||
hle/service/set/device_settings.h
|
hle/service/set/device_settings.h
|
||||||
hle/service/set/factory_settings_server.cpp
|
|
||||||
hle/service/set/factory_settings_server.h
|
|
||||||
hle/service/set/firmware_debug_settings_server.cpp
|
|
||||||
hle/service/set/firmware_debug_settings_server.h
|
|
||||||
hle/service/set/private_settings.cpp
|
hle/service/set/private_settings.cpp
|
||||||
hle/service/set/private_settings.h
|
hle/service/set/private_settings.h
|
||||||
|
hle/service/set/set_cal.cpp
|
||||||
|
hle/service/set/set_cal.h
|
||||||
|
hle/service/set/set_fd.cpp
|
||||||
|
hle/service/set/set_fd.h
|
||||||
|
hle/service/set/set_sys.cpp
|
||||||
|
hle/service/set/set_sys.h
|
||||||
hle/service/set/settings.cpp
|
hle/service/set/settings.cpp
|
||||||
hle/service/set/settings.h
|
hle/service/set/settings.h
|
||||||
hle/service/set/settings_server.cpp
|
|
||||||
hle/service/set/settings_server.h
|
|
||||||
hle/service/set/system_settings.cpp
|
hle/service/set/system_settings.cpp
|
||||||
hle/service/set/system_settings.h
|
hle/service/set/system_settings.h
|
||||||
hle/service/set/system_settings_server.cpp
|
|
||||||
hle/service/set/system_settings_server.h
|
|
||||||
hle/service/sm/sm.cpp
|
hle/service/sm/sm.cpp
|
||||||
hle/service/sm/sm.h
|
hle/service/sm/sm.h
|
||||||
hle/service/sm/sm_controller.cpp
|
hle/service/sm/sm_controller.cpp
|
||||||
@ -873,7 +959,7 @@ endif()
|
|||||||
|
|
||||||
create_target_directory_groups(core)
|
create_target_directory_groups(core)
|
||||||
|
|
||||||
target_link_libraries(core PUBLIC common PRIVATE audio_core hid_core network video_core nx_tzdb)
|
target_link_libraries(core PUBLIC common PRIVATE audio_core network video_core nx_tzdb)
|
||||||
target_link_libraries(core PUBLIC Boost::headers PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls RenderDoc::API)
|
target_link_libraries(core PUBLIC Boost::headers PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls RenderDoc::API)
|
||||||
if (MINGW)
|
if (MINGW)
|
||||||
target_link_libraries(core PRIVATE ${MSWSOCK_LIBRARY})
|
target_link_libraries(core PRIVATE ${MSWSOCK_LIBRARY})
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include "core/file_sys/savedata_factory.h"
|
#include "core/file_sys/savedata_factory.h"
|
||||||
#include "core/file_sys/vfs_concat.h"
|
#include "core/file_sys/vfs_concat.h"
|
||||||
#include "core/file_sys/vfs_real.h"
|
#include "core/file_sys/vfs_real.h"
|
||||||
#include "core/gpu_dirty_memory_manager.h"
|
#include "core/hid/hid_core.h"
|
||||||
#include "core/hle/kernel/k_memory_manager.h"
|
#include "core/hle/kernel/k_memory_manager.h"
|
||||||
#include "core/hle/kernel/k_process.h"
|
#include "core/hle/kernel/k_process.h"
|
||||||
#include "core/hle/kernel/k_resource_limit.h"
|
#include "core/hle/kernel/k_resource_limit.h"
|
||||||
@ -52,7 +52,6 @@
|
|||||||
#include "core/telemetry_session.h"
|
#include "core/telemetry_session.h"
|
||||||
#include "core/tools/freezer.h"
|
#include "core/tools/freezer.h"
|
||||||
#include "core/tools/renderdoc.h"
|
#include "core/tools/renderdoc.h"
|
||||||
#include "hid_core/hid_core.h"
|
|
||||||
#include "network/network.h"
|
#include "network/network.h"
|
||||||
#include "video_core/host1x/host1x.h"
|
#include "video_core/host1x/host1x.h"
|
||||||
#include "video_core/renderer_base.h"
|
#include "video_core/renderer_base.h"
|
||||||
@ -414,7 +413,6 @@ struct System::Impl {
|
|||||||
kernel.ShutdownCores();
|
kernel.ShutdownCores();
|
||||||
services.reset();
|
services.reset();
|
||||||
service_manager.reset();
|
service_manager.reset();
|
||||||
fs_controller.Reset();
|
|
||||||
cheat_engine.reset();
|
cheat_engine.reset();
|
||||||
telemetry_session.reset();
|
telemetry_session.reset();
|
||||||
time_manager.Shutdown();
|
time_manager.Shutdown();
|
||||||
@ -566,9 +564,6 @@ struct System::Impl {
|
|||||||
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
|
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
|
||||||
std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{};
|
std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{};
|
||||||
|
|
||||||
std::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES>
|
|
||||||
gpu_dirty_memory_managers;
|
|
||||||
|
|
||||||
std::deque<std::vector<u8>> user_channel;
|
std::deque<std::vector<u8>> user_channel;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -655,14 +650,8 @@ size_t System::GetCurrentHostThreadID() const {
|
|||||||
return impl->kernel.GetCurrentHostThreadID();
|
return impl->kernel.GetCurrentHostThreadID();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::span<GPUDirtyMemoryManager> System::GetGPUDirtyMemoryManager() {
|
void System::GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback) {
|
||||||
return impl->gpu_dirty_memory_managers;
|
return this->ApplicationProcess()->GatherGPUDirtyMemory(callback);
|
||||||
}
|
|
||||||
|
|
||||||
void System::GatherGPUDirtyMemory(std::function<void(PAddr, size_t)>& callback) {
|
|
||||||
for (auto& manager : impl->gpu_dirty_memory_managers) {
|
|
||||||
manager.Gather(callback);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfStatsResults System::GetAndResetPerfStats() {
|
PerfStatsResults System::GetAndResetPerfStats() {
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <span>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -117,7 +116,6 @@ class CpuManager;
|
|||||||
class Debugger;
|
class Debugger;
|
||||||
class DeviceMemory;
|
class DeviceMemory;
|
||||||
class ExclusiveMonitor;
|
class ExclusiveMonitor;
|
||||||
class GPUDirtyMemoryManager;
|
|
||||||
class PerfStats;
|
class PerfStats;
|
||||||
class Reporter;
|
class Reporter;
|
||||||
class SpeedLimiter;
|
class SpeedLimiter;
|
||||||
@ -226,9 +224,7 @@ public:
|
|||||||
/// Prepare the core emulation for a reschedule
|
/// Prepare the core emulation for a reschedule
|
||||||
void PrepareReschedule(u32 core_index);
|
void PrepareReschedule(u32 core_index);
|
||||||
|
|
||||||
std::span<GPUDirtyMemoryManager> GetGPUDirtyMemoryManager();
|
void GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback);
|
||||||
|
|
||||||
void GatherGPUDirtyMemory(std::function<void(PAddr, size_t)>& callback);
|
|
||||||
|
|
||||||
[[nodiscard]] size_t GetCurrentHostThreadID() const;
|
[[nodiscard]] size_t GetCurrentHostThreadID() const;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public:
|
|||||||
return [this] { ShutdownThreadFunction(); };
|
return [this] { ShutdownThreadFunction(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreemptSingleCore(bool from_running_environment = true);
|
void PreemptSingleCore(bool from_running_enviroment = true);
|
||||||
|
|
||||||
std::size_t CurrentCore() const {
|
std::size_t CurrentCore() const {
|
||||||
return current_core.load();
|
return current_core.load();
|
||||||
|
@ -114,7 +114,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KThread* GetActiveThread() override {
|
Kernel::KThread* GetActiveThread() override {
|
||||||
return state->active_thread.GetPointerUnsafe();
|
return state->active_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -147,14 +147,11 @@ private:
|
|||||||
|
|
||||||
std::scoped_lock lk{connection_lock};
|
std::scoped_lock lk{connection_lock};
|
||||||
|
|
||||||
// Find the process we are going to debug.
|
|
||||||
SetDebugProcess();
|
|
||||||
|
|
||||||
// Ensure everything is stopped.
|
// Ensure everything is stopped.
|
||||||
PauseEmulation();
|
PauseEmulation();
|
||||||
|
|
||||||
// Set up the new frontend.
|
// Set up the new frontend.
|
||||||
frontend = std::make_unique<GDBStub>(*this, system, debug_process.GetPointerUnsafe());
|
frontend = std::make_unique<GDBStub>(*this, system);
|
||||||
|
|
||||||
// Set the new state. This will tear down any existing state.
|
// Set the new state. This will tear down any existing state.
|
||||||
state = ConnectionState{
|
state = ConnectionState{
|
||||||
@ -197,20 +194,15 @@ private:
|
|||||||
UpdateActiveThread();
|
UpdateActiveThread();
|
||||||
|
|
||||||
if (state->info.type == SignalType::Watchpoint) {
|
if (state->info.type == SignalType::Watchpoint) {
|
||||||
frontend->Watchpoint(std::addressof(*state->active_thread),
|
frontend->Watchpoint(state->active_thread, *state->info.watchpoint);
|
||||||
*state->info.watchpoint);
|
|
||||||
} else {
|
} else {
|
||||||
frontend->Stopped(std::addressof(*state->active_thread));
|
frontend->Stopped(state->active_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SignalType::ShuttingDown:
|
case SignalType::ShuttingDown:
|
||||||
frontend->ShuttingDown();
|
frontend->ShuttingDown();
|
||||||
|
|
||||||
// Release members.
|
|
||||||
state->active_thread.Reset(nullptr);
|
|
||||||
debug_process.Reset(nullptr);
|
|
||||||
|
|
||||||
// Wait for emulation to shut down gracefully now.
|
// Wait for emulation to shut down gracefully now.
|
||||||
state->signal_pipe.close();
|
state->signal_pipe.close();
|
||||||
state->client_socket.shutdown(boost::asio::socket_base::shutdown_both);
|
state->client_socket.shutdown(boost::asio::socket_base::shutdown_both);
|
||||||
@ -230,7 +222,7 @@ private:
|
|||||||
stopped = true;
|
stopped = true;
|
||||||
PauseEmulation();
|
PauseEmulation();
|
||||||
UpdateActiveThread();
|
UpdateActiveThread();
|
||||||
frontend->Stopped(state->active_thread.GetPointerUnsafe());
|
frontend->Stopped(state->active_thread);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DebuggerAction::Continue:
|
case DebuggerAction::Continue:
|
||||||
@ -240,7 +232,7 @@ private:
|
|||||||
MarkResumed([&] {
|
MarkResumed([&] {
|
||||||
state->active_thread->SetStepState(Kernel::StepState::StepPending);
|
state->active_thread->SetStepState(Kernel::StepState::StepPending);
|
||||||
state->active_thread->Resume(Kernel::SuspendType::Debug);
|
state->active_thread->Resume(Kernel::SuspendType::Debug);
|
||||||
ResumeEmulation(state->active_thread.GetPointerUnsafe());
|
ResumeEmulation(state->active_thread);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case DebuggerAction::StepThreadLocked: {
|
case DebuggerAction::StepThreadLocked: {
|
||||||
@ -263,7 +255,6 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PauseEmulation() {
|
void PauseEmulation() {
|
||||||
Kernel::KScopedLightLock ll{debug_process->GetListLock()};
|
|
||||||
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
||||||
|
|
||||||
// Put all threads to sleep on next scheduler round.
|
// Put all threads to sleep on next scheduler round.
|
||||||
@ -273,9 +264,6 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ResumeEmulation(Kernel::KThread* except = nullptr) {
|
void ResumeEmulation(Kernel::KThread* except = nullptr) {
|
||||||
Kernel::KScopedLightLock ll{debug_process->GetListLock()};
|
|
||||||
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
|
||||||
|
|
||||||
// Wake up all threads.
|
// Wake up all threads.
|
||||||
for (auto& thread : ThreadList()) {
|
for (auto& thread : ThreadList()) {
|
||||||
if (std::addressof(thread) == except) {
|
if (std::addressof(thread) == except) {
|
||||||
@ -289,16 +277,15 @@ private:
|
|||||||
|
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void MarkResumed(Callback&& cb) {
|
void MarkResumed(Callback&& cb) {
|
||||||
|
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
||||||
stopped = false;
|
stopped = false;
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateActiveThread() {
|
void UpdateActiveThread() {
|
||||||
Kernel::KScopedLightLock ll{debug_process->GetListLock()};
|
|
||||||
|
|
||||||
auto& threads{ThreadList()};
|
auto& threads{ThreadList()};
|
||||||
for (auto& thread : threads) {
|
for (auto& thread : threads) {
|
||||||
if (std::addressof(thread) == state->active_thread.GetPointerUnsafe()) {
|
if (std::addressof(thread) == state->active_thread) {
|
||||||
// Thread is still alive, no need to update.
|
// Thread is still alive, no need to update.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -306,18 +293,12 @@ private:
|
|||||||
state->active_thread = std::addressof(threads.front());
|
state->active_thread = std::addressof(threads.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
void SetDebugProcess() {
|
|
||||||
debug_process = std::move(system.Kernel().GetProcessList().back());
|
|
||||||
}
|
|
||||||
|
|
||||||
Kernel::KProcess::ThreadList& ThreadList() {
|
Kernel::KProcess::ThreadList& ThreadList() {
|
||||||
return debug_process->GetThreadList();
|
return system.ApplicationProcess()->GetThreadList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
System& system;
|
System& system;
|
||||||
Kernel::KScopedAutoObject<Kernel::KProcess> debug_process;
|
|
||||||
std::unique_ptr<DebuggerFrontend> frontend;
|
std::unique_ptr<DebuggerFrontend> frontend;
|
||||||
|
|
||||||
boost::asio::io_context io_context;
|
boost::asio::io_context io_context;
|
||||||
@ -329,7 +310,7 @@ private:
|
|||||||
boost::process::async_pipe signal_pipe;
|
boost::process::async_pipe signal_pipe;
|
||||||
|
|
||||||
SignalInfo info;
|
SignalInfo info;
|
||||||
Kernel::KScopedAutoObject<Kernel::KThread> active_thread;
|
Kernel::KThread* active_thread;
|
||||||
std::array<u8, 4096> client_data;
|
std::array<u8, 4096> client_data;
|
||||||
bool pipe_data;
|
bool pipe_data;
|
||||||
};
|
};
|
||||||
|
@ -108,9 +108,9 @@ static std::string EscapeXML(std::string_view data) {
|
|||||||
return escaped;
|
return escaped;
|
||||||
}
|
}
|
||||||
|
|
||||||
GDBStub::GDBStub(DebuggerBackend& backend_, Core::System& system_, Kernel::KProcess* debug_process_)
|
GDBStub::GDBStub(DebuggerBackend& backend_, Core::System& system_)
|
||||||
: DebuggerFrontend(backend_), system{system_}, debug_process{debug_process_} {
|
: DebuggerFrontend(backend_), system{system_} {
|
||||||
if (GetProcess()->Is64Bit()) {
|
if (system.ApplicationProcess()->Is64Bit()) {
|
||||||
arch = std::make_unique<GDBStubA64>();
|
arch = std::make_unique<GDBStubA64>();
|
||||||
} else {
|
} else {
|
||||||
arch = std::make_unique<GDBStubA32>();
|
arch = std::make_unique<GDBStubA32>();
|
||||||
@ -276,7 +276,7 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
|
|||||||
const size_t size{static_cast<size_t>(strtoll(command.data() + sep, nullptr, 16))};
|
const size_t size{static_cast<size_t>(strtoll(command.data() + sep, nullptr, 16))};
|
||||||
|
|
||||||
std::vector<u8> mem(size);
|
std::vector<u8> mem(size);
|
||||||
if (GetMemory().ReadBlock(addr, mem.data(), size)) {
|
if (system.ApplicationMemory().ReadBlock(addr, mem.data(), size)) {
|
||||||
// Restore any bytes belonging to replaced instructions.
|
// Restore any bytes belonging to replaced instructions.
|
||||||
auto it = replaced_instructions.lower_bound(addr);
|
auto it = replaced_instructions.lower_bound(addr);
|
||||||
for (; it != replaced_instructions.end() && it->first < addr + size; it++) {
|
for (; it != replaced_instructions.end() && it->first < addr + size; it++) {
|
||||||
@ -310,8 +310,8 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
|
|||||||
const auto mem_substr{std::string_view(command).substr(mem_sep)};
|
const auto mem_substr{std::string_view(command).substr(mem_sep)};
|
||||||
const auto mem{Common::HexStringToVector(mem_substr, false)};
|
const auto mem{Common::HexStringToVector(mem_substr, false)};
|
||||||
|
|
||||||
if (GetMemory().WriteBlock(addr, mem.data(), size)) {
|
if (system.ApplicationMemory().WriteBlock(addr, mem.data(), size)) {
|
||||||
Core::InvalidateInstructionCacheRange(GetProcess(), addr, size);
|
Core::InvalidateInstructionCacheRange(system.ApplicationProcess(), addr, size);
|
||||||
SendReply(GDB_STUB_REPLY_OK);
|
SendReply(GDB_STUB_REPLY_OK);
|
||||||
} else {
|
} else {
|
||||||
SendReply(GDB_STUB_REPLY_ERR);
|
SendReply(GDB_STUB_REPLY_ERR);
|
||||||
@ -353,7 +353,7 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||||||
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
||||||
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
||||||
|
|
||||||
if (!GetMemory().IsValidVirtualAddressRange(addr, size)) {
|
if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||||
SendReply(GDB_STUB_REPLY_ERR);
|
SendReply(GDB_STUB_REPLY_ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -362,20 +362,22 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BreakpointType::Software:
|
case BreakpointType::Software:
|
||||||
replaced_instructions[addr] = GetMemory().Read32(addr);
|
replaced_instructions[addr] = system.ApplicationMemory().Read32(addr);
|
||||||
GetMemory().Write32(addr, arch->BreakpointInstruction());
|
system.ApplicationMemory().Write32(addr, arch->BreakpointInstruction());
|
||||||
Core::InvalidateInstructionCacheRange(GetProcess(), addr, sizeof(u32));
|
Core::InvalidateInstructionCacheRange(system.ApplicationProcess(), addr, sizeof(u32));
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
case BreakpointType::WriteWatch:
|
case BreakpointType::WriteWatch:
|
||||||
success = GetProcess()->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
|
||||||
|
Kernel::DebugWatchpointType::Write);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::ReadWatch:
|
case BreakpointType::ReadWatch:
|
||||||
success = GetProcess()->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
|
||||||
|
Kernel::DebugWatchpointType::Read);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::AccessWatch:
|
case BreakpointType::AccessWatch:
|
||||||
success =
|
success = system.ApplicationProcess()->InsertWatchpoint(
|
||||||
GetProcess()->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::Hardware:
|
case BreakpointType::Hardware:
|
||||||
default:
|
default:
|
||||||
@ -398,7 +400,7 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
|
|||||||
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
||||||
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
||||||
|
|
||||||
if (!GetMemory().IsValidVirtualAddressRange(addr, size)) {
|
if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||||
SendReply(GDB_STUB_REPLY_ERR);
|
SendReply(GDB_STUB_REPLY_ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -409,22 +411,24 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
|
|||||||
case BreakpointType::Software: {
|
case BreakpointType::Software: {
|
||||||
const auto orig_insn{replaced_instructions.find(addr)};
|
const auto orig_insn{replaced_instructions.find(addr)};
|
||||||
if (orig_insn != replaced_instructions.end()) {
|
if (orig_insn != replaced_instructions.end()) {
|
||||||
GetMemory().Write32(addr, orig_insn->second);
|
system.ApplicationMemory().Write32(addr, orig_insn->second);
|
||||||
Core::InvalidateInstructionCacheRange(GetProcess(), addr, sizeof(u32));
|
Core::InvalidateInstructionCacheRange(system.ApplicationProcess(), addr, sizeof(u32));
|
||||||
replaced_instructions.erase(addr);
|
replaced_instructions.erase(addr);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BreakpointType::WriteWatch:
|
case BreakpointType::WriteWatch:
|
||||||
success = GetProcess()->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
|
||||||
|
Kernel::DebugWatchpointType::Write);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::ReadWatch:
|
case BreakpointType::ReadWatch:
|
||||||
success = GetProcess()->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
|
||||||
|
Kernel::DebugWatchpointType::Read);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::AccessWatch:
|
case BreakpointType::AccessWatch:
|
||||||
success =
|
success = system.ApplicationProcess()->RemoveWatchpoint(
|
||||||
GetProcess()->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::Hardware:
|
case BreakpointType::Hardware:
|
||||||
default:
|
default:
|
||||||
@ -462,10 +466,10 @@ void GDBStub::HandleQuery(std::string_view command) {
|
|||||||
const auto target_xml{arch->GetTargetXML()};
|
const auto target_xml{arch->GetTargetXML()};
|
||||||
SendReply(PaginateBuffer(target_xml, command.substr(30)));
|
SendReply(PaginateBuffer(target_xml, command.substr(30)));
|
||||||
} else if (command.starts_with("Offsets")) {
|
} else if (command.starts_with("Offsets")) {
|
||||||
const auto main_offset = Core::FindMainModuleEntrypoint(GetProcess());
|
const auto main_offset = Core::FindMainModuleEntrypoint(system.ApplicationProcess());
|
||||||
SendReply(fmt::format("TextSeg={:x}", GetInteger(main_offset)));
|
SendReply(fmt::format("TextSeg={:x}", GetInteger(main_offset)));
|
||||||
} else if (command.starts_with("Xfer:libraries:read::")) {
|
} else if (command.starts_with("Xfer:libraries:read::")) {
|
||||||
auto modules = Core::FindModules(GetProcess());
|
auto modules = Core::FindModules(system.ApplicationProcess());
|
||||||
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
buffer += R"(<?xml version="1.0"?>)";
|
buffer += R"(<?xml version="1.0"?>)";
|
||||||
@ -479,7 +483,7 @@ void GDBStub::HandleQuery(std::string_view command) {
|
|||||||
SendReply(PaginateBuffer(buffer, command.substr(21)));
|
SendReply(PaginateBuffer(buffer, command.substr(21)));
|
||||||
} else if (command.starts_with("fThreadInfo")) {
|
} else if (command.starts_with("fThreadInfo")) {
|
||||||
// beginning of list
|
// beginning of list
|
||||||
const auto& threads = GetProcess()->GetThreadList();
|
const auto& threads = system.ApplicationProcess()->GetThreadList();
|
||||||
std::vector<std::string> thread_ids;
|
std::vector<std::string> thread_ids;
|
||||||
for (const auto& thread : threads) {
|
for (const auto& thread : threads) {
|
||||||
thread_ids.push_back(fmt::format("{:x}", thread.GetThreadId()));
|
thread_ids.push_back(fmt::format("{:x}", thread.GetThreadId()));
|
||||||
@ -493,7 +497,7 @@ void GDBStub::HandleQuery(std::string_view command) {
|
|||||||
buffer += R"(<?xml version="1.0"?>)";
|
buffer += R"(<?xml version="1.0"?>)";
|
||||||
buffer += "<threads>";
|
buffer += "<threads>";
|
||||||
|
|
||||||
const auto& threads = GetProcess()->GetThreadList();
|
const auto& threads = system.ApplicationProcess()->GetThreadList();
|
||||||
for (const auto& thread : threads) {
|
for (const auto& thread : threads) {
|
||||||
auto thread_name{Core::GetThreadName(&thread)};
|
auto thread_name{Core::GetThreadName(&thread)};
|
||||||
if (!thread_name) {
|
if (!thread_name) {
|
||||||
@ -555,28 +559,28 @@ void GDBStub::HandleVCont(std::string_view command, std::vector<DebuggerAction>&
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr std::array<std::pair<const char*, Kernel::Svc::MemoryState>, 22> MemoryStateNames{{
|
constexpr std::array<std::pair<const char*, Kernel::Svc::MemoryState>, 22> MemoryStateNames{{
|
||||||
{"----- Free ------", Kernel::Svc::MemoryState::Free},
|
{"----- Free -----", Kernel::Svc::MemoryState::Free},
|
||||||
{"Io ", Kernel::Svc::MemoryState::Io},
|
{"Io ", Kernel::Svc::MemoryState::Io},
|
||||||
{"Static ", Kernel::Svc::MemoryState::Static},
|
{"Static ", Kernel::Svc::MemoryState::Static},
|
||||||
{"Code ", Kernel::Svc::MemoryState::Code},
|
{"Code ", Kernel::Svc::MemoryState::Code},
|
||||||
{"CodeData ", Kernel::Svc::MemoryState::CodeData},
|
{"CodeData ", Kernel::Svc::MemoryState::CodeData},
|
||||||
{"Normal ", Kernel::Svc::MemoryState::Normal},
|
{"Normal ", Kernel::Svc::MemoryState::Normal},
|
||||||
{"Shared ", Kernel::Svc::MemoryState::Shared},
|
{"Shared ", Kernel::Svc::MemoryState::Shared},
|
||||||
{"AliasCode ", Kernel::Svc::MemoryState::AliasCode},
|
{"AliasCode ", Kernel::Svc::MemoryState::AliasCode},
|
||||||
{"AliasCodeData ", Kernel::Svc::MemoryState::AliasCodeData},
|
{"AliasCodeData ", Kernel::Svc::MemoryState::AliasCodeData},
|
||||||
{"Ipc ", Kernel::Svc::MemoryState::Ipc},
|
{"Ipc ", Kernel::Svc::MemoryState::Ipc},
|
||||||
{"Stack ", Kernel::Svc::MemoryState::Stack},
|
{"Stack ", Kernel::Svc::MemoryState::Stack},
|
||||||
{"ThreadLocal ", Kernel::Svc::MemoryState::ThreadLocal},
|
{"ThreadLocal ", Kernel::Svc::MemoryState::ThreadLocal},
|
||||||
{"Transferred ", Kernel::Svc::MemoryState::Transferred},
|
{"Transfered ", Kernel::Svc::MemoryState::Transfered},
|
||||||
{"SharedTransferred", Kernel::Svc::MemoryState::SharedTransferred},
|
{"SharedTransfered", Kernel::Svc::MemoryState::SharedTransfered},
|
||||||
{"SharedCode ", Kernel::Svc::MemoryState::SharedCode},
|
{"SharedCode ", Kernel::Svc::MemoryState::SharedCode},
|
||||||
{"Inaccessible ", Kernel::Svc::MemoryState::Inaccessible},
|
{"Inaccessible ", Kernel::Svc::MemoryState::Inaccessible},
|
||||||
{"NonSecureIpc ", Kernel::Svc::MemoryState::NonSecureIpc},
|
{"NonSecureIpc ", Kernel::Svc::MemoryState::NonSecureIpc},
|
||||||
{"NonDeviceIpc ", Kernel::Svc::MemoryState::NonDeviceIpc},
|
{"NonDeviceIpc ", Kernel::Svc::MemoryState::NonDeviceIpc},
|
||||||
{"Kernel ", Kernel::Svc::MemoryState::Kernel},
|
{"Kernel ", Kernel::Svc::MemoryState::Kernel},
|
||||||
{"GeneratedCode ", Kernel::Svc::MemoryState::GeneratedCode},
|
{"GeneratedCode ", Kernel::Svc::MemoryState::GeneratedCode},
|
||||||
{"CodeOut ", Kernel::Svc::MemoryState::CodeOut},
|
{"CodeOut ", Kernel::Svc::MemoryState::CodeOut},
|
||||||
{"Coverage ", Kernel::Svc::MemoryState::Coverage},
|
{"Coverage ", Kernel::Svc::MemoryState::Coverage},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
static constexpr const char* GetMemoryStateName(Kernel::Svc::MemoryState state) {
|
static constexpr const char* GetMemoryStateName(Kernel::Svc::MemoryState state) {
|
||||||
@ -609,7 +613,7 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
|
|||||||
std::string_view command_str{reinterpret_cast<const char*>(&command[0]), command.size()};
|
std::string_view command_str{reinterpret_cast<const char*>(&command[0]), command.size()};
|
||||||
std::string reply;
|
std::string reply;
|
||||||
|
|
||||||
auto* process = GetProcess();
|
auto* process = system.ApplicationProcess();
|
||||||
auto& page_table = process->GetPageTable();
|
auto& page_table = process->GetPageTable();
|
||||||
|
|
||||||
const char* commands = "Commands:\n"
|
const char* commands = "Commands:\n"
|
||||||
@ -710,7 +714,7 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KThread* GDBStub::GetThreadByID(u64 thread_id) {
|
Kernel::KThread* GDBStub::GetThreadByID(u64 thread_id) {
|
||||||
auto& threads{GetProcess()->GetThreadList()};
|
auto& threads{system.ApplicationProcess()->GetThreadList()};
|
||||||
for (auto& thread : threads) {
|
for (auto& thread : threads) {
|
||||||
if (thread.GetThreadId() == thread_id) {
|
if (thread.GetThreadId() == thread_id) {
|
||||||
return std::addressof(thread);
|
return std::addressof(thread);
|
||||||
@ -779,12 +783,4 @@ void GDBStub::SendStatus(char status) {
|
|||||||
backend.WriteToClient(buf);
|
backend.WriteToClient(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KProcess* GDBStub::GetProcess() {
|
|
||||||
return debug_process;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Memory::Memory& GDBStub::GetMemory() {
|
|
||||||
return GetProcess()->GetMemory();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@ -12,22 +12,13 @@
|
|||||||
#include "core/debugger/debugger_interface.h"
|
#include "core/debugger/debugger_interface.h"
|
||||||
#include "core/debugger/gdbstub_arch.h"
|
#include "core/debugger/gdbstub_arch.h"
|
||||||
|
|
||||||
namespace Kernel {
|
|
||||||
class KProcess;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Core::Memory {
|
|
||||||
class Memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class System;
|
class System;
|
||||||
|
|
||||||
class GDBStub : public DebuggerFrontend {
|
class GDBStub : public DebuggerFrontend {
|
||||||
public:
|
public:
|
||||||
explicit GDBStub(DebuggerBackend& backend, Core::System& system,
|
explicit GDBStub(DebuggerBackend& backend, Core::System& system);
|
||||||
Kernel::KProcess* debug_process);
|
|
||||||
~GDBStub() override;
|
~GDBStub() override;
|
||||||
|
|
||||||
void Connected() override;
|
void Connected() override;
|
||||||
@ -51,12 +42,8 @@ private:
|
|||||||
void SendReply(std::string_view data);
|
void SendReply(std::string_view data);
|
||||||
void SendStatus(char status);
|
void SendStatus(char status);
|
||||||
|
|
||||||
Kernel::KProcess* GetProcess();
|
|
||||||
Core::Memory::Memory& GetMemory();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
Kernel::KProcess* debug_process;
|
|
||||||
std::unique_ptr<GDBStubArch> arch;
|
std::unique_ptr<GDBStubArch> arch;
|
||||||
std::vector<char> current_command;
|
std::vector<char> current_command;
|
||||||
std::map<VAddr, u32> replaced_instructions;
|
std::map<VAddr, u32> replaced_instructions;
|
||||||
|
@ -31,12 +31,6 @@ public:
|
|||||||
DramMemoryMap::Base;
|
DramMemoryMap::Base;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
PAddr GetRawPhysicalAddr(const T* ptr) const {
|
|
||||||
return static_cast<PAddr>(reinterpret_cast<uintptr_t>(ptr) -
|
|
||||||
reinterpret_cast<uintptr_t>(buffer.BackingBasePointer()));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* GetPointer(Common::PhysicalAddress addr) {
|
T* GetPointer(Common::PhysicalAddress addr) {
|
||||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
||||||
@ -49,16 +43,6 @@ public:
|
|||||||
(GetInteger(addr) - DramMemoryMap::Base));
|
(GetInteger(addr) - DramMemoryMap::Base));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T* GetPointerFromRaw(PAddr addr) {
|
|
||||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() + addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
const T* GetPointerFromRaw(PAddr addr) const {
|
|
||||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() + addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Common::HostMemory buffer;
|
Common::HostMemory buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,208 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <atomic>
|
|
||||||
#include <deque>
|
|
||||||
#include <memory>
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "common/scratch_buffer.h"
|
|
||||||
#include "common/virtual_buffer.h"
|
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
constexpr size_t DEVICE_PAGEBITS = 12ULL;
|
|
||||||
constexpr size_t DEVICE_PAGESIZE = 1ULL << DEVICE_PAGEBITS;
|
|
||||||
constexpr size_t DEVICE_PAGEMASK = DEVICE_PAGESIZE - 1ULL;
|
|
||||||
|
|
||||||
class DeviceMemory;
|
|
||||||
|
|
||||||
namespace Memory {
|
|
||||||
class Memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DTraits>
|
|
||||||
struct DeviceMemoryManagerAllocator;
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
class DeviceMemoryManager {
|
|
||||||
using DeviceInterface = typename Traits::DeviceInterface;
|
|
||||||
using DeviceMethods = typename Traits::DeviceMethods;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DeviceMemoryManager(const DeviceMemory& device_memory);
|
|
||||||
~DeviceMemoryManager();
|
|
||||||
|
|
||||||
void BindInterface(DeviceInterface* device_inter);
|
|
||||||
|
|
||||||
DAddr Allocate(size_t size);
|
|
||||||
void AllocateFixed(DAddr start, size_t size);
|
|
||||||
void Free(DAddr start, size_t size);
|
|
||||||
|
|
||||||
void Map(DAddr address, VAddr virtual_address, size_t size, size_t process_id,
|
|
||||||
bool track = false);
|
|
||||||
|
|
||||||
void Unmap(DAddr address, size_t size);
|
|
||||||
|
|
||||||
void TrackContinuityImpl(DAddr address, VAddr virtual_address, size_t size, size_t process_id);
|
|
||||||
void TrackContinuity(DAddr address, VAddr virtual_address, size_t size, size_t process_id) {
|
|
||||||
std::scoped_lock lk(mapping_guard);
|
|
||||||
TrackContinuityImpl(address, virtual_address, size, process_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write / Read
|
|
||||||
template <typename T>
|
|
||||||
T* GetPointer(DAddr address);
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
const T* GetPointer(DAddr address) const;
|
|
||||||
|
|
||||||
template <typename Func>
|
|
||||||
void ApplyOpOnPAddr(PAddr address, Common::ScratchBuffer<u32>& buffer, Func&& operation) {
|
|
||||||
DAddr subbits = static_cast<DAddr>(address & page_mask);
|
|
||||||
const u32 base = compressed_device_addr[(address >> page_bits)];
|
|
||||||
if ((base >> MULTI_FLAG_BITS) == 0) [[likely]] {
|
|
||||||
const DAddr d_address = (static_cast<DAddr>(base) << page_bits) + subbits;
|
|
||||||
operation(d_address);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
InnerGatherDeviceAddresses(buffer, address);
|
|
||||||
for (u32 value : buffer) {
|
|
||||||
operation((static_cast<DAddr>(value) << page_bits) + subbits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Func>
|
|
||||||
void ApplyOpOnPointer(const u8* p, Common::ScratchBuffer<u32>& buffer, Func&& operation) {
|
|
||||||
PAddr address = GetRawPhysicalAddr<u8>(p);
|
|
||||||
ApplyOpOnPAddr(address, buffer, operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
PAddr GetPhysicalRawAddressFromDAddr(DAddr address) const {
|
|
||||||
PAddr subbits = static_cast<PAddr>(address & page_mask);
|
|
||||||
auto paddr = compressed_physical_ptr[(address >> page_bits)];
|
|
||||||
if (paddr == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return (static_cast<PAddr>(paddr - 1) << page_bits) + subbits;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void Write(DAddr address, T value);
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T Read(DAddr address) const;
|
|
||||||
|
|
||||||
u8* GetSpan(const DAddr src_addr, const std::size_t size);
|
|
||||||
const u8* GetSpan(const DAddr src_addr, const std::size_t size) const;
|
|
||||||
|
|
||||||
void ReadBlock(DAddr address, void* dest_pointer, size_t size);
|
|
||||||
void ReadBlockUnsafe(DAddr address, void* dest_pointer, size_t size);
|
|
||||||
void WriteBlock(DAddr address, const void* src_pointer, size_t size);
|
|
||||||
void WriteBlockUnsafe(DAddr address, const void* src_pointer, size_t size);
|
|
||||||
|
|
||||||
size_t RegisterProcess(Memory::Memory* memory);
|
|
||||||
void UnregisterProcess(size_t id);
|
|
||||||
|
|
||||||
void UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta);
|
|
||||||
|
|
||||||
static constexpr size_t AS_BITS = Traits::device_virtual_bits;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static constexpr size_t device_virtual_bits = Traits::device_virtual_bits;
|
|
||||||
static constexpr size_t device_as_size = 1ULL << device_virtual_bits;
|
|
||||||
static constexpr size_t physical_min_bits = 32;
|
|
||||||
static constexpr size_t physical_max_bits = 33;
|
|
||||||
static constexpr size_t page_bits = 12;
|
|
||||||
static constexpr size_t page_size = 1ULL << page_bits;
|
|
||||||
static constexpr size_t page_mask = page_size - 1ULL;
|
|
||||||
static constexpr u32 physical_address_base = 1U << page_bits;
|
|
||||||
static constexpr u32 MULTI_FLAG_BITS = 31;
|
|
||||||
static constexpr u32 MULTI_FLAG = 1U << MULTI_FLAG_BITS;
|
|
||||||
static constexpr u32 MULTI_MASK = ~MULTI_FLAG;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T* GetPointerFromRaw(PAddr addr) {
|
|
||||||
return reinterpret_cast<T*>(physical_base + addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
const T* GetPointerFromRaw(PAddr addr) const {
|
|
||||||
return reinterpret_cast<T*>(physical_base + addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
PAddr GetRawPhysicalAddr(const T* ptr) const {
|
|
||||||
return static_cast<PAddr>(reinterpret_cast<uintptr_t>(ptr) - physical_base);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WalkBlock(const DAddr addr, const std::size_t size, auto on_unmapped, auto on_memory,
|
|
||||||
auto increment);
|
|
||||||
|
|
||||||
void InnerGatherDeviceAddresses(Common::ScratchBuffer<u32>& buffer, PAddr address);
|
|
||||||
|
|
||||||
std::unique_ptr<DeviceMemoryManagerAllocator<Traits>> impl;
|
|
||||||
|
|
||||||
const uintptr_t physical_base;
|
|
||||||
DeviceInterface* device_inter;
|
|
||||||
Common::VirtualBuffer<u32> compressed_physical_ptr;
|
|
||||||
Common::VirtualBuffer<u32> compressed_device_addr;
|
|
||||||
Common::VirtualBuffer<u32> continuity_tracker;
|
|
||||||
|
|
||||||
// Process memory interfaces
|
|
||||||
|
|
||||||
std::deque<size_t> id_pool;
|
|
||||||
std::deque<Memory::Memory*> registered_processes;
|
|
||||||
|
|
||||||
// Memory protection management
|
|
||||||
|
|
||||||
static constexpr size_t guest_max_as_bits = 39;
|
|
||||||
static constexpr size_t guest_as_size = 1ULL << guest_max_as_bits;
|
|
||||||
static constexpr size_t guest_mask = guest_as_size - 1ULL;
|
|
||||||
static constexpr size_t process_id_start_bit = guest_max_as_bits;
|
|
||||||
|
|
||||||
std::pair<size_t, VAddr> ExtractCPUBacking(size_t page_index) {
|
|
||||||
auto content = cpu_backing_address[page_index];
|
|
||||||
const VAddr address = content & guest_mask;
|
|
||||||
const size_t process_id = static_cast<size_t>(content >> process_id_start_bit);
|
|
||||||
return std::make_pair(process_id, address);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InsertCPUBacking(size_t page_index, VAddr address, size_t process_id) {
|
|
||||||
cpu_backing_address[page_index] = address | (process_id << process_id_start_bit);
|
|
||||||
}
|
|
||||||
|
|
||||||
Common::VirtualBuffer<VAddr> cpu_backing_address;
|
|
||||||
static constexpr size_t subentries = 8 / sizeof(u8);
|
|
||||||
static constexpr size_t subentries_mask = subentries - 1;
|
|
||||||
class CounterEntry final {
|
|
||||||
public:
|
|
||||||
CounterEntry() = default;
|
|
||||||
|
|
||||||
std::atomic_uint8_t& Count(std::size_t page) {
|
|
||||||
return values[page & subentries_mask];
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::atomic_uint8_t& Count(std::size_t page) const {
|
|
||||||
return values[page & subentries_mask];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::array<std::atomic_uint8_t, subentries> values{};
|
|
||||||
};
|
|
||||||
static_assert(sizeof(CounterEntry) == subentries * sizeof(u8),
|
|
||||||
"CounterEntry should be 8 bytes!");
|
|
||||||
|
|
||||||
static constexpr size_t num_counter_entries =
|
|
||||||
(1ULL << (device_virtual_bits - page_bits)) / subentries;
|
|
||||||
using CachedPages = std::array<CounterEntry, num_counter_entries>;
|
|
||||||
std::unique_ptr<CachedPages> cached_pages;
|
|
||||||
std::mutex counter_guard;
|
|
||||||
std::mutex mapping_guard;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Core
|
|
@ -1,588 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <limits>
|
|
||||||
#include <memory>
|
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
#include "common/address_space.h"
|
|
||||||
#include "common/address_space.inc"
|
|
||||||
#include "common/alignment.h"
|
|
||||||
#include "common/assert.h"
|
|
||||||
#include "common/div_ceil.h"
|
|
||||||
#include "common/scope_exit.h"
|
|
||||||
#include "common/settings.h"
|
|
||||||
#include "core/device_memory.h"
|
|
||||||
#include "core/device_memory_manager.h"
|
|
||||||
#include "core/memory.h"
|
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
class MultiAddressContainer {
|
|
||||||
public:
|
|
||||||
MultiAddressContainer() = default;
|
|
||||||
~MultiAddressContainer() = default;
|
|
||||||
|
|
||||||
void GatherValues(u32 start_entry, Common::ScratchBuffer<u32>& buffer) {
|
|
||||||
buffer.resize(8);
|
|
||||||
buffer.resize(0);
|
|
||||||
size_t index = 0;
|
|
||||||
const auto add_value = [&](u32 value) {
|
|
||||||
buffer[index] = value;
|
|
||||||
index++;
|
|
||||||
buffer.resize(index);
|
|
||||||
};
|
|
||||||
|
|
||||||
u32 iter_entry = start_entry;
|
|
||||||
Entry* current = &storage[iter_entry - 1];
|
|
||||||
add_value(current->value);
|
|
||||||
while (current->next_entry != 0) {
|
|
||||||
iter_entry = current->next_entry;
|
|
||||||
current = &storage[iter_entry - 1];
|
|
||||||
add_value(current->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 Register(u32 value) {
|
|
||||||
return RegisterImplementation(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Register(u32 value, u32 start_entry) {
|
|
||||||
auto entry_id = RegisterImplementation(value);
|
|
||||||
u32 iter_entry = start_entry;
|
|
||||||
Entry* current = &storage[iter_entry - 1];
|
|
||||||
while (current->next_entry != 0) {
|
|
||||||
iter_entry = current->next_entry;
|
|
||||||
current = &storage[iter_entry - 1];
|
|
||||||
}
|
|
||||||
current->next_entry = entry_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<bool, u32> Unregister(u32 value, u32 start_entry) {
|
|
||||||
u32 iter_entry = start_entry;
|
|
||||||
Entry* previous{};
|
|
||||||
Entry* current = &storage[iter_entry - 1];
|
|
||||||
Entry* next{};
|
|
||||||
bool more_than_one_remaining = false;
|
|
||||||
u32 result_start{start_entry};
|
|
||||||
size_t count = 0;
|
|
||||||
while (current->value != value) {
|
|
||||||
count++;
|
|
||||||
previous = current;
|
|
||||||
iter_entry = current->next_entry;
|
|
||||||
current = &storage[iter_entry - 1];
|
|
||||||
}
|
|
||||||
// Find next
|
|
||||||
u32 next_entry = current->next_entry;
|
|
||||||
if (next_entry != 0) {
|
|
||||||
next = &storage[next_entry - 1];
|
|
||||||
more_than_one_remaining = next->next_entry != 0 || previous != nullptr;
|
|
||||||
}
|
|
||||||
if (previous) {
|
|
||||||
previous->next_entry = next_entry;
|
|
||||||
} else {
|
|
||||||
result_start = next_entry;
|
|
||||||
}
|
|
||||||
free_entries.emplace_back(iter_entry);
|
|
||||||
return std::make_pair(more_than_one_remaining || count > 1, result_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 ReleaseEntry(u32 start_entry) {
|
|
||||||
Entry* current = &storage[start_entry - 1];
|
|
||||||
free_entries.emplace_back(start_entry);
|
|
||||||
return current->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
u32 RegisterImplementation(u32 value) {
|
|
||||||
auto entry_id = GetNewEntry();
|
|
||||||
auto& entry = storage[entry_id - 1];
|
|
||||||
entry.next_entry = 0;
|
|
||||||
entry.value = value;
|
|
||||||
return entry_id;
|
|
||||||
}
|
|
||||||
u32 GetNewEntry() {
|
|
||||||
if (!free_entries.empty()) {
|
|
||||||
u32 result = free_entries.front();
|
|
||||||
free_entries.pop_front();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
storage.emplace_back();
|
|
||||||
u32 new_entry = static_cast<u32>(storage.size());
|
|
||||||
return new_entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Entry {
|
|
||||||
u32 next_entry{};
|
|
||||||
u32 value{};
|
|
||||||
};
|
|
||||||
|
|
||||||
std::deque<Entry> storage;
|
|
||||||
std::deque<u32> free_entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EmptyAllocator {
|
|
||||||
EmptyAllocator([[maybe_unused]] DAddr address) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
template <typename DTraits>
|
|
||||||
struct DeviceMemoryManagerAllocator {
|
|
||||||
static constexpr size_t device_virtual_bits = DTraits::device_virtual_bits;
|
|
||||||
static constexpr DAddr first_address = 1ULL << Memory::YUZU_PAGEBITS;
|
|
||||||
static constexpr DAddr max_device_area = 1ULL << device_virtual_bits;
|
|
||||||
|
|
||||||
DeviceMemoryManagerAllocator() : main_allocator(first_address) {}
|
|
||||||
|
|
||||||
Common::FlatAllocator<DAddr, 0, device_virtual_bits> main_allocator;
|
|
||||||
MultiAddressContainer multi_dev_address;
|
|
||||||
|
|
||||||
/// Returns true when vaddr -> vaddr+size is fully contained in the buffer
|
|
||||||
template <bool pin_area>
|
|
||||||
[[nodiscard]] bool IsInBounds(VAddr addr, u64 size) const noexcept {
|
|
||||||
return addr >= 0 && addr + size <= max_device_area;
|
|
||||||
}
|
|
||||||
|
|
||||||
DAddr Allocate(size_t size) {
|
|
||||||
return main_allocator.Allocate(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AllocateFixed(DAddr b_address, size_t b_size) {
|
|
||||||
main_allocator.AllocateFixed(b_address, b_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Free(DAddr b_address, size_t b_size) {
|
|
||||||
main_allocator.Free(b_address, b_size);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
DeviceMemoryManager<Traits>::DeviceMemoryManager(const DeviceMemory& device_memory_)
|
|
||||||
: physical_base{reinterpret_cast<const uintptr_t>(device_memory_.buffer.BackingBasePointer())},
|
|
||||||
device_inter{nullptr}, compressed_physical_ptr(device_as_size >> Memory::YUZU_PAGEBITS),
|
|
||||||
compressed_device_addr(1ULL << ((Settings::values.memory_layout_mode.GetValue() ==
|
|
||||||
Settings::MemoryLayout::Memory_4Gb
|
|
||||||
? physical_min_bits
|
|
||||||
: physical_max_bits) -
|
|
||||||
Memory::YUZU_PAGEBITS)),
|
|
||||||
continuity_tracker(device_as_size >> Memory::YUZU_PAGEBITS),
|
|
||||||
cpu_backing_address(device_as_size >> Memory::YUZU_PAGEBITS) {
|
|
||||||
impl = std::make_unique<DeviceMemoryManagerAllocator<Traits>>();
|
|
||||||
cached_pages = std::make_unique<CachedPages>();
|
|
||||||
|
|
||||||
const size_t total_virtual = device_as_size >> Memory::YUZU_PAGEBITS;
|
|
||||||
for (size_t i = 0; i < total_virtual; i++) {
|
|
||||||
compressed_physical_ptr[i] = 0;
|
|
||||||
continuity_tracker[i] = 1;
|
|
||||||
cpu_backing_address[i] = 0;
|
|
||||||
}
|
|
||||||
const size_t total_phys = 1ULL << ((Settings::values.memory_layout_mode.GetValue() ==
|
|
||||||
Settings::MemoryLayout::Memory_4Gb
|
|
||||||
? physical_min_bits
|
|
||||||
: physical_max_bits) -
|
|
||||||
Memory::YUZU_PAGEBITS);
|
|
||||||
for (size_t i = 0; i < total_phys; i++) {
|
|
||||||
compressed_device_addr[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
DeviceMemoryManager<Traits>::~DeviceMemoryManager() = default;
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::BindInterface(DeviceInterface* device_inter_) {
|
|
||||||
device_inter = device_inter_;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
DAddr DeviceMemoryManager<Traits>::Allocate(size_t size) {
|
|
||||||
return impl->Allocate(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::AllocateFixed(DAddr start, size_t size) {
|
|
||||||
return impl->AllocateFixed(start, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::Free(DAddr start, size_t size) {
|
|
||||||
impl->Free(start, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::Map(DAddr address, VAddr virtual_address, size_t size,
|
|
||||||
size_t process_id, bool track) {
|
|
||||||
Core::Memory::Memory* process_memory = registered_processes[process_id];
|
|
||||||
size_t start_page_d = address >> Memory::YUZU_PAGEBITS;
|
|
||||||
size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS;
|
|
||||||
std::scoped_lock lk(mapping_guard);
|
|
||||||
for (size_t i = 0; i < num_pages; i++) {
|
|
||||||
const VAddr new_vaddress = virtual_address + i * Memory::YUZU_PAGESIZE;
|
|
||||||
auto* ptr = process_memory->GetPointerSilent(Common::ProcessAddress(new_vaddress));
|
|
||||||
if (ptr == nullptr) [[unlikely]] {
|
|
||||||
compressed_physical_ptr[start_page_d + i] = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto phys_addr = static_cast<u32>(GetRawPhysicalAddr(ptr) >> Memory::YUZU_PAGEBITS) + 1U;
|
|
||||||
compressed_physical_ptr[start_page_d + i] = phys_addr;
|
|
||||||
InsertCPUBacking(start_page_d + i, new_vaddress, process_id);
|
|
||||||
const u32 base_dev = compressed_device_addr[phys_addr - 1U];
|
|
||||||
const u32 new_dev = static_cast<u32>(start_page_d + i);
|
|
||||||
if (base_dev == 0) [[likely]] {
|
|
||||||
compressed_device_addr[phys_addr - 1U] = new_dev;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
u32 start_id = base_dev & MULTI_MASK;
|
|
||||||
if ((base_dev >> MULTI_FLAG_BITS) == 0) {
|
|
||||||
start_id = impl->multi_dev_address.Register(base_dev);
|
|
||||||
compressed_device_addr[phys_addr - 1U] = MULTI_FLAG | start_id;
|
|
||||||
}
|
|
||||||
impl->multi_dev_address.Register(new_dev, start_id);
|
|
||||||
}
|
|
||||||
if (track) {
|
|
||||||
TrackContinuityImpl(address, virtual_address, size, process_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::Unmap(DAddr address, size_t size) {
|
|
||||||
size_t start_page_d = address >> Memory::YUZU_PAGEBITS;
|
|
||||||
size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS;
|
|
||||||
device_inter->InvalidateRegion(address, size);
|
|
||||||
std::scoped_lock lk(mapping_guard);
|
|
||||||
for (size_t i = 0; i < num_pages; i++) {
|
|
||||||
auto phys_addr = compressed_physical_ptr[start_page_d + i];
|
|
||||||
compressed_physical_ptr[start_page_d + i] = 0;
|
|
||||||
cpu_backing_address[start_page_d + i] = 0;
|
|
||||||
if (phys_addr != 0) [[likely]] {
|
|
||||||
const u32 base_dev = compressed_device_addr[phys_addr - 1U];
|
|
||||||
if ((base_dev >> MULTI_FLAG_BITS) == 0) [[likely]] {
|
|
||||||
compressed_device_addr[phys_addr - 1] = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto [more_entries, new_start] = impl->multi_dev_address.Unregister(
|
|
||||||
static_cast<u32>(start_page_d + i), base_dev & MULTI_MASK);
|
|
||||||
if (!more_entries) {
|
|
||||||
compressed_device_addr[phys_addr - 1] =
|
|
||||||
impl->multi_dev_address.ReleaseEntry(new_start);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
compressed_device_addr[phys_addr - 1] = new_start | MULTI_FLAG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::TrackContinuityImpl(DAddr address, VAddr virtual_address,
|
|
||||||
size_t size, size_t process_id) {
|
|
||||||
Core::Memory::Memory* process_memory = registered_processes[process_id];
|
|
||||||
size_t start_page_d = address >> Memory::YUZU_PAGEBITS;
|
|
||||||
size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS;
|
|
||||||
uintptr_t last_ptr = 0;
|
|
||||||
size_t page_count = 1;
|
|
||||||
for (size_t i = num_pages; i > 0; i--) {
|
|
||||||
size_t index = i - 1;
|
|
||||||
const VAddr new_vaddress = virtual_address + index * Memory::YUZU_PAGESIZE;
|
|
||||||
const uintptr_t new_ptr = reinterpret_cast<uintptr_t>(
|
|
||||||
process_memory->GetPointerSilent(Common::ProcessAddress(new_vaddress)));
|
|
||||||
if (new_ptr + page_size == last_ptr) {
|
|
||||||
page_count++;
|
|
||||||
} else {
|
|
||||||
page_count = 1;
|
|
||||||
}
|
|
||||||
last_ptr = new_ptr;
|
|
||||||
continuity_tracker[start_page_d + index] = static_cast<u32>(page_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
template <typename Traits>
|
|
||||||
u8* DeviceMemoryManager<Traits>::GetSpan(const DAddr src_addr, const std::size_t size) {
|
|
||||||
size_t page_index = src_addr >> page_bits;
|
|
||||||
size_t subbits = src_addr & page_mask;
|
|
||||||
if ((static_cast<size_t>(continuity_tracker[page_index]) << page_bits) >= size + subbits) {
|
|
||||||
return GetPointer<u8>(src_addr);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
const u8* DeviceMemoryManager<Traits>::GetSpan(const DAddr src_addr, const std::size_t size) const {
|
|
||||||
size_t page_index = src_addr >> page_bits;
|
|
||||||
size_t subbits = src_addr & page_mask;
|
|
||||||
if ((static_cast<size_t>(continuity_tracker[page_index]) << page_bits) >= size + subbits) {
|
|
||||||
return GetPointer<u8>(src_addr);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::InnerGatherDeviceAddresses(Common::ScratchBuffer<u32>& buffer,
|
|
||||||
PAddr address) {
|
|
||||||
size_t phys_addr = address >> page_bits;
|
|
||||||
std::scoped_lock lk(mapping_guard);
|
|
||||||
u32 backing = compressed_device_addr[phys_addr];
|
|
||||||
if ((backing >> MULTI_FLAG_BITS) != 0) {
|
|
||||||
impl->multi_dev_address.GatherValues(backing & MULTI_MASK, buffer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
buffer.resize(1);
|
|
||||||
buffer[0] = backing;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
template <typename T>
|
|
||||||
T* DeviceMemoryManager<Traits>::GetPointer(DAddr address) {
|
|
||||||
const size_t index = address >> Memory::YUZU_PAGEBITS;
|
|
||||||
const size_t offset = address & Memory::YUZU_PAGEMASK;
|
|
||||||
auto phys_addr = compressed_physical_ptr[index];
|
|
||||||
if (phys_addr == 0) [[unlikely]] {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return GetPointerFromRaw<T>((static_cast<PAddr>(phys_addr - 1) << Memory::YUZU_PAGEBITS) +
|
|
||||||
offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
template <typename T>
|
|
||||||
const T* DeviceMemoryManager<Traits>::GetPointer(DAddr address) const {
|
|
||||||
const size_t index = address >> Memory::YUZU_PAGEBITS;
|
|
||||||
const size_t offset = address & Memory::YUZU_PAGEMASK;
|
|
||||||
auto phys_addr = compressed_physical_ptr[index];
|
|
||||||
if (phys_addr == 0) [[unlikely]] {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return GetPointerFromRaw<T>((static_cast<PAddr>(phys_addr - 1) << Memory::YUZU_PAGEBITS) +
|
|
||||||
offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
template <typename T>
|
|
||||||
void DeviceMemoryManager<Traits>::Write(DAddr address, T value) {
|
|
||||||
T* ptr = GetPointer<T>(address);
|
|
||||||
if (!ptr) [[unlikely]] {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::memcpy(ptr, &value, sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
template <typename T>
|
|
||||||
T DeviceMemoryManager<Traits>::Read(DAddr address) const {
|
|
||||||
const T* ptr = GetPointer<T>(address);
|
|
||||||
T result{};
|
|
||||||
if (!ptr) [[unlikely]] {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
std::memcpy(&result, ptr, sizeof(T));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::WalkBlock(DAddr addr, std::size_t size, auto on_unmapped,
|
|
||||||
auto on_memory, auto increment) {
|
|
||||||
std::size_t remaining_size = size;
|
|
||||||
std::size_t page_index = addr >> Memory::YUZU_PAGEBITS;
|
|
||||||
std::size_t page_offset = addr & Memory::YUZU_PAGEMASK;
|
|
||||||
|
|
||||||
while (remaining_size) {
|
|
||||||
const size_t next_pages = static_cast<std::size_t>(continuity_tracker[page_index]);
|
|
||||||
const std::size_t copy_amount =
|
|
||||||
std::min((next_pages << Memory::YUZU_PAGEBITS) - page_offset, remaining_size);
|
|
||||||
const auto current_vaddr =
|
|
||||||
static_cast<u64>((page_index << Memory::YUZU_PAGEBITS) + page_offset);
|
|
||||||
SCOPE_EXIT({
|
|
||||||
page_index += next_pages;
|
|
||||||
page_offset = 0;
|
|
||||||
increment(copy_amount);
|
|
||||||
remaining_size -= copy_amount;
|
|
||||||
});
|
|
||||||
|
|
||||||
auto phys_addr = compressed_physical_ptr[page_index];
|
|
||||||
if (phys_addr == 0) {
|
|
||||||
on_unmapped(copy_amount, current_vaddr);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto* mem_ptr = GetPointerFromRaw<u8>(
|
|
||||||
(static_cast<PAddr>(phys_addr - 1) << Memory::YUZU_PAGEBITS) + page_offset);
|
|
||||||
on_memory(copy_amount, mem_ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::ReadBlock(DAddr address, void* dest_pointer, size_t size) {
|
|
||||||
device_inter->FlushRegion(address, size);
|
|
||||||
WalkBlock(
|
|
||||||
address, size,
|
|
||||||
[&](size_t copy_amount, DAddr current_vaddr) {
|
|
||||||
LOG_ERROR(
|
|
||||||
HW_Memory,
|
|
||||||
"Unmapped Device ReadBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
|
||||||
current_vaddr, address, size);
|
|
||||||
std::memset(dest_pointer, 0, copy_amount);
|
|
||||||
},
|
|
||||||
[&](size_t copy_amount, const u8* const src_ptr) {
|
|
||||||
std::memcpy(dest_pointer, src_ptr, copy_amount);
|
|
||||||
},
|
|
||||||
[&](const std::size_t copy_amount) {
|
|
||||||
dest_pointer = static_cast<u8*>(dest_pointer) + copy_amount;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::WriteBlock(DAddr address, const void* src_pointer, size_t size) {
|
|
||||||
WalkBlock(
|
|
||||||
address, size,
|
|
||||||
[&](size_t copy_amount, DAddr current_vaddr) {
|
|
||||||
LOG_ERROR(
|
|
||||||
HW_Memory,
|
|
||||||
"Unmapped Device WriteBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
|
||||||
current_vaddr, address, size);
|
|
||||||
},
|
|
||||||
[&](size_t copy_amount, u8* const dst_ptr) {
|
|
||||||
std::memcpy(dst_ptr, src_pointer, copy_amount);
|
|
||||||
},
|
|
||||||
[&](const std::size_t copy_amount) {
|
|
||||||
src_pointer = static_cast<const u8*>(src_pointer) + copy_amount;
|
|
||||||
});
|
|
||||||
device_inter->InvalidateRegion(address, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::ReadBlockUnsafe(DAddr address, void* dest_pointer, size_t size) {
|
|
||||||
WalkBlock(
|
|
||||||
address, size,
|
|
||||||
[&](size_t copy_amount, DAddr current_vaddr) {
|
|
||||||
LOG_ERROR(
|
|
||||||
HW_Memory,
|
|
||||||
"Unmapped Device ReadBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
|
||||||
current_vaddr, address, size);
|
|
||||||
std::memset(dest_pointer, 0, copy_amount);
|
|
||||||
},
|
|
||||||
[&](size_t copy_amount, const u8* const src_ptr) {
|
|
||||||
std::memcpy(dest_pointer, src_ptr, copy_amount);
|
|
||||||
},
|
|
||||||
[&](const std::size_t copy_amount) {
|
|
||||||
dest_pointer = static_cast<u8*>(dest_pointer) + copy_amount;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::WriteBlockUnsafe(DAddr address, const void* src_pointer,
|
|
||||||
size_t size) {
|
|
||||||
WalkBlock(
|
|
||||||
address, size,
|
|
||||||
[&](size_t copy_amount, DAddr current_vaddr) {
|
|
||||||
LOG_ERROR(
|
|
||||||
HW_Memory,
|
|
||||||
"Unmapped Device WriteBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
|
||||||
current_vaddr, address, size);
|
|
||||||
},
|
|
||||||
[&](size_t copy_amount, u8* const dst_ptr) {
|
|
||||||
std::memcpy(dst_ptr, src_pointer, copy_amount);
|
|
||||||
},
|
|
||||||
[&](const std::size_t copy_amount) {
|
|
||||||
src_pointer = static_cast<const u8*>(src_pointer) + copy_amount;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
size_t DeviceMemoryManager<Traits>::RegisterProcess(Memory::Memory* memory_device_inter) {
|
|
||||||
size_t new_id;
|
|
||||||
if (!id_pool.empty()) {
|
|
||||||
new_id = id_pool.front();
|
|
||||||
id_pool.pop_front();
|
|
||||||
registered_processes[new_id] = memory_device_inter;
|
|
||||||
} else {
|
|
||||||
registered_processes.emplace_back(memory_device_inter);
|
|
||||||
new_id = registered_processes.size() - 1U;
|
|
||||||
}
|
|
||||||
return new_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::UnregisterProcess(size_t id) {
|
|
||||||
registered_processes[id] = nullptr;
|
|
||||||
id_pool.push_front(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Traits>
|
|
||||||
void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta) {
|
|
||||||
bool locked = false;
|
|
||||||
auto lock = [&] {
|
|
||||||
if (!locked) {
|
|
||||||
counter_guard.lock();
|
|
||||||
locked = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
SCOPE_EXIT({
|
|
||||||
if (locked) {
|
|
||||||
counter_guard.unlock();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
u64 uncache_begin = 0;
|
|
||||||
u64 cache_begin = 0;
|
|
||||||
u64 uncache_bytes = 0;
|
|
||||||
u64 cache_bytes = 0;
|
|
||||||
const auto MarkRegionCaching = &DeviceMemoryManager<Traits>::DeviceMethods::MarkRegionCaching;
|
|
||||||
|
|
||||||
std::atomic_thread_fence(std::memory_order_acquire);
|
|
||||||
const size_t page_end = Common::DivCeil(addr + size, Memory::YUZU_PAGESIZE);
|
|
||||||
size_t page = addr >> Memory::YUZU_PAGEBITS;
|
|
||||||
auto [process_id, base_vaddress] = ExtractCPUBacking(page);
|
|
||||||
size_t vpage = base_vaddress >> Memory::YUZU_PAGEBITS;
|
|
||||||
auto* memory_device_inter = registered_processes[process_id];
|
|
||||||
for (; page != page_end; ++page) {
|
|
||||||
std::atomic_uint8_t& count = cached_pages->at(page >> 3).Count(page);
|
|
||||||
|
|
||||||
if (delta > 0) {
|
|
||||||
ASSERT_MSG(count.load(std::memory_order::relaxed) < std::numeric_limits<u8>::max(),
|
|
||||||
"Count may overflow!");
|
|
||||||
} else if (delta < 0) {
|
|
||||||
ASSERT_MSG(count.load(std::memory_order::relaxed) > 0, "Count may underflow!");
|
|
||||||
} else {
|
|
||||||
ASSERT_MSG(false, "Delta must be non-zero!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds or subtracts 1, as count is a unsigned 8-bit value
|
|
||||||
count.fetch_add(static_cast<u8>(delta), std::memory_order_release);
|
|
||||||
|
|
||||||
// Assume delta is either -1 or 1
|
|
||||||
if (count.load(std::memory_order::relaxed) == 0) {
|
|
||||||
if (uncache_bytes == 0) {
|
|
||||||
uncache_begin = vpage;
|
|
||||||
}
|
|
||||||
uncache_bytes += Memory::YUZU_PAGESIZE;
|
|
||||||
} else if (uncache_bytes > 0) {
|
|
||||||
lock();
|
|
||||||
MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS,
|
|
||||||
uncache_bytes, false);
|
|
||||||
uncache_bytes = 0;
|
|
||||||
}
|
|
||||||
if (count.load(std::memory_order::relaxed) == 1 && delta > 0) {
|
|
||||||
if (cache_bytes == 0) {
|
|
||||||
cache_begin = vpage;
|
|
||||||
}
|
|
||||||
cache_bytes += Memory::YUZU_PAGESIZE;
|
|
||||||
} else if (cache_bytes > 0) {
|
|
||||||
lock();
|
|
||||||
MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes,
|
|
||||||
true);
|
|
||||||
cache_bytes = 0;
|
|
||||||
}
|
|
||||||
vpage++;
|
|
||||||
}
|
|
||||||
if (uncache_bytes > 0) {
|
|
||||||
lock();
|
|
||||||
MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS, uncache_bytes,
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
if (cache_bytes > 0) {
|
|
||||||
lock();
|
|
||||||
MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
|
@ -26,7 +26,7 @@
|
|||||||
#include "core/file_sys/vfs_vector.h"
|
#include "core/file_sys/vfs_vector.h"
|
||||||
#include "core/hle/service/filesystem/filesystem.h"
|
#include "core/hle/service/filesystem/filesystem.h"
|
||||||
#include "core/hle/service/ns/language.h"
|
#include "core/hle/service/ns/language.h"
|
||||||
#include "core/hle/service/set/settings_server.h"
|
#include "core/hle/service/set/set.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
#include "core/loader/nso.h"
|
#include "core/loader/nso.h"
|
||||||
#include "core/memory/cheat_engine.h"
|
#include "core/memory/cheat_engine.h"
|
||||||
|
@ -97,9 +97,8 @@ std::string SaveDataAttribute::DebugInfo() const {
|
|||||||
static_cast<u8>(rank), index);
|
static_cast<u8>(rank), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveDataFactory::SaveDataFactory(Core::System& system_, ProgramId program_id_,
|
SaveDataFactory::SaveDataFactory(Core::System& system_, VirtualDir save_directory_)
|
||||||
VirtualDir save_directory_)
|
: dir{std::move(save_directory_)}, system{system_} {
|
||||||
: system{system_}, program_id{program_id_}, dir{std::move(save_directory_)} {
|
|
||||||
// Delete all temporary storages
|
// Delete all temporary storages
|
||||||
// On hardware, it is expected that temporary storage be empty at first use.
|
// On hardware, it is expected that temporary storage be empty at first use.
|
||||||
dir->DeleteSubdirectoryRecursive("temp");
|
dir->DeleteSubdirectoryRecursive("temp");
|
||||||
@ -111,7 +110,7 @@ VirtualDir SaveDataFactory::Create(SaveDataSpaceId space, const SaveDataAttribut
|
|||||||
PrintSaveDataAttributeWarnings(meta);
|
PrintSaveDataAttributeWarnings(meta);
|
||||||
|
|
||||||
const auto save_directory =
|
const auto save_directory =
|
||||||
GetFullPath(program_id, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
GetFullPath(system, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
||||||
|
|
||||||
return dir->CreateDirectoryRelative(save_directory);
|
return dir->CreateDirectoryRelative(save_directory);
|
||||||
}
|
}
|
||||||
@ -119,7 +118,7 @@ VirtualDir SaveDataFactory::Create(SaveDataSpaceId space, const SaveDataAttribut
|
|||||||
VirtualDir SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const {
|
VirtualDir SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const {
|
||||||
|
|
||||||
const auto save_directory =
|
const auto save_directory =
|
||||||
GetFullPath(program_id, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
GetFullPath(system, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
||||||
|
|
||||||
auto out = dir->GetDirectoryRelative(save_directory);
|
auto out = dir->GetDirectoryRelative(save_directory);
|
||||||
|
|
||||||
@ -148,14 +147,14 @@ std::string SaveDataFactory::GetSaveDataSpaceIdPath(SaveDataSpaceId space) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SaveDataFactory::GetFullPath(ProgramId program_id, VirtualDir dir,
|
std::string SaveDataFactory::GetFullPath(Core::System& system, VirtualDir dir,
|
||||||
SaveDataSpaceId space, SaveDataType type, u64 title_id,
|
SaveDataSpaceId space, SaveDataType type, u64 title_id,
|
||||||
u128 user_id, u64 save_id) {
|
u128 user_id, u64 save_id) {
|
||||||
// According to switchbrew, if a save is of type SaveData and the title id field is 0, it should
|
// According to switchbrew, if a save is of type SaveData and the title id field is 0, it should
|
||||||
// be interpreted as the title id of the current process.
|
// be interpreted as the title id of the current process.
|
||||||
if (type == SaveDataType::SaveData || type == SaveDataType::DeviceSaveData) {
|
if (type == SaveDataType::SaveData || type == SaveDataType::DeviceSaveData) {
|
||||||
if (title_id == 0) {
|
if (title_id == 0) {
|
||||||
title_id = program_id;
|
title_id = system.GetApplicationProcessProgramID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +201,7 @@ std::string SaveDataFactory::GetUserGameSaveDataRoot(u128 user_id, bool future)
|
|||||||
SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
|
SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
|
||||||
u128 user_id) const {
|
u128 user_id) const {
|
||||||
const auto path =
|
const auto path =
|
||||||
GetFullPath(program_id, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
GetFullPath(system, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
||||||
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
||||||
|
|
||||||
const auto size_file = relative_dir->GetFile(GetSaveDataSizeFileName());
|
const auto size_file = relative_dir->GetFile(GetSaveDataSizeFileName());
|
||||||
@ -221,7 +220,7 @@ SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
|
|||||||
void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
|
void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
|
||||||
SaveDataSize new_value) const {
|
SaveDataSize new_value) const {
|
||||||
const auto path =
|
const auto path =
|
||||||
GetFullPath(program_id, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
GetFullPath(system, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
||||||
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
||||||
|
|
||||||
const auto size_file = relative_dir->CreateFile(GetSaveDataSizeFileName());
|
const auto size_file = relative_dir->CreateFile(GetSaveDataSizeFileName());
|
||||||
|
@ -87,13 +87,10 @@ constexpr const char* GetSaveDataSizeFileName() {
|
|||||||
return ".yuzu_save_size";
|
return ".yuzu_save_size";
|
||||||
}
|
}
|
||||||
|
|
||||||
using ProgramId = u64;
|
|
||||||
|
|
||||||
/// File system interface to the SaveData archive
|
/// File system interface to the SaveData archive
|
||||||
class SaveDataFactory {
|
class SaveDataFactory {
|
||||||
public:
|
public:
|
||||||
explicit SaveDataFactory(Core::System& system_, ProgramId program_id_,
|
explicit SaveDataFactory(Core::System& system_, VirtualDir save_directory_);
|
||||||
VirtualDir save_directory_);
|
|
||||||
~SaveDataFactory();
|
~SaveDataFactory();
|
||||||
|
|
||||||
VirtualDir Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
|
VirtualDir Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
|
||||||
@ -102,7 +99,7 @@ public:
|
|||||||
VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
|
VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
|
||||||
|
|
||||||
static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
|
static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
|
||||||
static std::string GetFullPath(ProgramId program_id, VirtualDir dir, SaveDataSpaceId space,
|
static std::string GetFullPath(Core::System& system, VirtualDir dir, SaveDataSpaceId space,
|
||||||
SaveDataType type, u64 title_id, u128 user_id, u64 save_id);
|
SaveDataType type, u64 title_id, u128 user_id, u64 save_id);
|
||||||
static std::string GetUserGameSaveDataRoot(u128 user_id, bool future);
|
static std::string GetUserGameSaveDataRoot(u128 user_id, bool future);
|
||||||
|
|
||||||
@ -113,9 +110,8 @@ public:
|
|||||||
void SetAutoCreate(bool state);
|
void SetAutoCreate(bool state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& system;
|
|
||||||
ProgramId program_id;
|
|
||||||
VirtualDir dir;
|
VirtualDir dir;
|
||||||
|
Core::System& system;
|
||||||
bool auto_create{true};
|
bool auto_create{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "common/settings_enums.h"
|
#include "common/settings_enums.h"
|
||||||
#include "core/frontend/applets/controller.h"
|
#include "core/frontend/applets/controller.h"
|
||||||
#include "hid_core/frontend/emulated_controller.h"
|
#include "core/hid/emulated_controller.h"
|
||||||
#include "hid_core/hid_core.h"
|
#include "core/hid/hid_core.h"
|
||||||
#include "hid_core/hid_types.h"
|
#include "core/hid/hid_types.h"
|
||||||
|
|
||||||
namespace Core::Frontend {
|
namespace Core::Frontend {
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core/device_memory_manager.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public:
|
|||||||
|
|
||||||
~GPUDirtyMemoryManager() = default;
|
~GPUDirtyMemoryManager() = default;
|
||||||
|
|
||||||
void Collect(PAddr address, size_t size) {
|
void Collect(VAddr address, size_t size) {
|
||||||
TransformAddress t = BuildTransform(address, size);
|
TransformAddress t = BuildTransform(address, size);
|
||||||
TransformAddress tmp, original;
|
TransformAddress tmp, original;
|
||||||
do {
|
do {
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
std::memory_order_relaxed));
|
std::memory_order_relaxed));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gather(std::function<void(PAddr, size_t)>& callback) {
|
void Gather(std::function<void(VAddr, size_t)>& callback) {
|
||||||
{
|
{
|
||||||
std::scoped_lock lk(guard);
|
std::scoped_lock lk(guard);
|
||||||
TransformAddress t = current.exchange(default_transform, std::memory_order_relaxed);
|
TransformAddress t = current.exchange(default_transform, std::memory_order_relaxed);
|
||||||
@ -65,7 +65,7 @@ public:
|
|||||||
mask = mask >> empty_bits;
|
mask = mask >> empty_bits;
|
||||||
|
|
||||||
const size_t continuous_bits = std::countr_one(mask);
|
const size_t continuous_bits = std::countr_one(mask);
|
||||||
callback((static_cast<PAddr>(transform.address) << page_bits) + offset,
|
callback((static_cast<VAddr>(transform.address) << page_bits) + offset,
|
||||||
continuous_bits << align_bits);
|
continuous_bits << align_bits);
|
||||||
mask = continuous_bits < align_size ? (mask >> continuous_bits) : 0;
|
mask = continuous_bits < align_size ? (mask >> continuous_bits) : 0;
|
||||||
offset += continuous_bits << align_bits;
|
offset += continuous_bits << align_bits;
|
||||||
@ -80,7 +80,7 @@ private:
|
|||||||
u32 mask;
|
u32 mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr static size_t page_bits = DEVICE_PAGEBITS - 1;
|
constexpr static size_t page_bits = Memory::YUZU_PAGEBITS - 1;
|
||||||
constexpr static size_t page_size = 1ULL << page_bits;
|
constexpr static size_t page_size = 1ULL << page_bits;
|
||||||
constexpr static size_t page_mask = page_size - 1;
|
constexpr static size_t page_mask = page_size - 1;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ private:
|
|||||||
constexpr static size_t align_mask = align_size - 1;
|
constexpr static size_t align_mask = align_size - 1;
|
||||||
constexpr static TransformAddress default_transform = {.address = ~0U, .mask = 0U};
|
constexpr static TransformAddress default_transform = {.address = ~0U, .mask = 0U};
|
||||||
|
|
||||||
bool IsValid(PAddr address) {
|
bool IsValid(VAddr address) {
|
||||||
return address < (1ULL << 39);
|
return address < (1ULL << 39);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ private:
|
|||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformAddress BuildTransform(PAddr address, size_t size) {
|
TransformAddress BuildTransform(VAddr address, size_t size) {
|
||||||
const size_t minor_address = address & page_mask;
|
const size_t minor_address = address & page_mask;
|
||||||
const size_t minor_bit = minor_address >> align_bits;
|
const size_t minor_bit = minor_address >> align_bits;
|
||||||
const size_t top_bit = (minor_address + size + align_mask) >> align_bits;
|
const size_t top_bit = (minor_address + size + align_mask) >> align_bits;
|
||||||
|
@ -1,214 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <iterator>
|
|
||||||
#include <memory>
|
|
||||||
#include <optional>
|
|
||||||
#include <span>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "common/assert.h"
|
|
||||||
#include "common/scratch_buffer.h"
|
|
||||||
|
|
||||||
namespace Core::Memory {
|
|
||||||
|
|
||||||
enum GuestMemoryFlags : u32 {
|
|
||||||
Read = 1 << 0,
|
|
||||||
Write = 1 << 1,
|
|
||||||
Safe = 1 << 2,
|
|
||||||
Cached = 1 << 3,
|
|
||||||
|
|
||||||
SafeRead = Read | Safe,
|
|
||||||
SafeWrite = Write | Safe,
|
|
||||||
SafeReadWrite = SafeRead | SafeWrite,
|
|
||||||
SafeReadCachedWrite = SafeReadWrite | Cached,
|
|
||||||
|
|
||||||
UnsafeRead = Read,
|
|
||||||
UnsafeWrite = Write,
|
|
||||||
UnsafeReadWrite = UnsafeRead | UnsafeWrite,
|
|
||||||
UnsafeReadCachedWrite = UnsafeReadWrite | Cached,
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <typename M, typename T, GuestMemoryFlags FLAGS>
|
|
||||||
class GuestMemory {
|
|
||||||
using iterator = T*;
|
|
||||||
using const_iterator = const T*;
|
|
||||||
using value_type = T;
|
|
||||||
using element_type = T;
|
|
||||||
using iterator_category = std::contiguous_iterator_tag;
|
|
||||||
|
|
||||||
public:
|
|
||||||
GuestMemory() = delete;
|
|
||||||
explicit GuestMemory(M& memory, u64 addr, std::size_t size,
|
|
||||||
Common::ScratchBuffer<T>* backup = nullptr)
|
|
||||||
: m_memory{memory}, m_addr{addr}, m_size{size} {
|
|
||||||
static_assert(FLAGS & GuestMemoryFlags::Read || FLAGS & GuestMemoryFlags::Write);
|
|
||||||
if constexpr (FLAGS & GuestMemoryFlags::Read) {
|
|
||||||
Read(addr, size, backup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~GuestMemory() = default;
|
|
||||||
|
|
||||||
T* data() noexcept {
|
|
||||||
return m_data_span.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
const T* data() const noexcept {
|
|
||||||
return m_data_span.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size() const noexcept {
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size_bytes() const noexcept {
|
|
||||||
return this->size() * sizeof(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] T* begin() noexcept {
|
|
||||||
return this->data();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] const T* begin() const noexcept {
|
|
||||||
return this->data();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] T* end() noexcept {
|
|
||||||
return this->data() + this->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] const T* end() const noexcept {
|
|
||||||
return this->data() + this->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
T& operator[](size_t index) noexcept {
|
|
||||||
return m_data_span[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& operator[](size_t index) const noexcept {
|
|
||||||
return m_data_span[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetAddressAndSize(u64 addr, std::size_t size) noexcept {
|
|
||||||
m_addr = addr;
|
|
||||||
m_size = size;
|
|
||||||
m_addr_changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::span<T> Read(u64 addr, std::size_t size,
|
|
||||||
Common::ScratchBuffer<T>* backup = nullptr) noexcept {
|
|
||||||
m_addr = addr;
|
|
||||||
m_size = size;
|
|
||||||
if (m_size == 0) {
|
|
||||||
m_is_data_copy = true;
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->TrySetSpan()) {
|
|
||||||
if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
|
||||||
m_memory.FlushRegion(m_addr, this->size_bytes());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (backup) {
|
|
||||||
backup->resize_destructive(this->size());
|
|
||||||
m_data_span = *backup;
|
|
||||||
} else {
|
|
||||||
m_data_copy.resize(this->size());
|
|
||||||
m_data_span = std::span(m_data_copy);
|
|
||||||
}
|
|
||||||
m_is_data_copy = true;
|
|
||||||
m_span_valid = true;
|
|
||||||
if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
|
||||||
m_memory.ReadBlock(m_addr, this->data(), this->size_bytes());
|
|
||||||
} else {
|
|
||||||
m_memory.ReadBlockUnsafe(m_addr, this->data(), this->size_bytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m_data_span;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Write(std::span<T> write_data) noexcept {
|
|
||||||
if constexpr (FLAGS & GuestMemoryFlags::Cached) {
|
|
||||||
m_memory.WriteBlockCached(m_addr, write_data.data(), this->size_bytes());
|
|
||||||
} else if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
|
||||||
m_memory.WriteBlock(m_addr, write_data.data(), this->size_bytes());
|
|
||||||
} else {
|
|
||||||
m_memory.WriteBlockUnsafe(m_addr, write_data.data(), this->size_bytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TrySetSpan() noexcept {
|
|
||||||
if (u8* ptr = m_memory.GetSpan(m_addr, this->size_bytes()); ptr) {
|
|
||||||
m_data_span = {reinterpret_cast<T*>(ptr), this->size()};
|
|
||||||
m_span_valid = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool IsDataCopy() const noexcept {
|
|
||||||
return m_is_data_copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AddressChanged() const noexcept {
|
|
||||||
return m_addr_changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
M& m_memory;
|
|
||||||
u64 m_addr{};
|
|
||||||
size_t m_size{};
|
|
||||||
std::span<T> m_data_span{};
|
|
||||||
std::vector<T> m_data_copy{};
|
|
||||||
bool m_span_valid{false};
|
|
||||||
bool m_is_data_copy{false};
|
|
||||||
bool m_addr_changed{false};
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename M, typename T, GuestMemoryFlags FLAGS>
|
|
||||||
class GuestMemoryScoped : public GuestMemory<M, T, FLAGS> {
|
|
||||||
public:
|
|
||||||
GuestMemoryScoped() = delete;
|
|
||||||
explicit GuestMemoryScoped(M& memory, u64 addr, std::size_t size,
|
|
||||||
Common::ScratchBuffer<T>* backup = nullptr)
|
|
||||||
: GuestMemory<M, T, FLAGS>(memory, addr, size, backup) {
|
|
||||||
if constexpr (!(FLAGS & GuestMemoryFlags::Read)) {
|
|
||||||
if (!this->TrySetSpan()) {
|
|
||||||
if (backup) {
|
|
||||||
this->m_data_span = *backup;
|
|
||||||
this->m_span_valid = true;
|
|
||||||
this->m_is_data_copy = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~GuestMemoryScoped() {
|
|
||||||
if constexpr (FLAGS & GuestMemoryFlags::Write) {
|
|
||||||
if (this->size() == 0) [[unlikely]] {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->AddressChanged() || this->IsDataCopy()) {
|
|
||||||
ASSERT(this->m_span_valid);
|
|
||||||
if constexpr (FLAGS & GuestMemoryFlags::Cached) {
|
|
||||||
this->m_memory.WriteBlockCached(this->m_addr, this->data(), this->size_bytes());
|
|
||||||
} else if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
|
||||||
this->m_memory.WriteBlock(this->m_addr, this->data(), this->size_bytes());
|
|
||||||
} else {
|
|
||||||
this->m_memory.WriteBlockUnsafe(this->m_addr, this->data(), this->size_bytes());
|
|
||||||
}
|
|
||||||
} else if constexpr ((FLAGS & GuestMemoryFlags::Safe) ||
|
|
||||||
(FLAGS & GuestMemoryFlags::Cached)) {
|
|
||||||
this->m_memory.InvalidateRegion(this->m_addr, this->size_bytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
} // namespace Core::Memory
|
|
@ -2,8 +2,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "hid_core/frontend/emulated_console.h"
|
#include "core/hid/emulated_console.h"
|
||||||
#include "hid_core/frontend/input_converter.h"
|
#include "core/hid/input_converter.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
EmulatedConsole::EmulatedConsole() = default;
|
EmulatedConsole::EmulatedConsole() = default;
|
@ -17,8 +17,8 @@
|
|||||||
#include "common/point.h"
|
#include "common/point.h"
|
||||||
#include "common/quaternion.h"
|
#include "common/quaternion.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
#include "hid_core/frontend/motion_input.h"
|
#include "core/hid/hid_types.h"
|
||||||
#include "hid_core/hid_types.h"
|
#include "core/hid/motion_input.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
static constexpr std::size_t MaxTouchDevices = 32;
|
static constexpr std::size_t MaxTouchDevices = 32;
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#include "common/polyfill_ranges.h"
|
#include "common/polyfill_ranges.h"
|
||||||
#include "common/thread.h"
|
#include "common/thread.h"
|
||||||
#include "hid_core/frontend/emulated_controller.h"
|
#include "core/hid/emulated_controller.h"
|
||||||
#include "hid_core/frontend/input_converter.h"
|
#include "core/hid/input_converter.h"
|
||||||
#include "hid_core/hid_util.h"
|
#include "core/hle/service/hid/hid_util.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
|
constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
|
@ -15,9 +15,9 @@
|
|||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
#include "hid_core/frontend/motion_input.h"
|
#include "core/hid/hid_types.h"
|
||||||
#include "hid_core/hid_types.h"
|
#include "core/hid/irs_types.h"
|
||||||
#include "hid_core/irsensor/irs_types.h"
|
#include "core/hid/motion_input.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
const std::size_t max_emulated_controllers = 2;
|
const std::size_t max_emulated_controllers = 2;
|
@ -4,8 +4,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "hid_core/frontend/emulated_devices.h"
|
#include "core/hid/emulated_devices.h"
|
||||||
#include "hid_core/frontend/input_converter.h"
|
#include "core/hid/input_converter.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
|
|
@ -14,7 +14,7 @@
|
|||||||
#include "common/input.h"
|
#include "common/input.h"
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "hid_core/hid_types.h"
|
#include "core/hid/hid_types.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
using KeyboardDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
|
using KeyboardDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
|
@ -2,11 +2,11 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "hid_core/frontend/emulated_console.h"
|
#include "core/hid/emulated_console.h"
|
||||||
#include "hid_core/frontend/emulated_controller.h"
|
#include "core/hid/emulated_controller.h"
|
||||||
#include "hid_core/frontend/emulated_devices.h"
|
#include "core/hid/emulated_devices.h"
|
||||||
#include "hid_core/hid_core.h"
|
#include "core/hid/hid_core.h"
|
||||||
#include "hid_core/hid_util.h"
|
#include "core/hle/service/hid/hid_util.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
|
|
@ -6,7 +6,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "hid_core/hid_types.h"
|
#include "core/hid/hid_types.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
class EmulatedConsole;
|
class EmulatedConsole;
|
@ -5,7 +5,7 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "common/input.h"
|
#include "common/input.h"
|
||||||
#include "hid_core/frontend/input_converter.h"
|
#include "core/hid/input_converter.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
|
|
@ -2,12 +2,12 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
#include "core/hid/hid_types.h"
|
||||||
|
#include "core/hid/input_interpreter.h"
|
||||||
|
#include "core/hle/service/hid/controllers/npad.h"
|
||||||
#include "core/hle/service/hid/hid_server.h"
|
#include "core/hle/service/hid/hid_server.h"
|
||||||
|
#include "core/hle/service/hid/resource_manager.h"
|
||||||
#include "core/hle/service/sm/sm.h"
|
#include "core/hle/service/sm/sm.h"
|
||||||
#include "hid_core/frontend/input_interpreter.h"
|
|
||||||
#include "hid_core/hid_types.h"
|
|
||||||
#include "hid_core/resource_manager.h"
|
|
||||||
#include "hid_core/resources/npad/npad.h"
|
|
||||||
|
|
||||||
InputInterpreter::InputInterpreter(Core::System& system)
|
InputInterpreter::InputInterpreter(Core::System& system)
|
||||||
: npad{system.ServiceManager()
|
: npad{system.ServiceManager()
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "hid_core/hid_types.h"
|
#include "core/hid/hid_types.h"
|
||||||
|
|
||||||
namespace Core::IrSensor {
|
namespace Core::IrSensor {
|
||||||
|
|
@ -4,7 +4,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
#include "hid_core/frontend/motion_input.h"
|
#include "core/hid/motion_input.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
|
|
@ -81,12 +81,12 @@ enum class KMemoryState : u32 {
|
|||||||
|
|
||||||
ThreadLocal = static_cast<u32>(Svc::MemoryState::ThreadLocal) | FlagLinearMapped,
|
ThreadLocal = static_cast<u32>(Svc::MemoryState::ThreadLocal) | FlagLinearMapped,
|
||||||
|
|
||||||
Transferred = static_cast<u32>(Svc::MemoryState::Transferred) | FlagsMisc |
|
Transfered = static_cast<u32>(Svc::MemoryState::Transfered) | FlagsMisc |
|
||||||
FlagCanAlignedDeviceMap | FlagCanChangeAttribute | FlagCanUseIpc |
|
FlagCanAlignedDeviceMap | FlagCanChangeAttribute | FlagCanUseIpc |
|
||||||
FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
||||||
|
|
||||||
SharedTransferred = static_cast<u32>(Svc::MemoryState::SharedTransferred) | FlagsMisc |
|
SharedTransfered = static_cast<u32>(Svc::MemoryState::SharedTransfered) | FlagsMisc |
|
||||||
FlagCanAlignedDeviceMap | FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
FlagCanAlignedDeviceMap | FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
||||||
|
|
||||||
SharedCode = static_cast<u32>(Svc::MemoryState::SharedCode) | FlagMapped |
|
SharedCode = static_cast<u32>(Svc::MemoryState::SharedCode) | FlagMapped |
|
||||||
FlagReferenceCounted | FlagLinearMapped | FlagCanUseNonSecureIpc |
|
FlagReferenceCounted | FlagLinearMapped | FlagCanUseNonSecureIpc |
|
||||||
@ -130,8 +130,8 @@ static_assert(static_cast<u32>(KMemoryState::AliasCodeData) == 0x0FFFBD09);
|
|||||||
static_assert(static_cast<u32>(KMemoryState::Ipc) == 0x045C3C0A);
|
static_assert(static_cast<u32>(KMemoryState::Ipc) == 0x045C3C0A);
|
||||||
static_assert(static_cast<u32>(KMemoryState::Stack) == 0x045C3C0B);
|
static_assert(static_cast<u32>(KMemoryState::Stack) == 0x045C3C0B);
|
||||||
static_assert(static_cast<u32>(KMemoryState::ThreadLocal) == 0x0400000C);
|
static_assert(static_cast<u32>(KMemoryState::ThreadLocal) == 0x0400000C);
|
||||||
static_assert(static_cast<u32>(KMemoryState::Transferred) == 0x055C3C0D);
|
static_assert(static_cast<u32>(KMemoryState::Transfered) == 0x055C3C0D);
|
||||||
static_assert(static_cast<u32>(KMemoryState::SharedTransferred) == 0x045C380E);
|
static_assert(static_cast<u32>(KMemoryState::SharedTransfered) == 0x045C380E);
|
||||||
static_assert(static_cast<u32>(KMemoryState::SharedCode) == 0x0440380F);
|
static_assert(static_cast<u32>(KMemoryState::SharedCode) == 0x0440380F);
|
||||||
static_assert(static_cast<u32>(KMemoryState::Inaccessible) == 0x00000010);
|
static_assert(static_cast<u32>(KMemoryState::Inaccessible) == 0x00000010);
|
||||||
static_assert(static_cast<u32>(KMemoryState::NonSecureIpc) == 0x045C3811);
|
static_assert(static_cast<u32>(KMemoryState::NonSecureIpc) == 0x045C3811);
|
||||||
|
@ -431,82 +431,9 @@ Result KPageTableBase::InitializeForProcess(Svc::CreateProcessFlag as_type, bool
|
|||||||
m_memory_block_slab_manager));
|
m_memory_block_slab_manager));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KPageTableBase::FinalizeProcess() {
|
|
||||||
// Only process tables should be finalized.
|
|
||||||
ASSERT(!this->IsKernel());
|
|
||||||
|
|
||||||
// HLE processes don't have memory mapped.
|
|
||||||
R_SUCCEED_IF(m_impl == nullptr);
|
|
||||||
|
|
||||||
// NOTE: Here Nintendo calls an unknown OnFinalize function.
|
|
||||||
// this->OnFinalize();
|
|
||||||
|
|
||||||
// NOTE: Here Nintendo calls a second unknown OnFinalize function.
|
|
||||||
// this->OnFinalize2();
|
|
||||||
|
|
||||||
// Get implementation objects.
|
|
||||||
auto& impl = this->GetImpl();
|
|
||||||
auto& mm = m_kernel.MemoryManager();
|
|
||||||
|
|
||||||
// Traverse, freeing all pages.
|
|
||||||
{
|
|
||||||
// Get the address space size.
|
|
||||||
const size_t as_size = this->GetAddressSpaceSize();
|
|
||||||
|
|
||||||
// Begin the traversal.
|
|
||||||
TraversalContext context;
|
|
||||||
TraversalEntry cur_entry = {
|
|
||||||
.phys_addr = 0,
|
|
||||||
.block_size = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
bool cur_valid = false;
|
|
||||||
TraversalEntry next_entry;
|
|
||||||
bool next_valid;
|
|
||||||
size_t tot_size = 0;
|
|
||||||
|
|
||||||
next_valid = impl.BeginTraversal(std::addressof(next_entry), std::addressof(context),
|
|
||||||
this->GetAddressSpaceStart());
|
|
||||||
|
|
||||||
// Iterate over entries.
|
|
||||||
while (true) {
|
|
||||||
if ((!next_valid && !cur_valid) ||
|
|
||||||
(next_valid && cur_valid &&
|
|
||||||
next_entry.phys_addr == cur_entry.phys_addr + cur_entry.block_size)) {
|
|
||||||
cur_entry.block_size += next_entry.block_size;
|
|
||||||
} else {
|
|
||||||
if (cur_valid && IsHeapPhysicalAddressForFinalize(cur_entry.phys_addr)) {
|
|
||||||
mm.Close(cur_entry.phys_addr, cur_entry.block_size / PageSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update tracking variables.
|
|
||||||
tot_size += cur_entry.block_size;
|
|
||||||
cur_entry = next_entry;
|
|
||||||
cur_valid = next_valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur_entry.block_size + tot_size >= as_size) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_valid =
|
|
||||||
impl.ContinueTraversal(std::addressof(next_entry), std::addressof(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle the last block.
|
|
||||||
if (cur_valid && IsHeapPhysicalAddressForFinalize(cur_entry.phys_addr)) {
|
|
||||||
mm.Close(cur_entry.phys_addr, cur_entry.block_size / PageSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
R_SUCCEED();
|
|
||||||
}
|
|
||||||
|
|
||||||
void KPageTableBase::Finalize() {
|
void KPageTableBase::Finalize() {
|
||||||
this->FinalizeProcess();
|
|
||||||
|
|
||||||
auto HostUnmapCallback = [&](KProcessAddress addr, u64 size) {
|
auto HostUnmapCallback = [&](KProcessAddress addr, u64 size) {
|
||||||
if (m_impl->fastmem_arena) {
|
if (Settings::IsFastmemEnabled()) {
|
||||||
m_system.DeviceMemory().buffer.Unmap(GetInteger(addr), size, false);
|
m_system.DeviceMemory().buffer.Unmap(GetInteger(addr), size, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -559,8 +486,8 @@ KProcessAddress KPageTableBase::GetRegionAddress(Svc::MemoryState state) const {
|
|||||||
case Svc::MemoryState::Shared:
|
case Svc::MemoryState::Shared:
|
||||||
case Svc::MemoryState::AliasCode:
|
case Svc::MemoryState::AliasCode:
|
||||||
case Svc::MemoryState::AliasCodeData:
|
case Svc::MemoryState::AliasCodeData:
|
||||||
case Svc::MemoryState::Transferred:
|
case Svc::MemoryState::Transfered:
|
||||||
case Svc::MemoryState::SharedTransferred:
|
case Svc::MemoryState::SharedTransfered:
|
||||||
case Svc::MemoryState::SharedCode:
|
case Svc::MemoryState::SharedCode:
|
||||||
case Svc::MemoryState::GeneratedCode:
|
case Svc::MemoryState::GeneratedCode:
|
||||||
case Svc::MemoryState::CodeOut:
|
case Svc::MemoryState::CodeOut:
|
||||||
@ -595,8 +522,8 @@ size_t KPageTableBase::GetRegionSize(Svc::MemoryState state) const {
|
|||||||
case Svc::MemoryState::Shared:
|
case Svc::MemoryState::Shared:
|
||||||
case Svc::MemoryState::AliasCode:
|
case Svc::MemoryState::AliasCode:
|
||||||
case Svc::MemoryState::AliasCodeData:
|
case Svc::MemoryState::AliasCodeData:
|
||||||
case Svc::MemoryState::Transferred:
|
case Svc::MemoryState::Transfered:
|
||||||
case Svc::MemoryState::SharedTransferred:
|
case Svc::MemoryState::SharedTransfered:
|
||||||
case Svc::MemoryState::SharedCode:
|
case Svc::MemoryState::SharedCode:
|
||||||
case Svc::MemoryState::GeneratedCode:
|
case Svc::MemoryState::GeneratedCode:
|
||||||
case Svc::MemoryState::CodeOut:
|
case Svc::MemoryState::CodeOut:
|
||||||
@ -637,8 +564,8 @@ bool KPageTableBase::CanContain(KProcessAddress addr, size_t size, Svc::MemorySt
|
|||||||
case Svc::MemoryState::AliasCodeData:
|
case Svc::MemoryState::AliasCodeData:
|
||||||
case Svc::MemoryState::Stack:
|
case Svc::MemoryState::Stack:
|
||||||
case Svc::MemoryState::ThreadLocal:
|
case Svc::MemoryState::ThreadLocal:
|
||||||
case Svc::MemoryState::Transferred:
|
case Svc::MemoryState::Transfered:
|
||||||
case Svc::MemoryState::SharedTransferred:
|
case Svc::MemoryState::SharedTransfered:
|
||||||
case Svc::MemoryState::SharedCode:
|
case Svc::MemoryState::SharedCode:
|
||||||
case Svc::MemoryState::GeneratedCode:
|
case Svc::MemoryState::GeneratedCode:
|
||||||
case Svc::MemoryState::CodeOut:
|
case Svc::MemoryState::CodeOut:
|
||||||
|
@ -241,7 +241,6 @@ public:
|
|||||||
KResourceLimit* resource_limit, Core::Memory::Memory& memory,
|
KResourceLimit* resource_limit, Core::Memory::Memory& memory,
|
||||||
KProcessAddress aslr_space_start);
|
KProcessAddress aslr_space_start);
|
||||||
|
|
||||||
Result FinalizeProcess();
|
|
||||||
void Finalize();
|
void Finalize();
|
||||||
|
|
||||||
bool IsKernel() const {
|
bool IsKernel() const {
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/gpu_dirty_memory_manager.h"
|
|
||||||
#include "core/hle/kernel/k_process.h"
|
#include "core/hle/kernel/k_process.h"
|
||||||
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
||||||
#include "core/hle/kernel/k_shared_memory.h"
|
#include "core/hle/kernel/k_shared_memory.h"
|
||||||
@ -172,12 +171,6 @@ void KProcess::Finalize() {
|
|||||||
m_resource_limit->Close();
|
m_resource_limit->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear expensive resources, as the destructor is not called for guest objects.
|
|
||||||
for (auto& interface : m_arm_interfaces) {
|
|
||||||
interface.reset();
|
|
||||||
}
|
|
||||||
m_exclusive_monitor.reset();
|
|
||||||
|
|
||||||
// Perform inherited finalization.
|
// Perform inherited finalization.
|
||||||
KSynchronizationObject::Finalize();
|
KSynchronizationObject::Finalize();
|
||||||
}
|
}
|
||||||
@ -321,7 +314,7 @@ Result KProcess::Initialize(const Svc::CreateProcessParameter& params, const KPa
|
|||||||
|
|
||||||
// Ensure our memory is initialized.
|
// Ensure our memory is initialized.
|
||||||
m_memory.SetCurrentPageTable(*this);
|
m_memory.SetCurrentPageTable(*this);
|
||||||
m_memory.SetGPUDirtyManagers(m_kernel.System().GetGPUDirtyMemoryManager());
|
m_memory.SetGPUDirtyManagers(m_dirty_memory_managers);
|
||||||
|
|
||||||
// Ensure we can insert the code region.
|
// Ensure we can insert the code region.
|
||||||
R_UNLESS(m_page_table.CanContain(params.code_address, params.code_num_pages * PageSize,
|
R_UNLESS(m_page_table.CanContain(params.code_address, params.code_num_pages * PageSize,
|
||||||
@ -418,7 +411,7 @@ Result KProcess::Initialize(const Svc::CreateProcessParameter& params,
|
|||||||
|
|
||||||
// Ensure our memory is initialized.
|
// Ensure our memory is initialized.
|
||||||
m_memory.SetCurrentPageTable(*this);
|
m_memory.SetCurrentPageTable(*this);
|
||||||
m_memory.SetGPUDirtyManagers(m_kernel.System().GetGPUDirtyMemoryManager());
|
m_memory.SetGPUDirtyManagers(m_dirty_memory_managers);
|
||||||
|
|
||||||
// Ensure we can insert the code region.
|
// Ensure we can insert the code region.
|
||||||
R_UNLESS(m_page_table.CanContain(params.code_address, code_size, KMemoryState::Code),
|
R_UNLESS(m_page_table.CanContain(params.code_address, code_size, KMemoryState::Code),
|
||||||
@ -1142,7 +1135,8 @@ void KProcess::Switch(KProcess* cur_process, KProcess* next_process) {}
|
|||||||
KProcess::KProcess(KernelCore& kernel)
|
KProcess::KProcess(KernelCore& kernel)
|
||||||
: KAutoObjectWithSlabHeapAndContainer(kernel), m_page_table{kernel}, m_state_lock{kernel},
|
: KAutoObjectWithSlabHeapAndContainer(kernel), m_page_table{kernel}, m_state_lock{kernel},
|
||||||
m_list_lock{kernel}, m_cond_var{kernel.System()}, m_address_arbiter{kernel.System()},
|
m_list_lock{kernel}, m_cond_var{kernel.System()}, m_address_arbiter{kernel.System()},
|
||||||
m_handle_table{kernel}, m_exclusive_monitor{}, m_memory{kernel.System()} {}
|
m_handle_table{kernel}, m_dirty_memory_managers{},
|
||||||
|
m_exclusive_monitor{}, m_memory{kernel.System()} {}
|
||||||
KProcess::~KProcess() = default;
|
KProcess::~KProcess() = default;
|
||||||
|
|
||||||
Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std::size_t code_size,
|
Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std::size_t code_size,
|
||||||
@ -1324,4 +1318,10 @@ bool KProcess::RemoveWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointT
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KProcess::GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback) {
|
||||||
|
for (auto& manager : m_dirty_memory_managers) {
|
||||||
|
manager.Gather(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
#include "core/file_sys/program_metadata.h"
|
#include "core/file_sys/program_metadata.h"
|
||||||
|
#include "core/gpu_dirty_memory_manager.h"
|
||||||
#include "core/hle/kernel/code_set.h"
|
#include "core/hle/kernel/code_set.h"
|
||||||
#include "core/hle/kernel/k_address_arbiter.h"
|
#include "core/hle/kernel/k_address_arbiter.h"
|
||||||
#include "core/hle/kernel/k_capabilities.h"
|
#include "core/hle/kernel/k_capabilities.h"
|
||||||
@ -127,6 +128,7 @@ private:
|
|||||||
#ifdef HAS_NCE
|
#ifdef HAS_NCE
|
||||||
std::unordered_map<u64, u64> m_post_handlers{};
|
std::unordered_map<u64, u64> m_post_handlers{};
|
||||||
#endif
|
#endif
|
||||||
|
std::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES> m_dirty_memory_managers;
|
||||||
std::unique_ptr<Core::ExclusiveMonitor> m_exclusive_monitor;
|
std::unique_ptr<Core::ExclusiveMonitor> m_exclusive_monitor;
|
||||||
Core::Memory::Memory m_memory;
|
Core::Memory::Memory m_memory;
|
||||||
|
|
||||||
@ -509,6 +511,8 @@ public:
|
|||||||
return m_memory;
|
return m_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback);
|
||||||
|
|
||||||
Core::ExclusiveMonitor& GetExclusiveMonitor() const {
|
Core::ExclusiveMonitor& GetExclusiveMonitor() const {
|
||||||
return *m_exclusive_monitor;
|
return *m_exclusive_monitor;
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ Result KTransferMemory::Map(KProcessAddress address, size_t size, Svc::MemoryPer
|
|||||||
|
|
||||||
// Map the memory.
|
// Map the memory.
|
||||||
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
||||||
? KMemoryState::Transferred
|
? KMemoryState::Transfered
|
||||||
: KMemoryState::SharedTransferred;
|
: KMemoryState::SharedTransfered;
|
||||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup(
|
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup(
|
||||||
address, *m_page_group, state, KMemoryPermission::UserReadWrite));
|
address, *m_page_group, state, KMemoryPermission::UserReadWrite));
|
||||||
|
|
||||||
@ -96,8 +96,8 @@ Result KTransferMemory::Unmap(KProcessAddress address, size_t size) {
|
|||||||
|
|
||||||
// Unmap the memory.
|
// Unmap the memory.
|
||||||
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
||||||
? KMemoryState::Transferred
|
? KMemoryState::Transfered
|
||||||
: KMemoryState::SharedTransferred;
|
: KMemoryState::SharedTransfered;
|
||||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().UnmapPageGroup(address, *m_page_group, state));
|
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().UnmapPageGroup(address, *m_page_group, state));
|
||||||
|
|
||||||
// Mark ourselves as unmapped.
|
// Mark ourselves as unmapped.
|
||||||
|
@ -770,7 +770,6 @@ struct KernelCore::Impl {
|
|||||||
std::atomic<u64> next_thread_id{1};
|
std::atomic<u64> next_thread_id{1};
|
||||||
|
|
||||||
// Lists all processes that exist in the current session.
|
// Lists all processes that exist in the current session.
|
||||||
std::mutex process_list_lock;
|
|
||||||
std::vector<KProcess*> process_list;
|
std::vector<KProcess*> process_list;
|
||||||
std::atomic<KProcess*> application_process{};
|
std::atomic<KProcess*> application_process{};
|
||||||
std::unique_ptr<Kernel::GlobalSchedulerContext> global_scheduler_context;
|
std::unique_ptr<Kernel::GlobalSchedulerContext> global_scheduler_context;
|
||||||
@ -870,19 +869,9 @@ KResourceLimit* KernelCore::GetSystemResourceLimit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KernelCore::AppendNewProcess(KProcess* process) {
|
void KernelCore::AppendNewProcess(KProcess* process) {
|
||||||
process->Open();
|
|
||||||
|
|
||||||
std::scoped_lock lk{impl->process_list_lock};
|
|
||||||
impl->process_list.push_back(process);
|
impl->process_list.push_back(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelCore::RemoveProcess(KProcess* process) {
|
|
||||||
std::scoped_lock lk{impl->process_list_lock};
|
|
||||||
if (std::erase(impl->process_list, process)) {
|
|
||||||
process->Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KernelCore::MakeApplicationProcess(KProcess* process) {
|
void KernelCore::MakeApplicationProcess(KProcess* process) {
|
||||||
impl->MakeApplicationProcess(process);
|
impl->MakeApplicationProcess(process);
|
||||||
}
|
}
|
||||||
@ -895,15 +884,8 @@ const KProcess* KernelCore::ApplicationProcess() const {
|
|||||||
return impl->application_process;
|
return impl->application_process;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<KScopedAutoObject<KProcess>> KernelCore::GetProcessList() {
|
const std::vector<KProcess*>& KernelCore::GetProcessList() const {
|
||||||
std::list<KScopedAutoObject<KProcess>> processes;
|
return impl->process_list;
|
||||||
std::scoped_lock lk{impl->process_list_lock};
|
|
||||||
|
|
||||||
for (auto* const process : impl->process_list) {
|
|
||||||
processes.emplace_back(process);
|
|
||||||
}
|
|
||||||
|
|
||||||
return processes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel::GlobalSchedulerContext& KernelCore::GlobalSchedulerContext() {
|
Kernel::GlobalSchedulerContext& KernelCore::GlobalSchedulerContext() {
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -117,9 +116,8 @@ public:
|
|||||||
/// Retrieves a shared pointer to the system resource limit instance.
|
/// Retrieves a shared pointer to the system resource limit instance.
|
||||||
KResourceLimit* GetSystemResourceLimit();
|
KResourceLimit* GetSystemResourceLimit();
|
||||||
|
|
||||||
/// Adds/removes the given pointer to an internal list of active processes.
|
/// Adds the given shared pointer to an internal list of active processes.
|
||||||
void AppendNewProcess(KProcess* process);
|
void AppendNewProcess(KProcess* process);
|
||||||
void RemoveProcess(KProcess* process);
|
|
||||||
|
|
||||||
/// Makes the given process the new application process.
|
/// Makes the given process the new application process.
|
||||||
void MakeApplicationProcess(KProcess* process);
|
void MakeApplicationProcess(KProcess* process);
|
||||||
@ -131,7 +129,7 @@ public:
|
|||||||
const KProcess* ApplicationProcess() const;
|
const KProcess* ApplicationProcess() const;
|
||||||
|
|
||||||
/// Retrieves the list of processes.
|
/// Retrieves the list of processes.
|
||||||
std::list<KScopedAutoObject<KProcess>> GetProcessList();
|
const std::vector<KProcess*>& GetProcessList() const;
|
||||||
|
|
||||||
/// Gets the sole instance of the global scheduler
|
/// Gets the sole instance of the global scheduler
|
||||||
Kernel::GlobalSchedulerContext& GlobalSchedulerContext();
|
Kernel::GlobalSchedulerContext& GlobalSchedulerContext();
|
||||||
|
@ -74,15 +74,13 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, u64 out_proc
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto& memory = GetCurrentMemory(kernel);
|
auto& memory = GetCurrentMemory(kernel);
|
||||||
auto process_list = kernel.GetProcessList();
|
const auto& process_list = kernel.GetProcessList();
|
||||||
auto it = process_list.begin();
|
|
||||||
|
|
||||||
const auto num_processes = process_list.size();
|
const auto num_processes = process_list.size();
|
||||||
const auto copy_amount =
|
const auto copy_amount =
|
||||||
std::min(static_cast<std::size_t>(out_process_ids_size), num_processes);
|
std::min(static_cast<std::size_t>(out_process_ids_size), num_processes);
|
||||||
|
|
||||||
for (std::size_t i = 0; i < copy_amount && it != process_list.end(); ++i, ++it) {
|
for (std::size_t i = 0; i < copy_amount; ++i) {
|
||||||
memory.Write64(out_process_ids, (*it)->GetProcessId());
|
memory.Write64(out_process_ids, process_list[i]->GetProcessId());
|
||||||
out_process_ids += sizeof(u64);
|
out_process_ids += sizeof(u64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t add
|
|||||||
// Verify that the mapping is in range.
|
// Verify that the mapping is in range.
|
||||||
R_UNLESS(GetCurrentProcess(system.Kernel())
|
R_UNLESS(GetCurrentProcess(system.Kernel())
|
||||||
.GetPageTable()
|
.GetPageTable()
|
||||||
.CanContain(address, size, KMemoryState::Transferred),
|
.CanContain(address, size, KMemoryState::Transfered),
|
||||||
ResultInvalidMemoryRegion);
|
ResultInvalidMemoryRegion);
|
||||||
|
|
||||||
// Map the transfer memory.
|
// Map the transfer memory.
|
||||||
@ -117,7 +117,7 @@ Result UnmapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t a
|
|||||||
// Verify that the mapping is in range.
|
// Verify that the mapping is in range.
|
||||||
R_UNLESS(GetCurrentProcess(system.Kernel())
|
R_UNLESS(GetCurrentProcess(system.Kernel())
|
||||||
.GetPageTable()
|
.GetPageTable()
|
||||||
.CanContain(address, size, KMemoryState::Transferred),
|
.CanContain(address, size, KMemoryState::Transfered),
|
||||||
ResultInvalidMemoryRegion);
|
ResultInvalidMemoryRegion);
|
||||||
|
|
||||||
// Unmap the transfer memory.
|
// Unmap the transfer memory.
|
||||||
|
@ -27,8 +27,8 @@ enum class MemoryState : u32 {
|
|||||||
Ipc = 0x0A,
|
Ipc = 0x0A,
|
||||||
Stack = 0x0B,
|
Stack = 0x0B,
|
||||||
ThreadLocal = 0x0C,
|
ThreadLocal = 0x0C,
|
||||||
Transferred = 0x0D,
|
Transfered = 0x0D,
|
||||||
SharedTransferred = 0x0E,
|
SharedTransfered = 0x0E,
|
||||||
SharedCode = 0x0F,
|
SharedCode = 0x0F,
|
||||||
Inaccessible = 0x10,
|
Inaccessible = 0x10,
|
||||||
NonSecureIpc = 0x11,
|
NonSecureIpc = 0x11,
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "core/file_sys/patch_manager.h"
|
#include "core/file_sys/patch_manager.h"
|
||||||
#include "core/file_sys/registered_cache.h"
|
#include "core/file_sys/registered_cache.h"
|
||||||
#include "core/file_sys/savedata_factory.h"
|
#include "core/file_sys/savedata_factory.h"
|
||||||
|
#include "core/hid/hid_types.h"
|
||||||
#include "core/hle/kernel/k_event.h"
|
#include "core/hle/kernel/k_event.h"
|
||||||
#include "core/hle/kernel/k_transfer_memory.h"
|
#include "core/hle/kernel/k_transfer_memory.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
@ -36,7 +37,7 @@
|
|||||||
#include "core/hle/service/caps/caps_su.h"
|
#include "core/hle/service/caps/caps_su.h"
|
||||||
#include "core/hle/service/caps/caps_types.h"
|
#include "core/hle/service/caps/caps_types.h"
|
||||||
#include "core/hle/service/filesystem/filesystem.h"
|
#include "core/hle/service/filesystem/filesystem.h"
|
||||||
#include "core/hle/service/filesystem/save_data_controller.h"
|
#include "core/hle/service/hid/controllers/npad.h"
|
||||||
#include "core/hle/service/ipc_helpers.h"
|
#include "core/hle/service/ipc_helpers.h"
|
||||||
#include "core/hle/service/ns/ns.h"
|
#include "core/hle/service/ns/ns.h"
|
||||||
#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
|
#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
|
||||||
@ -47,8 +48,6 @@
|
|||||||
#include "core/hle/service/vi/vi.h"
|
#include "core/hle/service/vi/vi.h"
|
||||||
#include "core/hle/service/vi/vi_results.h"
|
#include "core/hle/service/vi/vi_results.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
#include "hid_core/hid_types.h"
|
|
||||||
#include "hid_core/resources/npad/npad.h"
|
|
||||||
|
|
||||||
namespace Service::AM {
|
namespace Service::AM {
|
||||||
|
|
||||||
@ -2179,7 +2178,7 @@ void IApplicationFunctions::EnsureSaveData(HLERequestContext& ctx) {
|
|||||||
attribute.type = FileSys::SaveDataType::SaveData;
|
attribute.type = FileSys::SaveDataType::SaveData;
|
||||||
|
|
||||||
FileSys::VirtualDir save_data{};
|
FileSys::VirtualDir save_data{};
|
||||||
const auto res = system.GetFileSystemController().OpenSaveDataController()->CreateSaveData(
|
const auto res = system.GetFileSystemController().CreateSaveData(
|
||||||
&save_data, FileSys::SaveDataSpaceId::NandUser, attribute);
|
&save_data, FileSys::SaveDataSpaceId::NandUser, attribute);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 4};
|
IPC::ResponseBuilder rb{ctx, 4};
|
||||||
@ -2354,7 +2353,7 @@ void IApplicationFunctions::ExtendSaveData(HLERequestContext& ctx) {
|
|||||||
"new_journal={:016X}",
|
"new_journal={:016X}",
|
||||||
static_cast<u8>(type), user_id[1], user_id[0], new_normal_size, new_journal_size);
|
static_cast<u8>(type), user_id[1], user_id[0], new_normal_size, new_journal_size);
|
||||||
|
|
||||||
system.GetFileSystemController().OpenSaveDataController()->WriteSaveDataSize(
|
system.GetFileSystemController().WriteSaveDataSize(
|
||||||
type, system.GetApplicationProcessProgramID(), user_id,
|
type, system.GetApplicationProcessProgramID(), user_id,
|
||||||
{new_normal_size, new_journal_size});
|
{new_normal_size, new_journal_size});
|
||||||
|
|
||||||
@ -2379,7 +2378,7 @@ void IApplicationFunctions::GetSaveDataSize(HLERequestContext& ctx) {
|
|||||||
LOG_DEBUG(Service_AM, "called with type={:02X}, user_id={:016X}{:016X}", type, user_id[1],
|
LOG_DEBUG(Service_AM, "called with type={:02X}, user_id={:016X}{:016X}", type, user_id[1],
|
||||||
user_id[0]);
|
user_id[0]);
|
||||||
|
|
||||||
const auto size = system.GetFileSystemController().OpenSaveDataController()->ReadSaveDataSize(
|
const auto size = system.GetFileSystemController().ReadSaveDataSize(
|
||||||
type, system.GetApplicationProcessProgramID(), user_id);
|
type, system.GetApplicationProcessProgramID(), user_id);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 6};
|
IPC::ResponseBuilder rb{ctx, 6};
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/frontend/applets/cabinet.h"
|
#include "core/frontend/applets/cabinet.h"
|
||||||
|
#include "core/hid/hid_core.h"
|
||||||
#include "core/hle/kernel/k_event.h"
|
#include "core/hle/kernel/k_event.h"
|
||||||
#include "core/hle/kernel/k_readable_event.h"
|
#include "core/hle/kernel/k_readable_event.h"
|
||||||
#include "core/hle/service/am/am.h"
|
#include "core/hle/service/am/am.h"
|
||||||
#include "core/hle/service/am/applets/applet_cabinet.h"
|
#include "core/hle/service/am/applets/applet_cabinet.h"
|
||||||
#include "core/hle/service/mii/mii_manager.h"
|
#include "core/hle/service/mii/mii_manager.h"
|
||||||
#include "core/hle/service/nfc/common/device.h"
|
#include "core/hle/service/nfc/common/device.h"
|
||||||
#include "hid_core/hid_core.h"
|
|
||||||
|
|
||||||
namespace Service::AM::Applets {
|
namespace Service::AM::Applets {
|
||||||
|
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/frontend/applets/controller.h"
|
#include "core/frontend/applets/controller.h"
|
||||||
|
#include "core/hid/emulated_controller.h"
|
||||||
|
#include "core/hid/hid_core.h"
|
||||||
|
#include "core/hid/hid_types.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
#include "core/hle/service/am/am.h"
|
#include "core/hle/service/am/am.h"
|
||||||
#include "core/hle/service/am/applets/applet_controller.h"
|
#include "core/hle/service/am/applets/applet_controller.h"
|
||||||
#include "hid_core/frontend/emulated_controller.h"
|
#include "core/hle/service/hid/controllers/npad.h"
|
||||||
#include "hid_core/hid_core.h"
|
|
||||||
#include "hid_core/hid_types.h"
|
|
||||||
#include "hid_core/resources/npad/npad.h"
|
|
||||||
|
|
||||||
namespace Service::AM::Applets {
|
namespace Service::AM::Applets {
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ struct UiSettingsDisplayOptions {
|
|||||||
bool is_system_or_launcher;
|
bool is_system_or_launcher;
|
||||||
bool is_registration_permitted;
|
bool is_registration_permitted;
|
||||||
bool show_skip_button;
|
bool show_skip_button;
|
||||||
bool additional_select;
|
bool aditional_select;
|
||||||
bool show_user_selector;
|
bool show_user_selector;
|
||||||
bool is_unqualified_user_selectable;
|
bool is_unqualified_user_selectable;
|
||||||
};
|
};
|
||||||
|
@ -85,7 +85,7 @@ Result AlbumManager::GetAlbumFileList(std::vector<AlbumEntry>& out_entries, Albu
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries,
|
Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries,
|
||||||
ContentType content_type, s64 start_posix_time,
|
ContentType contex_type, s64 start_posix_time,
|
||||||
s64 end_posix_time, u64 aruid) const {
|
s64 end_posix_time, u64 aruid) const {
|
||||||
if (!is_mounted) {
|
if (!is_mounted) {
|
||||||
return ResultIsNotMounted;
|
return ResultIsNotMounted;
|
||||||
@ -94,7 +94,7 @@ Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& ou
|
|||||||
std::vector<ApplicationAlbumEntry> album_entries;
|
std::vector<ApplicationAlbumEntry> album_entries;
|
||||||
const auto start_date = ConvertToAlbumDateTime(start_posix_time);
|
const auto start_date = ConvertToAlbumDateTime(start_posix_time);
|
||||||
const auto end_date = ConvertToAlbumDateTime(end_posix_time);
|
const auto end_date = ConvertToAlbumDateTime(end_posix_time);
|
||||||
const auto result = GetAlbumFileList(album_entries, content_type, start_date, end_date, aruid);
|
const auto result = GetAlbumFileList(album_entries, contex_type, start_date, end_date, aruid);
|
||||||
|
|
||||||
if (result.IsError()) {
|
if (result.IsError()) {
|
||||||
return result;
|
return result;
|
||||||
@ -113,14 +113,14 @@ Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& ou
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumEntry>& out_entries,
|
Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumEntry>& out_entries,
|
||||||
ContentType content_type, AlbumFileDateTime start_date,
|
ContentType contex_type, AlbumFileDateTime start_date,
|
||||||
AlbumFileDateTime end_date, u64 aruid) const {
|
AlbumFileDateTime end_date, u64 aruid) const {
|
||||||
if (!is_mounted) {
|
if (!is_mounted) {
|
||||||
return ResultIsNotMounted;
|
return ResultIsNotMounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& [file_id, path] : album_files) {
|
for (auto& [file_id, path] : album_files) {
|
||||||
if (file_id.type != content_type) {
|
if (file_id.type != contex_type) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (file_id.date > start_date) {
|
if (file_id.date > start_date) {
|
||||||
@ -139,7 +139,7 @@ Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumEntry>& out_en
|
|||||||
.hash{},
|
.hash{},
|
||||||
.datetime = file_id.date,
|
.datetime = file_id.date,
|
||||||
.storage = file_id.storage,
|
.storage = file_id.storage,
|
||||||
.content = content_type,
|
.content = contex_type,
|
||||||
.unknown = 1,
|
.unknown = 1,
|
||||||
};
|
};
|
||||||
out_entries.push_back(entry);
|
out_entries.push_back(entry);
|
||||||
|
@ -45,10 +45,10 @@ public:
|
|||||||
Result GetAlbumFileList(std::vector<AlbumEntry>& out_entries, AlbumStorage storage,
|
Result GetAlbumFileList(std::vector<AlbumEntry>& out_entries, AlbumStorage storage,
|
||||||
u8 flags) const;
|
u8 flags) const;
|
||||||
Result GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries,
|
Result GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries,
|
||||||
ContentType content_type, s64 start_posix_time, s64 end_posix_time,
|
ContentType contex_type, s64 start_posix_time, s64 end_posix_time,
|
||||||
u64 aruid) const;
|
u64 aruid) const;
|
||||||
Result GetAlbumFileList(std::vector<ApplicationAlbumEntry>& out_entries,
|
Result GetAlbumFileList(std::vector<ApplicationAlbumEntry>& out_entries,
|
||||||
ContentType content_type, AlbumFileDateTime start_date,
|
ContentType contex_type, AlbumFileDateTime start_date,
|
||||||
AlbumFileDateTime end_date, u64 aruid) const;
|
AlbumFileDateTime end_date, u64 aruid) const;
|
||||||
Result GetAutoSavingStorage(bool& out_is_autosaving) const;
|
Result GetAutoSavingStorage(bool& out_is_autosaving) const;
|
||||||
Result LoadAlbumScreenShotImage(LoadAlbumScreenShotImageOutput& out_image_output,
|
Result LoadAlbumScreenShotImage(LoadAlbumScreenShotImageOutput& out_image_output,
|
||||||
|
@ -12,7 +12,7 @@ constexpr Result ResultUnknown5(ErrorModule::Capture, 5);
|
|||||||
constexpr Result ResultUnknown6(ErrorModule::Capture, 6);
|
constexpr Result ResultUnknown6(ErrorModule::Capture, 6);
|
||||||
constexpr Result ResultUnknown7(ErrorModule::Capture, 7);
|
constexpr Result ResultUnknown7(ErrorModule::Capture, 7);
|
||||||
constexpr Result ResultOutOfRange(ErrorModule::Capture, 8);
|
constexpr Result ResultOutOfRange(ErrorModule::Capture, 8);
|
||||||
constexpr Result ResultInvalidTimestamp(ErrorModule::Capture, 12);
|
constexpr Result ResulInvalidTimestamp(ErrorModule::Capture, 12);
|
||||||
constexpr Result ResultInvalidStorage(ErrorModule::Capture, 13);
|
constexpr Result ResultInvalidStorage(ErrorModule::Capture, 13);
|
||||||
constexpr Result ResultInvalidFileContents(ErrorModule::Capture, 14);
|
constexpr Result ResultInvalidFileContents(ErrorModule::Capture, 14);
|
||||||
constexpr Result ResultIsNotMounted(ErrorModule::Capture, 21);
|
constexpr Result ResultIsNotMounted(ErrorModule::Capture, 21);
|
||||||
|
@ -24,13 +24,15 @@
|
|||||||
#include "core/hle/service/filesystem/fsp_ldr.h"
|
#include "core/hle/service/filesystem/fsp_ldr.h"
|
||||||
#include "core/hle/service/filesystem/fsp_pr.h"
|
#include "core/hle/service/filesystem/fsp_pr.h"
|
||||||
#include "core/hle/service/filesystem/fsp_srv.h"
|
#include "core/hle/service/filesystem/fsp_srv.h"
|
||||||
#include "core/hle/service/filesystem/romfs_controller.h"
|
|
||||||
#include "core/hle/service/filesystem/save_data_controller.h"
|
|
||||||
#include "core/hle/service/server_manager.h"
|
#include "core/hle/service/server_manager.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
namespace Service::FileSystem {
|
namespace Service::FileSystem {
|
||||||
|
|
||||||
|
// A default size for normal/journal save data size if application control metadata cannot be found.
|
||||||
|
// This should be large enough to satisfy even the most extreme requirements (~4.2GB)
|
||||||
|
constexpr u64 SUFFICIENT_SAVE_DATA_SIZE = 0xF0000000;
|
||||||
|
|
||||||
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
|
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
|
||||||
std::string_view dir_name_) {
|
std::string_view dir_name_) {
|
||||||
std::string dir_name(Common::FS::SanitizePath(dir_name_));
|
std::string dir_name(Common::FS::SanitizePath(dir_name_));
|
||||||
@ -295,65 +297,145 @@ FileSystemController::FileSystemController(Core::System& system_) : system{syste
|
|||||||
|
|
||||||
FileSystemController::~FileSystemController() = default;
|
FileSystemController::~FileSystemController() = default;
|
||||||
|
|
||||||
Result FileSystemController::RegisterProcess(
|
Result FileSystemController::RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory) {
|
||||||
ProcessId process_id, ProgramId program_id,
|
romfs_factory = std::move(factory);
|
||||||
std::shared_ptr<FileSys::RomFSFactory>&& romfs_factory) {
|
LOG_DEBUG(Service_FS, "Registered RomFS");
|
||||||
std::scoped_lock lk{registration_lock};
|
|
||||||
|
|
||||||
registrations.emplace(process_id, Registration{
|
|
||||||
.program_id = program_id,
|
|
||||||
.romfs_factory = std::move(romfs_factory),
|
|
||||||
.save_data_factory = CreateSaveDataFactory(program_id),
|
|
||||||
});
|
|
||||||
|
|
||||||
LOG_DEBUG(Service_FS, "Registered for process {}", process_id);
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result FileSystemController::OpenProcess(
|
Result FileSystemController::RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory) {
|
||||||
ProgramId* out_program_id, std::shared_ptr<SaveDataController>* out_save_data_controller,
|
ASSERT_MSG(save_data_factory == nullptr, "Tried to register a second save data");
|
||||||
std::shared_ptr<RomFsController>* out_romfs_controller, ProcessId process_id) {
|
save_data_factory = std::move(factory);
|
||||||
std::scoped_lock lk{registration_lock};
|
LOG_DEBUG(Service_FS, "Registered save data");
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
const auto it = registrations.find(process_id);
|
Result FileSystemController::RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory) {
|
||||||
if (it == registrations.end()) {
|
ASSERT_MSG(sdmc_factory == nullptr, "Tried to register a second SDMC");
|
||||||
|
sdmc_factory = std::move(factory);
|
||||||
|
LOG_DEBUG(Service_FS, "Registered SDMC");
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FileSystemController::RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory) {
|
||||||
|
ASSERT_MSG(bis_factory == nullptr, "Tried to register a second BIS");
|
||||||
|
bis_factory = std::move(factory);
|
||||||
|
LOG_DEBUG(Service_FS, "Registered BIS");
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileSystemController::SetPackedUpdate(FileSys::VirtualFile update_raw) {
|
||||||
|
LOG_TRACE(Service_FS, "Setting packed update for romfs");
|
||||||
|
|
||||||
|
if (romfs_factory == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
romfs_factory->SetPackedUpdate(std::move(update_raw));
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSys::VirtualFile FileSystemController::OpenRomFSCurrentProcess() const {
|
||||||
|
LOG_TRACE(Service_FS, "Opening RomFS for current process");
|
||||||
|
|
||||||
|
if (romfs_factory == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return romfs_factory->OpenCurrentProcess(system.GetApplicationProcessProgramID());
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSys::VirtualFile FileSystemController::OpenPatchedRomFS(u64 title_id,
|
||||||
|
FileSys::ContentRecordType type) const {
|
||||||
|
LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}", title_id);
|
||||||
|
|
||||||
|
if (romfs_factory == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return romfs_factory->OpenPatchedRomFS(title_id, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSys::VirtualFile FileSystemController::OpenPatchedRomFSWithProgramIndex(
|
||||||
|
u64 title_id, u8 program_index, FileSys::ContentRecordType type) const {
|
||||||
|
LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}, program_index={}", title_id,
|
||||||
|
program_index);
|
||||||
|
|
||||||
|
if (romfs_factory == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return romfs_factory->OpenPatchedRomFSWithProgramIndex(title_id, program_index, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSys::VirtualFile FileSystemController::OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
||||||
|
FileSys::ContentRecordType type) const {
|
||||||
|
LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}, storage_id={:02X}, type={:02X}",
|
||||||
|
title_id, storage_id, type);
|
||||||
|
|
||||||
|
if (romfs_factory == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return romfs_factory->Open(title_id, storage_id, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<FileSys::NCA> FileSystemController::OpenBaseNca(
|
||||||
|
u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type) const {
|
||||||
|
return romfs_factory->GetEntry(title_id, storage_id, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FileSystemController::CreateSaveData(FileSys::VirtualDir* out_save_data,
|
||||||
|
FileSys::SaveDataSpaceId space,
|
||||||
|
const FileSys::SaveDataAttribute& save_struct) const {
|
||||||
|
LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", space,
|
||||||
|
save_struct.DebugInfo());
|
||||||
|
|
||||||
|
if (save_data_factory == nullptr) {
|
||||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_program_id = it->second.program_id;
|
auto save_data = save_data_factory->Create(space, save_struct);
|
||||||
*out_save_data_controller =
|
if (save_data == nullptr) {
|
||||||
std::make_shared<SaveDataController>(system, it->second.save_data_factory);
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||||
*out_romfs_controller =
|
}
|
||||||
std::make_shared<RomFsController>(it->second.romfs_factory, it->second.program_id);
|
|
||||||
|
*out_save_data = save_data;
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSystemController::SetPackedUpdate(ProcessId process_id, FileSys::VirtualFile update_raw) {
|
Result FileSystemController::OpenSaveData(FileSys::VirtualDir* out_save_data,
|
||||||
LOG_TRACE(Service_FS, "Setting packed update for romfs");
|
FileSys::SaveDataSpaceId space,
|
||||||
|
const FileSys::SaveDataAttribute& attribute) const {
|
||||||
|
LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", space,
|
||||||
|
attribute.DebugInfo());
|
||||||
|
|
||||||
std::scoped_lock lk{registration_lock};
|
if (save_data_factory == nullptr) {
|
||||||
const auto it = registrations.find(process_id);
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||||
if (it == registrations.end()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it->second.romfs_factory->SetPackedUpdate(std::move(update_raw));
|
auto save_data = save_data_factory->Open(space, attribute);
|
||||||
|
if (save_data == nullptr) {
|
||||||
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_save_data = save_data;
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SaveDataController> FileSystemController::OpenSaveDataController() {
|
Result FileSystemController::OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space,
|
||||||
return std::make_shared<SaveDataController>(system, CreateSaveDataFactory(ProgramId{}));
|
FileSys::SaveDataSpaceId space) const {
|
||||||
}
|
LOG_TRACE(Service_FS, "Opening Save Data Space for space_id={:01X}", space);
|
||||||
|
|
||||||
std::shared_ptr<FileSys::SaveDataFactory> FileSystemController::CreateSaveDataFactory(
|
if (save_data_factory == nullptr) {
|
||||||
ProgramId program_id) {
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||||
using YuzuPath = Common::FS::YuzuPath;
|
}
|
||||||
const auto rw_mode = FileSys::Mode::ReadWrite;
|
|
||||||
|
|
||||||
auto vfs = system.GetFilesystem();
|
auto save_data_space = save_data_factory->GetSaveDataSpaceDirectory(space);
|
||||||
const auto nand_directory =
|
if (save_data_space == nullptr) {
|
||||||
vfs->OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::NANDDir), rw_mode);
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||||
return std::make_shared<FileSys::SaveDataFactory>(system, program_id,
|
}
|
||||||
std::move(nand_directory));
|
|
||||||
|
*out_save_data_space = save_data_space;
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result FileSystemController::OpenSDMC(FileSys::VirtualDir* out_sdmc) const {
|
Result FileSystemController::OpenSDMC(FileSys::VirtualDir* out_sdmc) const {
|
||||||
@ -458,6 +540,48 @@ u64 FileSystemController::GetTotalSpaceSize(FileSys::StorageId id) const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileSys::SaveDataSize FileSystemController::ReadSaveDataSize(FileSys::SaveDataType type,
|
||||||
|
u64 title_id, u128 user_id) const {
|
||||||
|
if (save_data_factory == nullptr) {
|
||||||
|
return {0, 0};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto value = save_data_factory->ReadSaveDataSize(type, title_id, user_id);
|
||||||
|
|
||||||
|
if (value.normal == 0 && value.journal == 0) {
|
||||||
|
FileSys::SaveDataSize new_size{SUFFICIENT_SAVE_DATA_SIZE, SUFFICIENT_SAVE_DATA_SIZE};
|
||||||
|
|
||||||
|
FileSys::NACP nacp;
|
||||||
|
const auto res = system.GetAppLoader().ReadControlData(nacp);
|
||||||
|
|
||||||
|
if (res != Loader::ResultStatus::Success) {
|
||||||
|
const FileSys::PatchManager pm{system.GetApplicationProcessProgramID(),
|
||||||
|
system.GetFileSystemController(),
|
||||||
|
system.GetContentProvider()};
|
||||||
|
const auto metadata = pm.GetControlMetadata();
|
||||||
|
const auto& nacp_unique = metadata.first;
|
||||||
|
|
||||||
|
if (nacp_unique != nullptr) {
|
||||||
|
new_size = {nacp_unique->GetDefaultNormalSaveSize(),
|
||||||
|
nacp_unique->GetDefaultJournalSaveSize()};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new_size = {nacp.GetDefaultNormalSaveSize(), nacp.GetDefaultJournalSaveSize()};
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteSaveDataSize(type, title_id, user_id, new_size);
|
||||||
|
return new_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileSystemController::WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
|
||||||
|
FileSys::SaveDataSize new_value) const {
|
||||||
|
if (save_data_factory != nullptr)
|
||||||
|
save_data_factory->WriteSaveDataSize(type, title_id, user_id, new_value);
|
||||||
|
}
|
||||||
|
|
||||||
void FileSystemController::SetGameCard(FileSys::VirtualFile file) {
|
void FileSystemController::SetGameCard(FileSys::VirtualFile file) {
|
||||||
gamecard = std::make_unique<FileSys::XCI>(file);
|
gamecard = std::make_unique<FileSys::XCI>(file);
|
||||||
const auto dir = gamecard->ConcatenatedPseudoDirectory();
|
const auto dir = gamecard->ConcatenatedPseudoDirectory();
|
||||||
@ -677,9 +801,14 @@ FileSys::VirtualDir FileSystemController::GetBCATDirectory(u64 title_id) const {
|
|||||||
return bis_factory->GetBCATDirectory(title_id);
|
return bis_factory->GetBCATDirectory(title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSystemController::SetAutoSaveDataCreation(bool enable) {
|
||||||
|
save_data_factory->SetAutoCreate(enable);
|
||||||
|
}
|
||||||
|
|
||||||
void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite) {
|
void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite) {
|
||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
bis_factory = nullptr;
|
bis_factory = nullptr;
|
||||||
|
save_data_factory = nullptr;
|
||||||
sdmc_factory = nullptr;
|
sdmc_factory = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,6 +836,11 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove
|
|||||||
bis_factory->GetUserNANDContents());
|
bis_factory->GetUserNANDContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (save_data_factory == nullptr) {
|
||||||
|
save_data_factory =
|
||||||
|
std::make_unique<FileSys::SaveDataFactory>(system, std::move(nand_directory));
|
||||||
|
}
|
||||||
|
|
||||||
if (sdmc_factory == nullptr) {
|
if (sdmc_factory == nullptr) {
|
||||||
sdmc_factory = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory),
|
sdmc_factory = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory),
|
||||||
std::move(sd_load_directory));
|
std::move(sd_load_directory));
|
||||||
@ -715,19 +849,12 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSystemController::Reset() {
|
|
||||||
std::scoped_lock lk{registration_lock};
|
|
||||||
registrations.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoopProcess(Core::System& system) {
|
void LoopProcess(Core::System& system) {
|
||||||
auto server_manager = std::make_unique<ServerManager>(system);
|
auto server_manager = std::make_unique<ServerManager>(system);
|
||||||
|
|
||||||
const auto FileSystemProxyFactory = [&] { return std::make_shared<FSP_SRV>(system); };
|
|
||||||
|
|
||||||
server_manager->RegisterNamedService("fsp-ldr", std::make_shared<FSP_LDR>(system));
|
server_manager->RegisterNamedService("fsp-ldr", std::make_shared<FSP_LDR>(system));
|
||||||
server_manager->RegisterNamedService("fsp:pr", std::make_shared<FSP_PR>(system));
|
server_manager->RegisterNamedService("fsp:pr", std::make_shared<FSP_PR>(system));
|
||||||
server_manager->RegisterNamedService("fsp-srv", std::move(FileSystemProxyFactory));
|
server_manager->RegisterNamedService("fsp-srv", std::make_shared<FSP_SRV>(system));
|
||||||
ServerManager::RunServer(std::move(server_manager));
|
ServerManager::RunServer(std::move(server_manager));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +43,6 @@ class ServiceManager;
|
|||||||
|
|
||||||
namespace FileSystem {
|
namespace FileSystem {
|
||||||
|
|
||||||
class RomFsController;
|
|
||||||
class SaveDataController;
|
|
||||||
|
|
||||||
enum class ContentStorageId : u32 {
|
enum class ContentStorageId : u32 {
|
||||||
System,
|
System,
|
||||||
User,
|
User,
|
||||||
@ -64,24 +61,32 @@ enum class OpenDirectoryMode : u64 {
|
|||||||
};
|
};
|
||||||
DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode);
|
DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode);
|
||||||
|
|
||||||
using ProcessId = u64;
|
|
||||||
using ProgramId = u64;
|
|
||||||
|
|
||||||
class FileSystemController {
|
class FileSystemController {
|
||||||
public:
|
public:
|
||||||
explicit FileSystemController(Core::System& system_);
|
explicit FileSystemController(Core::System& system_);
|
||||||
~FileSystemController();
|
~FileSystemController();
|
||||||
|
|
||||||
Result RegisterProcess(ProcessId process_id, ProgramId program_id,
|
Result RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory);
|
||||||
std::shared_ptr<FileSys::RomFSFactory>&& factory);
|
Result RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory);
|
||||||
Result OpenProcess(ProgramId* out_program_id,
|
Result RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory);
|
||||||
std::shared_ptr<SaveDataController>* out_save_data_controller,
|
Result RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory);
|
||||||
std::shared_ptr<RomFsController>* out_romfs_controller,
|
|
||||||
ProcessId process_id);
|
|
||||||
void SetPackedUpdate(ProcessId process_id, FileSys::VirtualFile update_raw);
|
|
||||||
|
|
||||||
std::shared_ptr<SaveDataController> OpenSaveDataController();
|
void SetPackedUpdate(FileSys::VirtualFile update_raw);
|
||||||
|
FileSys::VirtualFile OpenRomFSCurrentProcess() const;
|
||||||
|
FileSys::VirtualFile OpenPatchedRomFS(u64 title_id, FileSys::ContentRecordType type) const;
|
||||||
|
FileSys::VirtualFile OpenPatchedRomFSWithProgramIndex(u64 title_id, u8 program_index,
|
||||||
|
FileSys::ContentRecordType type) const;
|
||||||
|
FileSys::VirtualFile OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
||||||
|
FileSys::ContentRecordType type) const;
|
||||||
|
std::shared_ptr<FileSys::NCA> OpenBaseNca(u64 title_id, FileSys::StorageId storage_id,
|
||||||
|
FileSys::ContentRecordType type) const;
|
||||||
|
|
||||||
|
Result CreateSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space,
|
||||||
|
const FileSys::SaveDataAttribute& save_struct) const;
|
||||||
|
Result OpenSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space,
|
||||||
|
const FileSys::SaveDataAttribute& save_struct) const;
|
||||||
|
Result OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space,
|
||||||
|
FileSys::SaveDataSpaceId space) const;
|
||||||
Result OpenSDMC(FileSys::VirtualDir* out_sdmc) const;
|
Result OpenSDMC(FileSys::VirtualDir* out_sdmc) const;
|
||||||
Result OpenBISPartition(FileSys::VirtualDir* out_bis_partition,
|
Result OpenBISPartition(FileSys::VirtualDir* out_bis_partition,
|
||||||
FileSys::BisPartitionId id) const;
|
FileSys::BisPartitionId id) const;
|
||||||
@ -91,6 +96,11 @@ public:
|
|||||||
u64 GetFreeSpaceSize(FileSys::StorageId id) const;
|
u64 GetFreeSpaceSize(FileSys::StorageId id) const;
|
||||||
u64 GetTotalSpaceSize(FileSys::StorageId id) const;
|
u64 GetTotalSpaceSize(FileSys::StorageId id) const;
|
||||||
|
|
||||||
|
FileSys::SaveDataSize ReadSaveDataSize(FileSys::SaveDataType type, u64 title_id,
|
||||||
|
u128 user_id) const;
|
||||||
|
void WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
|
||||||
|
FileSys::SaveDataSize new_value) const;
|
||||||
|
|
||||||
void SetGameCard(FileSys::VirtualFile file);
|
void SetGameCard(FileSys::VirtualFile file);
|
||||||
FileSys::XCI* GetGameCard() const;
|
FileSys::XCI* GetGameCard() const;
|
||||||
|
|
||||||
@ -123,24 +133,15 @@ public:
|
|||||||
|
|
||||||
FileSys::VirtualDir GetBCATDirectory(u64 title_id) const;
|
FileSys::VirtualDir GetBCATDirectory(u64 title_id) const;
|
||||||
|
|
||||||
|
void SetAutoSaveDataCreation(bool enable);
|
||||||
|
|
||||||
// Creates the SaveData, SDMC, and BIS Factories. Should be called once and before any function
|
// Creates the SaveData, SDMC, and BIS Factories. Should be called once and before any function
|
||||||
// above is called.
|
// above is called.
|
||||||
void CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite = true);
|
void CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite = true);
|
||||||
|
|
||||||
void Reset();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<FileSys::SaveDataFactory> CreateSaveDataFactory(ProgramId program_id);
|
std::unique_ptr<FileSys::RomFSFactory> romfs_factory;
|
||||||
|
std::unique_ptr<FileSys::SaveDataFactory> save_data_factory;
|
||||||
struct Registration {
|
|
||||||
ProgramId program_id;
|
|
||||||
std::shared_ptr<FileSys::RomFSFactory> romfs_factory;
|
|
||||||
std::shared_ptr<FileSys::SaveDataFactory> save_data_factory;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::mutex registration_lock;
|
|
||||||
std::map<ProcessId, Registration> registrations;
|
|
||||||
|
|
||||||
std::unique_ptr<FileSys::SDMCFactory> sdmc_factory;
|
std::unique_ptr<FileSys::SDMCFactory> sdmc_factory;
|
||||||
std::unique_ptr<FileSys::BISFactory> bis_factory;
|
std::unique_ptr<FileSys::BISFactory> bis_factory;
|
||||||
|
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
#include "core/hle/service/filesystem/filesystem.h"
|
#include "core/hle/service/filesystem/filesystem.h"
|
||||||
#include "core/hle/service/filesystem/fsp_srv.h"
|
#include "core/hle/service/filesystem/fsp_srv.h"
|
||||||
#include "core/hle/service/filesystem/romfs_controller.h"
|
|
||||||
#include "core/hle/service/filesystem/save_data_controller.h"
|
|
||||||
#include "core/hle/service/hle_ipc.h"
|
#include "core/hle/service/hle_ipc.h"
|
||||||
#include "core/hle/service/ipc_helpers.h"
|
#include "core/hle/service/ipc_helpers.h"
|
||||||
#include "core/reporter.h"
|
#include "core/reporter.h"
|
||||||
@ -579,11 +577,9 @@ private:
|
|||||||
|
|
||||||
class ISaveDataInfoReader final : public ServiceFramework<ISaveDataInfoReader> {
|
class ISaveDataInfoReader final : public ServiceFramework<ISaveDataInfoReader> {
|
||||||
public:
|
public:
|
||||||
explicit ISaveDataInfoReader(Core::System& system_,
|
explicit ISaveDataInfoReader(Core::System& system_, FileSys::SaveDataSpaceId space,
|
||||||
std::shared_ptr<SaveDataController> save_data_controller_,
|
FileSystemController& fsc_)
|
||||||
FileSys::SaveDataSpaceId space)
|
: ServiceFramework{system_, "ISaveDataInfoReader"}, fsc{fsc_} {
|
||||||
: ServiceFramework{system_, "ISaveDataInfoReader"}, save_data_controller{
|
|
||||||
save_data_controller_} {
|
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &ISaveDataInfoReader::ReadSaveDataInfo, "ReadSaveDataInfo"},
|
{0, &ISaveDataInfoReader::ReadSaveDataInfo, "ReadSaveDataInfo"},
|
||||||
};
|
};
|
||||||
@ -630,7 +626,7 @@ private:
|
|||||||
|
|
||||||
void FindAllSaves(FileSys::SaveDataSpaceId space) {
|
void FindAllSaves(FileSys::SaveDataSpaceId space) {
|
||||||
FileSys::VirtualDir save_root{};
|
FileSys::VirtualDir save_root{};
|
||||||
const auto result = save_data_controller->OpenSaveDataSpace(&save_root, space);
|
const auto result = fsc.OpenSaveDataSpace(&save_root, space);
|
||||||
|
|
||||||
if (result != ResultSuccess || save_root == nullptr) {
|
if (result != ResultSuccess || save_root == nullptr) {
|
||||||
LOG_ERROR(Service_FS, "The save root for the space_id={:02X} was invalid!", space);
|
LOG_ERROR(Service_FS, "The save root for the space_id={:02X} was invalid!", space);
|
||||||
@ -727,8 +723,7 @@ private:
|
|||||||
};
|
};
|
||||||
static_assert(sizeof(SaveDataInfo) == 0x60, "SaveDataInfo has incorrect size.");
|
static_assert(sizeof(SaveDataInfo) == 0x60, "SaveDataInfo has incorrect size.");
|
||||||
|
|
||||||
ProcessId process_id = 0;
|
FileSystemController& fsc;
|
||||||
std::shared_ptr<SaveDataController> save_data_controller;
|
|
||||||
std::vector<SaveDataInfo> info;
|
std::vector<SaveDataInfo> info;
|
||||||
u64 next_entry_index = 0;
|
u64 next_entry_index = 0;
|
||||||
};
|
};
|
||||||
@ -868,20 +863,21 @@ FSP_SRV::FSP_SRV(Core::System& system_)
|
|||||||
if (Settings::values.enable_fs_access_log) {
|
if (Settings::values.enable_fs_access_log) {
|
||||||
access_log_mode = AccessLogMode::SdCard;
|
access_log_mode = AccessLogMode::SdCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should be true on creation
|
||||||
|
fsc.SetAutoSaveDataCreation(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
FSP_SRV::~FSP_SRV() = default;
|
FSP_SRV::~FSP_SRV() = default;
|
||||||
|
|
||||||
void FSP_SRV::SetCurrentProcess(HLERequestContext& ctx) {
|
void FSP_SRV::SetCurrentProcess(HLERequestContext& ctx) {
|
||||||
current_process_id = ctx.GetPID();
|
IPC::RequestParser rp{ctx};
|
||||||
|
current_process_id = rp.Pop<u64>();
|
||||||
|
|
||||||
LOG_DEBUG(Service_FS, "called. current_process_id=0x{:016X}", current_process_id);
|
LOG_DEBUG(Service_FS, "called. current_process_id=0x{:016X}", current_process_id);
|
||||||
|
|
||||||
const auto res =
|
|
||||||
fsc.OpenProcess(&program_id, &save_data_controller, &romfs_controller, current_process_id);
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(res);
|
rb.Push(ResultSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSP_SRV::OpenFileSystemWithPatch(HLERequestContext& ctx) {
|
void FSP_SRV::OpenFileSystemWithPatch(HLERequestContext& ctx) {
|
||||||
@ -920,8 +916,7 @@ void FSP_SRV::CreateSaveDataFileSystem(HLERequestContext& ctx) {
|
|||||||
uid[1], uid[0]);
|
uid[1], uid[0]);
|
||||||
|
|
||||||
FileSys::VirtualDir save_data_dir{};
|
FileSys::VirtualDir save_data_dir{};
|
||||||
save_data_controller->CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::NandUser,
|
fsc.CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::NandUser, save_struct);
|
||||||
save_struct);
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
@ -936,8 +931,7 @@ void FSP_SRV::CreateSaveDataFileSystemBySystemSaveDataId(HLERequestContext& ctx)
|
|||||||
LOG_DEBUG(Service_FS, "called save_struct = {}", save_struct.DebugInfo());
|
LOG_DEBUG(Service_FS, "called save_struct = {}", save_struct.DebugInfo());
|
||||||
|
|
||||||
FileSys::VirtualDir save_data_dir{};
|
FileSys::VirtualDir save_data_dir{};
|
||||||
save_data_controller->CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::NandSystem,
|
fsc.CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::NandSystem, save_struct);
|
||||||
save_struct);
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
@ -956,8 +950,7 @@ void FSP_SRV::OpenSaveDataFileSystem(HLERequestContext& ctx) {
|
|||||||
LOG_INFO(Service_FS, "called.");
|
LOG_INFO(Service_FS, "called.");
|
||||||
|
|
||||||
FileSys::VirtualDir dir{};
|
FileSys::VirtualDir dir{};
|
||||||
auto result =
|
auto result = fsc.OpenSaveData(&dir, parameters.space_id, parameters.attribute);
|
||||||
save_data_controller->OpenSaveData(&dir, parameters.space_id, parameters.attribute);
|
|
||||||
if (result != ResultSuccess) {
|
if (result != ResultSuccess) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 0};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 0};
|
||||||
rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND);
|
rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND);
|
||||||
@ -1008,7 +1001,7 @@ void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(HLERequestContext& ctx) {
|
|||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
rb.PushIpcInterface<ISaveDataInfoReader>(
|
rb.PushIpcInterface<ISaveDataInfoReader>(
|
||||||
std::make_shared<ISaveDataInfoReader>(system, save_data_controller, space));
|
std::make_shared<ISaveDataInfoReader>(system, space, fsc));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSP_SRV::OpenSaveDataInfoReaderOnlyCacheStorage(HLERequestContext& ctx) {
|
void FSP_SRV::OpenSaveDataInfoReaderOnlyCacheStorage(HLERequestContext& ctx) {
|
||||||
@ -1016,8 +1009,8 @@ void FSP_SRV::OpenSaveDataInfoReaderOnlyCacheStorage(HLERequestContext& ctx) {
|
|||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
rb.PushIpcInterface<ISaveDataInfoReader>(system, save_data_controller,
|
rb.PushIpcInterface<ISaveDataInfoReader>(system, FileSys::SaveDataSpaceId::TemporaryStorage,
|
||||||
FileSys::SaveDataSpaceId::TemporaryStorage);
|
fsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(HLERequestContext& ctx) {
|
void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(HLERequestContext& ctx) {
|
||||||
@ -1057,7 +1050,7 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(HLERequestContext& ctx) {
|
|||||||
LOG_DEBUG(Service_FS, "called");
|
LOG_DEBUG(Service_FS, "called");
|
||||||
|
|
||||||
if (!romfs) {
|
if (!romfs) {
|
||||||
auto current_romfs = romfs_controller->OpenRomFSCurrentProcess();
|
auto current_romfs = fsc.OpenRomFSCurrentProcess();
|
||||||
if (!current_romfs) {
|
if (!current_romfs) {
|
||||||
// TODO (bunnei): Find the right error code to use here
|
// TODO (bunnei): Find the right error code to use here
|
||||||
LOG_CRITICAL(Service_FS, "no file system interface available!");
|
LOG_CRITICAL(Service_FS, "no file system interface available!");
|
||||||
@ -1085,7 +1078,7 @@ void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) {
|
|||||||
LOG_DEBUG(Service_FS, "called with storage_id={:02X}, unknown={:08X}, title_id={:016X}",
|
LOG_DEBUG(Service_FS, "called with storage_id={:02X}, unknown={:08X}, title_id={:016X}",
|
||||||
storage_id, unknown, title_id);
|
storage_id, unknown, title_id);
|
||||||
|
|
||||||
auto data = romfs_controller->OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data);
|
auto data = fsc.OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
const auto archive = FileSys::SystemArchive::SynthesizeSystemArchive(title_id);
|
const auto archive = FileSys::SystemArchive::SynthesizeSystemArchive(title_id);
|
||||||
@ -1108,8 +1101,7 @@ void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) {
|
|||||||
|
|
||||||
const FileSys::PatchManager pm{title_id, fsc, content_provider};
|
const FileSys::PatchManager pm{title_id, fsc, content_provider};
|
||||||
|
|
||||||
auto base =
|
auto base = fsc.OpenBaseNca(title_id, storage_id, FileSys::ContentRecordType::Data);
|
||||||
romfs_controller->OpenBaseNca(title_id, storage_id, FileSys::ContentRecordType::Data);
|
|
||||||
auto storage = std::make_shared<IStorage>(
|
auto storage = std::make_shared<IStorage>(
|
||||||
system, pm.PatchRomFS(base.get(), std::move(data), FileSys::ContentRecordType::Data));
|
system, pm.PatchRomFS(base.get(), std::move(data), FileSys::ContentRecordType::Data));
|
||||||
|
|
||||||
@ -1137,8 +1129,9 @@ void FSP_SRV::OpenDataStorageWithProgramIndex(HLERequestContext& ctx) {
|
|||||||
|
|
||||||
LOG_DEBUG(Service_FS, "called, program_index={}", program_index);
|
LOG_DEBUG(Service_FS, "called, program_index={}", program_index);
|
||||||
|
|
||||||
auto patched_romfs = romfs_controller->OpenPatchedRomFSWithProgramIndex(
|
auto patched_romfs =
|
||||||
program_id, program_index, FileSys::ContentRecordType::Program);
|
fsc.OpenPatchedRomFSWithProgramIndex(system.GetApplicationProcessProgramID(), program_index,
|
||||||
|
FileSys::ContentRecordType::Program);
|
||||||
|
|
||||||
if (!patched_romfs) {
|
if (!patched_romfs) {
|
||||||
// TODO: Find the right error code to use here
|
// TODO: Find the right error code to use here
|
||||||
@ -1159,7 +1152,7 @@ void FSP_SRV::OpenDataStorageWithProgramIndex(HLERequestContext& ctx) {
|
|||||||
void FSP_SRV::DisableAutoSaveDataCreation(HLERequestContext& ctx) {
|
void FSP_SRV::DisableAutoSaveDataCreation(HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_FS, "called");
|
LOG_DEBUG(Service_FS, "called");
|
||||||
|
|
||||||
save_data_controller->SetAutoCreate(false);
|
fsc.SetAutoSaveDataCreation(false);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
|
@ -17,9 +17,6 @@ class FileSystemBackend;
|
|||||||
|
|
||||||
namespace Service::FileSystem {
|
namespace Service::FileSystem {
|
||||||
|
|
||||||
class RomFsController;
|
|
||||||
class SaveDataController;
|
|
||||||
|
|
||||||
enum class AccessLogVersion : u32 {
|
enum class AccessLogVersion : u32 {
|
||||||
V7_0_0 = 2,
|
V7_0_0 = 2,
|
||||||
|
|
||||||
@ -70,9 +67,6 @@ private:
|
|||||||
u64 current_process_id = 0;
|
u64 current_process_id = 0;
|
||||||
u32 access_log_program_index = 0;
|
u32 access_log_program_index = 0;
|
||||||
AccessLogMode access_log_mode = AccessLogMode::None;
|
AccessLogMode access_log_mode = AccessLogMode::None;
|
||||||
u64 program_id = 0;
|
|
||||||
std::shared_ptr<SaveDataController> save_data_controller;
|
|
||||||
std::shared_ptr<RomFsController> romfs_controller;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::FileSystem
|
} // namespace Service::FileSystem
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#include "core/hle/service/filesystem/romfs_controller.h"
|
|
||||||
|
|
||||||
namespace Service::FileSystem {
|
|
||||||
|
|
||||||
RomFsController::RomFsController(std::shared_ptr<FileSys::RomFSFactory> factory_, u64 program_id_)
|
|
||||||
: factory{std::move(factory_)}, program_id{program_id_} {}
|
|
||||||
RomFsController::~RomFsController() = default;
|
|
||||||
|
|
||||||
FileSys::VirtualFile RomFsController::OpenRomFSCurrentProcess() {
|
|
||||||
return factory->OpenCurrentProcess(program_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSys::VirtualFile RomFsController::OpenPatchedRomFS(u64 title_id,
|
|
||||||
FileSys::ContentRecordType type) {
|
|
||||||
return factory->OpenPatchedRomFS(title_id, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSys::VirtualFile RomFsController::OpenPatchedRomFSWithProgramIndex(
|
|
||||||
u64 title_id, u8 program_index, FileSys::ContentRecordType type) {
|
|
||||||
return factory->OpenPatchedRomFSWithProgramIndex(title_id, program_index, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSys::VirtualFile RomFsController::OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
|
||||||
FileSys::ContentRecordType type) {
|
|
||||||
return factory->Open(title_id, storage_id, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<FileSys::NCA> RomFsController::OpenBaseNca(u64 title_id,
|
|
||||||
FileSys::StorageId storage_id,
|
|
||||||
FileSys::ContentRecordType type) {
|
|
||||||
return factory->GetEntry(title_id, storage_id, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Service::FileSystem
|
|
@ -1,31 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "core/file_sys/nca_metadata.h"
|
|
||||||
#include "core/file_sys/romfs_factory.h"
|
|
||||||
#include "core/file_sys/vfs_types.h"
|
|
||||||
|
|
||||||
namespace Service::FileSystem {
|
|
||||||
|
|
||||||
class RomFsController {
|
|
||||||
public:
|
|
||||||
explicit RomFsController(std::shared_ptr<FileSys::RomFSFactory> factory_, u64 program_id_);
|
|
||||||
~RomFsController();
|
|
||||||
|
|
||||||
FileSys::VirtualFile OpenRomFSCurrentProcess();
|
|
||||||
FileSys::VirtualFile OpenPatchedRomFS(u64 title_id, FileSys::ContentRecordType type);
|
|
||||||
FileSys::VirtualFile OpenPatchedRomFSWithProgramIndex(u64 title_id, u8 program_index,
|
|
||||||
FileSys::ContentRecordType type);
|
|
||||||
FileSys::VirtualFile OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
|
||||||
FileSys::ContentRecordType type);
|
|
||||||
std::shared_ptr<FileSys::NCA> OpenBaseNca(u64 title_id, FileSys::StorageId storage_id,
|
|
||||||
FileSys::ContentRecordType type);
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::shared_ptr<FileSys::RomFSFactory> factory;
|
|
||||||
const u64 program_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Service::FileSystem
|
|
@ -1,99 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#include "core/core.h"
|
|
||||||
#include "core/file_sys/control_metadata.h"
|
|
||||||
#include "core/file_sys/errors.h"
|
|
||||||
#include "core/file_sys/patch_manager.h"
|
|
||||||
#include "core/hle/service/filesystem/save_data_controller.h"
|
|
||||||
#include "core/loader/loader.h"
|
|
||||||
|
|
||||||
namespace Service::FileSystem {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// A default size for normal/journal save data size if application control metadata cannot be found.
|
|
||||||
// This should be large enough to satisfy even the most extreme requirements (~4.2GB)
|
|
||||||
constexpr u64 SufficientSaveDataSize = 0xF0000000;
|
|
||||||
|
|
||||||
FileSys::SaveDataSize GetDefaultSaveDataSize(Core::System& system, u64 program_id) {
|
|
||||||
const FileSys::PatchManager pm{program_id, system.GetFileSystemController(),
|
|
||||||
system.GetContentProvider()};
|
|
||||||
const auto metadata = pm.GetControlMetadata();
|
|
||||||
const auto& nacp = metadata.first;
|
|
||||||
|
|
||||||
if (nacp != nullptr) {
|
|
||||||
return {nacp->GetDefaultNormalSaveSize(), nacp->GetDefaultJournalSaveSize()};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {SufficientSaveDataSize, SufficientSaveDataSize};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
SaveDataController::SaveDataController(Core::System& system_,
|
|
||||||
std::shared_ptr<FileSys::SaveDataFactory> factory_)
|
|
||||||
: system{system_}, factory{std::move(factory_)} {}
|
|
||||||
SaveDataController::~SaveDataController() = default;
|
|
||||||
|
|
||||||
Result SaveDataController::CreateSaveData(FileSys::VirtualDir* out_save_data,
|
|
||||||
FileSys::SaveDataSpaceId space,
|
|
||||||
const FileSys::SaveDataAttribute& attribute) {
|
|
||||||
LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", space,
|
|
||||||
save_struct.DebugInfo());
|
|
||||||
|
|
||||||
auto save_data = factory->Create(space, attribute);
|
|
||||||
if (save_data == nullptr) {
|
|
||||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_save_data = save_data;
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result SaveDataController::OpenSaveData(FileSys::VirtualDir* out_save_data,
|
|
||||||
FileSys::SaveDataSpaceId space,
|
|
||||||
const FileSys::SaveDataAttribute& attribute) {
|
|
||||||
auto save_data = factory->Open(space, attribute);
|
|
||||||
if (save_data == nullptr) {
|
|
||||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_save_data = save_data;
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result SaveDataController::OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space,
|
|
||||||
FileSys::SaveDataSpaceId space) {
|
|
||||||
auto save_data_space = factory->GetSaveDataSpaceDirectory(space);
|
|
||||||
if (save_data_space == nullptr) {
|
|
||||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_save_data_space = save_data_space;
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSys::SaveDataSize SaveDataController::ReadSaveDataSize(FileSys::SaveDataType type, u64 title_id,
|
|
||||||
u128 user_id) {
|
|
||||||
const auto value = factory->ReadSaveDataSize(type, title_id, user_id);
|
|
||||||
|
|
||||||
if (value.normal == 0 && value.journal == 0) {
|
|
||||||
const auto size = GetDefaultSaveDataSize(system, title_id);
|
|
||||||
factory->WriteSaveDataSize(type, title_id, user_id, size);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SaveDataController::WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
|
|
||||||
FileSys::SaveDataSize new_value) {
|
|
||||||
factory->WriteSaveDataSize(type, title_id, user_id, new_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SaveDataController::SetAutoCreate(bool state) {
|
|
||||||
factory->SetAutoCreate(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Service::FileSystem
|
|
@ -1,35 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "core/file_sys/nca_metadata.h"
|
|
||||||
#include "core/file_sys/savedata_factory.h"
|
|
||||||
#include "core/file_sys/vfs_types.h"
|
|
||||||
|
|
||||||
namespace Service::FileSystem {
|
|
||||||
|
|
||||||
class SaveDataController {
|
|
||||||
public:
|
|
||||||
explicit SaveDataController(Core::System& system,
|
|
||||||
std::shared_ptr<FileSys::SaveDataFactory> factory_);
|
|
||||||
~SaveDataController();
|
|
||||||
|
|
||||||
Result CreateSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space,
|
|
||||||
const FileSys::SaveDataAttribute& attribute);
|
|
||||||
Result OpenSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space,
|
|
||||||
const FileSys::SaveDataAttribute& attribute);
|
|
||||||
Result OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space,
|
|
||||||
FileSys::SaveDataSpaceId space);
|
|
||||||
|
|
||||||
FileSys::SaveDataSize ReadSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id);
|
|
||||||
void WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
|
|
||||||
FileSys::SaveDataSize new_value);
|
|
||||||
void SetAutoCreate(bool state);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Core::System& system;
|
|
||||||
const std::shared_ptr<FileSys::SaveDataFactory> factory;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Service::FileSystem
|
|
@ -131,7 +131,7 @@ private:
|
|||||||
u8 is_favorite;
|
u8 is_favorite;
|
||||||
u8 same_app;
|
u8 same_app;
|
||||||
u8 same_app_played;
|
u8 same_app_played;
|
||||||
u8 arbitrary_app_played;
|
u8 arbitary_app_played;
|
||||||
u64 group_id;
|
u64 group_id;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(SizedFriendFilter) == 0x10, "SizedFriendFilter is an invalid size");
|
static_assert(sizeof(SizedFriendFilter) == 0x10, "SizedFriendFilter is an invalid size");
|
||||||
|
@ -15,10 +15,9 @@
|
|||||||
namespace Service::Glue {
|
namespace Service::Glue {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::optional<u64> GetTitleIDForProcessID(Core::System& system, u64 process_id) {
|
std::optional<u64> GetTitleIDForProcessID(const Core::System& system, u64 process_id) {
|
||||||
auto list = system.Kernel().GetProcessList();
|
const auto& list = system.Kernel().GetProcessList();
|
||||||
|
const auto iter = std::find_if(list.begin(), list.end(), [&process_id](const auto& process) {
|
||||||
const auto iter = std::find_if(list.begin(), list.end(), [&process_id](auto& process) {
|
|
||||||
return process->GetProcessId() == process_id;
|
return process->GetProcessId() == process_id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/hle/kernel/k_shared_memory.h"
|
#include "core/hle/kernel/k_shared_memory.h"
|
||||||
#include "hid_core/hid_result.h"
|
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||||
#include "hid_core/resources/applet_resource.h"
|
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
|
||||||
#include "hid_core/resources/shared_memory_format.h"
|
#include "core/hle/service/hid/errors.h"
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
|
|
||||||
@ -87,9 +87,7 @@ Result AppletResource::RegisterAppletResourceUserId(u64 aruid, bool enable_input
|
|||||||
data_index = i;
|
data_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// TODO: Don't Handle pending delete here
|
if (registration_list.flag[i] == RegistrationStatus::None) {
|
||||||
if (registration_list.flag[i] == RegistrationStatus::None ||
|
|
||||||
registration_list.flag[i] == RegistrationStatus::PendingDelete) {
|
|
||||||
data_index = i;
|
data_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -106,22 +104,30 @@ Result AppletResource::RegisterAppletResourceUserId(u64 aruid, bool enable_input
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
|
void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
|
||||||
const u64 index = GetIndexFromAruid(aruid);
|
u64 index = GetIndexFromAruid(aruid);
|
||||||
|
|
||||||
if (index >= AruidIndexMax) {
|
if (index < AruidIndexMax) {
|
||||||
return;
|
if (data[index].flag.is_assigned) {
|
||||||
|
data[index].shared_memory_format = nullptr;
|
||||||
|
data[index].flag.is_assigned.Assign(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeAppletResourceId(aruid);
|
index = GetIndexFromAruid(aruid);
|
||||||
DestroySevenSixAxisTransferMemory();
|
if (index < AruidIndexMax) {
|
||||||
data[index].flag.raw = 0;
|
DestroySevenSixAxisTransferMemory();
|
||||||
data[index].aruid = 0;
|
data[index].flag.raw = 0;
|
||||||
|
data[index].aruid = 0;
|
||||||
|
|
||||||
registration_list.flag[index] = RegistrationStatus::PendingDelete;
|
index = GetIndexFromAruid(aruid);
|
||||||
|
if (index < AruidIndexMax) {
|
||||||
|
registration_list.flag[index] = RegistrationStatus::PendingDelete;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletResource::FreeAppletResourceId(u64 aruid) {
|
void AppletResource::FreeAppletResourceId(u64 aruid) {
|
||||||
const u64 index = GetIndexFromAruid(aruid);
|
u64 index = GetIndexFromAruid(aruid);
|
||||||
if (index >= AruidIndexMax) {
|
if (index >= AruidIndexMax) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -130,7 +136,6 @@ void AppletResource::FreeAppletResourceId(u64 aruid) {
|
|||||||
if (aruid_data.flag.is_assigned) {
|
if (aruid_data.flag.is_assigned) {
|
||||||
aruid_data.shared_memory_format = nullptr;
|
aruid_data.shared_memory_format = nullptr;
|
||||||
aruid_data.flag.is_assigned.Assign(false);
|
aruid_data.flag.is_assigned.Assign(false);
|
||||||
shared_memory_holder[index].Finalize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +144,7 @@ u64 AppletResource::GetActiveAruid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
|
Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
|
||||||
const u64 index = GetIndexFromAruid(aruid);
|
u64 index = GetIndexFromAruid(aruid);
|
||||||
if (index >= AruidIndexMax) {
|
if (index >= AruidIndexMax) {
|
||||||
return ResultAruidNotRegistered;
|
return ResultAruidNotRegistered;
|
||||||
}
|
}
|
||||||
@ -150,7 +155,7 @@ Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle,
|
|||||||
|
|
||||||
Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format,
|
Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format,
|
||||||
u64 aruid) {
|
u64 aruid) {
|
||||||
const u64 index = GetIndexFromAruid(aruid);
|
u64 index = GetIndexFromAruid(aruid);
|
||||||
if (index >= AruidIndexMax) {
|
if (index >= AruidIndexMax) {
|
||||||
return ResultAruidNotRegistered;
|
return ResultAruidNotRegistered;
|
||||||
}
|
}
|
@ -9,7 +9,7 @@
|
|||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
#include "hid_core/resources/shared_memory_holder.h"
|
#include "core/hle/service/hid/controllers/shared_memory_holder.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class System;
|
class System;
|
@ -2,9 +2,9 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "hid_core/resources/applet_resource.h"
|
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||||
#include "hid_core/resources/shared_memory_format.h"
|
#include "core/hle/service/hid/controllers/capture_button.h"
|
||||||
#include "hid_core/resources/system_buttons/capture_button.h"
|
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "hid_core/resources/controller_base.h"
|
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user