Skip to content

Commit

Permalink
Tidy up some error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Oct 8, 2023
1 parent 337044e commit b6e9675
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/libretro/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ static void InitNdsSystemConfig(const NDSHeader* header, melonds::BootMode bootM

if (!header && !(firmware && firmware->IsBootable())) {
// If we're trying to boot into the NDS menu, but we didn't load bootable firmware...
throw bios_exception("Booting to the NDS menu requires a bootable firmware dump.");
throw nds_firmware_not_bootable_exception(FirmwarePath());
}

if (!firmware) {
Expand Down Expand Up @@ -1406,7 +1406,7 @@ static void InitNdsSystemConfig(const NDSHeader* header, melonds::BootMode bootM

if (!header && (!firmware || !firmware->IsBootable() || !bios7 || !bios9)) {
// If we're trying to boot into the NDS menu, but we don't have all the required files...
throw bios_exception("Booting to the NDS menu requires native NDS BIOS files and bootable firmware.");
throw nds_sysfiles_incomplete_exception();
}

if (bios7 && bios9) {
Expand Down Expand Up @@ -1477,17 +1477,21 @@ static void InitDsiSystemConfig() {
retro_assert(firmwarePath.has_value());
// If we couldn't get the system directory, we wouldn't have gotten this far

if (firmwareName == melonds::config::values::NOT_FOUND) {
throw dsi_no_firmware_found_exception();
}

unique_ptr<SPI_Firmware::Firmware> firmware = LoadFirmware(*firmwarePath);
if (!firmware) {
throw firmware_missing_exception(firmwareName);
}

if (firmware && firmware->Header().ConsoleType != SPI_Firmware::FirmwareConsoleType::DSi) {
retro::warn("Expected firmware of type DSi, got %s", ConsoleTypeName(firmware->Header().ConsoleType).data());
firmware = nullptr;
throw wrong_firmware_type_exception(firmwareName, melonds::ConsoleType::DSi, firmware->Header().ConsoleType);
}
// DSi firmware isn't bootable, so we don't need to check for that here.

if (!firmware) {
throw bios_exception("Failed to load DSi BIOS file");
}

memcpy(DSi::ARM9iBIOS, bios9i.get(), sizeof(DSi::ARM9iBIOS));
memcpy(DSi::ARM7iBIOS, bios7i.get(), sizeof(DSi::ARM7iBIOS));
memcpy(NDS::ARM7BIOS, bios7.get(), sizeof(NDS::ARM7BIOS));
Expand Down
74 changes: 73 additions & 1 deletion src/libretro/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,75 @@ using std::optional;
using std::string;
using std::string_view;

melonds::nds_firmware_not_bootable_exception::nds_firmware_not_bootable_exception(string_view firmwareName) noexcept
: bios_exception(
fmt::format(
FMT_STRING(
"The firmware file at \"{}\" can't be used to boot to the DS menu."
),
firmwareName
),
"Ensure you have native DS (not DSi) firmware in your frontend's system folder. "
"Pick it in the core options, then restart the core. "
"If you just want to play a DS game, try setting Boot Mode to \"Direct\" "
"or BIOS/Firmware Mode to \"Built-In\" in the core options."
) {
}

melonds::wrong_firmware_type_exception::wrong_firmware_type_exception(
std::string_view firmwareName,
melonds::ConsoleType consoleType,
SPI_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."),
firmwareName,
firmwareConsoleType,
consoleType
),
fmt::format(
FMT_STRING(
"Ensure you have a {}-compatible firmware file in your frontend's system folder (any name works). "
"Pick it in the core options, then restart the core. "
"If you just want to play a DS game, try disabling DSi mode in the core options."
),
consoleType
)
) {
}

melonds::dsi_no_firmware_found_exception::dsi_no_firmware_found_exception() noexcept
: bios_exception(
"DSi mode requires a native firmware file, but none could be found.",
"Place your DSi firmware file in your frontend's system folder (any name works), then restart the core. "
"If you want to play a regular DS game, try disabling DSi mode in the core options."
) {
}

melonds::firmware_missing_exception::firmware_missing_exception(std::string_view firmwareName) noexcept
: bios_exception(
fmt::format(
FMT_STRING("The core is set to use the firmware file at \"{}\", but it wasn't there or it couldn't be loaded."),
firmwareName),
fmt::format(
FMT_STRING(
"Place your DSi firmware file in your frontend's system folder, name it \"{}\", then restart the core."
),
firmwareName
)
) {
}

melonds::nds_sysfiles_incomplete_exception::nds_sysfiles_incomplete_exception() noexcept
: bios_exception(
"Booting to the native DS menu requires native DS firmware and BIOS files, "
"but some of them were missing or couldn't be loaded.",
"Place your DS system files in your frontend's system folder, then restart the core. "
"If you want to play a regular DS game, try setting Boot Mode to \"Direct\" "
"and BIOS/Firmware Mode to \"Built-In\" in the core options."
) {
}

melonds::dsi_missing_bios_exception::dsi_missing_bios_exception(melonds::BiosType bios, string_view biosName) noexcept
: bios_exception(
fmt::format(FMT_STRING("DSi mode requires the {} BIOS file, but none was found."), bios),
Expand All @@ -48,9 +117,12 @@ melonds::dsi_no_nand_found_exception::dsi_no_nand_found_exception() noexcept
) {

}

melonds::dsi_nand_missing_exception::dsi_nand_missing_exception(string_view nandName) noexcept
: bios_exception(
fmt::format(FMT_STRING("The core is set to use the NAND file at \"{}\", but it wasn't there or it couldn't be loaded."), nandName),
fmt::format(
FMT_STRING("The core is set to use the NAND file at \"{}\", but it wasn't there or it couldn't be loaded."),
nandName),
fmt::format(
FMT_STRING("Place your NAND file in your frontend's system folder, name it \"{}\", then restart the core."),
nandName
Expand Down
30 changes: 30 additions & 0 deletions src/libretro/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ namespace melonds
using config_exception::config_exception;
};

class dsi_no_firmware_found_exception : public bios_exception {
public:
dsi_no_firmware_found_exception() noexcept;
};

class firmware_missing_exception : public bios_exception {
public:
firmware_missing_exception(std::string_view firmwareName) noexcept;
};

class wrong_firmware_type_exception: public bios_exception {
public:
wrong_firmware_type_exception(
std::string_view firmwareName,
melonds::ConsoleType consoleType,
SPI_Firmware::FirmwareConsoleType firmwareConsoleType
) noexcept;
};

class nds_firmware_not_bootable_exception : public bios_exception {
public:
explicit nds_firmware_not_bootable_exception(std::string_view firmwareName) noexcept;
};


class nds_sysfiles_incomplete_exception : public bios_exception {
public:
explicit nds_sysfiles_incomplete_exception() noexcept;
};

/// Thrown when attempting to load a required BIOS file that is missing.
class dsi_missing_bios_exception : public bios_exception {
public:
Expand Down

0 comments on commit b6e9675

Please sign in to comment.