Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code for identifying the current DSP ucode #2174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/DSi_DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions src/DSi_DSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Teakra { class Teakra; }
namespace melonDS
{
class DSi;
enum class UCodeID;
class DSi_DSP
{
public:
Expand Down Expand Up @@ -74,6 +75,7 @@ class DSi_DSP
u16 SNDExCnt;

Teakra::Teakra* TeakraCore;
UCodeID CurrentUCodeID;

bool SCFG_RST;

Expand Down
95 changes: 95 additions & 0 deletions src/DSi_DSP_UCodes.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 103 additions & 0 deletions src/DSi_DSP_UCodes.h
Original file line number Diff line number Diff line change
@@ -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
Loading