Skip to content

Commit

Permalink
Update melonDS and libretro-common
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Nov 7, 2023
1 parent 1fac37d commit fedd688
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 149 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ and this project roughly adheres to [Semantic Versioning](https://semver.org/spe

## [Unreleased]

Nothing right now.
### Changed

- Updated melonDS to commit 24a33e5.
- Updated libretro-common to commit fce57fd.

## [0.7.25] - 2023-11-06

Expand Down
4 changes: 2 additions & 2 deletions cmake/FetchDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function(fetch_dependency name default_url default_tag)
FetchContent_GetProperties(${name})
endfunction()

fetch_dependency("melonDS" "https://github.com/melonDS-emu/melonDS.git" "b8963b0")
fetch_dependency("libretro-common" "https://github.com/libretro/libretro-common.git" "01c6122")
fetch_dependency("melonDS" "https://github.com/melonDS-emu/melonDS.git" "24a33e5")
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.git" "47585fd")
fetch_dependency(libslirp "https://github.com/JesseTG/libslirp-mirror.git" "44e7877")
Expand Down
26 changes: 0 additions & 26 deletions src/libretro/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,6 @@ namespace melonds {
Arm9i,
};

constexpr std::string_view ConsoleTypeName(ConsoleType type) noexcept {
switch (type) {
case ConsoleType::DS:
return "DS";
case ConsoleType::DSi:
return "DSi";
}
}

constexpr std::string_view ConsoleTypeName(SPI_Firmware::FirmwareConsoleType type) noexcept {
switch (type) {
case SPI_Firmware::FirmwareConsoleType::DS:
return "DS";
case SPI_Firmware::FirmwareConsoleType::DSi:
return "DSi";
case SPI_Firmware::FirmwareConsoleType::DSLite:
return "DS Lite";
case SPI_Firmware::FirmwareConsoleType::iQueDSLite:
return "iQue DS Lite";
case SPI_Firmware::FirmwareConsoleType::iQueDS:
return "iQue DS";
default:
return "unknown";
}
}

enum class ScreenSwapMode {
Hold,
Toggle,
Expand Down
132 changes: 60 additions & 72 deletions src/libretro/config/config.cpp

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/libretro/config/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ std::optional<melonds::TouchMode> melonds::config::ParseTouchMode(const char* va
return nullopt;
}

optional<SPI_Firmware::IpAddress> melonds::config::ParseIpAddress(const char* value) noexcept {
optional<IpAddress> melonds::config::ParseIpAddress(const char* value) noexcept {
ZoneScopedN("melonds::config::ParseIpAddress");
if (string_is_empty(value))
return nullopt;
Expand All @@ -190,7 +190,7 @@ optional<SPI_Firmware::IpAddress> melonds::config::ParseIpAddress(const char* va
// Both in_addr and ip represent an IPv4 address,
// but they may have different alignment requirements.
// Better safe than sorry.
SPI_Firmware::IpAddress ip;
IpAddress ip;
memcpy(&ip, &address, sizeof(address));
return ip;
}
Expand All @@ -212,7 +212,7 @@ bool melonds::config::IsDsiNandImage(const retro::dirent &file) noexcept {
return true;
}

bool melonds::config::IsFirmwareImage(const retro::dirent& file, SPI_Firmware::FirmwareHeader& header) noexcept {
bool melonds::config::IsFirmwareImage(const retro::dirent& file, Firmware::FirmwareHeader& header) noexcept {
ZoneScopedN("melonds::config::IsFirmwareImage");
ZoneText(file.path, strnlen(file.path, sizeof(file.path)));

Expand Down Expand Up @@ -257,14 +257,14 @@ bool melonds::config::IsFirmwareImage(const retro::dirent& file, SPI_Firmware::F
return false;
}

SPI_Firmware::FirmwareHeader& loadedHeader = *reinterpret_cast<SPI_Firmware::FirmwareHeader*>(&buffer);
Firmware::FirmwareHeader& loadedHeader = *reinterpret_cast<Firmware::FirmwareHeader*>(&buffer);

switch (loadedHeader.ConsoleType) {
case SPI_Firmware::FirmwareConsoleType::DS:
case SPI_Firmware::FirmwareConsoleType::DSi:
case SPI_Firmware::FirmwareConsoleType::iQueDSLite:
case SPI_Firmware::FirmwareConsoleType::iQueDS:
case SPI_Firmware::FirmwareConsoleType::DSLite:
case Firmware::FirmwareConsoleType::DS:
case Firmware::FirmwareConsoleType::DSi:
case Firmware::FirmwareConsoleType::iQueDSLite:
case Firmware::FirmwareConsoleType::iQueDS:
case Firmware::FirmwareConsoleType::DSLite:
break;
default:
retro::debug("{} doesn't look like valid firmware (unrecognized ConsoleType 0x{:02X})", file.path, (u8)loadedHeader.ConsoleType);
Expand Down
4 changes: 2 additions & 2 deletions src/libretro/config/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ namespace melonds::config {
std::optional<melonds::MicInputMode> ParseMicInputMode(const char* value) noexcept;
std::optional<melonds::TouchMode> ParseTouchMode(const char* value) noexcept;

std::optional<SPI_Firmware::IpAddress> ParseIpAddress(const char* value) noexcept;
std::optional<IpAddress> ParseIpAddress(const char* value) noexcept;

constexpr std::array<size_t, 2> DSI_NAND_SIZES = { 251658304, 257425472 };
constexpr std::array<size_t, 3> FIRMWARE_SIZES = { 131072, 262144, 524288 };

bool IsDsiNandImage(const retro::dirent &file) noexcept;
bool IsFirmwareImage(const retro::dirent &file, SPI_Firmware::FirmwareHeader& header) noexcept;
bool IsFirmwareImage(const retro::dirent &file, Firmware::FirmwareHeader& header) noexcept;
}

#endif //MELONDS_DS_CONSTANTS_HPP
2 changes: 1 addition & 1 deletion src/libretro/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ melonds::nds_firmware_not_bootable_exception::nds_firmware_not_bootable_exceptio
melonds::wrong_firmware_type_exception::wrong_firmware_type_exception(
std::string_view firmwareName,
melonds::ConsoleType consoleType,
SPI_Firmware::FirmwareConsoleType firmwareConsoleType
Firmware::FirmwareConsoleType firmwareConsoleType
) noexcept : bios_exception(
fmt::format(
FMT_STRING("The firmware file at \"{}\" is for the {}, but it can't be used in {} mode."),
Expand Down
2 changes: 1 addition & 1 deletion src/libretro/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace melonds
wrong_firmware_type_exception(
std::string_view firmwareName,
melonds::ConsoleType consoleType,
SPI_Firmware::FirmwareConsoleType firmwareConsoleType
Firmware::FirmwareConsoleType firmwareConsoleType
) noexcept;
};

Expand Down
37 changes: 20 additions & 17 deletions src/libretro/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,26 @@ struct fmt::formatter<Platform::StopReason> : fmt::formatter<std::string_view> {
};

template<>
struct fmt::formatter<SPI_Firmware::FirmwareConsoleType> : fmt::formatter<std::string_view> {
struct fmt::formatter<Firmware::FirmwareConsoleType> : fmt::formatter<std::string_view> {
// use inherited 'formatter<string_view>::parse'…
// … and only implement 'format':
template<typename FmtContext>
auto format(SPI_Firmware::FirmwareConsoleType c, FmtContext& ctx) {
auto format(Firmware::FirmwareConsoleType c, FmtContext& ctx) {
string_view name = "unknown";
switch (c) {
case SPI_Firmware::FirmwareConsoleType::DS:
case Firmware::FirmwareConsoleType::DS:
name = "DS";
break;
case SPI_Firmware::FirmwareConsoleType::DSLite:
case Firmware::FirmwareConsoleType::DSLite:
name = "DS Lite";
break;
case SPI_Firmware::FirmwareConsoleType::DSi:
case Firmware::FirmwareConsoleType::DSi:
name = "DSi";
break;
case SPI_Firmware::FirmwareConsoleType::iQueDS:
case Firmware::FirmwareConsoleType::iQueDS:
name = "iQue DS";
break;
case SPI_Firmware::FirmwareConsoleType::iQueDSLite:
case Firmware::FirmwareConsoleType::iQueDSLite:
name = "iQueue DS Lite";
break;
}
Expand Down Expand Up @@ -163,35 +163,35 @@ struct fmt::formatter<DSi_NAND::ConsoleRegion> : fmt::formatter<std::string_view
};

template<>
struct fmt::formatter<SPI_Firmware::Language> : fmt::formatter<std::string_view> {
struct fmt::formatter<Firmware::Language> : fmt::formatter<std::string_view> {
// use inherited 'formatter<string_view>::parse'…
// … and only implement 'format':
template<typename FmtContext>
auto format(SPI_Firmware::Language c, FmtContext& ctx) {
auto format(Firmware::Language c, FmtContext& ctx) {
string_view name = "<unknown>";
switch (c) {
case SPI_Firmware::Language::Japanese:
case Firmware::Language::Japanese:
name = "Japanese";
break;
case SPI_Firmware::Language::English:
case Firmware::Language::English:
name = "English";
break;
case SPI_Firmware::Language::French:
case Firmware::Language::French:
name = "French";
break;
case SPI_Firmware::Language::German:
case Firmware::Language::German:
name = "German";
break;
case SPI_Firmware::Language::Italian:
case Firmware::Language::Italian:
name = "Italian";
break;
case SPI_Firmware::Language::Spanish:
case Firmware::Language::Spanish:
name = "Spanish";
break;
case SPI_Firmware::Language::Chinese:
case Firmware::Language::Chinese:
name = "Chinese";
break;
case SPI_Firmware::Language::Reserved:
case Firmware::Language::Reserved:
name = "Reserved";
break;
}
Expand Down Expand Up @@ -303,6 +303,9 @@ struct fmt::formatter<retro_language> : fmt::formatter<std::string_view> {
case RETRO_LANGUAGE_HUNGARIAN:
name = "Hungarian";
break;
case RETRO_LANGUAGE_BELARUSIAN:
name = "Belarusian";
break;
}
return formatter<string_view>::format(name, ctx);
}
Expand Down
10 changes: 6 additions & 4 deletions src/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,11 @@ static void melonds::read_microphone(melonds::InputState& inputState) noexcept {
static void melonds::render_audio() {
ZoneScopedN("melonds::render_audio");
static int16_t audio_buffer[0x1000]; // 4096 samples == 2048 stereo frames
u32 size = std::min(SPU::GetOutputSize(), static_cast<int>(sizeof(audio_buffer) / (2 * sizeof(int16_t))));
retro_assert(NDS::SPU != nullptr);
u32 size = std::min(NDS::SPU->GetOutputSize(), static_cast<int>(sizeof(audio_buffer) / (2 * sizeof(int16_t))));
// Ensure that we don't overrun the buffer

size_t read = SPU::ReadOutput(audio_buffer, size);
size_t read = NDS::SPU->ReadOutput(audio_buffer, size);
retro::audio_sample_batch(audio_buffer, read);
}

Expand All @@ -499,7 +500,8 @@ static void SetConsoleTime() noexcept {
tm tm;
struct tm* tmPtr = localtime(&now);
memcpy(&tm, tmPtr, sizeof(tm)); // Reduce the odds of race conditions in case some other thread uses this
RTC::SetDateTime(tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
retro_assert(NDS::RTC != nullptr);
NDS::RTC->SetDateTime(tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
// tm.tm_mon is 0-indexed, but RTC::SetDateTime expects 1-indexed
}

Expand Down Expand Up @@ -745,7 +747,7 @@ static void melonds::load_games(

InitFlushFirmwareTask();

if (loadedGbaCart && (NDS::IsLoadedARM9BIOSBuiltIn() || NDS::IsLoadedARM7BIOSBuiltIn() || SPI_Firmware::IsLoadedFirmwareBuiltIn())) {
if (loadedGbaCart && (NDS::IsLoadedARM9BIOSBuiltIn() || NDS::IsLoadedARM7BIOSBuiltIn() || NDS::SPI->GetFirmwareMem()->IsLoadedFirmwareBuiltIn())) {
// If we're using FreeBIOS and are trying to load a GBA cart...
retro::set_warn_message(
"FreeBIOS does not support GBA connectivity. "
Expand Down
2 changes: 1 addition & 1 deletion src/libretro/platform/lan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Config {
#ifdef HAVE_NETWORKING_DIRECT_MODE
bool melonds::IsAdapterAcceptable(const LAN_PCap::AdapterData& adapter) noexcept {
ZoneScopedN("Platform::LAN_Init::LAN_PCap::IsAdapterAcceptable");
const SPI_Firmware::MacAddress& mac = *reinterpret_cast<const SPI_Firmware::MacAddress*>(adapter.MAC);
const MacAddress& mac = *reinterpret_cast<const MacAddress*>(adapter.MAC);

if (mac == BAD_MAC || mac == BROADCAST_MAC)
return false;
Expand Down
14 changes: 10 additions & 4 deletions src/libretro/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

#include "power.hpp"

#include <cmath>

#include <NDS.h>
#include <DSi.h>
#include <DSi_I2C.h>
#include <SPI.h>
#include <retro_assert.h>

#include "config.hpp"
#include "environment.hpp"
Expand Down Expand Up @@ -73,13 +75,17 @@ retro::task::TaskSpec melonds::power::PowerStatusUpdateTask() noexcept
// If the threshold is 0, the battery level is always okay
// If the threshold is 100, the battery level is never okay
bool ok = charging || static_cast<unsigned>(devicePower->percent) > config::system::DsPowerOkayThreshold();
SPI_Powerman::SetBatteryLevelOkay(ok);
retro_assert(NDS::SPI != nullptr);
retro_assert(NDS::SPI->GetPowerMan() != nullptr);
NDS::SPI->GetPowerMan()->SetBatteryLevelOkay(ok);
break;
}
case ConsoleType::DSi: {
u8 batteryLevel = GetDsiBatteryLevel(devicePower->percent == RETRO_POWERSTATE_NO_ESTIMATE ? 100 : devicePower->percent);
DSi_BPTWL::SetBatteryCharging(charging);
DSi_BPTWL::SetBatteryLevel(batteryLevel);
retro_assert(DSi::I2C != nullptr);
retro_assert(DSi::I2C->GetBPTWL() != nullptr);
DSi::I2C->GetBPTWL()->SetBatteryCharging(charging);
DSi::I2C->GetBPTWL()->SetBatteryLevel(batteryLevel);
break;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/libretro/sram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ static void FlushGbaSram(retro::task::TaskHandle &task, const retro_game_info& g

static void FlushFirmware(const string& firmwarePath, const string& wfcSettingsPath) noexcept {
ZoneScopedN("melonds::sram::FlushFirmware");
using SPI_Firmware::Firmware;
using namespace melonds;

retro_assert(!firmwarePath.empty());
retro_assert(path_is_absolute(firmwarePath.c_str()));
retro_assert(!wfcSettingsPath.empty());
retro_assert(path_is_absolute(wfcSettingsPath.c_str()));
retro_assert(NDS::SPI != nullptr);

const Firmware* firmware = SPI_Firmware::GetFirmware();
const Firmware* firmware = NDS::SPI->GetFirmware();

retro_assert(firmware != nullptr);
retro_assert(firmware->Buffer() != nullptr);

if (firmware->Header().Identifier != SPI_Firmware::GENERATED_FIRMWARE_IDENTIFIER) {
if (firmware->GetHeader().Identifier != GENERATED_FIRMWARE_IDENTIFIER) {
// If this is a native firmware blob...
int32_t existingFirmwareFileSize = path_get_size(firmwarePath.c_str());
if (existingFirmwareFileSize == -1) {
Expand All @@ -168,7 +168,7 @@ static void FlushFirmware(const string& firmwarePath, const string& wfcSettingsP
retro::error("Failed to write {}-byte firmware to \"{}\"", firmware->Length(), firmwarePath);
}
} else {
u32 expectedWfcSettingsSize = sizeof(firmware->ExtendedAccessPoints()) + sizeof(firmware->AccessPoints());
u32 expectedWfcSettingsSize = sizeof(firmware->GetExtendedAccessPoints()) + sizeof(firmware->GetAccessPoints());
int32_t existingWfcSettingsSize = path_get_size(wfcSettingsPath.c_str());
if (existingWfcSettingsSize == -1) {
retro::debug("Wi-Fi settings file at \"{}\" doesn't exist, creating it", wfcSettingsPath);
Expand All @@ -182,14 +182,14 @@ static void FlushFirmware(const string& firmwarePath, const string& wfcSettingsP
);
}
retro_assert(string_ends_with(wfcSettingsPath.c_str(), "/wfcsettings.bin"));
u32 eapstart = firmware->ExtendedAccessPointOffset();
u32 eapend = eapstart + sizeof(firmware->ExtendedAccessPoints());
u32 apstart = firmware->WifiAccessPointOffset();
u32 eapstart = firmware->GetExtendedAccessPointOffset();
u32 eapend = eapstart + sizeof(firmware->GetExtendedAccessPoints());
u32 apstart = firmware->GetWifiAccessPointOffset();

// assert that the extended access points come just before the regular ones
retro_assert(eapend == apstart);

const u8* buffer = firmware->ExtendedAccessPointPosition();
const u8* buffer = firmware->GetExtendedAccessPointPosition();
if (filestream_write_file(wfcSettingsPath.c_str(), buffer, expectedWfcSettingsSize)) {
retro::debug("Flushed {}-byte WFC settings to \"{}\"", expectedWfcSettingsSize, wfcSettingsPath);
} else {
Expand Down Expand Up @@ -394,7 +394,7 @@ void Platform::WriteGBASave(const u8 *savedata, u32 savelen, u32 writeoffset, u3
}
}

void Platform::WriteFirmware(const SPI_Firmware::Firmware &firmware, u32 writeoffset, u32 writelen) {
void Platform::WriteFirmware(const Firmware& firmware, u32 writeoffset, u32 writelen) {
ZoneScopedN("Platform::WriteFirmware");

TimeToFirmwareFlush = melonds::config::save::FlushDelay();
Expand Down

0 comments on commit fedd688

Please sign in to comment.