Compare commits

...

3 Commits

Author SHA1 Message Date
CasualPokePlayer 6a0d29b5d4
Merge 7cddfcf018 into 0c5dd28b1c 2024-12-31 14:14:36 -06:00
Nadia Holmquist Pedersen 0c5dd28b1c just case the string length to int to make std::min happy in all cases 2024-12-26 09:17:46 +01:00
CasualPokePlayer 7cddfcf018 Add code for identifying the current DSP ucode
Doesn't do much here, at most it provides some debug info
Lays a very shallow foundation for any potential DSP HLE
2024-10-27 02:58:12 -07:00
6 changed files with 212 additions and 4 deletions

View File

@ -20,6 +20,7 @@ add_library(core STATIC
DSi_AES.cpp
DSi_Camera.cpp
DSi_DSP.cpp
DSi_DSP_UCodes.cpp
DSi_I2C.cpp
DSi_NAND.cpp
DSi_NDMA.cpp

View File

@ -20,6 +20,7 @@
#include "DSi.h"
#include "DSi_DSP.h"
#include "DSi_DSP_UCodes.h"
#include "FIFO.h"
#include "NDS.h"
#include "Platform.h"
@ -113,6 +114,7 @@ DSi_DSP::DSi_DSP(melonDS::DSi& dsi) : DSi(dsi)
TeakraCore = new Teakra::Teakra();
SCFG_RST = false;
CurrentUCodeID = UCodeID::UNKNOWN;
// ????
//if (!TeakraCore) return false;
@ -188,6 +190,11 @@ bool DSi_DSP::IsRstReleased() const
}
void DSi_DSP::SetRstLine(bool release)
{
if (!SCFG_RST && release)
{
CurrentUCodeID = IdentifyUCode(DSi);
}
SCFG_RST = release;
Reset();
DSPTimestamp = DSi.ARM9Timestamp; // only start now!

View File

@ -30,6 +30,7 @@ namespace Teakra { class Teakra; }
namespace melonDS
{
class DSi;
enum class UCodeID;
class DSi_DSP
{
public:
@ -74,6 +75,7 @@ private:
u16 SNDExCnt;
Teakra::Teakra* TeakraCore;
UCodeID CurrentUCodeID;
bool SCFG_RST;

95
src/DSi_DSP_UCodes.cpp Normal file
View File

@ -0,0 +1,95 @@
/*
Copyright 2016-2024 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#include "DSi.h"
#include "DSi_DSP_UCodes.h"
#include "CRC32.h"
#include "Platform.h"
namespace melonDS
{
using Platform::Log;
using Platform::LogLevel;
// static block of zero'd memory for unmapped DSP memory
static const u8 DSPZeroPage[0x8000] = {};
UCodeID IdentifyUCode(melonDS::DSi& dsi)
{
u32 crc = 0;
// Hash NWRAM B, which contains the DSP program
// The hash should be in the DSP's memory view
for (u32 addr = 0; addr < 0x40000; addr += 0x8000)
{
const u8* ptr = dsi.NWRAMMap_B[2][(addr >> 15) & 0x7];
if (!ptr) ptr = DSPZeroPage;
crc = CRC32(ptr, 0x8000, crc);
}
switch (crc)
{
case 0x7867C94B:
Log(LogLevel::Debug, "Identified AAC Sound App DSP UCode\n");
return UCodeID::AAC_SOUND_APP;
case 0x0CAFEF48:
Log(LogLevel::Debug, "Identified AAC SDK v0 DSP UCode\n");
return UCodeID::AAC_SDK_V0;
case 0xCD2A8B1B:
Log(LogLevel::Debug, "Identified Graphics SDK v0 DSP UCode\n");
return UCodeID::GRAPHICS_SDK_V0;
case 0x7EEE19FE:
Log(LogLevel::Debug, "Identified G711 SDK v1 DSP UCode\n");
return UCodeID::G711_SDK_V1;
case 0x7323B75B:
Log(LogLevel::Debug, "Identified Graphics SDK v1 DSP UCode\n");
return UCodeID::GRAPHICS_SDK_V1;
case 0xBD4B63B6:
Log(LogLevel::Debug, "Identified Graphics SDK v1 Patch DSP UCode\n");
return UCodeID::GRAPHICS_SDK_V1_PATCH;
case 0x6056C6FF:
Log(LogLevel::Debug, "Identified G711 SDK v2 DSP UCode\n");
return UCodeID::G711_SDK_V2;
case 0x448BB6A2:
Log(LogLevel::Debug, "Identified Graphics SDK v2 DSP UCode\n");
return UCodeID::GRAPHICS_SDK_V2;
case 0x2C281DAE:
Log(LogLevel::Debug, "Identified G711 SDK v3 DSP UCode\n");
return UCodeID::G711_SDK_V3;
case 0x63CAEC33:
Log(LogLevel::Debug, "Identified Graphics SDK v3 DSP UCode\n");
return UCodeID::GRAPHICS_SDK_V3;
case 0x2A1D7F94:
Log(LogLevel::Debug, "Identified G711 SDK v4 DSP UCode\n");
return UCodeID::G711_SDK_V4;
case 0x1451EB84:
Log(LogLevel::Debug, "Identified Graphics SDK v4 DSP UCode\n");
return UCodeID::GRAPHICS_SDK_V4;
case 0x4EBEB519:
Log(LogLevel::Debug, "Identified G711 SDK v5 DSP UCode\n");
return UCodeID::G711_SDK_V5;
case 0x2C974FC8:
Log(LogLevel::Debug, "Identified Graphics SDK v5 DSP UCode\n");
return UCodeID::GRAPHICS_SDK_V5;
default:
Log(LogLevel::Debug, "Unknown DSP UCode (CRC = %08X)\n", crc);
return UCodeID::UNKNOWN;
}
}
}

103
src/DSi_DSP_UCodes.h Normal file
View File

@ -0,0 +1,103 @@
/*
Copyright 2016-2024 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#ifndef DSI_DSP_UCODES_H
#define DSI_DSP_UCODES_H
namespace melonDS
{
class DSi;
// DSP ucodes are COFF files embed into the DSi ROM in some fashion
// DSP ucodes all appear to simply be from the DSi's SDK (as evidenced by the build paths in the COFF)
// Presumingly, developers could not actually make their own ucodes, that was reserved for Nintendo
enum class UCodeID
{
// AAC decoder in DSi Sound app
// COFF build timestamp: 8/4/2008
// This appears to be from an extremely early version of the DSi's SDK
// This SDK was presumingly never available to 3rd party developers, as the build timestamp is before the DSi's release
// As such, nothing else appears to use this ucode
AAC_SOUND_APP,
// AAC decoder present in v0 SDK
// COFF build timestamp: 10/21/2008
// At least 1 DSiWare app (Futo Sutando Tsuki - Banbura DX Rajio) is known to contain this
AAC_SDK_V0,
// Graphics ucode present in v0 SDK
// COFF build timestamp: 10/21/2008
// As least 1 DSiWare app (Hobonichi Rosenzu 2010, rev 0) is known to contain this
GRAPHICS_SDK_V0,
// G711 encoder/decoder present in v1 SDK
// COFF build timestamp: 2/13/2009
// Appears to be a replacement for the AAC decoder
G711_SDK_V1,
// Graphics ucode present in v1 SDK
// COFF build timestamp: 2/13/2009
GRAPHICS_SDK_V1,
// Graphics ucode present in v1 SDK
// COFF build timestamp: 4/3/2009
// Appears to be a patch against the previous graphics ucode
// Known to sometimes be present alongside the SDK v1 G711 ucode
GRAPHICS_SDK_V1_PATCH,
// G711 encoder/decoder present in v2 SDK
// COFF build timestamp: 4/8/2009
G711_SDK_V2,
// Graphics ucode present in v2 SDK
// COFF build timestamp: 4/8/2009
GRAPHICS_SDK_V2,
// G711 encoder/decoder present in v3 SDK
// COFF build timestamp: 9/16/2009
G711_SDK_V3,
// Graphics ucode present in v3 SDK
// COFF build timestamp: 9/16/2009
GRAPHICS_SDK_V3,
// G711 encoder/decoder present in v4 SDK
// COFF build timestamp: 11/9/2009
G711_SDK_V4,
// Graphics ucode present in v4 SDK
// COFF build timestamp: 11/9/2009
GRAPHICS_SDK_V4,
// G711 encoder/decoder present in v5 SDK
// COFF build timestamp: 1/13/2010
G711_SDK_V5,
// Graphics ucode present in v5 SDK
// COFF build timestamp: 1/13/2010
GRAPHICS_SDK_V5,
// Unknown ucode...
UNKNOWN = -1,
};
UCodeID IdentifyUCode(melonDS::DSi& dsi);
}
#endif // DSI_DSP_UCODES_H

View File

@ -1086,7 +1086,7 @@ std::optional<DSi_NAND::NANDImage> EmuInstance::loadNAND(const std::array<u8, DS
// setting up username
auto username = firmcfg.GetQString("Username");
size_t usernameLength = std::min(username.length(), (qsizetype) 10);
size_t usernameLength = std::min((int) username.length(), 10);
memset(&settings.Nickname, 0, sizeof(settings.Nickname));
memcpy(&settings.Nickname, username.utf16(), usernameLength * sizeof(char16_t));
@ -1102,7 +1102,7 @@ std::optional<DSi_NAND::NANDImage> EmuInstance::loadNAND(const std::array<u8, DS
// setup message
auto message = firmcfg.GetQString("Message");
size_t messageLength = std::min(message.length(), (qsizetype) 26);
size_t messageLength = std::min((int) message.length(), 26);
memset(&settings.Message, 0, sizeof(settings.Message));
memcpy(&settings.Message, message.utf16(), messageLength * sizeof(char16_t));
@ -1673,7 +1673,7 @@ void EmuInstance::customizeFirmware(Firmware& firmware, bool overridesettings) n
auto username = firmcfg.GetQString("Username");
if (!username.isEmpty())
{ // If the frontend defines a username, take it. If not, leave the existing one.
size_t usernameLength = std::min(username.length(), (qsizetype) 10);
size_t usernameLength = std::min((int) username.length(), 10);
currentData.NameLength = usernameLength;
memcpy(currentData.Nickname, username.utf16(), usernameLength * sizeof(char16_t));
}
@ -1708,7 +1708,7 @@ void EmuInstance::customizeFirmware(Firmware& firmware, bool overridesettings) n
auto message = firmcfg.GetQString("Message");
if (!message.isEmpty())
{
size_t messageLength = std::min(message.length(), (qsizetype) 26);
size_t messageLength = std::min((int) message.length(), 26);
currentData.MessageLength = messageLength;
memcpy(currentData.Message, message.data(), messageLength * sizeof(char16_t));
}