From 8423dae6ff24173d435f743eab2fe609ab86cab3 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 7 Aug 2024 15:53:58 +0200 Subject: [PATCH 1/6] Add "Open melonDS directory" menu option --- src/frontend/qt_sdl/Window.cpp | 7 +++++++ src/frontend/qt_sdl/Window.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index f39bbb37..440f3e20 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #ifndef _WIN32 #include #include @@ -366,6 +367,12 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) : actUndoStateLoad->setShortcut(QKeySequence(Qt::Key_F12)); connect(actUndoStateLoad, &QAction::triggered, this, &MainWindow::onUndoStateLoad); + menu->addSeparator(); + actOpenConfig = menu->addAction("Open melonDS directory"); + connect(actOpenConfig, &QAction::triggered, this, [&]() { + QDesktopServices::openUrl(QUrl::fromLocalFile(emuDirectory)); + }); + menu->addSeparator(); actQuit = menu->addAction("Quit"); diff --git a/src/frontend/qt_sdl/Window.h b/src/frontend/qt_sdl/Window.h index aff8507f..c3ed166c 100644 --- a/src/frontend/qt_sdl/Window.h +++ b/src/frontend/qt_sdl/Window.h @@ -264,6 +264,7 @@ public: QAction* actSaveState[9]; QAction* actLoadState[9]; QAction* actUndoStateLoad; + QAction* actOpenConfig; QAction* actQuit; QAction* actPause; From a17490141299099c8d836d7230ebfe09138c3ca7 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 7 Aug 2024 17:23:48 +0200 Subject: [PATCH 2/6] fix building with system libslirp --- src/frontend/qt_sdl/CMakeLists.txt | 3 -- src/net/Net_Slirp.cpp | 65 +----------------------------- src/net/Net_Slirp.h | 2 +- 3 files changed, 2 insertions(+), 68 deletions(-) diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 559b7a2d..c857bbbc 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -164,9 +164,6 @@ target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../net") -target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../net/libslirp/src") -get_target_property(SLIRP_BINARY_DIR slirp BINARY_DIR) -target_include_directories(melonDS PUBLIC "${SLIRP_BINARY_DIR}") # for libslirp-version.h if (USE_QT6) target_include_directories(melonDS PUBLIC ${Qt6Gui_PRIVATE_INCLUDE_DIRS}) else() diff --git a/src/net/Net_Slirp.cpp b/src/net/Net_Slirp.cpp index fef4d19c..2200b074 100644 --- a/src/net/Net_Slirp.cpp +++ b/src/net/Net_Slirp.cpp @@ -23,12 +23,7 @@ #include "FIFO.h" #include "Platform.h" -#include - -// "register" is indirectly used by slirp.h but isn't allowed in C++17, this is a workaround -#define register -// Needed for Slirp's definition so we can adjust the opaque pointer in the move constructor -#include +#include #ifdef __WIN32__ #include @@ -163,63 +158,6 @@ Net_Slirp::Net_Slirp(const Platform::SendPacketCallback& callback) noexcept : Ca Ctx = slirp_new(&cfg, &cb, this); } - -Net_Slirp::Net_Slirp(Net_Slirp&& other) noexcept -{ - RXBuffer = other.RXBuffer; - IPv4ID = other.IPv4ID; - Ctx = other.Ctx; - PollListSize = other.PollListSize; - Callback = std::move(other.Callback); - memcpy(PollList, other.PollList, sizeof(PollList)); - - other.RXBuffer = {}; - other.IPv4ID = 0; - other.Ctx = nullptr; - other.PollListSize = 0; - other.Callback = nullptr; - memset(other.PollList, 0, sizeof(other.PollList)); - - if (Ctx) - { - Ctx->opaque = this; - // Gotta ensure that the context doesn't try to pass around a dead object - } -} - -Net_Slirp& Net_Slirp::operator=(Net_Slirp&& other) noexcept -{ - if (this != &other) - { - if (Ctx) - { - slirp_cleanup(Ctx); - } - - RXBuffer = other.RXBuffer; - IPv4ID = other.IPv4ID; - Ctx = other.Ctx; - PollListSize = other.PollListSize; - Callback = std::move(other.Callback); - memcpy(PollList, other.PollList, sizeof(PollList)); - - other.RXBuffer = {}; - other.IPv4ID = 0; - other.Ctx = nullptr; - other.PollListSize = 0; - other.Callback = nullptr; - memset(other.PollList, 0, sizeof(other.PollList)); - - if (Ctx) - { - Ctx->opaque = this; - // Gotta ensure that the context doesn't try to pass around a dead object - } - } - - return *this; -} - Net_Slirp::~Net_Slirp() noexcept { if (Ctx) @@ -229,7 +167,6 @@ Net_Slirp::~Net_Slirp() noexcept } } - void FinishUDPFrame(u8* data, int len) { u8* ipheader = &data[0xE]; diff --git a/src/net/Net_Slirp.h b/src/net/Net_Slirp.h index 5f9b6587..256b3058 100644 --- a/src/net/Net_Slirp.h +++ b/src/net/Net_Slirp.h @@ -24,7 +24,7 @@ #include "Platform.h" #include "NetDriver.h" -#include +#include #ifdef __WIN32__ #include From b47563e888630ae7c95992d60e311f37c9f47466 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 7 Aug 2024 17:28:25 +0200 Subject: [PATCH 3/6] Apply FixInterfaceIncludes to the slirp package again to work around package inconsistencies --- src/net/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/net/CMakeLists.txt b/src/net/CMakeLists.txt index 082c00fb..0d4698df 100644 --- a/src/net/CMakeLists.txt +++ b/src/net/CMakeLists.txt @@ -1,3 +1,5 @@ +include(FixInterfaceIncludes) + add_library(net-utils STATIC Net.cpp Net_PCap.cpp @@ -13,6 +15,7 @@ target_include_directories(net-utils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") option(USE_SYSTEM_LIBSLIRP "Use system libslirp instead of the bundled version" OFF) if (USE_SYSTEM_LIBSLIRP) pkg_check_modules(Slirp REQUIRED IMPORTED_TARGET slirp) + fix_interface_includes(PkgConfig::Slirp) target_link_libraries(net-utils PRIVATE PkgConfig::Slirp) else() add_subdirectory(libslirp EXCLUDE_FROM_ALL) From 4359bccfcbec2b149d4b01870897bf849e9a69ce Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 7 Aug 2024 17:45:56 +0200 Subject: [PATCH 4/6] fix the slirp shit some more --- src/net/CMakeLists.txt | 5 ++--- src/net/Net_Slirp.cpp | 2 +- src/net/Net_Slirp.h | 2 +- src/net/libslirp/CMakeLists.txt | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/net/CMakeLists.txt b/src/net/CMakeLists.txt index 0d4698df..62bb557c 100644 --- a/src/net/CMakeLists.txt +++ b/src/net/CMakeLists.txt @@ -16,9 +16,8 @@ option(USE_SYSTEM_LIBSLIRP "Use system libslirp instead of the bundled version" if (USE_SYSTEM_LIBSLIRP) pkg_check_modules(Slirp REQUIRED IMPORTED_TARGET slirp) fix_interface_includes(PkgConfig::Slirp) - target_link_libraries(net-utils PRIVATE PkgConfig::Slirp) + target_link_libraries(net-utils PUBLIC PkgConfig::Slirp) else() add_subdirectory(libslirp EXCLUDE_FROM_ALL) - target_include_directories(net-utils SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/libslirp/glib") - target_link_libraries(net-utils PRIVATE slirp) + target_link_libraries(net-utils PUBLIC slirp) endif() diff --git a/src/net/Net_Slirp.cpp b/src/net/Net_Slirp.cpp index 2200b074..0386c586 100644 --- a/src/net/Net_Slirp.cpp +++ b/src/net/Net_Slirp.cpp @@ -23,7 +23,7 @@ #include "FIFO.h" #include "Platform.h" -#include +#include #ifdef __WIN32__ #include diff --git a/src/net/Net_Slirp.h b/src/net/Net_Slirp.h index 256b3058..5f9b6587 100644 --- a/src/net/Net_Slirp.h +++ b/src/net/Net_Slirp.h @@ -24,7 +24,7 @@ #include "Platform.h" #include "NetDriver.h" -#include +#include #ifdef __WIN32__ #include diff --git a/src/net/libslirp/CMakeLists.txt b/src/net/libslirp/CMakeLists.txt index 67b8ac78..99d0b3f7 100644 --- a/src/net/libslirp/CMakeLists.txt +++ b/src/net/libslirp/CMakeLists.txt @@ -49,9 +49,9 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/libslirp-version.h.in" "${CMAKE_ add_library(slirp STATIC ${SOURCES}) target_compile_definitions(slirp PUBLIC LIBSLIRP_STATIC_BUILD) -target_include_directories(slirp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/glib") -target_include_directories(slirp PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") -target_include_directories(slirp PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") +target_include_directories(slirp SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/glib") +target_include_directories(slirp SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") +target_include_directories(slirp SYSTEM PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") target_compile_definitions(slirp PRIVATE BUILDING_LIBSLIRP) target_compile_definitions(slirp PRIVATE "G_LOG_DOMAIN=\"Slirp\"") From 53c58bd7773541f93cde45e0b2fcc0b7b40afbc2 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 7 Aug 2024 17:49:29 +0200 Subject: [PATCH 5/6] fix potential issue with glib shim min/max defines --- src/net/libslirp/glib/glib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net/libslirp/glib/glib.h b/src/net/libslirp/glib/glib.h index e979b12a..3563f7f5 100644 --- a/src/net/libslirp/glib/glib.h +++ b/src/net/libslirp/glib/glib.h @@ -68,10 +68,10 @@ #define GLIB_SIZEOF_VOID_P 8 #ifndef MAX -#define MAX(a, b) (a > b ? a : b) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef MIN -#define MIN(a, b) (a < b ? a : b) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif #ifndef TRUE From ec71b15505e8e6f66c22402ba929bea5545c31fc Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 8 Aug 2024 05:36:06 +0200 Subject: [PATCH 6/6] Add a Nix flake (#2097) Adds a Nix flake, allowing easy building and running of melonDS using the Nix package manager, as well as potentially very stable and reproducible CI in the future. --- flake.lock | 61 +++++++++++++++++++++++++ flake.nix | 72 ++++++++++++++++++++++++++++++ src/frontend/qt_sdl/CMakeLists.txt | 2 + 3 files changed, 135 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..bd799223 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722813957, + "narHash": "sha256-IAoYyYnED7P8zrBFMnmp7ydaJfwTnwcnqxUElC1I26Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cb9a96f23c491c081b38eab96d22fa958043c9fa", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..5074a7fb --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + description = "Nintendo DS emulator"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + inherit (pkgs.lib) cmakeBool optionals makeLibraryPath; + inherit (pkgs.stdenv) isLinux isDarwin; + + versionSuffix = with self; if sourceInfo?dirtyShortRev + then sourceInfo.dirtyShortRev + else sourceInfo.shortRev; + + melonDS = pkgs.stdenv.mkDerivation { + pname = "melonDS"; + version = "0.9.5-${versionSuffix}"; + src = ./.; + + nativeBuildInputs = with pkgs; [ + cmake + ninja + pkg-config + kdePackages.wrapQtAppsHook + ]; + + buildInputs = (with pkgs; [ + kdePackages.qtbase + kdePackages.qtmultimedia + extra-cmake-modules + SDL2 + zstd + libarchive + libGL + libslirp + ]) ++ optionals isLinux [ + pkgs.wayland + pkgs.kdePackages.qtwayland + ]; + + cmakeFlags = [ + (cmakeBool "USE_QT6" true) + (cmakeBool "USE_SYSTEM_LIBSLIRP" true) + ]; + + qtWrapperArgs = optionals isLinux [ + "--prefix LD_LIBRARY_PATH : ${makeLibraryPath [ pkgs.libpcap ]}" + ] ++ optionals isDarwin [ + "--prefix DYLD_LIBRARY_PATH : ${makeLibraryPath [ pkgs.libpcap ]}" + ]; + + passthru = { + exePath = if isDarwin then + "/Applications/melonDS.app/Contents/MacOS/melonDS" + else "/bin/melonDS"; + }; + }; + in { + packages.default = melonDS; + apps.default = flake-utils.lib.mkApp { + drv = self.packages.${system}.default; + }; + devShells.default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + }; + } + ); +} diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index c857bbbc..fc7819a1 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -240,6 +240,8 @@ if (UNIX AND NOT APPLE) INTERPROCEDURAL_OPTIMIZATION OFF INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF) endif() +elseif(APPLE) + install(TARGETS melonDS BUNDLE DESTINATION "${CMAKE_INSTALL_PREFIX}/Applications") endif() if (ENABLE_OGLRENDERER)