Update melonDS to 94ba7c1

This commit is contained in:
Jesse Talavera 2024-07-18 10:15:41 -04:00
parent f0b516ba58
commit 3f13d408c1
10 changed files with 78 additions and 55 deletions

View File

@ -37,7 +37,7 @@ function(fetch_dependency name default_url default_tag)
FetchContent_GetProperties(${name})
endfunction()
fetch_dependency(melonDS "https://github.com/melonDS-emu/melonDS" "b55eb43")
fetch_dependency(melonDS "https://github.com/melonDS-emu/melonDS" "94ba7c1")
fetch_dependency("libretro-common" "https://github.com/libretro/libretro-common.git" "fce57fd")
fetch_dependency("embed-binaries" "https://github.com/andoalon/embed-binaries.git" "21f28ca")
fetch_dependency(glm "https://github.com/g-truc/glm" "33b0eb9")

View File

@ -66,6 +66,8 @@ add_library(melondsds_libretro MODULE
render/software.hpp
retro/dirent.cpp
retro/dirent.hpp
retro/file.cpp
retro/file.hpp
retro/http.cpp
retro/http.hpp
retro/info.cpp
@ -142,17 +144,23 @@ endif ()
if (HAVE_NETWORKING)
target_sources(melondsds_libretro PRIVATE
${melonDS_SOURCE_DIR}/src/frontend/qt_sdl/Net_Slirp.cpp
${melonDS_SOURCE_DIR}/src/frontend/qt_sdl/Net_Slirp.h
${melonDS_SOURCE_DIR}/src/net/Net_Slirp.cpp
${melonDS_SOURCE_DIR}/src/net/Net_Slirp.h
${melonDS_SOURCE_DIR}/src/net/Net.cpp
${melonDS_SOURCE_DIR}/src/net/Net.h
${melonDS_SOURCE_DIR}/src/net/LocalMP.cpp
${melonDS_SOURCE_DIR}/src/net/LocalMP.h
${melonDS_SOURCE_DIR}/src/net/PacketDispatcher.cpp
${melonDS_SOURCE_DIR}/src/net/PacketDispatcher.h
platform/lan.cpp
)
target_include_directories(melondsds_libretro SYSTEM PRIVATE "${melonDS_SOURCE_DIR}/src/frontend/qt_sdl")
target_include_directories(melondsds_libretro SYSTEM PRIVATE "${melonDS_SOURCE_DIR}/src/net")
if (HAVE_NETWORKING_DIRECT_MODE)
target_sources(melondsds_libretro PRIVATE
${melonDS_SOURCE_DIR}/src/frontend/qt_sdl/Net_PCap.cpp
${melonDS_SOURCE_DIR}/src/frontend/qt_sdl/Net_PCap.h
${melonDS_SOURCE_DIR}/src/net/Net_PCap.cpp
${melonDS_SOURCE_DIR}/src/net/Net_PCap.h
)
endif()
endif ()

View File

@ -87,7 +87,7 @@ using std::string;
using std::string_view;
using std::unique_ptr;
using std::vector;
using LAN_PCap::AdapterData;
using Net_PCap::AdapterData;
constexpr unsigned AUTO_SDCARD_SIZE = 0;
constexpr uint64_t DEFAULT_SDCARD_SIZE = 4096ull * 1024ull * 1024ull; // 4GB
@ -934,7 +934,7 @@ bool MelonDsDs::RegisterCoreOptions() noexcept {
bool pcapOk;
{
ZoneScopedN("LAN_PCap::Init");
pcapOk = LAN_PCap::Init(false);
pcapOk = Net_PCap::InitAdapterList();
}
#ifdef HAVE_NETWORKING_DIRECT_MODE
@ -950,9 +950,9 @@ bool MelonDsDs::RegisterCoreOptions() noexcept {
// Zero all option values except for the first (Automatic)
memset(wifiAdapterOption->values + 1, 0, sizeof(retro_core_option_value) * (RETRO_NUM_CORE_OPTION_VALUES_MAX - 1));
int length = std::min<int>(LAN_PCap::NumAdapters, RETRO_NUM_CORE_OPTION_VALUES_MAX - 1);
int length = std::min<int>(Net_PCap::NumAdapters, RETRO_NUM_CORE_OPTION_VALUES_MAX - 1);
for (int i = 0; i < length; ++i) {
const LAN_PCap::AdapterData& adapter = LAN_PCap::Adapters[i];
const Net_PCap::AdapterData& adapter = Net_PCap::Adapters[i];
if (IsAdapterAcceptable(adapter)) {
// If this interface would potentially work...

View File

@ -208,9 +208,12 @@ static melonDS::NDSArgs MelonDsDs::GetNdsArgs(
ApplyCommonArgs(config, ndsargs);
retro_assert(ndsargs.ARM7BIOS != nullptr);
retro_assert(ndsargs.ARM9BIOS != nullptr);
// Try to load the ARM7 and ARM9 BIOS files (but don't bother with the ARM9 BIOS if the ARM7 BIOS failed)
bool bios7Loaded = !isFirmwareGenerated && LoadBios(config.Bios7Path(), BiosType::Arm7, ndsargs.ARM7BIOS);
bool bios9Loaded = bios7Loaded && LoadBios(config.Bios9Path(), BiosType::Arm9, ndsargs.ARM9BIOS);
bool bios7Loaded = !isFirmwareGenerated && LoadBios(config.Bios7Path(), BiosType::Arm7, *ndsargs.ARM7BIOS);
bool bios9Loaded = bios7Loaded && LoadBios(config.Bios9Path(), BiosType::Arm9, *ndsargs.ARM9BIOS);
if (config.SysfileMode() == SysfileMode::Native && !(bios7Loaded && bios9Loaded)) {
// If we're trying to load native BIOS files, but at least one of them failed...
@ -237,8 +240,8 @@ static melonDS::NDSArgs MelonDsDs::GetNdsArgs(
retro::debug("Installed native ARM7 and ARM9 NDS BIOS images");
}
else {
ndsargs.ARM9BIOS = melonDS::bios_arm9_bin;
ndsargs.ARM7BIOS = melonDS::bios_arm7_bin;
ndsargs.ARM9BIOS = std::make_unique<melonDS::ARM9BIOSImage>(melonDS::bios_arm9_bin);
ndsargs.ARM7BIOS = std::make_unique<melonDS::ARM7BIOSImage>(melonDS::bios_arm7_bin);
retro::debug("Installed built-in ARM7 and ARM9 NDS BIOS images");
}
@ -271,23 +274,23 @@ static melonDS::DSiArgs MelonDsDs::GetDSiArgs(const CoreConfig& config, const re
}
// DSi mode requires all native BIOS files
std::array<uint8_t, melonDS::DSiBIOSSize> arm7i;
if (!LoadBios(config.DsiBios7Path(), BiosType::Arm7i, arm7i)) {
unique_ptr<melonDS::DSiBIOSImage> arm7i = make_unique<melonDS::DSiBIOSImage>();
if (!LoadBios(config.DsiBios7Path(), BiosType::Arm7i, *arm7i)) {
throw dsi_missing_bios_exception(BiosType::Arm7i, config.DsiBios7Path());
}
std::array<uint8_t, melonDS::DSiBIOSSize> arm9i;
if (!LoadBios(config.DsiBios9Path(), BiosType::Arm9i, arm9i)) {
unique_ptr<melonDS::DSiBIOSImage> arm9i = make_unique<melonDS::DSiBIOSImage>();
if (!LoadBios(config.DsiBios9Path(), BiosType::Arm9i, *arm9i)) {
throw dsi_missing_bios_exception(BiosType::Arm9i, config.DsiBios9Path());
}
std::array<uint8_t, melonDS::ARM7BIOSSize> arm7;
if (!LoadBios(config.Bios7Path(), BiosType::Arm7, arm7)) {
unique_ptr<melonDS::ARM7BIOSImage> arm7 = make_unique<melonDS::ARM7BIOSImage>();
if (!LoadBios(config.Bios7Path(), BiosType::Arm7, *arm7)) {
throw dsi_missing_bios_exception(BiosType::Arm7, config.Bios7Path());
}
std::array<uint8_t, melonDS::ARM9BIOSSize> arm9;
if (!LoadBios(config.Bios9Path(), BiosType::Arm9, arm9)) {
unique_ptr<melonDS::ARM9BIOSImage> arm9 = make_unique<melonDS::ARM9BIOSImage>();
if (!LoadBios(config.Bios9Path(), BiosType::Arm9, *arm9)) {
throw dsi_missing_bios_exception(BiosType::Arm9, config.Bios9Path());
}
@ -317,7 +320,7 @@ static melonDS::DSiArgs MelonDsDs::GetDSiArgs(const CoreConfig& config, const re
throw environment_exception("Failed to get the system directory, which means the NAND image can't be loaded.");
}
NANDImage nand = LoadNANDImage(*nandPath, &arm7i[0x8308]);
NANDImage nand = LoadNANDImage(*nandPath, &(*arm7i)[0x8308]);
unique_ptr<melonDS::NDSCart::CartCommon> ndsRom = ndsInfo ? LoadNdsCart(config, *ndsInfo) : nullptr;
{ // Scoped to limit the mount's lifetime
@ -341,12 +344,12 @@ static melonDS::DSiArgs MelonDsDs::GetDSiArgs(const CoreConfig& config, const re
{
.NDSROM = std::move(ndsRom),
.GBAROM = nullptr, // Irrelevant on DSi
.ARM9BIOS = arm9,
.ARM7BIOS = arm7,
.ARM9BIOS = std::move(arm9),
.ARM7BIOS = std::move(arm7),
.Firmware = std::move(*firmware),
},
arm9i,
arm7i,
std::move(arm9i),
std::move(arm7i),
std::move(nand),
LoadDSiSDCardImage(config),
};
@ -412,7 +415,7 @@ static unique_ptr<melonDS::NDSCart::CartCommon> MelonDsDs::LoadNdsCart(const Cor
std::unique_ptr<melonDS::NDSCart::CartCommon> cart;
{
ZoneScopedN("NDSCart::ParseROM");
cart = melonDS::NDSCart::ParseROM(reinterpret_cast<const uint8_t*>(rom.data()), rom.size(), std::move(sdargs));
cart = melonDS::NDSCart::ParseROM(reinterpret_cast<const uint8_t*>(rom.data()), rom.size(), nullptr, std::move(sdargs));
}
if (!cart) {

View File

@ -159,6 +159,12 @@ bool MelonDsDs::config::IsFirmwareImage(const retro::dirent& file, Firmware::Fir
return false;
}
if (strncmp(reinterpret_cast<const char*>(loadedHeader.Identifier.data()), "MAC", 3) != 0) {
// If this isn't a valid firmware image, then we don't want to load it
retro::debug("{} doesn't look like valid firmware (identifier is \"{}\")", file.path, fmt::join(loadedHeader.Identifier, ""));
return false;
}
memcpy(&header, &buffer, sizeof(buffer));
return true;
}

View File

@ -35,7 +35,7 @@
#include "../PlatformOGLPrivate.h"
#include "../sram.hpp"
namespace LAN_PCap {
namespace Net_PCap {
struct AdapterData;
}
@ -119,7 +119,7 @@ namespace MelonDsDs {
[[gnu::cold]] void RenderErrorScreen() noexcept;
[[gnu::cold]] void InitContent(unsigned type, std::span<const retro_game_info> game);
const LAN_PCap::AdapterData* SelectNetworkInterface(const LAN_PCap::AdapterData* adapters, int numAdapters) const noexcept;
const Net_PCap::AdapterData* SelectNetworkInterface(std::span<const Net_PCap::AdapterData> adapters) const noexcept;
retro::task::TaskSpec PowerStatusUpdateTask() noexcept;
retro::task::TaskSpec OnScreenDisplayTask() noexcept;

View File

@ -33,7 +33,6 @@
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#include <frontend/FrontendUtil.h>
#undef isnan
#include <fmt/format.h>

View File

@ -19,6 +19,7 @@
#include <libretro.h>
#include <NDS.h> // TODO: Submit a forward declaration PR
#include <GBACart.h>
#include <NDSCart.h>

View File

@ -21,6 +21,7 @@
#ifdef HAVE_NETWORKING_DIRECT_MODE
#include <pcap/pcap.h>
#include <Net_PCap.h>
#define PCAP_IF_WIRELESS 0x00000008 /* interface is wireless (*NOT* necessarily Wi-Fi!) */
#define PCAP_IF_CONNECTION_STATUS 0x00000030 /* connection status: */
#define PCAP_IF_CONNECTION_STATUS_UNKNOWN 0x00000000 /* unknown */
@ -32,7 +33,7 @@ namespace MelonDsDs {
constexpr std::array<uint8_t, 6> BAD_MAC = {0, 0, 0, 0, 0, 0};
constexpr std::array<uint8_t, 6> BROADCAST_MAC = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
bool IsAdapterAcceptable(const LAN_PCap::AdapterData& adapter) noexcept;
bool IsAdapterAcceptable(const Net_PCap::AdapterData& adapter) noexcept;
}
#endif
#endif //MELONDS_DS_PCAP_HPP

View File

@ -18,8 +18,8 @@
#include <string_view>
#include <Platform.h>
#include <dynamic/dylib.h>
#include <frontend/qt_sdl/LAN_PCap.h>
#include <frontend/qt_sdl/LAN_Socket.h>
#include <Net_PCap.h>
#include <Net_Slirp.h>
#include <retro_assert.h>
#include <pcap/pcap.h>
@ -35,13 +35,13 @@ using std::string;
using std::string_view;
struct Slirp;
namespace LAN_Socket
namespace Net_Slirp
{
extern Slirp* Ctx;
}
#ifdef HAVE_NETWORKING_DIRECT_MODE
namespace LAN_PCap
namespace Net_PCap
{
extern Platform::DynamicLibrary* PCapLib;
}
@ -54,7 +54,7 @@ namespace Config {
}
#ifdef HAVE_NETWORKING_DIRECT_MODE
bool MelonDsDs::IsAdapterAcceptable(const LAN_PCap::AdapterData& adapter) noexcept {
bool MelonDsDs::IsAdapterAcceptable(const Net_PCap::AdapterData& adapter) noexcept {
ZoneScopedN(TracyFunction);
const MacAddress& mac = *reinterpret_cast<const MacAddress*>(adapter.MAC);
@ -72,13 +72,13 @@ bool MelonDsDs::IsAdapterAcceptable(const LAN_PCap::AdapterData& adapter) noexce
return true;
}
const LAN_PCap::AdapterData* MelonDsDs::CoreState::SelectNetworkInterface(const LAN_PCap::AdapterData* adapters, int numAdapters) const noexcept {
const Net_PCap::AdapterData* MelonDsDs::CoreState::SelectNetworkInterface(std::span<const Net_PCap::AdapterData> adapters) const noexcept {
ZoneScopedN(TracyFunction);
using namespace MelonDsDs;
if (Config.NetworkInterface() != config::values::AUTO) {
const auto* selected = std::find_if(adapters, adapters + numAdapters, [this](const LAN_PCap::AdapterData& a) {
const auto* selected = std::find_if(adapters.begin(), adapters.end(), [this](const Net_PCap::AdapterData& a) {
string mac = fmt::format("{:02x}", fmt::join(a.MAC, ":"));
return Config.NetworkInterface() == mac;
@ -88,9 +88,7 @@ const LAN_PCap::AdapterData* MelonDsDs::CoreState::SelectNetworkInterface(const
return selected;
}
const auto* best = std::max_element(adapters, adapters + numAdapters, [](const LAN_PCap::AdapterData& a, const LAN_PCap::AdapterData& b) {
retro_assert(a.Internal != nullptr);
retro_assert(b.Internal != nullptr);
const auto* best = std::max_element(adapters.begin(), adapters.end(), [](const Net_PCap::AdapterData& a, const Net_PCap::AdapterData& b) {
const pcap_if_t& a_if = *static_cast<const pcap_if_t*>(a.Internal);
const pcap_if_t& b_if = *static_cast<const pcap_if_t*>(b.Internal);
@ -121,7 +119,7 @@ const LAN_PCap::AdapterData* MelonDsDs::CoreState::SelectNetworkInterface(const
return a_score < b_score;
});
retro_assert(best != adapters + numAdapters);
retro_assert(best != adapters.end());
return best;
}
@ -130,16 +128,17 @@ const LAN_PCap::AdapterData* MelonDsDs::CoreState::SelectNetworkInterface(const
bool MelonDsDs::CoreState::LanInit() noexcept {
ZoneScopedN(TracyFunction);
retro_assert(_activeNetworkMode == MelonDsDs::NetworkMode::None);
retro_assert(LAN_Socket::Ctx == nullptr);
retro_assert(Net_Slirp::Ctx == nullptr);
// LAN::PCap may already be initialized if we're using direct mode,
// as it was necessary to query the available interfaces for the core options
switch (Config.NetworkMode()) {
#ifdef HAVE_NETWORKING_DIRECT_MODE
case MelonDsDs::NetworkMode::Direct: {
const LAN_PCap::AdapterData* adapter = SelectNetworkInterface(LAN_PCap::Adapters, LAN_PCap::NumAdapters);
std::span adapters(Net_PCap::Adapters, Net_PCap::NumAdapters);
const Net_PCap::AdapterData* adapter = SelectNetworkInterface(adapters);
Config::LANDevice = adapter->DeviceName;
if (LAN_PCap::Init(true)) {
if (Net_PCap::InitAdapterList()) {
retro::debug(
"Initialized direct-mode Wi-fi support with adapter {} ({:02x})\n",
adapter->FriendlyName,
@ -158,7 +157,7 @@ bool MelonDsDs::CoreState::LanInit() noexcept {
}
#endif
case MelonDsDs::NetworkMode::Indirect:
if (LAN_Socket::Init()) {
if (Net_Slirp::Init()) {
retro::debug("Initialized indirect-mode Wi-fi support\n");
_activeNetworkMode = MelonDsDs::NetworkMode::Indirect;
return true;
@ -176,11 +175,17 @@ void MelonDsDs::CoreState::LanDeinit() noexcept {
ZoneScopedN(TracyFunction);
#ifdef HAVE_NETWORKING_DIRECT_MODE
LAN_PCap::DeInit();
retro_assert(LAN_PCap::PCapLib == nullptr);
Net_PCap::DeInit();
retro_assert(Net_PCap::PCapLib == nullptr);
if (Net_PCap::Adapters) {
delete[] Net_PCap::Adapters;
Net_PCap::Adapters = nullptr;
Net_PCap::NumAdapters = 0;
}
#endif
LAN_Socket::DeInit();
retro_assert(LAN_Socket::Ctx == nullptr);
Net_Slirp::DeInit();
retro_assert(Net_Slirp::Ctx == nullptr);
_activeNetworkMode = MelonDsDs::NetworkMode::None;
}
@ -190,10 +195,10 @@ int MelonDsDs::CoreState::LanSendPacket(std::span<std::byte> data) noexcept {
switch (_activeNetworkMode) {
#ifdef HAVE_NETWORKING_DIRECT_MODE
case MelonDsDs::NetworkMode::Direct:
return LAN_PCap::SendPacket((u8*)data.data(), data.size());
return Net_PCap::SendPacket((u8*)data.data(), data.size());
#endif
case MelonDsDs::NetworkMode::Indirect:
return LAN_Socket::SendPacket((u8*)data.data(), data.size());
return Net_Slirp::SendPacket((u8*)data.data(), data.size());
default:
return 0;
}
@ -204,10 +209,10 @@ int MelonDsDs::CoreState::LanRecvPacket(u8 *data) noexcept {
switch (_activeNetworkMode) {
#ifdef HAVE_NETWORKING_DIRECT_MODE
case MelonDsDs::NetworkMode::Direct:
return LAN_PCap::RecvPacket(data);
return Net_PCap::RecvPacket(data);
#endif
case MelonDsDs::NetworkMode::Indirect:
return LAN_Socket::RecvPacket(data);
return Net_Slirp::RecvPacket(data);
default:
return 0;
}