diff options
152 files changed, 1830 insertions, 857 deletions
diff --git a/.travis.yml b/.travis.yml index 9edfc0809..4f2b17465 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,12 @@ matrix: dist: trusty addons: apt: + sources: + - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' + - sourceline: 'deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu trusty main' packages: - - clang-format-3.9 + - clang-format-6.0 script: "./.travis/clang-format/script.sh" - os: linux env: NAME="linux build" @@ -24,7 +28,7 @@ matrix: - os: osx env: NAME="macos build" sudo: false - osx_image: xcode7.3 + osx_image: xcode9.2 install: "./.travis/macos/deps.sh" script: "./.travis/macos/build.sh" after_success: "./.travis/macos/upload.sh" @@ -32,7 +36,7 @@ matrix: deploy: provider: releases api_key: - secure: IuTT8DjxzNgOtaEsyOpz1JaSmtDtHSsWZnJKmSBwXAzgP2ZU4Ja3/q0z5PwbC5Ql7kuFahuYTE5oi7lbJBuu2P3y1Wj2zvFozGUkA3JUvEXDNOPS9QTJ1EYd6O+wenZoj7d/Pn+ZeIgyEafnnZsGBb8lMQnV9MfIHgYlZQ5EyF3n4XikT2h1UbDBYx74ciXZIxFEulx68kDr9Q4/U+zIYQmYv2N+lgXSLDkFrCJ046gRcujPYGPqE6jVw0kKni80CTTpuDF5prU8yIBeiffjkJ3Qx1a17G07eZ4r83P4XUOlaHbRBmA/8ywZvLF2Gep3wGKfSFgMWbPxBJk5ZSYcOOAgMsEcg0+gBK9gLTwO4pbmc2GvqP21yRQBzgtbFoEtAHLu5lVPBkZU7kZuRMJtRdqvFIwOLhpnRS8IknFOD5vjtaFiNdGWaK9ePdsGvplijnXcPafkumakc4+eVEiXb6/KzdX1zXdur5tuUPFytm0Oy6IJcGIf8FHXGvUlmWsnPzwfusij9JgeQOP+uegc9PdBfL+h7L5rk+ilELt3cXD5K7wgov/4hkl5istNJ2bm0IioIstWss8QQQTkyscGoeh/oXmUpOL4FdsTvsWhDR3QKeq8nSzgDkqLe0iSbplQGnC7o7ytNbldmxJvf3nylwglA8w3HlqLHtZLkUOcuQ0= + secure: ElsIAlbvVXBNKsP31nVPysh+mf0GQA4DiL/y5iJeQxKQYR6iRoNo+RfzOBmdswdo0bE/PGeBAlfzCkp15gjhWf6Je0N6dRpczmcmLq6SSQFn1Mpq00xMJB2AgQIlaHs6KFgoUA173EBKbPwgU/NubTFpJFm/Wa+NcSWAHQXKL9KT2M3qKpxNkPl3mKEVsbch4REP+T/46vsa+ikw0VE0kIs6V93LqUQZpI2F0Dhihx8Cxr5iedkE1QsNK+QSX9iItMHbfek9OH980gP7L3lkZltyAA1Pk0c37OAgz2PwczwNKwCT8jg9PMzdcKmWouvLyAkZFuA806ElzwHY3oEd91Zm6+Bk5n24yBKZ9027AZzw38NK2Z2m9Akb8+ar8PdsKU6N5pDutX9qSLayr0oMgJ0s7/xnGBGdL3gfkPCFc50xO/2DxlsOR+zAhPNM9Y76hhGy6A7/40+9uzrJvd4nAuDvIXRzi2Yl2L7mKBE4suMKbFLtk2LlgM0qY5JMVTQ8NliaEtqopfPur2KWFVJUpWDNLtNX8xGqhfwg7cLjIiGmnxSaJBTDuZI6dpEjkWkU0n1xYhGqEqit8DbehYzazozMJ+Vsr8hku7jGlUtlw+U6HG1e19O2y4aGeSwYPROcCNz+BLwmVM8oZE3Roy3qoaa2yiFf+sy6rUHznrhsfEM= file_glob: true file: "artifacts/*" skip_cleanup: true diff --git a/.travis/clang-format/script.sh b/.travis/clang-format/script.sh index 80a0f47e5..0f6e8e6e4 100755 --- a/.travis/clang-format/script.sh +++ b/.travis/clang-format/script.sh @@ -7,7 +7,7 @@ if grep -nr '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .travis* fi # Default clang-format points to default 3.5 version one -CLANG_FORMAT=clang-format-3.9 +CLANG_FORMAT=clang-format-6.0 $CLANG_FORMAT --version if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then diff --git a/CMakeLists.txt b/CMakeLists.txt index d814bb74f..5dee41abc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,17 @@ cmake_minimum_required(VERSION 3.6) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules") include(DownloadExternals) +include(CMakeDependentOption) project(yuzu) +# Set bundled sdl2/qt as dependent options. +# OFF by default, but if ENABLE_SDL2 and MSVC are true then ON option(ENABLE_SDL2 "Enable the SDL2 frontend" ON) -option(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" OFF) +CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" ON "ENABLE_SDL2;MSVC" OFF) option(ENABLE_QT "Enable the Qt frontend" ON) -option(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" OFF) +CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" ON "ENABLE_SDL2;MSVC" OFF) if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit) message(STATUS "Copying pre-commit hook") @@ -54,15 +57,18 @@ function(detect_architecture symbol arch) endif() endfunction() -if (MSVC) - detect_architecture("_M_AMD64" x86_64) - detect_architecture("_M_IX86" x86) - detect_architecture("_M_ARM" ARM) -else() - detect_architecture("__x86_64__" x86_64) - detect_architecture("__i386__" x86) - detect_architecture("__arm__" ARM) +if (NOT ENABLE_GENERIC) + if (MSVC) + detect_architecture("_M_AMD64" x86_64) + detect_architecture("_M_IX86" x86) + detect_architecture("_M_ARM" ARM) + else() + detect_architecture("__x86_64__" x86_64) + detect_architecture("__i386__" x86) + detect_architecture("__arm__" ARM) + endif() endif() + if (NOT DEFINED ARCHITECTURE) set(ARCHITECTURE "GENERIC") set(ARCHITECTURE_GENERIC 1) @@ -316,6 +322,53 @@ if (UNIX OR MINGW) endif() endif() +# Setup a custom clang-format target (if clang-format can be found) that will run +# against all the src files. This should be used before making a pull request. +# ======================================================================= + +set(CLANG_FORMAT_POSTFIX "-6.0") +find_program(CLANG_FORMAT + NAMES clang-format${CLANG_FORMAT_POSTFIX} + clang-format + PATHS ${CMAKE_BINARY_DIR}/externals) +# if find_program doesn't find it, try to download from externals +if (NOT CLANG_FORMAT) + if (WIN32) + message(STATUS "Clang format not found! Downloading...") + set(CLANG_FORMAT "${CMAKE_BINARY_DIR}/externals/clang-format${CLANG_FORMAT_POSTFIX}.exe") + file(DOWNLOAD + https://github.com/yuzu-emu/ext-windows-bin/raw/master/clang-format${CLANG_FORMAT_POSTFIX}.exe + "${CLANG_FORMAT}" SHOW_PROGRESS + STATUS DOWNLOAD_SUCCESS) + if (NOT DOWNLOAD_SUCCESS EQUAL 0) + message(WARNING "Could not download clang format! Disabling the clang format target") + file(REMOVE ${CLANG_FORMAT}) + unset(CLANG_FORMAT) + endif() + else() + message(WARNING "Clang format not found! Disabling the clang format target") + endif() +endif() + +if (CLANG_FORMAT) + set(SRCS ${CMAKE_SOURCE_DIR}/src) + set(CCOMMENT "Running clang format against all the .h and .cpp files in src/") + if (WIN32) + add_custom_target(clang-format + COMMAND powershell.exe -Command "${CLANG_FORMAT} -i @(Get-ChildItem -Recurse ${SRCS}/* -Include \'*.h\', \'*.cpp\')" + COMMENT ${CCOMMENT}) + elseif(MINGW) + add_custom_target(clang-format + COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp | xargs `cygpath -u ${CLANG_FORMAT}` -i + COMMENT ${CCOMMENT}) + else() + add_custom_target(clang-format + COMMAND find ${SRCS} -iname *.h -o -iname *.cpp | xargs ${CLANG_FORMAT} -i + COMMENT ${CCOMMENT}) + endif() + unset(SRCS) + unset(CCOMMENT) +endif() # Include source code # =================== @@ -323,12 +376,14 @@ endif() # This function should be passed a list of all files in a target. It will automatically generate # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the # one in the filesystem. -function(create_directory_groups) +function(create_target_directory_groups target_name) # Place any files that aren't in the source list in a separate group so that they don't get in # the way. source_group("Other Files" REGULAR_EXPRESSION ".") - foreach(file_name ${ARGV}) + get_target_property(target_sources "${target_name}" SOURCES) + + foreach(file_name IN LISTS target_sources) get_filename_component(dir_name "${file_name}" PATH) # Group names use '\' as a separator even though the entire rest of CMake uses '/'... string(REPLACE "/" "\\" group_name "${dir_name}") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 767bd23bf..ce0608db2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,16 @@ If you believe you have a valid issue report, please post text or a screenshot from the log (the console window that opens alongside yuzu) and build version (hex string visible in the titlebar and zip filename), as well as your hardware and software information if applicable. # Contributing -yuzu is a brand new project, so we have a great opportunity to keep things clean and well organized early on. As such, coding style is very important when making commits. We run clang-format on our CI to check the code. Please use it to format your code when contributing. However, it doesn't cover all the rules below. Some of them aren't very strict rules since we want to be flexible and we understand that under certain circumstances some of them can be counterproductive. Just try to follow as many of them as possible: +yuzu is a brand new project, so we have a great opportunity to keep things clean and well organized early on. As such, coding style is very important when making commits. We run clang-format on our CI to check the code. Please use it to format your code when contributing. However, it doesn't cover all the rules below. Some of them aren't very strict rules since we want to be flexible and we understand that under certain circumstances some of them can be counterproductive. Just try to follow as many of them as possible. + +# Using clang format (version 6.0) +When generating the native build script for your toolset, cmake will try to find the correct version of clang format (or will download it on windows). Before running cmake, please install clang format version 6.0 for your platform as follows: + +* Windows: do nothing; cmake will download a pre built binary for MSVC and MINGW. MSVC users can additionally install a clang format Visual Studio extension to add features like format on save. +* OSX: run `brew install clang-format`. +* Linux: use your package manager to get an appropriate binary. + +If clang format is found, then cmake will add a custom build target that can be run at any time to run clang format against *all* source files and update the formatting in them. This should be used before making a pull request so that the reviewers can spend more time reviewing the code instead of having to worry about minor style violations. On MSVC, you can run clang format by building the clang-format project in the solution. On OSX, you can either use the Makefile target `make clang-format` or by building the clang-format target in XCode. For Makefile builds, you can use the clang-format target with `make clang-format` ### General Rules * A lot of code was taken from other projects (e.g. Citra, Dolphin, PPSSPP, Gekko). In general, when editing other people's code, follow the style of the module you're in (or better yet, fix the style if it drastically differs from our guide). diff --git a/appveyor.yml b/appveyor.yml index 954be4e8f..fe6b649f5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,8 +13,8 @@ environment: # Tell msys2 to inherit the current directory when starting the shell CHERE_INVOKING: 1 matrix: - - BUILD_TYPE: mingw - BUILD_TYPE: msvc + - BUILD_TYPE: mingw platform: - x64 @@ -80,12 +80,19 @@ after_build: $env:BUILD_SYMBOLS = $MSVC_BUILD_PDB $env:BUILD_UPDATE = $MSVC_SEVENZIP + $BUILD_DIR = ".\msvc_build\bin\Release" + + # Make a debug symbol upload mkdir pdb - Get-ChildItem ".\msvc_build\bin\" -Recurse -Filter "*.pdb" | Copy-Item -destination .\pdb + Get-ChildItem "$BUILD_DIR\" -Recurse -Filter "*.pdb" | Copy-Item -destination .\pdb 7z a -tzip $MSVC_BUILD_PDB .\pdb\*.pdb + rm "$BUILD_DIR\*.pdb" mkdir $RELEASE_DIST - Get-ChildItem ".\msvc_build\bin\" -Recurse -Filter "yuzu*.exe" | Copy-Item -destination $RELEASE_DIST + # get rid of extra exes by copying everything over, then deleting all the exes, then copying just the exes we want + Copy-Item "$BUILD_DIR\*" -Destination $RELEASE_DIST -Recurse + rm "$RELEASE_DIST\*.exe" + Get-ChildItem "$BUILD_DIR" -Recurse -Filter "yuzu*.exe" | Copy-Item -destination $RELEASE_DIST Copy-Item .\license.txt -Destination $RELEASE_DIST Copy-Item .\README.md -Destination $RELEASE_DIST 7z a -tzip $MSVC_BUILD_ZIP $RELEASE_DIST\* @@ -163,7 +170,7 @@ deploy: provider: GitHub release: $(appveyor_repo_tag_name) auth_token: - secure: "argb6oi2TYLB4wDy+HoCC8PuGAmsnocSk12CQ5614XAPO+NVPndlkLv1utnDFfg2" + secure: QqePPnXbkzmXct5c8hZ2X5AbsthbI6cS1Sr+VBzcD8oUOIjfWJJKXVAQGUbQAbb0 artifact: update,build draft: false prerelease: false diff --git a/externals/catch b/externals/catch -Subproject 3dcc9233515ea69e45a11be369f867a944e72e7 +Subproject cd76f5730c9a3afa19f3b9c83608d9c7ab325a1 diff --git a/externals/getopt/CMakeLists.txt b/externals/getopt/CMakeLists.txt index c8b745d55..ad7a2b363 100644 --- a/externals/getopt/CMakeLists.txt +++ b/externals/getopt/CMakeLists.txt @@ -1,11 +1,9 @@ -set(SRCS - getopt.c - ) -set(HEADERS - getopt.h - ) +add_library(getopt + getopt.c + getopt.h +) + +create_target_directory_groups(getopt) -create_directory_groups(${SRCS} ${HEADERS}) -add_library(getopt ${SRCS} ${HEADERS}) target_compile_definitions(getopt PUBLIC STATIC_GETOPT) target_include_directories(getopt INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/externals/glad/CMakeLists.txt b/externals/glad/CMakeLists.txt index 6d35a844b..c43ae475a 100644 --- a/externals/glad/CMakeLists.txt +++ b/externals/glad/CMakeLists.txt @@ -1,13 +1,10 @@ -set(SRCS - src/glad.c - ) -set(HEADERS - include/KHR/khrplatform.h - include/glad/glad.h - ) +add_library(glad STATIC + src/glad.c + include/KHR/khrplatform.h + include/glad/glad.h +) -create_directory_groups(${SRCS} ${HEADERS}) -add_library(glad STATIC ${SRCS} ${HEADERS}) +create_target_directory_groups(glad) target_include_directories(glad PUBLIC "include/") if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") diff --git a/externals/inih/CMakeLists.txt b/externals/inih/CMakeLists.txt index cff36a581..2a75852c2 100644 --- a/externals/inih/CMakeLists.txt +++ b/externals/inih/CMakeLists.txt @@ -1,12 +1,9 @@ -set(SRCS - inih/ini.c - inih/cpp/INIReader.cpp - ) -set(HEADERS - inih/ini.h - inih/cpp/INIReader.h - ) +add_library(inih + inih/ini.c + inih/ini.h + inih/cpp/INIReader.cpp + inih/cpp/INIReader.h +) -create_directory_groups(${SRCS} ${HEADERS}) -add_library(inih ${SRCS} ${HEADERS}) +create_target_directory_groups(inih) target_include_directories(inih INTERFACE .) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 26cf9480b..1af80769a 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -24,78 +24,72 @@ if ($ENV{CI}) endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp" @ONLY) -set(SRCS - break_points.cpp - file_util.cpp - hash.cpp - logging/filter.cpp - logging/text_formatter.cpp - logging/backend.cpp - memory_util.cpp - microprofile.cpp - misc.cpp - param_package.cpp - scm_rev.cpp - string_util.cpp - telemetry.cpp - thread.cpp - timer.cpp - ) - -set(HEADERS - alignment.h - assert.h - bit_field.h - bit_set.h - break_points.h - chunk_file.h - code_block.h - color.h - common_funcs.h - common_paths.h - common_types.h - file_util.h - hash.h - linear_disk_cache.h - logging/text_formatter.h - logging/filter.h - logging/log.h - logging/backend.h - math_util.h - memory_util.h - microprofile.h - microprofileui.h - param_package.h - platform.h - quaternion.h - scm_rev.h - scope_exit.h - string_util.h - swap.h - synchronized_wrapper.h - telemetry.h - thread.h - thread_queue_list.h - threadsafe_queue.h - timer.h - vector_math.h - ) +add_library(common STATIC + alignment.h + assert.h + bit_field.h + bit_set.h + break_points.cpp + break_points.h + chunk_file.h + code_block.h + color.h + common_funcs.h + common_paths.h + common_types.h + file_util.cpp + file_util.h + hash.cpp + hash.h + linear_disk_cache.h + logging/backend.cpp + logging/backend.h + logging/filter.cpp + logging/filter.h + logging/log.h + logging/text_formatter.cpp + logging/text_formatter.h + math_util.h + memory_util.cpp + memory_util.h + microprofile.cpp + microprofile.h + microprofileui.h + misc.cpp + param_package.cpp + param_package.h + platform.h + quaternion.h + scm_rev.cpp + scm_rev.h + scope_exit.h + string_util.cpp + string_util.h + swap.h + synchronized_wrapper.h + telemetry.cpp + telemetry.h + thread.cpp + thread.h + thread_queue_list.h + threadsafe_queue.h + timer.cpp + timer.h + vector_math.h +) if(ARCHITECTURE_x86_64) - set(SRCS ${SRCS} + target_sources(common + PRIVATE x64/cpu_detect.cpp - ) - - set(HEADERS ${HEADERS} x64/cpu_detect.h x64/xbyak_abi.h x64/xbyak_util.h - ) + ) endif() -create_directory_groups(${SRCS} ${HEADERS}) +create_target_directory_groups(common) -add_library(common STATIC ${SRCS} ${HEADERS}) target_link_libraries(common PUBLIC Boost::boost microprofile) if (ARCHITECTURE_x86_64) target_link_libraries(common PRIVATE xbyak) diff --git a/src/common/bit_set.h b/src/common/bit_set.h index 9c2e6b28c..84e3cbe58 100644 --- a/src/common/bit_set.h +++ b/src/common/bit_set.h @@ -236,7 +236,7 @@ public: IntTy m_val; }; -} // Common +} // namespace Common typedef Common::BitSet<u8> BitSet8; typedef Common::BitSet<u16> BitSet16; diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h index 5145a3657..972ef9039 100644 --- a/src/common/chunk_file.h +++ b/src/common/chunk_file.h @@ -607,8 +607,9 @@ public: u32 cookie = arbitraryNumber; Do(cookie); if (mode == PointerWrap::MODE_READ && cookie != arbitraryNumber) { - LOG_ERROR(Common, "After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). " - "Aborting savestate load...", + LOG_ERROR(Common, + "After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). " + "Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); SetError(ERROR_FAILURE); } diff --git a/src/common/color.h b/src/common/color.h index 4ebd4f3d0..24a445dac 100644 --- a/src/common/color.h +++ b/src/common/color.h @@ -256,4 +256,4 @@ inline void EncodeX24S8(u8 stencil, u8* bytes) { bytes[3] = stencil; } -} // namespace +} // namespace Color diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 5ab036b34..4e1d702f7 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -873,20 +873,19 @@ bool IOFile::Flush() { } bool IOFile::Resize(u64 size) { - if (!IsOpen() || - 0 != + if (!IsOpen() || 0 != #ifdef _WIN32 - // ector: _chsize sucks, not 64-bit safe - // F|RES: changed to _chsize_s. i think it is 64-bit safe - _chsize_s(_fileno(m_file), size) + // ector: _chsize sucks, not 64-bit safe + // F|RES: changed to _chsize_s. i think it is 64-bit safe + _chsize_s(_fileno(m_file), size) #else - // TODO: handle 64bit and growing - ftruncate(fileno(m_file), size) + // TODO: handle 64bit and growing + ftruncate(fileno(m_file), size) #endif - ) + ) m_good = false; return m_good; } -} // namespace +} // namespace FileUtil diff --git a/src/common/file_util.h b/src/common/file_util.h index 94adfcd7e..630232a25 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -253,7 +253,7 @@ private: bool m_good = true; }; -} // namespace +} // namespace FileUtil // To deal with Windows being dumb at unicode: template <typename T> diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index ba0acfb72..e136482b6 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -132,4 +132,4 @@ void LogMessage(Class log_class, Level log_level, const char* filename, unsigned PrintColoredMessage(entry); } -} +} // namespace Log diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index c4fe2acbf..70744e3e5 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -47,4 +47,4 @@ Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsign const char* function, const char* format, va_list args); void SetFilter(Filter* filter); -} +} // namespace Log diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index 12e5bb45d..733247b51 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp @@ -94,4 +94,4 @@ bool Filter::ParseFilterRule(const std::string::const_iterator begin, bool Filter::CheckMessage(Class log_class, Level level) const { return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]); } -} +} // namespace Log diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h index b51df61de..16fa72642 100644 --- a/src/common/logging/filter.h +++ b/src/common/logging/filter.h @@ -50,4 +50,4 @@ public: private: std::array<Level, (size_t)Class::Count> class_levels; }; -} +} // namespace Log diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index f71e748d1..e7e46c76b 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp @@ -129,4 +129,4 @@ void PrintColoredMessage(const Entry& entry) { #undef ESC #endif } -} +} // namespace Log diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h index 749268310..66e86d9ec 100644 --- a/src/common/logging/text_formatter.h +++ b/src/common/logging/text_formatter.h @@ -28,4 +28,4 @@ void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len); void PrintMessage(const Entry& entry); /// Prints the same message as `PrintMessage`, but colored acoording to the severity level. void PrintColoredMessage(const Entry& entry); -} +} // namespace Log diff --git a/src/common/memory_util.cpp b/src/common/memory_util.cpp index c19729b21..759ad02ca 100644 --- a/src/common/memory_util.cpp +++ b/src/common/memory_util.cpp @@ -40,11 +40,12 @@ void* AllocateExecutableMemory(size_t size, bool low) { if (low && (!map_hint)) map_hint = (char*)round_page(512 * 1024 * 1024); /* 0.5 GB rounded up to the next page */ #endif - void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE + void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_ANON | MAP_PRIVATE #if defined(ARCHITECTURE_X64) && defined(MAP_32BIT) - | (low ? MAP_32BIT : 0) + | (low ? MAP_32BIT : 0) #endif - , + , -1, 0); #endif /* defined(_WIN32) */ diff --git a/src/common/quaternion.h b/src/common/quaternion.h index 77f626bcb..ea39298c1 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h @@ -46,4 +46,4 @@ inline Quaternion<float> MakeQuaternion(const Math::Vec3<float>& axis, float ang return {axis * std::sin(angle / 2), std::cos(angle / 2)}; } -} // namspace Math +} // namespace Math diff --git a/src/common/scm_rev.h b/src/common/scm_rev.h index 18aaa1735..db0f4a947 100644 --- a/src/common/scm_rev.h +++ b/src/common/scm_rev.h @@ -12,4 +12,4 @@ extern const char g_scm_desc[]; extern const char g_build_name[]; extern const char g_build_date[]; -} // namespace +} // namespace Common diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h index 072ab285d..baf1f1c9e 100644 --- a/src/common/scope_exit.h +++ b/src/common/scope_exit.h @@ -22,7 +22,7 @@ template <typename Func> ScopeExitHelper<Func> ScopeExit(Func&& func) { return ScopeExitHelper<Func>(std::move(func)); } -} +} // namespace detail /** * This macro allows you to conveniently specify a block of code that will run on scope exit. Handy diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 6959915fa..e9a2a6b00 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -202,7 +202,7 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ #ifdef _WIN32 ":" #endif - ); + ); if (std::string::npos == dir_end) dir_end = 0; else @@ -462,4 +462,4 @@ std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, size_t max_l return std::string(buffer, len); } -} +} // namespace Common diff --git a/src/common/string_util.h b/src/common/string_util.h index 259360aec..ceb8df48e 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -134,4 +134,4 @@ bool ComparePartialString(InIt begin, InIt end, const char* other) { * NUL-terminated then the string ends at max_len characters. */ std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, size_t max_len); -} +} // namespace Common diff --git a/src/common/telemetry.h b/src/common/telemetry.h index dd6bbd759..3694c76f2 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -53,10 +53,10 @@ template <typename T> class Field : public FieldInterface { public: Field(FieldType type, std::string name, const T& value) - : type(type), name(std::move(name)), value(value) {} + : name(std::move(name)), type(type), value(value) {} Field(FieldType type, std::string name, T&& value) - : type(type), name(std::move(name)), value(std::move(value)) {} + : name(std::move(name)), type(type), value(std::move(value)) {} Field(const Field& other) : Field(other.type, other.name, other.value) {} diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h index edd0e4a3f..38a450d69 100644 --- a/src/common/thread_queue_list.h +++ b/src/common/thread_queue_list.h @@ -158,4 +158,4 @@ private: std::array<Queue, NUM_QUEUES> queues; }; -} // namespace +} // namespace Common diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h index 6090d93e1..fd3fbdd4b 100644 --- a/src/common/x64/xbyak_abi.h +++ b/src/common/x64/xbyak_abi.h @@ -60,20 +60,41 @@ const Xbyak::Reg ABI_PARAM4 = Xbyak::util::r9; const BitSet32 ABI_ALL_CALLER_SAVED = BuildRegSet({ // GPRs - Xbyak::util::rcx, Xbyak::util::rdx, Xbyak::util::r8, Xbyak::util::r9, Xbyak::util::r10, + Xbyak::util::rcx, + Xbyak::util::rdx, + Xbyak::util::r8, + Xbyak::util::r9, + Xbyak::util::r10, Xbyak::util::r11, // XMMs - Xbyak::util::xmm0, Xbyak::util::xmm1, Xbyak::util::xmm2, Xbyak::util::xmm3, Xbyak::util::xmm4, + Xbyak::util::xmm0, + Xbyak::util::xmm1, + Xbyak::util::xmm2, + Xbyak::util::xmm3, + Xbyak::util::xmm4, Xbyak::util::xmm5, }); const BitSet32 ABI_ALL_CALLEE_SAVED = BuildRegSet({ // GPRs - Xbyak::util::rbx, Xbyak::util::rsi, Xbyak::util::rdi, Xbyak::util::rbp, Xbyak::util::r12, - Xbyak::util::r13, Xbyak::util::r14, Xbyak::util::r15, + Xbyak::util::rbx, + Xbyak::util::rsi, + Xbyak::util::rdi, + Xbyak::util::rbp, + Xbyak::util::r12, + Xbyak::util::r13, + Xbyak::util::r14, + Xbyak::util::r15, // XMMs - Xbyak::util::xmm6, Xbyak::util::xmm7, Xbyak::util::xmm8, Xbyak::util::xmm9, Xbyak::util::xmm10, - Xbyak::util::xmm11, Xbyak::util::xmm12, Xbyak::util::xmm13, Xbyak::util::xmm14, + Xbyak::util::xmm6, + Xbyak::util::xmm7, + Xbyak::util::xmm8, + Xbyak::util::xmm9, + Xbyak::util::xmm10, + Xbyak::util::xmm11, + Xbyak::util::xmm12, + Xbyak::util::xmm13, + Xbyak::util::xmm14, Xbyak::util::xmm15, }); @@ -90,18 +111,40 @@ const Xbyak::Reg ABI_PARAM4 = Xbyak::util::rcx; const BitSet32 ABI_ALL_CALLER_SAVED = BuildRegSet({ // GPRs - Xbyak::util::rcx, Xbyak::util::rdx, Xbyak::util::rdi, Xbyak::util::rsi, Xbyak::util::r8, - Xbyak::util::r9, Xbyak::util::r10, Xbyak::util::r11, + Xbyak::util::rcx, + Xbyak::util::rdx, + Xbyak::util::rdi, + Xbyak::util::rsi, + Xbyak::util::r8, + Xbyak::util::r9, + Xbyak::util::r10, + Xbyak::util::r11, // XMMs - Xbyak::util::xmm0, Xbyak::util::xmm1, Xbyak::util::xmm2, Xbyak::util::xmm3, Xbyak::util::xmm4, - Xbyak::util::xmm5, Xbyak::util::xmm6, Xbyak::util::xmm7, Xbyak::util::xmm8, Xbyak::util::xmm9, - Xbyak::util::xmm10, Xbyak::util::xmm11, Xbyak::util::xmm12, Xbyak::util::xmm13, - Xbyak::util::xmm14, Xbyak::util::xmm15, + Xbyak::util::xmm0, + Xbyak::util::xmm1, + Xbyak::util::xmm2, + Xbyak::util::xmm3, + Xbyak::util::xmm4, + Xbyak::util::xmm5, + Xbyak::util::xmm6, + Xbyak::util::xmm7, + Xbyak::util::xmm8, + Xbyak::util::xmm9, + Xbyak::util::xmm10, + Xbyak::util::xmm11, + Xbyak::util::xmm12, + Xbyak::util::xmm13, + Xbyak::util::xmm14, + Xbyak::util::xmm15, }); const BitSet32 ABI_ALL_CALLEE_SAVED = BuildRegSet({ // GPRs - Xbyak::util::rbx, Xbyak::util::rbp, Xbyak::util::r12, Xbyak::util::r13, Xbyak::util::r14, + Xbyak::util::rbx, + Xbyak::util::rbp, + Xbyak::util::r12, + Xbyak::util::r13, + Xbyak::util::r14, Xbyak::util::r15, }); diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 20e41038b..7153c4f3f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,175 +1,190 @@ -set(SRCS - arm/dynarmic/arm_dynarmic.cpp - arm/unicorn/arm_unicorn.cpp - core.cpp - core_timing.cpp - file_sys/archive_backend.cpp - file_sys/disk_archive.cpp - file_sys/ivfc_archive.cpp - file_sys/path_parser.cpp - file_sys/savedata_archive.cpp - file_sys/title_metadata.cpp - frontend/emu_window.cpp - frontend/framebuffer_layout.cpp - gdbstub/gdbstub.cpp - hle/config_mem.cpp - hle/kernel/address_arbiter.cpp - hle/kernel/client_port.cpp - hle/kernel/client_session.cpp - hle/kernel/condition_variable.cpp - hle/kernel/domain.cpp - hle/kernel/event.cpp - hle/kernel/handle_table.cpp - hle/kernel/hle_ipc.cpp - hle/kernel/kernel.cpp - hle/kernel/memory.cpp - hle/kernel/mutex.cpp - hle/kernel/object_address_table.cpp - hle/kernel/process.cpp - hle/kernel/resource_limit.cpp - hle/kernel/server_port.cpp - hle/kernel/server_session.cpp - hle/kernel/shared_memory.cpp - hle/kernel/svc.cpp - hle/kernel/thread.cpp - hle/kernel/timer.cpp - hle/kernel/vm_manager.cpp - hle/kernel/wait_object.cpp - hle/lock.cpp - hle/romfs.cpp - hle/service/acc/acc.cpp - hle/service/acc/acc_u0.cpp - hle/service/am/am.cpp - hle/service/am/applet_oe.cpp - hle/service/aoc/aoc_u.cpp - hle/service/apm/apm.cpp - hle/service/audio/audio.cpp - hle/service/audio/audout_u.cpp - hle/service/hid/hid.cpp - hle/service/lm/lm.cpp - hle/service/nvdrv/devices/nvdisp_disp0.cpp - hle/service/nvdrv/devices/nvhost_as_gpu.cpp - hle/service/nvdrv/devices/nvmap.cpp - hle/service/nvdrv/interface.cpp - hle/service/nvdrv/nvdrv.cpp - hle/service/pctl/pctl.cpp - hle/service/pctl/pctl_a.cpp - hle/service/service.cpp - hle/service/sm/controller.cpp - hle/service/sm/sm.cpp - hle/service/time/time.cpp - hle/service/time/time_s.cpp - hle/service/vi/vi.cpp - hle/service/vi/vi_m.cpp - hle/shared_page.cpp - hw/hw.cpp - hw/lcd.cpp - loader/elf.cpp - loader/linker.cpp - loader/loader.cpp - loader/nro.cpp - loader/nso.cpp - tracer/recorder.cpp - memory.cpp - perf_stats.cpp - settings.cpp - telemetry_session.cpp - ) +add_library(core STATIC + arm/arm_interface.h + arm/unicorn/arm_unicorn.cpp + arm/unicorn/arm_unicorn.h + core.cpp + core.h + core_timing.cpp + core_timing.h + file_sys/archive_backend.cpp + file_sys/archive_backend.h + file_sys/directory_backend.h + file_sys/disk_archive.cpp + file_sys/disk_archive.h + file_sys/errors.h + file_sys/file_backend.h + file_sys/ivfc_archive.cpp + file_sys/ivfc_archive.h + file_sys/path_parser.cpp + file_sys/path_parser.h + file_sys/savedata_archive.cpp + file_sys/savedata_archive.h + file_sys/title_metadata.cpp + file_sys/title_metadata.h + frontend/emu_window.cpp + frontend/emu_window.h + frontend/framebuffer_layout.cpp + frontend/framebuffer_layout.h + frontend/input.h + gdbstub/gdbstub.cpp + gdbstub/gdbstub.h + hle/config_mem.cpp + hle/config_mem.h + hle/ipc.h + hle/ipc_helpers.h + hle/kernel/address_arbiter.cpp + hle/kernel/address_arbiter.h + hle/kernel/client_port.cpp + hle/kernel/client_port.h + hle/kernel/client_session.cpp + hle/kernel/client_session.h + hle/kernel/condition_variable.cpp + hle/kernel/condition_variable.h + hle/kernel/domain.cpp + hle/kernel/domain.h + hle/kernel/errors.h + hle/kernel/event.cpp + hle/kernel/event.h + hle/kernel/handle_table.cpp + hle/kernel/handle_table.h + hle/kernel/hle_ipc.cpp + hle/kernel/hle_ipc.h + hle/kernel/kernel.cpp + hle/kernel/kernel.h + hle/kernel/memory.cpp + hle/kernel/memory.h + hle/kernel/mutex.cpp + hle/kernel/mutex.h + hle/kernel/object_address_table.cpp + hle/kernel/object_address_table.h + hle/kernel/process.cpp + hle/kernel/process.h + hle/kernel/resource_limit.cpp + hle/kernel/resource_limit.h + hle/kernel/server_port.cpp + hle/kernel/server_port.h + hle/kernel/server_session.cpp + hle/kernel/server_session.h + hle/kernel/session.h + hle/kernel/shared_memory.cpp + hle/kernel/shared_memory.h + hle/kernel/svc.cpp + hle/kernel/svc.h + hle/kernel/svc_wrap.h + hle/kernel/sync_object.h + hle/kernel/thread.cpp + hle/kernel/thread.h + hle/kernel/timer.cpp + hle/kernel/timer.h + hle/kernel/vm_manager.cpp + hle/kernel/vm_manager.h + hle/kernel/wait_object.cpp + hle/kernel/wait_object.h + hle/lock.cpp + hle/lock.h + hle/result.h + hle/romfs.cpp + hle/romfs.h + hle/service/acc/acc.cpp + hle/service/acc/acc.h + hle/service/acc/acc_u0.cpp + hle/service/acc/acc_u0.h + hle/service/am/am.cpp + hle/service/am/am.h + hle/service/am/applet_oe.cpp + hle/service/am/applet_oe.h + hle/service/aoc/aoc_u.cpp + hle/service/aoc/aoc_u.h + hle/service/apm/apm.cpp + hle/service/apm/apm.h + hle/service/audio/audio.cpp + hle/service/audio/audio.h + hle/service/audio/audout_u.cpp + hle/service/audio/audout_u.h + hle/service/hid/hid.cpp + hle/service/hid/hid.h + hle/service/lm/lm.cpp + hle/service/lm/lm.h + hle/service/nvdrv/devices/nvdevice.h + hle/service/nvdrv/devices/nvdisp_disp0.cpp + hle/service/nvdrv/devices/nvdisp_disp0.h + hle/service/nvdrv/devices/nvhost_as_gpu.cpp + hle/service/nvdrv/devices/nvhost_as_gpu.h + hle/service/nvdrv/devices/nvmap.cpp + hle/service/nvdrv/devices/nvmap.h + hle/service/nvdrv/interface.cpp + hle/service/nvdrv/interface.h + hle/service/nvdrv/nvdrv.cpp + hle/service/nvdrv/nvdrv.h + hle/service/pctl/pctl.cpp + hle/service/pctl/pctl.h + hle/service/pctl/pctl_a.cpp + hle/service/pctl/pctl_a.h + hle/service/service.cpp + hle/service/service.h + hle/service/set/set.cpp + hle/service/set/set.h + hle/service/sm/controller.cpp + hle/service/sm/controller.h + hle/service/sm/sm.cpp + hle/service/sm/sm.h + hle/service/sockets/bsd_u.cpp + hle/service/sockets/bsd_u.h + hle/service/sockets/sfdnsres.h + hle/service/sockets/sockets.cpp + hle/service/sockets/sockets.h + hle/service/time/time.cpp + hle/service/time/time.h + hle/service/time/time_s.cpp + hle/service/time/time_s.h + hle/service/time/time_u.cpp + hle/service/time/time_u.h + hle/service/vi/vi.cpp + hle/service/vi/vi.h + hle/service/vi/vi_m.cpp + hle/service/vi/vi_m.h + hle/shared_page.cpp + hle/shared_page.h + hw/hw.cpp + hw/hw.h + hw/lcd.cpp + hw/lcd.h + loader/deconstructed_rom_directory.cpp + loader/deconstructed_rom_directory.h + loader/elf.cpp + loader/elf.h + loader/linker.cpp + loader/linker.h + loader/loader.cpp + loader/loader.h + loader/nro.cpp + loader/nro.h + loader/nso.cpp + loader/nso.h + memory.cpp + memory.h + memory_setup.h + mmio.h + perf_stats.cpp + perf_stats.h + settings.cpp + settings.h + telemetry_session.cpp + telemetry_session.h + tracer/citrace.h + tracer/recorder.cpp + tracer/recorder.h +) -set(HEADERS - arm/arm_interface.h - arm/dynarmic/arm_dynarmic.h - arm/unicorn/arm_unicorn.h - core.h - core_timing.h - file_sys/archive_backend.h - file_sys/directory_backend.h - file_sys/disk_archive.h - file_sys/errors.h - file_sys/file_backend.h - file_sys/ivfc_archive.h - file_sys/path_parser.h - file_sys/savedata_archive.h - frontend/emu_window.h - frontend/framebuffer_layout.h - frontend/input.h - gdbstub/gdbstub.h - hle/config_mem.h - hle/ipc.h - hle/ipc_helpers.h - hle/kernel/address_arbiter.h - hle/kernel/client_port.h - hle/kernel/client_session.h - hle/kernel/condition_variable.h - hle/kernel/domain.h - hle/kernel/errors.h - hle/kernel/event.h - hle/kernel/handle_table.h - hle/kernel/hle_ipc.h - hle/kernel/kernel.h - hle/kernel/memory.h - hle/kernel/mutex.h - hle/kernel/object_address_table.h - hle/kernel/process.h - hle/kernel/resource_limit.h - hle/kernel/server_port.h - hle/kernel/server_session.h - hle/kernel/session.h - hle/kernel/shared_memory.h - hle/kernel/sync_object.h - hle/kernel/svc.h - hle/kernel/svc_wrap.h - hle/kernel/thread.h - hle/kernel/timer.h - hle/kernel/vm_manager.h - hle/kernel/wait_object.h - hle/lock.h - hle/result.h - hle/romfs.h - hle/service/acc/acc.h - hle/service/acc/acc_u0.h - hle/service/am/am.h - hle/service/am/applet_oe.h - hle/service/aoc/aoc_u.h - hle/service/apm/apm.h - hle/service/audio/audio.h - hle/service/audio/audout_u.h - hle/service/hid/hid.h - hle/service/lm/lm.h - hle/service/nvdrv/devices/nvdevice.h - hle/service/nvdrv/devices/nvdisp_disp0.h - hle/service/nvdrv/devices/nvhost_as_gpu.h - hle/service/nvdrv/devices/nvmap.h - hle/service/nvdrv/interface.h - hle/service/nvdrv/nvdrv.h - hle/service/pctl/pctl.h - hle/service/pctl/pctl_a.h - hle/service/service.h - hle/service/sm/controller.h - hle/service/sm/sm.h - hle/service/time/time.h - hle/service/time/time_s.h - hle/service/vi/vi.h - hle/service/vi/vi_m.h - hle/shared_page.h - hw/hw.h - hw/lcd.h - loader/elf.h - loader/linker.h - loader/loader.h - loader/nro.h - loader/nso.h - tracer/recorder.h - tracer/citrace.h - memory.h - memory_setup.h - mmio.h - perf_stats.h - settings.h - telemetry_session.h - ) +create_target_directory_groups(core) -create_directory_groups(${SRCS} ${HEADERS}) -add_library(core STATIC ${SRCS} ${HEADERS}) -target_link_libraries(core PUBLIC common PRIVATE dynarmic video_core) +target_link_libraries(core PUBLIC common PRIVATE video_core) target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static unicorn) + +if (ARCHITECTURE_x86_64) + target_sources(core PRIVATE + arm/dynarmic/arm_dynarmic.cpp + arm/dynarmic/arm_dynarmic.h + ) + target_link_libraries(core PRIVATE dynarmic) +endif() diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 2ad48dcc7..72c54f984 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -46,7 +46,7 @@ public: ARM_Interface::ThreadContext ctx; parent.SaveContext(ctx); parent.inner_unicorn.LoadContext(ctx); - parent.inner_unicorn.ExecuteInstructions(num_instructions); + parent.inner_unicorn.ExecuteInstructions(static_cast<int>(num_instructions)); parent.inner_unicorn.SaveContext(ctx); parent.LoadContext(ctx); num_interpreted_instructions += num_instructions; @@ -163,9 +163,9 @@ void ARM_Dynarmic::LoadContext(const ARM_Interface::ThreadContext& ctx) { jit.SetRegisters(ctx.cpu_registers); jit.SetSP(ctx.sp); jit.SetPC(ctx.pc); - jit.SetPstate(ctx.cpsr); + jit.SetPstate(static_cast<u32>(ctx.cpsr)); jit.SetVectors(ctx.fpu_registers); - jit.SetFpcr(ctx.fpscr); + jit.SetFpcr(static_cast<u32>(ctx.fpscr)); cb->tpidrr0_el0 = ctx.tls_address; } diff --git a/src/core/core.cpp b/src/core/core.cpp index 1f7769609..dc21e4f04 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -5,7 +5,9 @@ #include <memory> #include <utility> #include "common/logging/log.h" +#ifdef ARCHITECTURE_x86_64 #include "core/arm/dynarmic/arm_dynarmic.h" +#endif #include "core/arm/unicorn/arm_unicorn.h" #include "core/core.h" #include "core/core_timing.h" @@ -143,7 +145,12 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { break; case Settings::CpuCore::Dynarmic: default: +#ifdef ARCHITECTURE_x86_64 cpu_core = std::make_unique<ARM_Dynarmic>(); +#else + cpu_core = std::make_unique<ARM_Unicorn>(); + LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available"); +#endif break; } diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index a0656f0a8..9e1bf2d0e 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -122,7 +122,7 @@ u64 GetTicks() { } void AddTicks(u64 ticks) { - downcount -= ticks; + downcount -= static_cast<int>(ticks); } u64 GetIdleTicks() { @@ -208,7 +208,7 @@ void Advance() { Event evt = std::move(event_queue.front()); std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<Event>()); event_queue.pop_back(); - evt.type->callback(evt.userdata, global_timer - evt.time); + evt.type->callback(evt.userdata, static_cast<int>(global_timer - evt.time)); } is_global_timer_sane = false; diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp index 87a240d7a..fc472b44f 100644 --- a/src/core/file_sys/archive_backend.cpp +++ b/src/core/file_sys/archive_backend.cpp @@ -119,4 +119,4 @@ std::vector<u8> Path::AsBinary() const { return {}; } } -} +} // namespace FileSys diff --git a/src/core/file_sys/title_metadata.h b/src/core/file_sys/title_metadata.h index 1fc157bf3..a4c7d1089 100644 --- a/src/core/file_sys/title_metadata.h +++ b/src/core/file_sys/title_metadata.h @@ -4,6 +4,7 @@ #pragma once +#include <array> #include <string> #include <vector> #include "common/common_types.h" diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 05c872d89..2f3ccb689 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -183,11 +183,11 @@ static u8 NibbleToHex(u8 n) { } /** -* Converts input hex string characters into an array of equivalent of u8 bytes. -* -* @param src Pointer to array of output hex string characters. -* @param len Length of src array. -*/ + * Converts input hex string characters into an array of equivalent of u8 bytes. + * + * @param src Pointer to array of output hex string characters. + * @param len Length of src array. + */ static u32 HexToInt(const u8* src, size_t len) { u32 output = 0; while (len-- > 0) { @@ -299,17 +299,17 @@ static std::map<u32, Breakpoint>& GetBreakpointList(BreakpointType type) { static void RemoveBreakpoint(BreakpointType type, PAddr addr) { std::map<u32, Breakpoint>& p = GetBreakpointList(type); - auto bp = p.find(addr); + auto bp = p.find(static_cast<u32>(addr)); if (bp != p.end()) { LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: %08x bytes at %08x of type %d\n", bp->second.len, bp->second.addr, type); - p.erase(addr); + p.erase(static_cast<u32>(addr)); } } BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, BreakpointType type) { std::map<u32, Breakpoint>& p = GetBreakpointList(type); - auto next_breakpoint = p.lower_bound(addr); + auto next_breakpoint = p.lower_bound(static_cast<u32>(addr)); BreakpointAddress breakpoint; if (next_breakpoint != p.end()) { @@ -330,7 +330,7 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) { std::map<u32, Breakpoint>& p = GetBreakpointList(type); - auto bp = p.find(addr); + auto bp = p.find(static_cast<u32>(addr)); if (bp != p.end()) { u32 len = bp->second.len; @@ -452,7 +452,8 @@ static void SendSignal(u32 signal) { std::string buffer = Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, - htonl(Core::CPU().GetPC()), 13, htonl(Core::CPU().GetReg(13))); + htonl(static_cast<u_long>(Core::CPU().GetPC())), 13, + htonl(static_cast<u_long>(Core::CPU().GetReg(13)))); LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str()); SendReply(buffer.c_str()); } @@ -539,7 +540,7 @@ static void ReadRegister() { } if (id <= R15_REGISTER) { - IntToGdbHex(reply, Core::CPU().GetReg(id)); + IntToGdbHex(reply, static_cast<u32>(Core::CPU().GetReg(static_cast<u64>(id)))); } else if (id == CPSR_REGISTER) { IntToGdbHex(reply, Core::CPU().GetCPSR()); } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { @@ -563,7 +564,7 @@ static void ReadRegisters() { u8* bufptr = buffer; for (int reg = 0; reg <= R15_REGISTER; reg++) { - IntToGdbHex(bufptr + reg * CHAR_BIT, Core::CPU().GetReg(reg)); + IntToGdbHex(bufptr + reg * CHAR_BIT, static_cast<u32>(Core::CPU().GetReg(reg))); } bufptr += (16 * CHAR_BIT); @@ -1034,4 +1035,4 @@ bool GetCpuStepFlag() { void SetCpuStepFlag(bool is_step) { step_loop = is_step; } -}; +}; // namespace GDBStub diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h index 8f12c6a1d..201fca095 100644 --- a/src/core/gdbstub/gdbstub.h +++ b/src/core/gdbstub/gdbstub.h @@ -91,4 +91,4 @@ bool GetCpuStepFlag(); * @param is_step */ void SetCpuStepFlag(bool is_step); -} +} // namespace GDBStub diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp index e386ccdc6..038af7909 100644 --- a/src/core/hle/config_mem.cpp +++ b/src/core/hle/config_mem.cpp @@ -28,4 +28,4 @@ void Init() { config_mem.firm_ctr_sdk_ver = 0x0000F297; } -} // namespace +} // namespace ConfigMem diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h index 42fa6d789..1840d1760 100644 --- a/src/core/hle/config_mem.h +++ b/src/core/hle/config_mem.h @@ -53,4 +53,4 @@ extern ConfigMemDef config_mem; void Init(); -} // namespace +} // namespace ConfigMem diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index 1840fac12..0dcaede67 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h @@ -133,6 +133,10 @@ struct BufferDescriptorC { address |= static_cast<VAddr>(address_bits_32_47) << 32; return address; } + + u64 Size() const { + return static_cast<u64>(size); + } }; static_assert(sizeof(BufferDescriptorC) == 8, "BufferDescriptorC size is incorrect"); diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 25530a3c8..4c9b0de28 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -54,6 +54,10 @@ public: unsigned GetCurrentOffset() const { return static_cast<unsigned>(index); } + + void SetCurrentOffset(unsigned offset) { + index = static_cast<ptrdiff_t>(offset); + } }; class RequestBuilder : public RequestHelperBase { diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h index 1d24401b1..f902ddf2d 100644 --- a/src/core/hle/kernel/address_arbiter.h +++ b/src/core/hle/kernel/address_arbiter.h @@ -57,4 +57,4 @@ private: ~AddressArbiter() override; }; -} // namespace FileSys +} // namespace Kernel diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index ce5d94e99..fb2b6f7a3 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp @@ -39,4 +39,4 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() { return MakeResult(std::get<SharedPtr<ClientSession>>(sessions)); } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h index 8f7d6ac44..a829aeb6d 100644 --- a/src/core/hle/kernel/client_port.h +++ b/src/core/hle/kernel/client_port.h @@ -47,4 +47,4 @@ private: ~ClientPort() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index 646a5cc64..72773d8b1 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -48,4 +48,4 @@ ResultCode ClientSession::SendSyncRequest(SharedPtr<Thread> thread) { return server->HandleSyncRequest(std::move(thread)); } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h index 671174ec4..d6ab4f893 100644 --- a/src/core/hle/kernel/client_session.h +++ b/src/core/hle/kernel/client_session.h @@ -45,4 +45,4 @@ private: ~ClientSession() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/condition_variable.cpp b/src/core/hle/kernel/condition_variable.cpp index 5942eae61..561666384 100644 --- a/src/core/hle/kernel/condition_variable.cpp +++ b/src/core/hle/kernel/condition_variable.cpp @@ -43,7 +43,7 @@ void ConditionVariable::Acquire(Thread* thread) { ResultCode ConditionVariable::Release(s32 target) { if (target == -1) { // When -1, wake up all waiting threads - SetAvailableCount(GetWaitingThreads().size()); + SetAvailableCount(static_cast<s32>(GetWaitingThreads().size())); WakeupAllWaitingThreads(); } else { // Otherwise, wake up just a single thread diff --git a/src/core/hle/kernel/condition_variable.h b/src/core/hle/kernel/condition_variable.h index 0610a284f..0d54031cb 100644 --- a/src/core/hle/kernel/condition_variable.h +++ b/src/core/hle/kernel/condition_variable.h @@ -4,8 +4,8 @@ #pragma once -#include <queue> #include <string> +#include <queue> #include "common/common_types.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/wait_object.h" diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index 23f9df0d6..9cae2369f 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -52,4 +52,4 @@ void Event::WakeupAllWaitingThreads() { signaled = false; } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index cc41abb85..e5c924a75 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -49,4 +49,4 @@ private: ~Event() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index 12506e64c..74d3d0514 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -104,4 +104,4 @@ void HandleTable::Clear() { next_free_slot = 0; } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h index dba5573a8..935cc22b5 100644 --- a/src/core/hle/kernel/handle_table.h +++ b/src/core/hle/kernel/handle_table.h @@ -130,4 +130,4 @@ private: extern HandleTable g_handle_table; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index ac62a0d5a..ecf32c18a 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -81,13 +81,8 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { for (unsigned i = 0; i < command_header->num_buf_w_descriptors; ++i) { buffer_w_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>()); } - if (command_header->buf_c_descriptor_flags != - IPC::CommandHeader::BufferDescriptorCFlag::Disabled) { - if (command_header->buf_c_descriptor_flags != - IPC::CommandHeader::BufferDescriptorCFlag::OneDescriptor) { - UNIMPLEMENTED(); - } - } + + buffer_c_offset = rp.GetCurrentOffset() + command_header->data_size; // Padding to align to 16 bytes rp.AlignWithPadding(); @@ -104,9 +99,8 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { data_payload_offset = rp.GetCurrentOffset(); - if (domain_message_header && - domain_message_header->command == - IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) { + if (domain_message_header && domain_message_header->command == + IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) { // CloseVirtualHandle command does not have SFC* or any data return; } @@ -117,6 +111,31 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'O')); } + rp.SetCurrentOffset(buffer_c_offset); + + // For Inline buffers, the response data is written directly to buffer_c_offset + // and in this case we don't have any BufferDescriptorC on the request. + if (command_header->buf_c_descriptor_flags > + IPC::CommandHeader::BufferDescriptorCFlag::InlineDescriptor) { + if (command_header->buf_c_descriptor_flags == + IPC::CommandHeader::BufferDescriptorCFlag::OneDescriptor) { + buffer_c_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorC>()); + } else { + unsigned num_buf_c_descriptors = + static_cast<unsigned>(command_header->buf_c_descriptor_flags.Value()) - 2; + + // This is used to detect possible underflows, in case something is broken + // with the two ifs above and the flags value is == 0 || == 1. + ASSERT(num_buf_c_descriptors < 14); + + for (unsigned i = 0; i < num_buf_c_descriptors; ++i) { + buffer_c_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorC>()); + } + } + } + + rp.SetCurrentOffset(data_payload_offset); + command = rp.Pop<u32_le>(); rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. } @@ -190,7 +209,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, P for (auto& object : domain_objects) { request_handlers.emplace_back(object); - dst_cmdbuf[domain_offset++] = request_handlers.size(); + dst_cmdbuf[domain_offset++] = static_cast<u32_le>(request_handlers.size()); } } return RESULT_SUCCESS; diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 6dceb766d..80fa48d7f 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -143,6 +143,10 @@ public: return buffer_b_desciptors; } + const std::vector<IPC::BufferDescriptorC>& BufferDescriptorC() const { + return buffer_c_desciptors; + } + const std::unique_ptr<IPC::DomainMessageHeader>& GetDomainMessageHeader() const { return domain_message_header; } @@ -200,8 +204,10 @@ private: std::vector<IPC::BufferDescriptorABW> buffer_a_desciptors; std::vector<IPC::BufferDescriptorABW> buffer_b_desciptors; std::vector<IPC::BufferDescriptorABW> buffer_w_desciptors; + std::vector<IPC::BufferDescriptorC> buffer_c_desciptors; unsigned data_payload_offset{}; + unsigned buffer_c_offset{}; u32_le command{}; }; diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp index 517dc47a8..0149a3ed6 100644 --- a/src/core/hle/kernel/resource_limit.cpp +++ b/src/core/hle/kernel/resource_limit.cpp @@ -151,4 +151,4 @@ void ResourceLimitsInit() { void ResourceLimitsShutdown() {} -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h index 42874eb8d..1a0ca11f1 100644 --- a/src/core/hle/kernel/resource_limit.h +++ b/src/core/hle/kernel/resource_limit.h @@ -123,4 +123,4 @@ void ResourceLimitsInit(); // Destroys the resource limits void ResourceLimitsShutdown(); -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index 49a9cdfa3..0b7061403 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -50,4 +50,4 @@ std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> ServerPort::CreatePortP return std::make_tuple(std::move(server_port), std::move(client_port)); } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h index 6fe7c7f2f..9ef4ecc35 100644 --- a/src/core/hle/kernel/server_port.h +++ b/src/core/hle/kernel/server_port.h @@ -72,4 +72,4 @@ private: ~ServerPort() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index f4360ddf3..6ff4ef8c1 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h @@ -113,4 +113,4 @@ private: * in the command buffer. */ ResultCode TranslateHLERequest(ServerSession* server_session); -} +} // namespace Kernel diff --git a/src/core/hle/kernel/session.cpp b/src/core/hle/kernel/session.cpp index 8a2a7e3fd..642914744 100644 --- a/src/core/hle/kernel/session.cpp +++ b/src/core/hle/kernel/session.cpp @@ -9,4 +9,4 @@ namespace Kernel { Session::Session() {} Session::~Session() {} -} +} // namespace Kernel diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index 2cf319e99..e69b034a7 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -24,4 +24,4 @@ public: ServerSession* server = nullptr; ///< The server endpoint of the session. SharedPtr<ClientPort> port; ///< The port that this session is associated with (optional). }; -} +} // namespace Kernel diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 93a6f2182..e948819c0 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -98,10 +98,10 @@ public: ResultCode Unmap(Process* target_process, VAddr address); /** - * Gets a pointer to the shared memory block - * @param offset Offset from the start of the shared memory block to get pointer - * @return Pointer to the shared memory block from the specified offset - */ + * Gets a pointer to the shared memory block + * @param offset Offset from the start of the shared memory block to get pointer + * @return Pointer to the shared memory block from the specified offset + */ u8* GetPointer(u32 offset = 0); /// Process that created this shared memory block. @@ -129,4 +129,4 @@ private: ~SharedMemory() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 088058ebc..516309036 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -57,7 +57,7 @@ static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { } /// Connect to an OS service given the port name, returns the handle to the port to out -static ResultCode ConnectToPort(Handle* out_handle, VAddr port_name_address) { +static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address) { if (!Memory::IsValidVirtualAddress(port_name_address)) return ERR_NOT_FOUND; @@ -253,8 +253,8 @@ static ResultCode CancelSynchronization(Handle thread_handle) { } /// Attempts to locks a mutex, creating it if it does not already exist -static ResultCode LockMutex(Handle holding_thread_handle, VAddr mutex_addr, - Handle requesting_thread_handle) { +static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr, + Handle requesting_thread_handle) { LOG_TRACE(Kernel_SVC, "called holding_thread_handle=0x%08X, mutex_addr=0x%llx, " "requesting_current_thread_handle=0x%08X", @@ -278,7 +278,7 @@ static ResultCode LockMutex(Handle holding_thread_handle, VAddr mutex_addr, } /// Unlock a mutex -static ResultCode UnlockMutex(VAddr mutex_addr) { +static ResultCode ArbitrateUnlock(VAddr mutex_addr) { LOG_TRACE(Kernel_SVC, "called mutex_addr=0x%llx", mutex_addr); SharedPtr<Mutex> mutex = g_object_address_table.Get<Mutex>(mutex_addr); @@ -315,7 +315,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) *result = g_current_process->allowed_thread_priority_mask; break; case GetInfoType::MapRegionBaseAddr: - *result = vm_manager.GetAddressSpaceBaseAddr(); + *result = vm_manager.GetMapRegionBaseAddr(); break; case GetInfoType::MapRegionSize: *result = vm_manager.GetAddressSpaceSize(); @@ -739,6 +739,18 @@ static ResultCode SetThreadCoreMask(u64, u64, u64) { return RESULT_SUCCESS; } +static ResultCode CreateSharedMemory(Handle* handle, u64 sz, u32 local_permissions, + u32 remote_permissions) { + LOG_TRACE(Kernel_SVC, "called, sz=0x%llx, localPerms=0x%08x, remotePerms=0x%08x", sz, + local_permissions, remote_permissions); + auto sharedMemHandle = SharedMemory::Create( + g_handle_table.Get<Process>(KernelHandle::CurrentProcess), sz, + (Kernel::MemoryPermission)local_permissions, (Kernel::MemoryPermission)remote_permissions); + + CASCADE_RESULT(*handle, g_handle_table.Create(sharedMemHandle)); + return RESULT_SUCCESS; +} + namespace { struct FunctionDef { using Func = void(); @@ -776,12 +788,12 @@ static const FunctionDef SVC_Table[] = { {0x17, SvcWrap<ResetSignal>, "ResetSignal"}, {0x18, SvcWrap<WaitSynchronization>, "WaitSynchronization"}, {0x19, SvcWrap<CancelSynchronization>, "CancelSynchronization"}, - {0x1A, SvcWrap<LockMutex>, "LockMutex"}, - {0x1B, SvcWrap<UnlockMutex>, "UnlockMutex"}, + {0x1A, SvcWrap<ArbitrateLock>, "ArbitrateLock"}, + {0x1B, SvcWrap<ArbitrateUnlock>, "ArbitrateUnlock"}, {0x1C, SvcWrap<WaitProcessWideKeyAtomic>, "WaitProcessWideKeyAtomic"}, {0x1D, SvcWrap<SignalProcessWideKey>, "SignalProcessWideKey"}, {0x1E, SvcWrap<GetSystemTick>, "GetSystemTick"}, - {0x1F, SvcWrap<ConnectToPort>, "ConnectToPort"}, + {0x1F, SvcWrap<ConnectToNamedPort>, "ConnectToNamedPort"}, {0x20, nullptr, "SendSyncRequestLight"}, {0x21, SvcWrap<SendSyncRequest>, "SendSyncRequest"}, {0x22, nullptr, "SendSyncRequestWithUserBuffer"}, @@ -825,12 +837,12 @@ static const FunctionDef SVC_Table[] = { {0x48, nullptr, "Unknown"}, {0x49, nullptr, "Unknown"}, {0x4A, nullptr, "Unknown"}, - {0x4B, nullptr, "Unknown"}, - {0x4C, nullptr, "Unknown"}, + {0x4B, nullptr, "CreateJitMemory"}, + {0x4C, nullptr, "MapJitMemory"}, {0x4D, nullptr, "SleepSystem"}, {0x4E, nullptr, "ReadWriteRegister"}, {0x4F, nullptr, "SetProcessActivity"}, - {0x50, nullptr, "CreateSharedMemory"}, + {0x50, SvcWrap<CreateSharedMemory>, "CreateSharedMemory"}, {0x51, nullptr, "MapTransferMemory"}, {0x52, nullptr, "UnmapTransferMemory"}, {0x53, nullptr, "CreateInterruptEvent"}, diff --git a/src/core/hle/kernel/svc.h b/src/core/hle/kernel/svc.h index 42cc41da3..bc471d01e 100644 --- a/src/core/hle/kernel/svc.h +++ b/src/core/hle/kernel/svc.h @@ -14,7 +14,11 @@ struct MemoryInfo { u32 type; u32 attributes; u32 permission; + u32 device_refcount; + u32 ipc_refcount; + INSERT_PADDING_WORDS(1); }; +static_assert(sizeof(MemoryInfo) == 0x28, "MemoryInfo has incorrect size."); struct PageInfo { u64 flags; diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h index fd7054bbd..7a165d8dc 100644 --- a/src/core/hle/kernel/svc_wrap.h +++ b/src/core/hle/kernel/svc_wrap.h @@ -145,6 +145,15 @@ void SvcWrap() { FuncReturn(retval); } +template <ResultCode func(Handle*, u64, u32, u32)> +void SvcWrap() { + u32 param_1 = 0; + u32 retval = + func(¶m_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw; + Core::CPU().SetReg(1, param_1); + FuncReturn(retval); +} + //////////////////////////////////////////////////////////////////////////////////////////////////// // Function wrappers that return type u32 diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index a93a6c87a..8da745634 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp @@ -111,4 +111,4 @@ void TimersInit() { void TimersShutdown() {} -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/timer.h b/src/core/hle/kernel/timer.h index 82552372d..82d19cefc 100644 --- a/src/core/hle/kernel/timer.h +++ b/src/core/hle/kernel/timer.h @@ -76,4 +76,4 @@ void TimersInit(); /// Tears down the timer variables void TimersShutdown(); -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index bf261699e..93662a45e 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -375,6 +375,11 @@ u64 VMManager::GetAddressSpaceSize() { return MAX_ADDRESS; } +VAddr VMManager::GetMapRegionBaseAddr() { + LOG_WARNING(Kernel, "(STUBBED) called"); + return Memory::HEAP_VADDR; +} + VAddr VMManager::GetNewMapRegionBaseAddr() { LOG_WARNING(Kernel, "(STUBBED) called"); return 0x8000000; diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h index 7a7fee54a..b17385c7c 100644 --- a/src/core/hle/kernel/vm_manager.h +++ b/src/core/hle/kernel/vm_manager.h @@ -192,6 +192,9 @@ public: /// Gets the total address space address size, used by svcGetInfo u64 GetAddressSpaceSize(); + /// Gets the map region base address, used by svcGetInfo + VAddr GetMapRegionBaseAddr(); + /// Gets the base address for a new memory region, used by svcGetInfo VAddr GetNewMapRegionBaseAddr(); diff --git a/src/core/hle/service/acc/acc_u0.cpp b/src/core/hle/service/acc/acc_u0.cpp index 147f4e62e..7f0192fd3 100644 --- a/src/core/hle/service/acc/acc_u0.cpp +++ b/src/core/hle/service/acc/acc_u0.cpp @@ -9,15 +9,76 @@ namespace Service { namespace Account { +class IProfile final : public ServiceFramework<IProfile> { +public: + IProfile() : ServiceFramework("IProfile") { + static const FunctionInfo functions[] = { + {1, &IProfile::GetBase, "GetBase"}, + }; + RegisterHandlers(functions); + } + +private: + void GetBase(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + ProfileBase profile_base{}; + IPC::RequestBuilder rb{ctx, 16}; + rb.Push(RESULT_SUCCESS); + rb.PushRaw(profile_base); + } +}; + +class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { +public: + IManagerForApplication() : ServiceFramework("IProfile") { + static const FunctionInfo functions[] = { + {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"}, + }; + RegisterHandlers(functions); + } + +private: + void CheckAvailability(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + IPC::RequestBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(true); // TODO: Check when this is supposed to return true and when not + } +}; + +void ACC_U0::GetUserExistence(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + IPC::RequestBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(true); // TODO: Check when this is supposed to return true and when not +} + +void ACC_U0::GetProfile(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface<IProfile>(); + LOG_DEBUG(Service, "called"); +} + void ACC_U0::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); IPC::RequestBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } +void ACC_U0::GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface<IManagerForApplication>(); + LOG_DEBUG(Service, "called"); +} + ACC_U0::ACC_U0() : ServiceFramework("acc:u0") { static const FunctionInfo functions[] = { + {1, &ACC_U0::GetUserExistence, "GetUserExistence"}, + {5, &ACC_U0::GetProfile, "GetProfile"}, {100, &ACC_U0::InitializeApplicationInfo, "InitializeApplicationInfo"}, + {101, &ACC_U0::GetBaasAccountManagerForApplication, "GetBaasAccountManagerForApplication"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/acc/acc_u0.h b/src/core/hle/service/acc/acc_u0.h index ac243d5b8..51676e859 100644 --- a/src/core/hle/service/acc/acc_u0.h +++ b/src/core/hle/service/acc/acc_u0.h @@ -9,13 +9,28 @@ namespace Service { namespace Account { +// TODO: RE this structure +struct UserData { + INSERT_PADDING_BYTES(0x80); +}; +static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); + +// TODO: RE this structure +struct ProfileBase { + INSERT_PADDING_BYTES(0x38); +}; +static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase structure has incorrect size"); + class ACC_U0 final : public ServiceFramework<ACC_U0> { public: ACC_U0(); ~ACC_U0() = default; private: + void GetUserExistence(Kernel::HLERequestContext& ctx); + void GetProfile(Kernel::HLERequestContext& ctx); void InitializeApplicationInfo(Kernel::HLERequestContext& ctx); + void GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx); }; } // namespace Account diff --git a/src/core/hle/service/am/applet_oe.cpp b/src/core/hle/service/am/applet_oe.cpp index b360e7e5f..b4a6ad232 100644 --- a/src/core/hle/service/am/applet_oe.cpp +++ b/src/core/hle/service/am/applet_oe.cpp @@ -55,6 +55,8 @@ class ISelfController final : public ServiceFramework<ISelfController> { public: ISelfController() : ServiceFramework("ISelfController") { static const FunctionInfo functions[] = { + {1, &ISelfController::LockExit, "LockExit"}, + {2, &ISelfController::UnlockExit, "UnlockExit"}, {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"}, {12, &ISelfController::SetPerformanceModeChangedNotification, @@ -128,6 +130,20 @@ private: LOG_WARNING(Service, "(STUBBED) called enabled=%u", static_cast<u32>(enabled)); } + + void LockExit(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service, "(STUBBED) called"); + } + + void UnlockExit(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service, "(STUBBED) called"); + } }; class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> { @@ -201,10 +217,77 @@ private: Kernel::SharedPtr<Kernel::Event> event; }; +class IStorageAccessor final : public ServiceFramework<IStorageAccessor> { +public: + explicit IStorageAccessor(std::vector<u8> buffer) + : ServiceFramework("IStorageAccessor"), buffer(std::move(buffer)) { + static const FunctionInfo functions[] = { + {0, &IStorageAccessor::GetSize, "GetSize"}, + {11, &IStorageAccessor::Read, "Read"}, + }; + RegisterHandlers(functions); + } + +private: + std::vector<u8> buffer; + + void GetSize(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 4}; + + rb.Push(RESULT_SUCCESS); + rb.Push(static_cast<u64>(buffer.size())); + + LOG_DEBUG(Service, "called"); + } + + void Read(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + u64 offset = rp.Pop<u64>(); + + const auto& output_buffer = ctx.BufferDescriptorC()[0]; + + ASSERT(offset + output_buffer.Size() <= buffer.size()); + + Memory::WriteBlock(output_buffer.Address(), buffer.data() + offset, output_buffer.Size()); + + IPC::RequestBuilder rb{ctx, 2}; + + rb.Push(RESULT_SUCCESS); + + LOG_DEBUG(Service, "called"); + } +}; + +class IStorage final : public ServiceFramework<IStorage> { +public: + explicit IStorage(std::vector<u8> buffer) + : ServiceFramework("IStorage"), buffer(std::move(buffer)) { + static const FunctionInfo functions[] = { + {0, &IStorage::Open, "Open"}, + }; + RegisterHandlers(functions); + } + +private: + std::vector<u8> buffer; + + void Open(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; + + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface<AM::IStorageAccessor>(buffer); + + LOG_DEBUG(Service, "called"); + } +}; + class IApplicationFunctions final : public ServiceFramework<IApplicationFunctions> { public: IApplicationFunctions() : ServiceFramework("IApplicationFunctions") { static const FunctionInfo functions[] = { + {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, + {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"}, {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"}, {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"}, @@ -215,6 +298,26 @@ public: } private: + void PopLaunchParameter(Kernel::HLERequestContext& ctx) { + constexpr u8 data[0x88] = { + 0xca, 0x97, 0x94, 0xc7, // Magic + 1, 0, 0, 0, // IsAccountSelected (bool) + 1, 0, 0, 0, // User Id (word 0) + 0, 0, 0, 0, // User Id (word 1) + 0, 0, 0, 0, // User Id (word 2) + 0, 0, 0, 0 // User Id (word 3) + }; + + std::vector<u8> buffer(data, data + sizeof(data)); + + IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; + + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface<AM::IStorage>(buffer); + + LOG_DEBUG(Service, "called"); + } + void SetTerminateResult(Kernel::HLERequestContext& ctx) { // Takes an input u32 Result, no output. // For example, in some cases official apps use this with error 0x2A2 then uses svcBreak. @@ -228,6 +331,13 @@ private: LOG_WARNING(Service, "(STUBBED) called, result=0x%08X", result); } + void GetDesiredLanguage(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.Push<u64>(SystemLanguage::English); + LOG_WARNING(Service, "(STUBBED) called"); + } + void InitializeGamePlayRecording(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/am/applet_oe.h b/src/core/hle/service/am/applet_oe.h index beb75bf2a..6ee5b0e9f 100644 --- a/src/core/hle/service/am/applet_oe.h +++ b/src/core/hle/service/am/applet_oe.h @@ -10,6 +10,12 @@ namespace Service { namespace AM { +// TODO: Add more languages +enum SystemLanguage { + Japanese = 0, + English = 1, +}; + class AppletOE final : public ServiceFramework<AppletOE> { public: AppletOE(); diff --git a/src/core/hle/service/apm/apm.cpp b/src/core/hle/service/apm/apm.cpp index 66d94ff52..bf7e12288 100644 --- a/src/core/hle/service/apm/apm.cpp +++ b/src/core/hle/service/apm/apm.cpp @@ -51,7 +51,8 @@ private: APM::APM() : ServiceFramework("apm") { static const FunctionInfo functions[] = { - {0x00000000, &APM::OpenSession, "OpenSession"}, {0x00000001, nullptr, "GetPerformanceMode"}, + {0x00000000, &APM::OpenSession, "OpenSession"}, + {0x00000001, nullptr, "GetPerformanceMode"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 6254237fa..be7a6ff65 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -18,9 +18,9 @@ namespace HID { // Updating period for each HID device. // TODO(shinyquagsire23): These need better values. -constexpr u64 pad_update_ticks = BASE_CLOCK_RATE / 234; -constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE / 104; -constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE / 101; +constexpr u64 pad_update_ticks = BASE_CLOCK_RATE / 10000; +constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE / 10000; +constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE / 10000; class IAppletResource final : public ServiceFramework<IAppletResource> { public: diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 2d0d2fb65..13c9ee3d3 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -47,6 +47,7 @@ private: /// Log field type enum class Field : u8 { + Skip = 1, Message = 2, Line = 3, Filename = 4, @@ -85,6 +86,11 @@ private: while (addr < end_addr) { const Field field{static_cast<Field>(Memory::Read8(addr++))}; size_t length{Memory::Read8(addr++)}; + + if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) { + ++addr; + } + switch (field) { case Field::Message: message = Memory::ReadCString(addr, length); @@ -99,6 +105,7 @@ private: function = Memory::ReadCString(addr, length); break; } + addr += length; } diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp index 0670ca155..417455200 100644 --- a/src/core/hle/service/nvdrv/interface.cpp +++ b/src/core/hle/service/nvdrv/interface.cpp @@ -48,6 +48,18 @@ void NVDRV::Ioctl(Kernel::HLERequestContext& ctx) { rb.Push(nv_result); } +void NVDRV::Close(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + + IPC::RequestParser rp{ctx}; + u32 fd = rp.Pop<u32>(); + + auto result = nvdrv->Close(fd); + + IPC::RequestBuilder rb{ctx, 2}; + rb.Push(result); +} + void NVDRV::Initialize(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); IPC::RequestBuilder rb{ctx, 3}; @@ -55,12 +67,25 @@ void NVDRV::Initialize(Kernel::HLERequestContext& ctx) { rb.Push<u32>(0); } +void NVDRV::SetClientPID(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + u64 pid = rp.Pop<u64>(); + u64 unk = rp.Pop<u64>(); + + LOG_WARNING(Service, "(STUBBED) called, pid=0x%llx, unk=0x%llx", pid, unk); + + IPC::RequestBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); +} + NVDRV::NVDRV(std::shared_ptr<Module> nvdrv, const char* name) : ServiceFramework(name), nvdrv(std::move(nvdrv)) { static const FunctionInfo functions[] = { {0, &NVDRV::Open, "Open"}, {1, &NVDRV::Ioctl, "Ioctl"}, + {2, &NVDRV::Close, "Close"}, {3, &NVDRV::Initialize, "Initialize"}, + {8, &NVDRV::SetClientPID, "SetClientPID"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/nvdrv/interface.h b/src/core/hle/service/nvdrv/interface.h index 8c95b7217..2283f358e 100644 --- a/src/core/hle/service/nvdrv/interface.h +++ b/src/core/hle/service/nvdrv/interface.h @@ -20,7 +20,9 @@ public: private: void Open(Kernel::HLERequestContext& ctx); void Ioctl(Kernel::HLERequestContext& ctx); + void Close(Kernel::HLERequestContext& ctx); void Initialize(Kernel::HLERequestContext& ctx); + void SetClientPID(Kernel::HLERequestContext& ctx); std::shared_ptr<Module> nvdrv; }; diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index cf525a875..9d3013c16 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -7,8 +7,8 @@ #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" #include "core/hle/service/nvdrv/devices/nvmap.h" -#include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvdrv/interface.h" +#include "core/hle/service/nvdrv/nvdrv.h" namespace Service { namespace Nvidia { @@ -49,5 +49,15 @@ u32 Module::Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector return device->ioctl(command, input, output); } +ResultCode Module::Close(u32 fd) { + auto itr = open_files.find(fd); + ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device"); + + open_files.erase(itr); + + // TODO(flerovium): return correct result code if operation failed. + return RESULT_SUCCESS; +} + } // namespace Nvidia } // namespace Service diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h index 1940ced99..e44644624 100644 --- a/src/core/hle/service/nvdrv/nvdrv.h +++ b/src/core/hle/service/nvdrv/nvdrv.h @@ -35,6 +35,8 @@ public: u32 Open(std::string device_name); /// Sends an ioctl command to the specified file descriptor. u32 Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output); + /// Closes a device file descriptor and returns operation success. + ResultCode Close(u32 fd); private: /// Id to use for the next open file descriptor. diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index fe76b381c..19213a2f4 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -24,8 +24,10 @@ #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/pctl/pctl.h" #include "core/hle/service/service.h" +#include "core/hle/service/set/set.h" #include "core/hle/service/sm/controller.h" #include "core/hle/service/sm/sm.h" +#include "core/hle/service/sockets/sockets.h" #include "core/hle/service/time/time.h" #include "core/hle/service/vi/vi.h" @@ -174,8 +176,10 @@ void Init() { LM::InstallInterfaces(*SM::g_service_manager); Nvidia::InstallInterfaces(*SM::g_service_manager); PCTL::InstallInterfaces(*SM::g_service_manager); + Sockets::InstallInterfaces(*SM::g_service_manager); Time::InstallInterfaces(*SM::g_service_manager); VI::InstallInterfaces(*SM::g_service_manager); + Set::InstallInterfaces(*SM::g_service_manager); LOG_DEBUG(Service, "initialized OK"); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 8e1c5b399..9c2e826da 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -21,7 +21,7 @@ class ClientPort; class ServerPort; class ServerSession; class HLERequestContext; -} +} // namespace Kernel namespace Service { @@ -189,4 +189,4 @@ extern std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_ /// Adds a port to the named port table void AddNamedPort(std::string name, Kernel::SharedPtr<Kernel::ClientPort> port); -} // namespace +} // namespace Service diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp new file mode 100644 index 000000000..3715acd74 --- /dev/null +++ b/src/core/hle/service/set/set.cpp @@ -0,0 +1,42 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <chrono> +#include "common/logging/log.h" +#include "core/hle/ipc_helpers.h" +#include "core/hle/kernel/client_port.h" +#include "core/hle/kernel/client_session.h" +#include "core/hle/service/set/set.h" + +namespace Service { +namespace Set { + +void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { + constexpr std::array<u8, 13> lang_codes{}; + + const auto& output_buffer = ctx.BufferDescriptorC()[0]; + + Memory::WriteBlock(output_buffer.Address(), lang_codes.data(), lang_codes.size()); + + IPC::RequestBuilder rb{ctx, 4}; + + rb.Push(RESULT_SUCCESS); + rb.Push(static_cast<u64>(lang_codes.size())); + + LOG_WARNING(Service, "(STUBBED) called"); +} + +SET::SET(const char* name) : ServiceFramework(name) { + static const FunctionInfo functions[] = { + {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, + }; + RegisterHandlers(functions); +} + +void InstallInterfaces(SM::ServiceManager& service_manager) { + std::make_shared<SET>("set")->InstallAsService(service_manager); +} + +} // namespace Set +} // namespace Service diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h new file mode 100644 index 000000000..61e957946 --- /dev/null +++ b/src/core/hle/service/set/set.h @@ -0,0 +1,25 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/service.h" + +namespace Service { +namespace Set { + +class SET final : public ServiceFramework<SET> { +public: + explicit SET(const char* name); + ~SET() = default; + +private: + void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); +}; + +/// Registers all Set services with the specified service manager. +void InstallInterfaces(SM::ServiceManager& service_manager); + +} // namespace Set +} // namespace Service diff --git a/src/core/hle/service/sm/controller.cpp b/src/core/hle/service/sm/controller.cpp index e8f5d0e4a..7b1c8ee37 100644 --- a/src/core/hle/service/sm/controller.cpp +++ b/src/core/hle/service/sm/controller.cpp @@ -32,6 +32,12 @@ void Controller::DuplicateSession(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service, "called"); } +void Controller::DuplicateSessionEx(Kernel::HLERequestContext& ctx) { + DuplicateSession(ctx); + + LOG_WARNING(Service, "(STUBBED) called, using DuplicateSession"); +} + void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); @@ -46,7 +52,7 @@ Controller::Controller() : ServiceFramework("IpcController") { {0x00000001, nullptr, "ConvertDomainToSession"}, {0x00000002, &Controller::DuplicateSession, "DuplicateSession"}, {0x00000003, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"}, - {0x00000004, nullptr, "DuplicateSessionEx"}, + {0x00000004, &Controller::DuplicateSessionEx, "DuplicateSessionEx"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/sm/controller.h b/src/core/hle/service/sm/controller.h index 0b873b492..7b4bc4b75 100644 --- a/src/core/hle/service/sm/controller.h +++ b/src/core/hle/service/sm/controller.h @@ -17,6 +17,7 @@ public: private: void ConvertSessionToDomain(Kernel::HLERequestContext& ctx); void DuplicateSession(Kernel::HLERequestContext& ctx); + void DuplicateSessionEx(Kernel::HLERequestContext& ctx); void QueryPointerBufferSize(Kernel::HLERequestContext& ctx); }; diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index f3bffac54..c4078f02f 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -103,6 +103,7 @@ void SM::GetService(Kernel::HLERequestContext& ctx) { rb.Push(client_port.Code()); LOG_ERROR(Service_SM, "called service=%s -> error 0x%08X", name.c_str(), client_port.Code().raw); + UNIMPLEMENTED(); return; } diff --git a/src/core/hle/service/sockets/bsd_u.cpp b/src/core/hle/service/sockets/bsd_u.cpp new file mode 100644 index 000000000..a819acc96 --- /dev/null +++ b/src/core/hle/service/sockets/bsd_u.cpp @@ -0,0 +1,67 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/ipc_helpers.h" +#include "core/hle/service/sockets/bsd_u.h" + +namespace Service { +namespace Sockets { + +void BSD_U::RegisterClient(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + + IPC::RequestBuilder rb{ctx, 3}; + + rb.Push(RESULT_SUCCESS); + rb.Push<u32>(0); // bsd errno +} + +void BSD_U::Socket(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + u32 domain = rp.Pop<u32>(); + u32 type = rp.Pop<u32>(); + u32 protocol = rp.Pop<u32>(); + + LOG_WARNING(Service, "(STUBBED) called domain=%u type=%u protocol=%u", domain, type, protocol); + + u32 fd = next_fd++; + + IPC::RequestBuilder rb{ctx, 4}; + + rb.Push(RESULT_SUCCESS); + rb.Push<u32>(fd); + rb.Push<u32>(0); // bsd errno +} + +void BSD_U::Connect(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + + IPC::RequestBuilder rb{ctx, 4}; + + rb.Push(RESULT_SUCCESS); + rb.Push<u32>(0); // ret + rb.Push<u32>(0); // bsd errno +} + +void BSD_U::SendTo(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + + IPC::RequestBuilder rb{ctx, 4}; + + rb.Push(RESULT_SUCCESS); + rb.Push<u32>(0); // ret + rb.Push<u32>(0); // bsd errno +} + +BSD_U::BSD_U() : ServiceFramework("bsd:u") { + static const FunctionInfo functions[] = {{0, &BSD_U::RegisterClient, "RegisterClient"}, + {2, &BSD_U::Socket, "Socket"}, + {11, &BSD_U::SendTo, "SendTo"}, + {14, &BSD_U::Connect, "Connect"}}; + RegisterHandlers(functions); +} + +} // namespace Sockets +} // namespace Service diff --git a/src/core/hle/service/sockets/bsd_u.h b/src/core/hle/service/sockets/bsd_u.h new file mode 100644 index 000000000..1fe96d850 --- /dev/null +++ b/src/core/hle/service/sockets/bsd_u.h @@ -0,0 +1,29 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/kernel/hle_ipc.h" +#include "core/hle/service/service.h" + +namespace Service { +namespace Sockets { + +class BSD_U final : public ServiceFramework<BSD_U> { +public: + BSD_U(); + ~BSD_U() = default; + +private: + void RegisterClient(Kernel::HLERequestContext& ctx); + void Socket(Kernel::HLERequestContext& ctx); + void Connect(Kernel::HLERequestContext& ctx); + void SendTo(Kernel::HLERequestContext& ctx); + + /// Id to use for the next open file descriptor. + u32 next_fd = 1; +}; + +} // namespace Sockets +} // namespace Service diff --git a/src/core/hle/service/sockets/sfdnsres.h b/src/core/hle/service/sockets/sfdnsres.h new file mode 100644 index 000000000..32a3ac8c5 --- /dev/null +++ b/src/core/hle/service/sockets/sfdnsres.h @@ -0,0 +1,22 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/kernel/hle_ipc.h" +#include "core/hle/service/service.h" + +namespace Service { +namespace Sockets { + +class SFDNSRES final : public ServiceFramework<SFDNSRES> { +public: + SFDNSRES() : ServiceFramework("sfdnsres") {} + ~SFDNSRES() = default; + +private: +}; + +} // namespace Sockets +} // namespace Service diff --git a/src/core/hle/service/sockets/sockets.cpp b/src/core/hle/service/sockets/sockets.cpp new file mode 100644 index 000000000..f1396eaa1 --- /dev/null +++ b/src/core/hle/service/sockets/sockets.cpp @@ -0,0 +1,18 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/service/sockets/bsd_u.h" +#include "core/hle/service/sockets/sfdnsres.h" +#include "core/hle/service/sockets/sockets.h" + +namespace Service { +namespace Sockets { + +void InstallInterfaces(SM::ServiceManager& service_manager) { + std::make_shared<BSD_U>()->InstallAsService(service_manager); + std::make_shared<SFDNSRES>()->InstallAsService(service_manager); +} + +} // namespace Sockets +} // namespace Service diff --git a/src/core/hle/service/sockets/sockets.h b/src/core/hle/service/sockets/sockets.h new file mode 100644 index 000000000..7e89c8d2c --- /dev/null +++ b/src/core/hle/service/sockets/sockets.h @@ -0,0 +1,16 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/service.h" + +namespace Service { +namespace Sockets { + +/// Registers all Sockets services with the specified service manager. +void InstallInterfaces(SM::ServiceManager& service_manager); + +} // namespace Sockets +} // namespace Service diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index e3d58aa60..9fed89246 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -2,14 +2,142 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <chrono> +#include "common/logging/log.h" +#include "core/hle/ipc_helpers.h" +#include "core/hle/kernel/client_port.h" +#include "core/hle/kernel/client_session.h" #include "core/hle/service/time/time.h" #include "core/hle/service/time/time_s.h" +#include "core/hle/service/time/time_u.h" namespace Service { namespace Time { +class ISystemClock final : public ServiceFramework<ISystemClock> { +public: + ISystemClock() : ServiceFramework("ISystemClock") { + static const FunctionInfo functions[] = { + {0, &ISystemClock::GetCurrentTime, "GetCurrentTime"}, + }; + RegisterHandlers(functions); + } + +private: + void GetCurrentTime(Kernel::HLERequestContext& ctx) { + const s64 time_since_epoch{std::chrono::duration_cast<std::chrono::milliseconds>( + std::chrono::system_clock::now().time_since_epoch()) + .count()}; + IPC::RequestBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.Push<u64>(time_since_epoch); + LOG_DEBUG(Service, "called"); + } +}; + +class ISteadyClock final : public ServiceFramework<ISteadyClock> { +public: + ISteadyClock() : ServiceFramework("ISteadyClock") {} +}; + +class ITimeZoneService final : public ServiceFramework<ITimeZoneService> { +public: + ITimeZoneService() : ServiceFramework("ITimeZoneService") { + static const FunctionInfo functions[] = { + {0, &ITimeZoneService::GetDeviceLocationName, "GetDeviceLocationName"}, + {2, &ITimeZoneService::GetTotalLocationNameCount, "GetTotalLocationNameCount"}, + {101, &ITimeZoneService::ToCalendarTimeWithMyRule, "ToCalendarTimeWithMyRule"}, + }; + RegisterHandlers(functions); + } + +private: + void GetDeviceLocationName(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + LocationName location_name{}; + IPC::RequestBuilder rb{ctx, (sizeof(LocationName) / 4) + 2}; + rb.Push(RESULT_SUCCESS); + rb.PushRaw(location_name); + } + + void GetTotalLocationNameCount(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + IPC::RequestBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push<u32>(0); + } + + void ToCalendarTimeWithMyRule(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + u64 posix_time = rp.Pop<u64>(); + + LOG_WARNING(Service, "(STUBBED) called, posix_time=0x%016llX", posix_time); + + CalendarTime calendar_time{2018, 1, 1, 0, 0, 0}; + CalendarAdditionalInfo additional_info{}; + IPC::RequestBuilder rb{ctx, 10}; + rb.Push(RESULT_SUCCESS); + rb.PushRaw(calendar_time); + rb.PushRaw(additional_info); + } +}; + +void Module::Interface::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) { + auto client_port = std::make_shared<ISystemClock>()->CreatePort(); + auto session = client_port->Connect(); + if (session.Succeeded()) { + LOG_DEBUG(Service, "called, initialized ISystemClock -> session=%u", + (*session)->GetObjectId()); + IPC::RequestBuilder rb{ctx, 2, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushMoveObjects(std::move(session).Unwrap()); + } else { + UNIMPLEMENTED(); + } +} + +void Module::Interface::GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx) { + auto client_port = std::make_shared<ISystemClock>()->CreatePort(); + auto session = client_port->Connect(); + if (session.Succeeded()) { + LOG_DEBUG(Service, "called, initialized ISystemClock -> session=%u", + (*session)->GetObjectId()); + IPC::RequestBuilder rb{ctx, 2, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushMoveObjects(std::move(session).Unwrap()); + } else { + UNIMPLEMENTED(); + } +} + +void Module::Interface::GetStandardSteadyClock(Kernel::HLERequestContext& ctx) { + auto client_port = std::make_shared<ISteadyClock>()->CreatePort(); + auto session = client_port->Connect(); + if (session.Succeeded()) { + LOG_DEBUG(Service, "called, initialized ISteadyClock -> session=%u", + (*session)->GetObjectId()); + IPC::RequestBuilder rb{ctx, 2, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushMoveObjects(std::move(session).Unwrap()); + } else { + UNIMPLEMENTED(); + } +} + +void Module::Interface::GetTimeZoneService(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface<ITimeZoneService>(); + LOG_DEBUG(Service, "called"); +} + +Module::Interface::Interface(std::shared_ptr<Module> time, const char* name) + : ServiceFramework(name), time(std::move(time)) {} + void InstallInterfaces(SM::ServiceManager& service_manager) { - std::make_shared<TimeS>()->InstallAsService(service_manager); + auto time = std::make_shared<Module>(); + std::make_shared<TIME_S>(time)->InstallAsService(service_manager); + std::make_shared<TIME_U>(time)->InstallAsService(service_manager); } } // namespace Time diff --git a/src/core/hle/service/time/time.h b/src/core/hle/service/time/time.h index 7d0803e24..399f474d6 100644 --- a/src/core/hle/service/time/time.h +++ b/src/core/hle/service/time/time.h @@ -9,6 +9,46 @@ namespace Service { namespace Time { +// TODO(Rozelette) RE this structure +struct LocationName { + INSERT_PADDING_BYTES(0x24); +}; +static_assert(sizeof(LocationName) == 0x24, "LocationName is incorrect size"); + +struct CalendarTime { + u16_le year; + u8 month; // Starts at 1 + u8 day; // Starts at 1 + u8 hour; + u8 minute; + u8 second; + INSERT_PADDING_BYTES(1); +}; +static_assert(sizeof(CalendarTime) == 0x8, "CalendarTime structure has incorrect size"); + +// TODO(Rozelette) RE this structure +struct CalendarAdditionalInfo { + INSERT_PADDING_BYTES(0x18); +}; +static_assert(sizeof(CalendarAdditionalInfo) == 0x18, + "CalendarAdditionalInfo structure has incorrect size"); + +class Module final { +public: + class Interface : public ServiceFramework<Interface> { + public: + Interface(std::shared_ptr<Module> time, const char* name); + + void GetStandardUserSystemClock(Kernel::HLERequestContext& ctx); + void GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx); + void GetStandardSteadyClock(Kernel::HLERequestContext& ctx); + void GetTimeZoneService(Kernel::HLERequestContext& ctx); + + protected: + std::shared_ptr<Module> time; + }; +}; + /// Registers all Time services with the specified service manager. void InstallInterfaces(SM::ServiceManager& service_manager); diff --git a/src/core/hle/service/time/time_s.cpp b/src/core/hle/service/time/time_s.cpp index 6b0597d8e..1634d3300 100644 --- a/src/core/hle/service/time/time_s.cpp +++ b/src/core/hle/service/time/time_s.cpp @@ -2,54 +2,14 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include <chrono> -#include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/client_port.h" -#include "core/hle/kernel/client_session.h" #include "core/hle/service/time/time_s.h" namespace Service { namespace Time { -class ISystemClock final : public ServiceFramework<ISystemClock> { -public: - ISystemClock() : ServiceFramework("ISystemClock") { - static const FunctionInfo functions[] = { - {0, &ISystemClock::GetCurrentTime, "GetCurrentTime"}, - }; - RegisterHandlers(functions); - } - -private: - void GetCurrentTime(Kernel::HLERequestContext& ctx) { - const s64 time_since_epoch{std::chrono::duration_cast<std::chrono::milliseconds>( - std::chrono::system_clock::now().time_since_epoch()) - .count()}; - IPC::RequestBuilder rb{ctx, 4}; - rb.Push(RESULT_SUCCESS); - rb.Push<u64>(time_since_epoch); - LOG_DEBUG(Service, "called"); - } -}; - -void TimeS::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) { - auto client_port = std::make_shared<ISystemClock>()->CreatePort(); - auto session = client_port->Connect(); - if (session.Succeeded()) { - LOG_DEBUG(Service, "called, initialized ISystemClock -> session=%u", - (*session)->GetObjectId()); - IPC::RequestBuilder rb{ctx, 2, 0, 1}; - rb.Push(RESULT_SUCCESS); - rb.PushMoveObjects(std::move(session).Unwrap()); - } else { - UNIMPLEMENTED(); - } -} - -TimeS::TimeS() : ServiceFramework("time:s") { +TIME_S::TIME_S(std::shared_ptr<Module> time) : Module::Interface(std::move(time), "time:s") { static const FunctionInfo functions[] = { - {0x00000000, &TimeS::GetStandardUserSystemClock, "GetStandardUserSystemClock"}, + {0, &TIME_S::GetStandardUserSystemClock, "GetStandardUserSystemClock"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/time/time_s.h b/src/core/hle/service/time/time_s.h index 073227910..abc2a8c5a 100644 --- a/src/core/hle/service/time/time_s.h +++ b/src/core/hle/service/time/time_s.h @@ -4,19 +4,14 @@ #pragma once -#include "core/hle/kernel/hle_ipc.h" -#include "core/hle/service/service.h" +#include "core/hle/service/time/time.h" namespace Service { namespace Time { -class TimeS final : public ServiceFramework<TimeS> { +class TIME_S final : public Module::Interface { public: - TimeS(); - ~TimeS() = default; - -private: - void GetStandardUserSystemClock(Kernel::HLERequestContext& ctx); + explicit TIME_S(std::shared_ptr<Module> time); }; } // namespace Time diff --git a/src/core/hle/service/time/time_u.cpp b/src/core/hle/service/time/time_u.cpp new file mode 100644 index 000000000..ae4f78adf --- /dev/null +++ b/src/core/hle/service/time/time_u.cpp @@ -0,0 +1,21 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/service/time/time_u.h" + +namespace Service { +namespace Time { + +TIME_U::TIME_U(std::shared_ptr<Module> time) : Module::Interface(std::move(time), "time:u") { + static const FunctionInfo functions[] = { + {0, &TIME_U::GetStandardUserSystemClock, "GetStandardUserSystemClock"}, + {1, &TIME_U::GetStandardNetworkSystemClock, "GetStandardNetworkSystemClock"}, + {2, &TIME_U::GetStandardSteadyClock, "GetStandardSteadyClock"}, + {3, &TIME_U::GetTimeZoneService, "GetTimeZoneService"}, + }; + RegisterHandlers(functions); +} + +} // namespace Time +} // namespace Service diff --git a/src/core/hle/service/time/time_u.h b/src/core/hle/service/time/time_u.h new file mode 100644 index 000000000..f99d25057 --- /dev/null +++ b/src/core/hle/service/time/time_u.h @@ -0,0 +1,18 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/time/time.h" + +namespace Service { +namespace Time { + +class TIME_U final : public Module::Interface { +public: + explicit TIME_U(std::shared_ptr<Module> time); +}; + +} // namespace Time +} // namespace Service diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index cae2c4466..c624e734e 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -26,7 +26,7 @@ public: // This default size was chosen arbitrarily. static constexpr size_t DefaultBufferSize = 0x40; Parcel() : buffer(DefaultBufferSize) {} - Parcel(std::vector<u8> data) : buffer(std::move(data)) {} + explicit Parcel(std::vector<u8> data) : buffer(std::move(data)) {} virtual ~Parcel() = default; template <typename T> @@ -47,8 +47,9 @@ public: } std::vector<u8> ReadBlock(size_t length) { - std::vector<u8> data(length); - std::memcpy(data.data(), buffer.data() + read_index, length); + const u8* const begin = buffer.data() + read_index; + const u8* const end = begin + length; + std::vector<u8> data(begin, end); read_index += length; read_index = Common::AlignUp(read_index, 4); return data; @@ -94,16 +95,16 @@ public: Header header{}; header.data_offset = sizeof(Header); - header.data_size = write_index - sizeof(Header); + header.data_size = static_cast<u32_le>(write_index - sizeof(Header)); std::memcpy(buffer.data(), &header, sizeof(Header)); return buffer; } protected: - virtual void SerializeData(){}; + virtual void SerializeData() {} - virtual void DeserializeData(){}; + virtual void DeserializeData() {} private: struct Header { @@ -121,7 +122,7 @@ private: class NativeWindow : public Parcel { public: - NativeWindow(u32 id) : Parcel() { + explicit NativeWindow(u32 id) : Parcel() { data.id = id; } ~NativeWindow() override = default; @@ -137,7 +138,7 @@ private: u32_le process_id; u32_le id; INSERT_PADDING_BYTES(0xC); - std::array<u8, 8> dspdrv = {'d', 's', 'p', 'd', 'r', 'v'}; + std::array<u8, 8> dispdrv = {'d', 'i', 's', 'p', 'd', 'r', 'v', '\0'}; INSERT_PADDING_BYTES(8); }; static_assert(sizeof(Data) == 0x28, "ParcelData has wrong size"); @@ -147,12 +148,12 @@ private: class IGBPConnectRequestParcel : public Parcel { public: - IGBPConnectRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { + explicit IGBPConnectRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { Deserialize(); } ~IGBPConnectRequestParcel() override = default; - void DeserializeData() { + void DeserializeData() override { std::u16string token = ReadInterfaceToken(); data = Read<Data>(); } @@ -168,7 +169,7 @@ public: class IGBPConnectResponseParcel : public Parcel { public: - IGBPConnectResponseParcel(u32 width, u32 height) : Parcel() { + explicit IGBPConnectResponseParcel(u32 width, u32 height) : Parcel() { data.width = width; data.height = height; } @@ -194,12 +195,13 @@ private: class IGBPSetPreallocatedBufferRequestParcel : public Parcel { public: - IGBPSetPreallocatedBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { + explicit IGBPSetPreallocatedBufferRequestParcel(const std::vector<u8>& buffer) + : Parcel(buffer) { Deserialize(); } ~IGBPSetPreallocatedBufferRequestParcel() override = default; - void DeserializeData() { + void DeserializeData() override { std::u16string token = ReadInterfaceToken(); data = Read<Data>(); ASSERT(data.graphic_buffer_length == sizeof(IGBPBuffer)); @@ -231,12 +233,12 @@ protected: class IGBPDequeueBufferRequestParcel : public Parcel { public: - IGBPDequeueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { + explicit IGBPDequeueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { Deserialize(); } ~IGBPDequeueBufferRequestParcel() override = default; - void DeserializeData() { + void DeserializeData() override { std::u16string token = ReadInterfaceToken(); data = Read<Data>(); } @@ -254,7 +256,7 @@ public: class IGBPDequeueBufferResponseParcel : public Parcel { public: - IGBPDequeueBufferResponseParcel(u32 slot) : Parcel(), slot(slot) {} + explicit IGBPDequeueBufferResponseParcel(u32 slot) : Parcel(), slot(slot) {} ~IGBPDequeueBufferResponseParcel() override = default; protected: @@ -271,12 +273,12 @@ protected: class IGBPRequestBufferRequestParcel : public Parcel { public: - IGBPRequestBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { + explicit IGBPRequestBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { Deserialize(); } ~IGBPRequestBufferRequestParcel() override = default; - void DeserializeData() { + void DeserializeData() override { std::u16string token = ReadInterfaceToken(); slot = Read<u32_le>(); } @@ -286,7 +288,7 @@ public: class IGBPRequestBufferResponseParcel : public Parcel { public: - IGBPRequestBufferResponseParcel(IGBPBuffer buffer) : Parcel(), buffer(buffer) {} + explicit IGBPRequestBufferResponseParcel(IGBPBuffer buffer) : Parcel(), buffer(buffer) {} ~IGBPRequestBufferResponseParcel() override = default; protected: @@ -307,12 +309,12 @@ protected: class IGBPQueueBufferRequestParcel : public Parcel { public: - IGBPQueueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { + explicit IGBPQueueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { Deserialize(); } ~IGBPQueueBufferRequestParcel() override = default; - void DeserializeData() { + void DeserializeData() override { std::u16string token = ReadInterfaceToken(); data = Read<Data>(); } @@ -330,7 +332,7 @@ public: class IGBPQueueBufferResponseParcel : public Parcel { public: - IGBPQueueBufferResponseParcel(u32 width, u32 height) : Parcel() { + explicit IGBPQueueBufferResponseParcel(u32 width, u32 height) : Parcel() { data.width = width; data.height = height; } @@ -356,7 +358,7 @@ private: class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> { public: - IHOSBinderDriver(std::shared_ptr<NVFlinger> nv_flinger) + explicit IHOSBinderDriver(std::shared_ptr<NVFlinger> nv_flinger) : ServiceFramework("IHOSBinderDriver"), nv_flinger(std::move(nv_flinger)) { static const FunctionInfo functions[] = { {0, &IHOSBinderDriver::TransactParcel, "TransactParcel"}, @@ -506,7 +508,7 @@ private: class IManagerDisplayService final : public ServiceFramework<IManagerDisplayService> { public: - IManagerDisplayService(std::shared_ptr<NVFlinger> nv_flinger) + explicit IManagerDisplayService(std::shared_ptr<NVFlinger> nv_flinger) : ServiceFramework("IManagerDisplayService"), nv_flinger(std::move(nv_flinger)) { static const FunctionInfo functions[] = { {1020, &IManagerDisplayService::CloseDisplay, "CloseDisplay"}, diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp index 9ce8af961..bba4a0715 100644 --- a/src/core/hle/shared_page.cpp +++ b/src/core/hle/shared_page.cpp @@ -82,4 +82,4 @@ void Init() { CoreTiming::ScheduleEvent(0, update_time_event); } -} // namespace +} // namespace SharedPage diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h index 864695ae1..a58259888 100644 --- a/src/core/hle/shared_page.h +++ b/src/core/hle/shared_page.h @@ -66,4 +66,4 @@ extern SharedPageDef shared_page; void Init(); -} // namespace +} // namespace SharedPage diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index a751b1d62..0db604c76 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -91,4 +91,4 @@ void Shutdown() { LCD::Shutdown(); LOG_DEBUG(HW, "shutdown OK"); } -} +} // namespace HW diff --git a/src/core/hw/hw.h b/src/core/hw/hw.h index a3c5d2ea3..5890d2b5c 100644 --- a/src/core/hw/hw.h +++ b/src/core/hw/hw.h @@ -47,4 +47,4 @@ void Init(); /// Shutdown hardware void Shutdown(); -} // namespace +} // namespace HW diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index 763ac1c4d..690079b65 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp @@ -64,4 +64,4 @@ void Shutdown() { LOG_DEBUG(HW_LCD, "shutdown OK"); } -} // namespace +} // namespace LCD diff --git a/src/core/hw/lcd.h b/src/core/hw/lcd.h index 191fd44af..d2db9700f 100644 --- a/src/core/hw/lcd.h +++ b/src/core/hw/lcd.h @@ -83,4 +83,4 @@ void Init(); /// Shutdown hardware void Shutdown(); -} // namespace +} // namespace LCD diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp new file mode 100644 index 000000000..4bee5fb86 --- /dev/null +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -0,0 +1,105 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/common_funcs.h" +#include "common/common_paths.h" +#include "common/file_util.h" +#include "common/logging/log.h" +#include "common/string_util.h" +#include "core/hle/kernel/process.h" +#include "core/hle/kernel/resource_limit.h" +#include "core/loader/deconstructed_rom_directory.h" +#include "core/loader/nso.h" +#include "core/memory.h" + +namespace Loader { + +AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, + std::string filepath) + : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + +FileType AppLoader_DeconstructedRomDirectory::IdentifyType(FileUtil::IOFile& file, + const std::string& filepath) { + bool is_main_found{}; + bool is_rtld_found{}; + bool is_sdk_found{}; + + const auto callback = [&](unsigned* num_entries_out, const std::string& directory, + const std::string& virtual_name) -> bool { + // Skip directories + std::string physical_name = directory + virtual_name; + if (FileUtil::IsDirectory(physical_name)) { + return true; + } + + // Verify filename + if (Common::ToLower(virtual_name) == "main") { + is_main_found = true; + } else if (Common::ToLower(virtual_name) == "rtld") { + is_rtld_found = true; + } else if (Common::ToLower(virtual_name) == "sdk") { + is_sdk_found = true; + } else { + // Contrinue searching + return true; + } + + // Verify file is an NSO + FileUtil::IOFile file(physical_name, "rb"); + if (AppLoader_NSO::IdentifyType(file, physical_name) != FileType::NSO) { + return false; + } + + // We are done if we've found and verified all required NSOs + return !(is_main_found && is_rtld_found && is_sdk_found); + }; + + // Search the directory recursively, looking for the required modules + const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; + FileUtil::ForeachDirectoryEntry(nullptr, directory, callback); + + if (is_main_found && is_rtld_found && is_sdk_found) { + return FileType::DeconstructedRomDirectory; + } + + return FileType::Error; +} + +ResultStatus AppLoader_DeconstructedRomDirectory::Load( + Kernel::SharedPtr<Kernel::Process>& process) { + if (is_loaded) { + return ResultStatus::ErrorAlreadyLoaded; + } + if (!file.IsOpen()) { + return ResultStatus::Error; + } + + process = Kernel::Process::Create("main"); + + // Load NSO modules + VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; + for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", + "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { + const std::string path = + filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP + module; + const VAddr load_addr = next_load_addr; + next_load_addr = AppLoader_NSO::LoadModule(path, load_addr); + if (next_load_addr) { + LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", module, load_addr); + } else { + next_load_addr = load_addr; + } + } + + process->svc_access_mask.set(); + process->address_mappings = default_address_mappings; + process->resource_limit = + Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); + process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); + + is_loaded = true; + return ResultStatus::Success; +} + +} // namespace Loader diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h new file mode 100644 index 000000000..162541d54 --- /dev/null +++ b/src/core/loader/deconstructed_rom_directory.h @@ -0,0 +1,42 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <string> +#include "common/common_types.h" +#include "core/hle/kernel/kernel.h" +#include "core/loader/loader.h" + +namespace Loader { + +/** + * This class loads a "deconstructed ROM directory", which are the typical format we see for Switch + * game dumps. The path should be a "main" NSO, which must be in a directory that contains the other + * standard ExeFS NSOs (e.g. rtld, sdk, etc.). It will automatically find and load these. + * Furthermore, it will look for the first .istorage file (optionally) and use this for the RomFS. + */ +class AppLoader_DeconstructedRomDirectory final : public AppLoader { +public: + AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, std::string filepath); + + /** + * Returns the type of the file + * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. + * @return FileType found, or FileType::Error if this loader doesn't know it + */ + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); + + FileType GetFileType() override { + return IdentifyType(file, filepath); + } + + ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + +private: + std::string filepath; +}; + +} // namespace Loader diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 9ba913dbe..b87320656 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -323,8 +323,9 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { } if (codeset_segment->size != 0) { - LOG_ERROR(Loader, "ELF has more than one segment of the same type. Skipping extra " - "segment (id %i)", + LOG_ERROR(Loader, + "ELF has more than one segment of the same type. Skipping extra " + "segment (id %i)", i); continue; } @@ -364,7 +365,10 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const namespace Loader { -FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) { +AppLoader_ELF::AppLoader_ELF(FileUtil::IOFile&& file, std::string filename) + : AppLoader(std::move(file)), filename(std::move(filename)) {} + +FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file, const std::string&) { static constexpr u16 ELF_MACHINE_ARM{0x28}; u32 magic = 0; diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 113da5917..ee741a789 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -16,18 +16,18 @@ namespace Loader { /// Loads an ELF/AXF file class AppLoader_ELF final : public AppLoader { public: - AppLoader_ELF(FileUtil::IOFile&& file, std::string filename) - : AppLoader(std::move(file)), filename(std::move(filename)) {} + AppLoader_ELF(FileUtil::IOFile&& file, std::string filename); /** * Returns the type of the file * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. * @return FileType found, or FileType::Error if this loader doesn't know it */ - static FileType IdentifyType(FileUtil::IOFile& file); + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); FileType GetFileType() override { - return IdentifyType(file); + return IdentifyType(file, filename); } ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 92defd381..2ec08506d 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -7,12 +7,11 @@ #include "common/logging/log.h" #include "common/string_util.h" #include "core/hle/kernel/process.h" +#include "core/loader/deconstructed_rom_directory.h" #include "core/loader/elf.h" #include "core/loader/nro.h" #include "core/loader/nso.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// - namespace Loader { const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { @@ -21,14 +20,15 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { {0x1F000000, 0x600000, false}, // entire VRAM }; -FileType IdentifyFile(FileUtil::IOFile& file) { +FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath) { FileType type; #define CHECK_TYPE(loader) \ - type = AppLoader_##loader::IdentifyType(file); \ + type = AppLoader_##loader::IdentifyType(file, filepath); \ if (FileType::Error != type) \ return type; + CHECK_TYPE(DeconstructedRomDirectory) CHECK_TYPE(ELF) CHECK_TYPE(NSO) CHECK_TYPE(NRO) @@ -45,13 +45,13 @@ FileType IdentifyFile(const std::string& file_name) { return FileType::Unknown; } - return IdentifyFile(file); + return IdentifyFile(file, file_name); } FileType GuessFromExtension(const std::string& extension_) { std::string extension = Common::ToLower(extension_); - if (extension == ".elf" || extension == ".axf") + if (extension == ".elf") return FileType::ELF; else if (extension == ".nro") return FileType::NRO; @@ -69,6 +69,8 @@ const char* GetFileTypeString(FileType type) { return "NRO"; case FileType::NSO: return "NSO"; + case FileType::DeconstructedRomDirectory: + return "Directory"; case FileType::Error: case FileType::Unknown: break; @@ -102,6 +104,10 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileTyp case FileType::NRO: return std::make_unique<AppLoader_NRO>(std::move(file), filepath); + // NX deconstructed ROM directory. + case FileType::DeconstructedRomDirectory: + return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file), filepath); + default: return nullptr; } @@ -117,7 +123,7 @@ std::unique_ptr<AppLoader> GetLoader(const std::string& filename) { std::string filename_filename, filename_extension; Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); - FileType type = IdentifyFile(file); + FileType type = IdentifyFile(file, filename); FileType filename_type = GuessFromExtension(filename_extension); if (type != filename_type) { diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index dd6bb4e64..dd44ee9a6 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -20,9 +20,6 @@ struct AddressMapping; class Process; } // namespace Kernel -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Loader namespace - namespace Loader { /// File types supported by CTR @@ -32,14 +29,16 @@ enum class FileType { ELF, NSO, NRO, + DeconstructedRomDirectory, }; /** * Identifies the type of a bootable file based on the magic value in its header. * @param file open file + * @param filepath Path of the file that we are opening. * @return FileType of file */ -FileType IdentifyFile(FileUtil::IOFile& file); +FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath); /** * Identifies the type of a bootable file based on the magic value in its header. diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index a5d09512b..6f8a2f21e 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -5,6 +5,7 @@ #include <vector> #include "common/common_funcs.h" +#include "common/file_util.h" #include "common/logging/log.h" #include "common/swap.h" #include "core/hle/kernel/process.h" @@ -45,7 +46,10 @@ struct ModHeader { }; static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); -FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file) { +AppLoader_NRO::AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) + : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + +FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file, const std::string&) { // Read NSO header NroHeader nro_header{}; file.Seek(0, SEEK_SET); @@ -62,20 +66,6 @@ static constexpr u32 PageAlignSize(u32 size) { return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; } -static std::vector<u8> ReadSegment(FileUtil::IOFile& file, const NroSegmentHeader& header) { - std::vector<u8> data; - data.resize(header.size); - - file.Seek(header.offset + sizeof(NroHeader), SEEK_SET); - size_t bytes_read{file.ReadBytes(data.data(), header.size)}; - if (header.size != PageAlignSize(static_cast<u32>(bytes_read))) { - LOG_CRITICAL(Loader, "Failed to read NRO segment bytes", header.size); - return {}; - } - - return data; -} - bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { FileUtil::IOFile file(path, "rb"); if (!file.IsOpen()) { @@ -95,7 +85,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { // Build program image Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", 0); std::vector<u8> program_image; - program_image.resize(PageAlignSize(nro_header.file_size + nro_header.bss_size)); + program_image.resize(PageAlignSize(nro_header.file_size)); file.Seek(0, SEEK_SET); file.ReadBytes(program_image.data(), nro_header.file_size); @@ -107,23 +97,17 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { // Read MOD header ModHeader mod_header{}; - u32 bss_size{Memory::PAGE_SIZE}; // Default .bss to page size if MOD0 section doesn't exist + // Default .bss to NRO header bss size if MOD0 section doesn't exist + u32 bss_size{PageAlignSize(nro_header.bss_size)}; std::memcpy(&mod_header, program_image.data() + nro_header.module_header_offset, sizeof(ModHeader)); const bool has_mod_header{mod_header.magic == Common::MakeMagic('M', 'O', 'D', '0')}; if (has_mod_header) { // Resize program image to include .bss section and page align each section bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset); - codeset->data.size += bss_size; - } - program_image.resize(PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)); - - // Relocate symbols if there was a proper MOD header - This must happen after the image has been - // loaded into memory - if (has_mod_header) { - Relocate(program_image, nro_header.module_header_offset + mod_header.dynamic_offset, - load_base); } + codeset->data.size += bss_size; + program_image.resize(static_cast<u32>(program_image.size()) + bss_size); // Load codeset for current process codeset->name = path; @@ -141,9 +125,11 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { return ResultStatus::Error; } - // Load and relocate "main" and "sdk" NSO - static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; process = Kernel::Process::Create("main"); + + // Load NRO + static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; + if (!LoadNro(filepath, base_addr)) { return ResultStatus::ErrorInvalidFormat; } @@ -154,8 +140,6 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); process->Run(base_addr, 48, Kernel::DEFAULT_STACK_SIZE); - ResolveImports(); - is_loaded = true; return ResultStatus::Success; } diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index e20fa1555..599adb253 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -4,10 +4,8 @@ #pragma once -#include <map> #include <string> #include "common/common_types.h" -#include "common/file_util.h" #include "core/hle/kernel/kernel.h" #include "core/loader/linker.h" #include "core/loader/loader.h" @@ -17,18 +15,18 @@ namespace Loader { /// Loads an NRO file class AppLoader_NRO final : public AppLoader, Linker { public: - AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) - : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath); /** * Returns the type of the file * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. * @return FileType found, or FileType::Error if this loader doesn't know it */ - static FileType IdentifyType(FileUtil::IOFile& file); + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); FileType GetFileType() override { - return IdentifyType(file); + return IdentifyType(file, filepath); } ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index ff96e129b..3ccbbb824 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -4,8 +4,8 @@ #include <vector> #include <lz4.h> - #include "common/common_funcs.h" +#include "common/file_util.h" #include "common/logging/log.h" #include "common/swap.h" #include "core/hle/kernel/process.h" @@ -47,7 +47,10 @@ struct ModHeader { }; static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); -FileType AppLoader_NSO::IdentifyType(FileUtil::IOFile& file) { +AppLoader_NSO::AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath) + : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + +FileType AppLoader_NSO::IdentifyType(FileUtil::IOFile& file, const std::string&) { u32 magic = 0; file.Seek(0, SEEK_SET); if (1 != file.ReadArray<u32>(&magic, 1)) { @@ -88,7 +91,7 @@ static constexpr u32 PageAlignSize(u32 size) { return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; } -VAddr AppLoader_NSO::LoadNso(const std::string& path, VAddr load_base, bool relocate) { +VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) { FileUtil::IOFile file(path, "rb"); if (!file.IsOpen()) { return {}; @@ -135,12 +138,6 @@ VAddr AppLoader_NSO::LoadNso(const std::string& path, VAddr load_base, bool relo const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; program_image.resize(image_size); - // Relocate symbols if there was a proper MOD header - This must happen after the image has been - // loaded into memory - if (has_mod_header && relocate) { - Relocate(program_image, module_offset + mod_header.dynamic_offset, load_base); - } - // Load codeset for current process codeset->name = path; codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); @@ -159,21 +156,9 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { process = Kernel::Process::Create("main"); - // Load NSO modules - VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; - for (const auto& module : - {"rtld", "sdk", "subsdk0", "subsdk1", "subsdk2", "subsdk3", "subsdk4"}) { - const std::string path = filepath.substr(0, filepath.find_last_of("/\\")) + "/" + module; - const VAddr load_addr = next_load_addr; - next_load_addr = LoadNso(path, load_addr); - if (next_load_addr) { - LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", module, load_addr); - } else { - next_load_addr = load_addr; - } - } - // Load "main" module - LoadNso(filepath, next_load_addr); + // Load module + LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR); + LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", filepath.c_str(), Memory::PROCESS_IMAGE_VADDR); process->svc_access_mask.set(); process->address_mappings = default_address_mappings; @@ -181,8 +166,6 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); - ResolveImports(); - is_loaded = true; return ResultStatus::Success; } diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 03424e70d..1ae30a824 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -4,10 +4,8 @@ #pragma once -#include <map> #include <string> #include "common/common_types.h" -#include "common/file_util.h" #include "core/hle/kernel/kernel.h" #include "core/loader/linker.h" #include "core/loader/loader.h" @@ -17,25 +15,25 @@ namespace Loader { /// Loads an NSO file class AppLoader_NSO final : public AppLoader, Linker { public: - AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath) - : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath); /** * Returns the type of the file * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. * @return FileType found, or FileType::Error if this loader doesn't know it */ - static FileType IdentifyType(FileUtil::IOFile& file); + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); FileType GetFileType() override { - return IdentifyType(file); + return IdentifyType(file, filepath); } + static VAddr LoadModule(const std::string& path, VAddr load_base); + ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; private: - VAddr LoadNso(const std::string& path, VAddr load_base, bool relocate = false); - std::string filepath; }; diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 74a598852..a3d2d4951 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -219,6 +219,9 @@ void Write(const VAddr vaddr, const T data) { bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { auto& page_table = process.vm_manager.page_table; + if ((vaddr >> PAGE_BITS) >= PAGE_TABLE_NUM_ENTRIES) + return false; + const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS]; if (page_pointer) return true; diff --git a/src/core/memory_setup.h b/src/core/memory_setup.h index ff4dcc936..6f82a131e 100644 --- a/src/core/memory_setup.h +++ b/src/core/memory_setup.h @@ -29,4 +29,4 @@ void MapMemoryRegion(PageTable& page_table, VAddr base, u64 size, u8* target); void MapIoRegion(PageTable& page_table, VAddr base, u64 size, MMIORegionPointer mmio_handler); void UnmapRegion(PageTable& page_table, VAddr base, u64 size); -} +} // namespace Memory diff --git a/src/core/mmio.h b/src/core/mmio.h index f45126da8..5e3cc01af 100644 --- a/src/core/mmio.h +++ b/src/core/mmio.h @@ -35,4 +35,4 @@ public: }; using MMIORegionPointer = std::shared_ptr<MMIORegion>; -}; +}; // namespace Memory diff --git a/src/core/settings.h b/src/core/settings.h index 56fb189ae..6f8cd0f03 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -100,7 +100,8 @@ enum Values { }; static const std::array<const char*, NumAnalogs> mapping = {{ - "lstick", "rstick", + "lstick", + "rstick", }}; } // namespace NativeAnalog diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index a613889f0..bea05a09b 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -7,13 +7,16 @@ #include "common/assert.h" #include "common/file_util.h" #include "common/scm_rev.h" +#ifdef ARCHITECTURE_x86_64 #include "common/x64/cpu_detect.h" +#endif #include "core/core.h" #include "core/settings.h" #include "core/telemetry_session.h" namespace Core { +#ifdef ARCHITECTURE_x86_64 static const char* CpuVendorToStr(Common::CPUVendor vendor) { switch (vendor) { case Common::CPUVendor::INTEL: @@ -25,6 +28,7 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) { } UNREACHABLE(); } +#endif static u64 GenerateTelemetryId() { u64 telemetry_id{}; @@ -113,7 +117,8 @@ TelemetrySession::TelemetrySession() { AddField(Telemetry::FieldType::App, "BuildDate", Common::g_build_date); AddField(Telemetry::FieldType::App, "BuildName", Common::g_build_name); - // Log user system information +// Log user system information +#ifdef ARCHITECTURE_x86_64 AddField(Telemetry::FieldType::UserSystem, "CPU_Model", Common::GetCPUCaps().cpu_string); AddField(Telemetry::FieldType::UserSystem, "CPU_BrandString", Common::GetCPUCaps().brand_string); @@ -135,6 +140,9 @@ TelemetrySession::TelemetrySession() { Common::GetCPUCaps().sse4_1); AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE42", Common::GetCPUCaps().sse4_2); +#else + AddField(Telemetry::FieldType::UserSystem, "CPU_Model", "Other"); +#endif #ifdef __APPLE__ AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Apple"); #elif defined(_WIN32) diff --git a/src/core/tracer/citrace.h b/src/core/tracer/citrace.h index 215f86359..21fdc127a 100644 --- a/src/core/tracer/citrace.h +++ b/src/core/tracer/citrace.h @@ -97,4 +97,4 @@ struct CTStreamElement { }; #pragma pack() -} +} // namespace CiTrace diff --git a/src/core/tracer/recorder.cpp b/src/core/tracer/recorder.cpp index 55b3b5efc..f3b0d6a8f 100644 --- a/src/core/tracer/recorder.cpp +++ b/src/core/tracer/recorder.cpp @@ -205,4 +205,4 @@ template void Recorder::RegisterWritten(u32, u8); template void Recorder::RegisterWritten(u32, u16); template void Recorder::RegisterWritten(u32, u32); template void Recorder::RegisterWritten(u32, u64); -} +} // namespace CiTrace diff --git a/src/core/tracer/recorder.h b/src/core/tracer/recorder.h index 39e6ec4fd..629c2f6d2 100644 --- a/src/core/tracer/recorder.h +++ b/src/core/tracer/recorder.h @@ -63,9 +63,9 @@ private: CTStreamElement data; /** - * Extra data to store along "core" data. - * This is e.g. used for data used in MemoryUpdates. - */ + * Extra data to store along "core" data. + * This is e.g. used for data used in MemoryUpdates. + */ std::vector<u8> extra_data; /// Optional CRC hash (e.g. for hashing memory regions) @@ -84,4 +84,4 @@ private: std::unordered_map<boost::crc_32_type::value_type /*hash*/, u32 /*file_offset*/> memory_regions; }; -} // namespace +} // namespace CiTrace diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 92792a702..1c7db28c0 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -1,25 +1,18 @@ -set(SRCS - analog_from_button.cpp - keyboard.cpp - main.cpp - motion_emu.cpp - ) +add_library(input_common STATIC + analog_from_button.cpp + analog_from_button.h + keyboard.cpp + keyboard.h + main.cpp + main.h + motion_emu.cpp + motion_emu.h -set(HEADERS - analog_from_button.h - keyboard.h - main.h - motion_emu.h - ) + $<$<BOOL:${SDL2_FOUND}>:sdl/sdl.cpp sdl/sdl.h> +) -if(SDL2_FOUND) - set(SRCS ${SRCS} sdl/sdl.cpp) - set(HEADERS ${HEADERS} sdl/sdl.h) -endif() - -create_directory_groups(${SRCS} ${HEADERS}) +create_target_directory_groups(input_common) -add_library(input_common STATIC ${SRCS} ${HEADERS}) target_link_libraries(input_common PUBLIC core PRIVATE common) if(SDL2_FOUND) diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 95d40f09f..b12623d55 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -52,7 +52,8 @@ MotionEmu* GetMotionEmu() { std::string GenerateKeyboardParam(int key_code) { Common::ParamPackage param{ - {"engine", "keyboard"}, {"code", std::to_string(key_code)}, + {"engine", "keyboard"}, + {"code", std::to_string(key_code)}, }; return param.Serialize(); } diff --git a/src/input_common/sdl/sdl.cpp b/src/input_common/sdl/sdl.cpp index 88b557c5d..3b87d6b65 100644 --- a/src/input_common/sdl/sdl.cpp +++ b/src/input_common/sdl/sdl.cpp @@ -425,7 +425,7 @@ std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> GetPollers( pollers.push_back(std::make_unique<SDLButtonPoller>()); break; } - return std::move(pollers); + return pollers; } } // namespace Polling } // namespace SDL diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 1b8fb2a9f..12f1b93e0 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,20 +1,16 @@ -set(SRCS - common/param_package.cpp - core/arm/arm_test_common.cpp - core/core_timing.cpp - core/file_sys/path_parser.cpp - core/memory/memory.cpp - glad.cpp - tests.cpp - ) +add_executable(tests + common/param_package.cpp + core/arm/arm_test_common.cpp + core/arm/arm_test_common.h + core/core_timing.cpp + core/file_sys/path_parser.cpp + core/memory/memory.cpp + glad.cpp + tests.cpp +) -set(HEADERS - core/arm/arm_test_common.h - ) +create_target_directory_groups(tests) -create_directory_groups(${SRCS} ${HEADERS}) - -add_executable(tests ${SRCS} ${HEADERS}) target_link_libraries(tests PRIVATE common core) target_link_libraries(tests PRIVATE glad) # To support linker work-around target_link_libraries(tests PRIVATE ${PLATFORM_LIBRARIES} catch-single-include Threads::Threads) diff --git a/src/tests/common/param_package.cpp b/src/tests/common/param_package.cpp index efec2cc86..19d372236 100644 --- a/src/tests/common/param_package.cpp +++ b/src/tests/common/param_package.cpp @@ -10,7 +10,9 @@ namespace Common { TEST_CASE("ParamPackage", "[common]") { ParamPackage original{ - {"abc", "xyz"}, {"def", "42"}, {"jkl", "$$:1:$2$,3"}, + {"abc", "xyz"}, + {"def", "42"}, + {"jkl", "$$:1:$2$,3"}, }; original.Set("ghi", 3.14f); ParamPackage copy(original.Serialize()); diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 3fd177c46..69f2b4afd 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -1,23 +1,19 @@ -set(SRCS - renderer_base.cpp - renderer_opengl/gl_shader_util.cpp - renderer_opengl/gl_state.cpp - renderer_opengl/renderer_opengl.cpp - video_core.cpp - ) +add_library(video_core STATIC + renderer_base.cpp + renderer_base.h + renderer_opengl/gl_resource_manager.h + renderer_opengl/gl_shader_util.cpp + renderer_opengl/gl_shader_util.h + renderer_opengl/gl_state.cpp + renderer_opengl/gl_state.h + renderer_opengl/renderer_opengl.cpp + renderer_opengl/renderer_opengl.h + utils.h + video_core.cpp + video_core.h +) -set(HEADERS - renderer_base.h - renderer_opengl/gl_resource_manager.h - renderer_opengl/gl_shader_util.h - renderer_opengl/gl_state.h - renderer_opengl/renderer_opengl.h - utils.h - video_core.h - ) +create_target_directory_groups(video_core) -create_directory_groups(${SRCS} ${HEADERS}) - -add_library(video_core STATIC ${SRCS} ${HEADERS}) target_link_libraries(video_core PUBLIC common core) target_link_libraries(video_core PRIVATE glad) diff --git a/src/video_core/renderer_opengl/gl_shader_util.h b/src/video_core/renderer_opengl/gl_shader_util.h index c66e8acd3..a4bcffdfa 100644 --- a/src/video_core/renderer_opengl/gl_shader_util.h +++ b/src/video_core/renderer_opengl/gl_shader_util.h @@ -16,4 +16,4 @@ namespace GLShader { */ GLuint LoadProgram(const char* vertex_shader, const char* fragment_shader); -} // namespace +} // namespace GLShader diff --git a/src/video_core/utils.h b/src/video_core/utils.h index d8567f314..d94a10417 100644 --- a/src/video_core/utils.h +++ b/src/video_core/utils.h @@ -49,4 +49,4 @@ static inline u32 GetMortonOffset(u32 x, u32 y, u32 bytes_per_pixel) { return (i + offset) * bytes_per_pixel; } -} // namespace +} // namespace VideoCore diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 106d62562..864691baa 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -39,4 +39,4 @@ void Shutdown() { LOG_DEBUG(Render, "shutdown OK"); } -} // namespace +} // namespace VideoCore diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h index 0b8785898..1fd90b9d0 100644 --- a/src/video_core/video_core.h +++ b/src/video_core/video_core.h @@ -31,4 +31,4 @@ bool Init(EmuWindow* emu_window); /// Shutdown the video core void Shutdown(); -} // namespace +} // namespace VideoCore diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index c52d5627a..0c4056c49 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -3,83 +3,84 @@ set(CMAKE_AUTORCC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules) -set(SRCS - about_dialog.cpp - configuration/config.cpp - configuration/configure_debug.cpp - configuration/configure_dialog.cpp - configuration/configure_general.cpp - configuration/configure_graphics.cpp - configuration/configure_input.cpp - configuration/configure_system.cpp - debugger/profiler.cpp - debugger/registers.cpp - debugger/wait_tree.cpp - util/spinbox.cpp - util/util.cpp - bootmanager.cpp - game_list.cpp - hotkeys.cpp - main.cpp - ui_settings.cpp - yuzu.rc - Info.plist - ) - -set(HEADERS - about_dialog.h - configuration/config.h - configuration/configure_debug.h - configuration/configure_dialog.h - configuration/configure_general.h - configuration/configure_graphics.h - configuration/configure_input.h - configuration/configure_system.h - debugger/profiler.h - debugger/registers.h - debugger/wait_tree.h - util/spinbox.h - util/util.h - bootmanager.h - game_list.h - game_list_p.h - hotkeys.h - main.h - ui_settings.h - ) +add_executable(yuzu + Info.plist + about_dialog.cpp + about_dialog.h + bootmanager.cpp + bootmanager.h + configuration/config.cpp + configuration/config.h + configuration/configure_debug.cpp + configuration/configure_debug.h + configuration/configure_dialog.cpp + configuration/configure_dialog.h + configuration/configure_general.cpp + configuration/configure_general.h + configuration/configure_graphics.cpp + configuration/configure_graphics.h + configuration/configure_input.cpp + configuration/configure_input.h + configuration/configure_system.cpp + configuration/configure_system.h + debugger/profiler.cpp + debugger/profiler.h + debugger/registers.cpp + debugger/registers.h + debugger/wait_tree.cpp + debugger/wait_tree.h + game_list.cpp + game_list.h + game_list_p.h + hotkeys.cpp + hotkeys.h + main.cpp + main.h + ui_settings.cpp + ui_settings.h + util/spinbox.cpp + util/spinbox.h + util/util.cpp + util/util.h + yuzu.rc +) set(UIS - aboutdialog.ui - configuration/configure.ui - configuration/configure_debug.ui - configuration/configure_general.ui - configuration/configure_graphics.ui - configuration/configure_input.ui - configuration/configure_system.ui - debugger/registers.ui - hotkeys.ui - main.ui - ) + aboutdialog.ui + configuration/configure.ui + configuration/configure_debug.ui + configuration/configure_general.ui + configuration/configure_graphics.ui + configuration/configure_input.ui + configuration/configure_system.ui + debugger/registers.ui + hotkeys.ui + main.ui +) file(GLOB_RECURSE ICONS ${CMAKE_SOURCE_DIR}/dist/icons/*) file(GLOB_RECURSE THEMES ${CMAKE_SOURCE_DIR}/dist/qt_themes/*) -create_directory_groups(${SRCS} ${HEADERS} ${UIS}) +qt5_wrap_ui(UI_HDRS ${UIS}) -if (Qt5_FOUND) - qt5_wrap_ui(UI_HDRS ${UIS}) -else() - qt4_wrap_ui(UI_HDRS ${UIS}) -endif() +target_sources(yuzu + PRIVATE + ${ICONS} + ${THEMES} + ${UI_HDRS} + ${UIS} +) if (APPLE) set(MACOSX_ICON "../../dist/yuzu.icns") set_source_files_properties(${MACOSX_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - add_executable(yuzu MACOSX_BUNDLE ${SRCS} ${HEADERS} ${UI_HDRS} ${MACOSX_ICON} ${ICONS}) + target_sources(yuzu PRIVATE ${MACOSX_ICON}) + set_target_properties(yuzu PROPERTIES MACOSX_BUNDLE TRUE) set_target_properties(yuzu PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) -else() - add_executable(yuzu ${SRCS} ${HEADERS} ${UI_HDRS} ${ICONS}) endif() + +create_target_directory_groups(yuzu) + target_link_libraries(yuzu PRIVATE common core input_common video_core) target_link_libraries(yuzu PRIVATE Boost::boost glad Qt5::OpenGL Qt5::Widgets) target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 843ac6ad7..469988d63 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -1,12 +1,8 @@ #include <QApplication> #include <QHBoxLayout> #include <QKeyEvent> - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -// Required for screen DPI information #include <QScreen> #include <QWindow> -#endif #include "common/microprofile.h" #include "common/scm_rev.h" @@ -19,8 +15,7 @@ #include "input_common/motion_emu.h" #include "yuzu/bootmanager.h" -EmuThread::EmuThread(GRenderWindow* render_window) - : exec_step(false), running(false), stop_run(false), render_window(render_window) {} +EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {} void EmuThread::run() { render_window->MakeCurrent(); @@ -120,15 +115,13 @@ GRenderWindow::~GRenderWindow() { void GRenderWindow::moveContext() { DoneCurrent(); -// We need to move GL context to the swapping thread in Qt5 -#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) + // If the thread started running, move the GL Context to the new thread. Otherwise, move it // back. auto thread = (QThread::currentThread() == qApp->thread() && emu_thread != nullptr) ? emu_thread : qApp->thread(); child->context()->moveToThread(thread); -#endif } void GRenderWindow::SwapBuffers() { @@ -191,12 +184,8 @@ QByteArray GRenderWindow::saveGeometry() { } qreal GRenderWindow::windowPixelRatio() { -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) // windowHandle() might not be accessible until the window is displayed to screen. return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f; -#else - return 1.0f; -#endif } void GRenderWindow::closeEvent(QCloseEvent* event) { @@ -299,9 +288,7 @@ void GRenderWindow::OnEmulationStopping() { void GRenderWindow::showEvent(QShowEvent* event) { QWidget::showEvent(event); -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) // windowHandle() is not initialized until the Window is shown, so we connect it here. - connect(this->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, - SLOT(OnFramebufferSizeChanged()), Qt::UniqueConnection); -#endif + connect(windowHandle(), &QWindow::screenChanged, this, &GRenderWindow::OnFramebufferSizeChanged, + Qt::UniqueConnection); } diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 6974edcbb..130bc613b 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -58,7 +58,7 @@ public: * @return True if the emulation thread is running, otherwise false * @note This function is thread-safe */ - bool IsRunning() { + bool IsRunning() const { return running; } @@ -68,12 +68,12 @@ public: void RequestStop() { stop_run = true; SetRunning(false); - }; + } private: - bool exec_step; - bool running; - std::atomic<bool> stop_run; + bool exec_step = false; + bool running = false; + std::atomic<bool> stop_run{false}; std::mutex running_mutex; std::condition_variable running_cv; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 6a40f035c..f9ddb9edc 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -26,10 +26,18 @@ const std::array<int, Settings::NativeButton::NumButtons> Config::default_button const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{ { - Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_E, + Qt::Key_Up, + Qt::Key_Down, + Qt::Key_Left, + Qt::Key_Right, + Qt::Key_E, }, { - Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, Qt::Key_R, + Qt::Key_I, + Qt::Key_K, + Qt::Key_J, + Qt::Key_L, + Qt::Key_R, }, }}; diff --git a/src/yuzu/configuration/configure.ui b/src/yuzu/configuration/configure.ui index babd583a2..c5303851c 100644 --- a/src/yuzu/configuration/configure.ui +++ b/src/yuzu/configuration/configure.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>740</width> + <width>461</width> <height>500</height> </rect> </property> diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index 10043e6e8..78559e2bb 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp @@ -14,7 +14,11 @@ const std::array<std::string, ConfigureInput::ANALOG_SUB_BUTTONS_NUM> ConfigureInput::analog_sub_buttons{{ - "up", "down", "left", "right", "modifier", + "up", + "down", + "left", + "right", + "modifier", }}; static QString getKeyName(int key_code) { @@ -36,7 +40,8 @@ static void SetAnalogButton(const Common::ParamPackage& input_param, Common::ParamPackage& analog_param, const std::string& button_name) { if (analog_param.Get("engine", "") != "analog_from_button") { analog_param = { - {"engine", "analog_from_button"}, {"modifier_scale", "0.5"}, + {"engine", "analog_from_button"}, + {"modifier_scale", "0.5"}, }; } analog_param.Set(button_name, input_param.Serialize()); @@ -107,11 +112,17 @@ ConfigureInput::ConfigureInput(QWidget* parent) analog_map_buttons = {{ { - ui->buttonLStickUp, ui->buttonLStickDown, ui->buttonLStickLeft, ui->buttonLStickRight, + ui->buttonLStickUp, + ui->buttonLStickDown, + ui->buttonLStickLeft, + ui->buttonLStickRight, ui->buttonLStickMod, }, { - ui->buttonRStickUp, ui->buttonRStickDown, ui->buttonRStickLeft, ui->buttonRStickRight, + ui->buttonRStickUp, + ui->buttonRStickDown, + ui->buttonRStickLeft, + ui->buttonRStickRight, ui->buttonRStickMod, }, }}; diff --git a/src/yuzu/configuration/configure_input.ui b/src/yuzu/configuration/configure_input.ui index c162ca02c..377b79c77 100644 --- a/src/yuzu/configuration/configure_input.ui +++ b/src/yuzu/configuration/configure_input.ui @@ -15,9 +15,9 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_5"> <item> - <layout class="QGridLayout" name="gridLayout_7"> + <layout class="QGridLayout" name="buttons"> <item row="3" column="1"> - <widget class="QGroupBox" name="faceButtons_6"> + <widget class="QGroupBox" name="misc"> <property name="title"> <string>Misc.</string> </property> @@ -29,9 +29,9 @@ </property> <layout class="QGridLayout" name="gridLayout_6"> <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_25"> + <layout class="QVBoxLayout" name="buttonMiscPlusVerticalLayout"> <item> - <widget class="QLabel" name="label_29"> + <widget class="QLabel" name="labelPlus"> <property name="text"> <string>Plus:</string> </property> @@ -47,9 +47,9 @@ </layout> </item> <item row="0" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_26"> + <layout class="QVBoxLayout" name="buttonMiscMinusVerticalLayout"> <item> - <widget class="QLabel" name="label_30"> + <widget class="QLabel" name="labelMinus"> <property name="text"> <string>Minus:</string> </property> @@ -65,9 +65,9 @@ </layout> </item> <item row="1" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_27"> + <layout class="QVBoxLayout" name="buttonMiscHomeVerticalLayout"> <item> - <widget class="QLabel" name="label_31"> + <widget class="QLabel" name="labelHome"> <property name="text"> <string>Home:</string> </property> @@ -83,9 +83,9 @@ </layout> </item> <item row="1" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_28"> + <layout class="QVBoxLayout" name="buttonMiscScrCapVerticalLayout"> <item> - <widget class="QLabel" name="label_11"> + <widget class="QLabel" name="labelScrCap"> <property name="text"> <string>Screen Capture:</string> @@ -130,9 +130,9 @@ Capture:</string> </property> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout"> + <layout class="QVBoxLayout" name="buttonFaceButtonsAVerticalLayout"> <item> - <widget class="QLabel" name="label"> + <widget class="QLabel" name="labelA"> <property name="text"> <string>A:</string> </property> @@ -148,9 +148,9 @@ Capture:</string> </layout> </item> <item row="0" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_2"> + <layout class="QVBoxLayout" name="buttonFaceButtonsBVerticalLayout"> <item> - <widget class="QLabel" name="label_2"> + <widget class="QLabel" name="labelB"> <property name="text"> <string>B:</string> </property> @@ -166,9 +166,9 @@ Capture:</string> </layout> </item> <item row="1" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_3"> + <layout class="QVBoxLayout" name="buttonFaceButtonsXVerticalLayout"> <item> - <widget class="QLabel" name="label_3"> + <widget class="QLabel" name="labelX"> <property name="text"> <string>X:</string> </property> @@ -184,9 +184,9 @@ Capture:</string> </layout> </item> <item row="1" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_4"> + <layout class="QVBoxLayout" name="buttonFaceButtonsYVerticalLayout"> <item> - <widget class="QLabel" name="label_4"> + <widget class="QLabel" name="labelY"> <property name="text"> <string>Y:</string> </property> @@ -205,7 +205,7 @@ Capture:</string> </widget> </item> <item row="0" column="1"> - <widget class="QGroupBox" name="faceButtons_2"> + <widget class="QGroupBox" name="Dpad"> <property name="title"> <string>Directional Pad</string> </property> @@ -217,9 +217,9 @@ Capture:</string> </property> <layout class="QGridLayout" name="gridLayout_2"> <item row="1" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_12"> + <layout class="QVBoxLayout" name="buttonDpadUpVerticalLayout"> <item> - <widget class="QLabel" name="label_34"> + <widget class="QLabel" name="labelDpadUp"> <property name="text"> <string>Up:</string> </property> @@ -235,9 +235,9 @@ Capture:</string> </layout> </item> <item row="1" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_9"> + <layout class="QVBoxLayout" name="buttonDpadDownVerticalLayout"> <item> - <widget class="QLabel" name="label_35"> + <widget class="QLabel" name="labelDpadDown"> <property name="text"> <string>Down:</string> </property> @@ -253,9 +253,9 @@ Capture:</string> </layout> </item> <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_10"> + <layout class="QVBoxLayout" name="buttonDpadLeftVerticalLayout"> <item> - <widget class="QLabel" name="label_32"> + <widget class="QLabel" name="labelDpadLeft"> <property name="text"> <string>Left:</string> </property> @@ -271,9 +271,9 @@ Capture:</string> </layout> </item> <item row="0" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_11"> + <layout class="QVBoxLayout" name="buttonDpadRightVerticalLayout"> <item> - <widget class="QLabel" name="label_33"> + <widget class="QLabel" name="labelDpadRight"> <property name="text"> <string>Right:</string> </property> @@ -292,7 +292,7 @@ Capture:</string> </widget> </item> <item row="3" column="0"> - <widget class="QGroupBox" name="faceButtons_3"> + <widget class="QGroupBox" name="shoulderButtons"> <property name="title"> <string>Shoulder Buttons</string> </property> @@ -304,9 +304,9 @@ Capture:</string> </property> <layout class="QGridLayout" name="gridLayout_3"> <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_13"> + <layout class="QVBoxLayout" name="buttonShoulderButtonsLVerticalLayout"> <item> - <widget class="QLabel" name="label_17"> + <widget class="QLabel" name="labelL"> <property name="text"> <string>L:</string> </property> @@ -322,9 +322,9 @@ Capture:</string> </layout> </item> <item row="0" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_14"> + <layout class="QVBoxLayout" name="buttonShoulderButtonsRVerticalLayout"> <item> - <widget class="QLabel" name="label_19"> + <widget class="QLabel" name="labelR"> <property name="text"> <string>R:</string> </property> @@ -340,9 +340,9 @@ Capture:</string> </layout> </item> <item row="1" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_15"> + <layout class="QVBoxLayout" name="buttonShoulderButtonsZLVerticalLayout"> <item> - <widget class="QLabel" name="label_20"> + <widget class="QLabel" name="labelZL"> <property name="text"> <string>ZL:</string> </property> @@ -358,9 +358,9 @@ Capture:</string> </layout> </item> <item row="1" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_16"> + <layout class="QVBoxLayout" name="buttonShoulderButtonsZRVerticalLayout"> <item> - <widget class="QLabel" name="label_18"> + <widget class="QLabel" name="labelZR"> <property name="text"> <string>ZR:</string> </property> @@ -376,9 +376,9 @@ Capture:</string> </layout> </item> <item row="2" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_8"> + <layout class="QVBoxLayout" name="buttonShoulderButtonsSLVerticalLayout"> <item> - <widget class="QLabel" name="label_7"> + <widget class="QLabel" name="labelSL"> <property name="text"> <string>SL:</string> </property> @@ -394,9 +394,9 @@ Capture:</string> </layout> </item> <item row="2" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_29"> + <layout class="QVBoxLayout" name="buttonShoulderButtonsSRVerticalLayout"> <item> - <widget class="QLabel" name="label_8"> + <widget class="QLabel" name="labelSR"> <property name="text"> <string>SR:</string> </property> @@ -415,7 +415,7 @@ Capture:</string> </widget> </item> <item row="1" column="1"> - <widget class="QGroupBox" name="faceButtons_5"> + <widget class="QGroupBox" name="RStick"> <property name="title"> <string>Right Stick</string> </property> @@ -430,9 +430,9 @@ Capture:</string> </property> <layout class="QGridLayout" name="gridLayout_5"> <item row="1" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_24"> + <layout class="QVBoxLayout" name="buttonRStickDownVerticalLayout"> <item> - <widget class="QLabel" name="label_26"> + <widget class="QLabel" name="labelRStickDown"> <property name="text"> <string>Down:</string> </property> @@ -448,9 +448,9 @@ Capture:</string> </layout> </item> <item row="0" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_22"> + <layout class="QVBoxLayout" name="buttonRStickRightVerticalLayout"> <item> - <widget class="QLabel" name="label_27"> + <widget class="QLabel" name="labelRStickRight"> <property name="text"> <string>Right:</string> </property> @@ -473,9 +473,9 @@ Capture:</string> </widget> </item> <item row="1" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_21"> + <layout class="QVBoxLayout" name="buttonRStickLeftVerticalLayout"> <item> - <widget class="QLabel" name="label_25"> + <widget class="QLabel" name="labelRStickLeft"> <property name="text"> <string>Left:</string> </property> @@ -491,9 +491,9 @@ Capture:</string> </layout> </item> <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_25"> + <layout class="QVBoxLayout" name="buttonRStickUpVerticalLayout"> <item> - <widget class="QLabel" name="label_28"> + <widget class="QLabel" name="labelRStickUp"> <property name="text"> <string>Up:</string> </property> @@ -509,9 +509,9 @@ Capture:</string> </layout> </item> <item row="2" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_6"> + <layout class="QVBoxLayout" name="buttonRStickPressedVerticalLayout"> <item> - <widget class="QLabel" name="label_5"> + <widget class="QLabel" name="labelRStickPressed"> <property name="text"> <string>Pressed:</string> </property> @@ -527,9 +527,9 @@ Capture:</string> </layout> </item> <item row="2" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_32"> + <layout class="QVBoxLayout" name="buttonRStickModVerticalLayout"> <item> - <widget class="QLabel" name="label_10"> + <widget class="QLabel" name="labelRStickMod"> <property name="text"> <string>Modifier:</string> </property> @@ -548,7 +548,7 @@ Capture:</string> </widget> </item> <item row="1" column="0"> - <widget class="QGroupBox" name="faceButtons_4"> + <widget class="QGroupBox" name="LStick"> <property name="title"> <string>Left Stick</string> </property> @@ -560,9 +560,9 @@ Capture:</string> </property> <layout class="QGridLayout" name="gridLayout_4"> <item row="1" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_20"> + <layout class="QVBoxLayout" name="buttonLStickDownVerticalLayout"> <item> - <widget class="QLabel" name="label_22"> + <widget class="QLabel" name="labelLStickDown"> <property name="text"> <string>Down:</string> </property> @@ -585,9 +585,9 @@ Capture:</string> </widget> </item> <item row="0" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_18"> + <layout class="QVBoxLayout" name="buttonLStickRightVerticalLayout"> <item> - <widget class="QLabel" name="label_23"> + <widget class="QLabel" name="labelLStickRight"> <property name="text"> <string>Right:</string> </property> @@ -603,9 +603,9 @@ Capture:</string> </layout> </item> <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_17"> + <layout class="QVBoxLayout" name="buttonLStickLeftVerticalLayout"> <item> - <widget class="QLabel" name="label_21"> + <widget class="QLabel" name="labelLStickLeft"> <property name="text"> <string>Left:</string> </property> @@ -621,9 +621,9 @@ Capture:</string> </layout> </item> <item row="1" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_19"> + <layout class="QVBoxLayout" name="buttonLStickUpVerticalLayout"> <item> - <widget class="QLabel" name="label_24"> + <widget class="QLabel" name="labelLStickUp"> <property name="text"> <string>Up:</string> </property> @@ -639,9 +639,9 @@ Capture:</string> </layout> </item> <item row="3" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_31"> + <layout class="QVBoxLayout" name="buttonLStickModVerticalLayout"> <item> - <widget class="QLabel" name="label_9"> + <widget class="QLabel" name="labelLStickMod"> <property name="text"> <string>Modifier:</string> </property> @@ -657,9 +657,9 @@ Capture:</string> </layout> </item> <item row="3" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_7" stretch="0,0"> + <layout class="QVBoxLayout" name="buttonLStickPressedVerticalLayout" stretch="0,0"> <item> - <widget class="QLabel" name="label_6"> + <widget class="QLabel" name="labelLStickPressed"> <property name="text"> <string>Pressed:</string> </property> diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index d198e38ae..d09505a0f 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -9,7 +9,18 @@ #include "yuzu/ui_settings.h" static const std::array<int, 12> days_in_month = {{ - 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, + 31, + 29, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31, }}; ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { @@ -72,5 +83,6 @@ void ConfigureSystem::refreshConsoleID() { if (reply == QMessageBox::No) return; u64 console_id{}; - ui->label_console_id->setText("Console ID: 0x" + QString::number(console_id, 16).toUpper()); + ui->label_console_id->setText( + tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper())); } diff --git a/src/yuzu/debugger/profiler.cpp b/src/yuzu/debugger/profiler.cpp index cc9babe84..8b30e0a85 100644 --- a/src/yuzu/debugger/profiler.cpp +++ b/src/yuzu/debugger/profiler.cpp @@ -74,7 +74,7 @@ QAction* MicroProfileDialog::toggleViewAction() { toggle_view_action = new QAction(windowTitle(), this); toggle_view_action->setCheckable(true); toggle_view_action->setChecked(isVisible()); - connect(toggle_view_action, SIGNAL(toggled(bool)), SLOT(setVisible(bool))); + connect(toggle_view_action, &QAction::toggled, this, &MicroProfileDialog::setVisible); } return toggle_view_action; @@ -107,7 +107,8 @@ MicroProfileWidget::MicroProfileWidget(QWidget* parent) : QWidget(parent) { MicroProfileSetDisplayMode(1); // Timers screen MicroProfileInitUI(); - connect(&update_timer, SIGNAL(timeout()), SLOT(update())); + connect(&update_timer, &QTimer::timeout, this, + static_cast<void (MicroProfileWidget::*)()>(&MicroProfileWidget::update)); } void MicroProfileWidget::paintEvent(QPaintEvent* ev) { diff --git a/src/yuzu/debugger/wait_tree.h b/src/yuzu/debugger/wait_tree.h index 4034e909b..e538174eb 100644 --- a/src/yuzu/debugger/wait_tree.h +++ b/src/yuzu/debugger/wait_tree.h @@ -20,7 +20,7 @@ class Mutex; class ConditionVariable; class Thread; class Timer; -} +} // namespace Kernel class WaitTreeThread; diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 679c89828..76ced4de4 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -114,8 +114,7 @@ GameList::SearchField::SearchField(GameList* parent) : QWidget{parent} { edit_filter->setPlaceholderText(tr("Enter pattern to filter")); edit_filter->installEventFilter(keyReleaseEater); edit_filter->setClearButtonEnabled(true); - connect(edit_filter, SIGNAL(textChanged(const QString&)), parent, - SLOT(onTextChanged(const QString&))); + connect(edit_filter, &QLineEdit::textChanged, parent, &GameList::onTextChanged); label_filter_result = new QLabel; button_filter_close = new QToolButton(this); button_filter_close->setText("X"); @@ -124,7 +123,7 @@ GameList::SearchField::SearchField(GameList* parent) : QWidget{parent} { "#000000; font-weight: bold; background: #F0F0F0; }" "QToolButton:hover{ border: none; padding: 0px; color: " "#EEEEEE; font-weight: bold; background: #E81123}"); - connect(button_filter_close, SIGNAL(clicked()), parent, SLOT(onFilterCloseClicked())); + connect(button_filter_close, &QToolButton::clicked, parent, &GameList::onFilterCloseClicked); layout_filter->setSpacing(10); layout_filter->addWidget(label_filter); layout_filter->addWidget(edit_filter); @@ -137,8 +136,8 @@ GameList::SearchField::SearchField(GameList* parent) : QWidget{parent} { * Checks if all words separated by spaces are contained in another string * This offers a word order insensitive search function * - * @param String that gets checked if it contains all words of the userinput string - * @param String containing all words getting checked + * @param haystack String that gets checked if it contains all words of the userinput string + * @param userinput String containing all words getting checked * @return true if the haystack contains all words of userinput */ bool GameList::containsAllWords(QString haystack, QString userinput) { diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index 4823a1296..7aff597b7 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h @@ -49,7 +49,7 @@ public: QString edit_filter_text_old; protected: - bool eventFilter(QObject* obj, QEvent* event); + bool eventFilter(QObject* obj, QEvent* event) override; }; QHBoxLayout* layout_filter = nullptr; QTreeView* tree_view = nullptr; diff --git a/src/yuzu/hotkeys.cpp b/src/yuzu/hotkeys.cpp index 42f026464..61acb38ee 100644 --- a/src/yuzu/hotkeys.cpp +++ b/src/yuzu/hotkeys.cpp @@ -5,6 +5,7 @@ #include <map> #include <QKeySequence> #include <QShortcut> +#include <QTreeWidgetItem> #include <QtGlobal> #include "yuzu/hotkeys.h" #include "yuzu/ui_settings.h" diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 31f2825ee..e5252abdc 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -175,7 +175,7 @@ void GMainWindow::InitializeRecentFileMenuActions() { for (int i = 0; i < max_recent_files_item; ++i) { actions_recent_files[i] = new QAction(this); actions_recent_files[i]->setVisible(false); - connect(actions_recent_files[i], SIGNAL(triggered()), this, SLOT(OnMenuRecentFile())); + connect(actions_recent_files[i], &QAction::triggered, this, &GMainWindow::OnMenuRecentFile); ui.menu_recent_files->addAction(actions_recent_files[i]); } @@ -190,10 +190,10 @@ void GMainWindow::InitializeHotkeys() { RegisterHotkey("Main Window", "Exit Fullscreen", QKeySequence::Cancel, Qt::ApplicationShortcut); LoadHotkeys(); - connect(GetHotkey("Main Window", "Load File", this), SIGNAL(activated()), this, - SLOT(OnMenuLoadFile())); - connect(GetHotkey("Main Window", "Start Emulation", this), SIGNAL(activated()), this, - SLOT(OnStartGame())); + connect(GetHotkey("Main Window", "Load File", this), &QShortcut::activated, this, + &GMainWindow::OnMenuLoadFile); + connect(GetHotkey("Main Window", "Start Emulation", this), &QShortcut::activated, this, + &GMainWindow::OnStartGame); connect(GetHotkey("Main Window", "Fullscreen", render_window), &QShortcut::activated, ui.action_Fullscreen, &QAction::trigger); connect(GetHotkey("Main Window", "Fullscreen", render_window), &QShortcut::activatedAmbiguously, @@ -245,13 +245,14 @@ void GMainWindow::RestoreUIState() { } void GMainWindow::ConnectWidgetEvents() { - connect(game_list, SIGNAL(GameChosen(QString)), this, SLOT(OnGameListLoadFile(QString))); - connect(game_list, SIGNAL(OpenSaveFolderRequested(u64)), this, - SLOT(OnGameListOpenSaveFolder(u64))); + connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile); + connect(game_list, &GameList::OpenSaveFolderRequested, this, + &GMainWindow::OnGameListOpenSaveFolder); - connect(this, SIGNAL(EmulationStarting(EmuThread*)), render_window, - SLOT(OnEmulationStarting(EmuThread*))); - connect(this, SIGNAL(EmulationStopping()), render_window, SLOT(OnEmulationStopping())); + connect(this, &GMainWindow::EmulationStarting, render_window, + &GRenderWindow::OnEmulationStarting); + connect(this, &GMainWindow::EmulationStopping, render_window, + &GRenderWindow::OnEmulationStopping); connect(&status_bar_update_timer, &QTimer::timeout, this, &GMainWindow::UpdateStatusBar); } @@ -398,17 +399,17 @@ void GMainWindow::BootGame(const QString& filename) { render_window->moveContext(); emu_thread->start(); - connect(render_window, SIGNAL(Closed()), this, SLOT(OnStopGame())); + connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views // before the CPU continues - connect(emu_thread.get(), SIGNAL(DebugModeEntered()), registersWidget, - SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection); - connect(emu_thread.get(), SIGNAL(DebugModeEntered()), waitTreeWidget, - SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection); - connect(emu_thread.get(), SIGNAL(DebugModeLeft()), registersWidget, SLOT(OnDebugModeLeft()), - Qt::BlockingQueuedConnection); - connect(emu_thread.get(), SIGNAL(DebugModeLeft()), waitTreeWidget, SLOT(OnDebugModeLeft()), - Qt::BlockingQueuedConnection); + connect(emu_thread.get(), &EmuThread::DebugModeEntered, registersWidget, + &RegistersWidget::OnDebugModeEntered, Qt::BlockingQueuedConnection); + connect(emu_thread.get(), &EmuThread::DebugModeEntered, waitTreeWidget, + &WaitTreeWidget::OnDebugModeEntered, Qt::BlockingQueuedConnection); + connect(emu_thread.get(), &EmuThread::DebugModeLeft, registersWidget, + &RegistersWidget::OnDebugModeLeft, Qt::BlockingQueuedConnection); + connect(emu_thread.get(), &EmuThread::DebugModeLeft, waitTreeWidget, + &WaitTreeWidget::OnDebugModeLeft, Qt::BlockingQueuedConnection); // Update the GUI registersWidget->OnDebugModeEntered(); @@ -437,7 +438,7 @@ void GMainWindow::ShutdownGame() { emu_thread = nullptr; // The emulation is stopped, so closing the window or not does not matter anymore - disconnect(render_window, SIGNAL(Closed()), this, SLOT(OnStopGame())); + disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); // Update the GUI ui.action_Start->setEnabled(false); @@ -548,8 +549,7 @@ void GMainWindow::OnStartGame() { emu_thread->SetRunning(true); qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus"); qRegisterMetaType<std::string>("std::string"); - connect(emu_thread.get(), SIGNAL(ErrorThrown(Core::System::ResultStatus, std::string)), this, - SLOT(OnCoreError(Core::System::ResultStatus, std::string))); + connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError); ui.action_Start->setEnabled(false); ui.action_Start->setText(tr("Continue")); diff --git a/src/yuzu/ui_settings.h b/src/yuzu/ui_settings.h index d093da641..9036ce2c1 100644 --- a/src/yuzu/ui_settings.h +++ b/src/yuzu/ui_settings.h @@ -50,4 +50,4 @@ struct Values { }; extern Values values; -} +} // namespace UISettings diff --git a/src/yuzu/util/spinbox.cpp b/src/yuzu/util/spinbox.cpp index 92753ec1c..14ef1e884 100644 --- a/src/yuzu/util/spinbox.cpp +++ b/src/yuzu/util/spinbox.cpp @@ -39,7 +39,7 @@ CSpinBox::CSpinBox(QWidget* parent) // TODO: Might be nice to not immediately call the slot. // Think of an address that is being replaced by a different one, in which case a lot // invalid intermediate addresses would be read from during editing. - connect(lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(OnEditingFinished())); + connect(lineEdit(), &QLineEdit::textEdited, this, &CSpinBox::OnEditingFinished); UpdateText(); } diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index 433e210b0..297dab653 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -1,21 +1,18 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules) -set(SRCS - emu_window/emu_window_sdl2.cpp - config.cpp - yuzu.cpp - yuzu.rc - ) -set(HEADERS - emu_window/emu_window_sdl2.h - config.h - default_ini.h - resource.h - ) +add_executable(yuzu-cmd + config.cpp + config.h + default_ini.h + emu_window/emu_window_sdl2.cpp + emu_window/emu_window_sdl2.h + resource.h + yuzu.cpp + yuzu.rc +) -create_directory_groups(${SRCS} ${HEADERS}) +create_target_directory_groups(yuzu-cmd) -add_executable(yuzu-cmd ${SRCS} ${HEADERS}) target_link_libraries(yuzu-cmd PRIVATE common core input_common) target_link_libraries(yuzu-cmd PRIVATE inih glad) if (MSVC) diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index e5be72213..bf79d2e81 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -49,10 +49,18 @@ static const std::array<int, Settings::NativeButton::NumButtons> default_buttons static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs{{ { - SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_D, + SDL_SCANCODE_UP, + SDL_SCANCODE_DOWN, + SDL_SCANCODE_LEFT, + SDL_SCANCODE_RIGHT, + SDL_SCANCODE_D, }, { - SDL_SCANCODE_I, SDL_SCANCODE_K, SDL_SCANCODE_J, SDL_SCANCODE_L, SDL_SCANCODE_D, + SDL_SCANCODE_I, + SDL_SCANCODE_K, + SDL_SCANCODE_J, + SDL_SCANCODE_L, + SDL_SCANCODE_D, }, }}; |