Skip to content

Commit 7cddfcf

Browse files
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
1 parent 4ae4397 commit 7cddfcf

File tree

5 files changed

+208
-0
lines changed

5 files changed

+208
-0
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_library(core STATIC
2020
DSi_AES.cpp
2121
DSi_Camera.cpp
2222
DSi_DSP.cpp
23+
DSi_DSP_UCodes.cpp
2324
DSi_I2C.cpp
2425
DSi_NAND.cpp
2526
DSi_NDMA.cpp

src/DSi_DSP.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "DSi.h"
2222
#include "DSi_DSP.h"
23+
#include "DSi_DSP_UCodes.h"
2324
#include "FIFO.h"
2425
#include "NDS.h"
2526
#include "Platform.h"
@@ -113,6 +114,7 @@ DSi_DSP::DSi_DSP(melonDS::DSi& dsi) : DSi(dsi)
113114

114115
TeakraCore = new Teakra::Teakra();
115116
SCFG_RST = false;
117+
CurrentUCodeID = UCodeID::UNKNOWN;
116118

117119
// ????
118120
//if (!TeakraCore) return false;
@@ -188,6 +190,11 @@ bool DSi_DSP::IsRstReleased() const
188190
}
189191
void DSi_DSP::SetRstLine(bool release)
190192
{
193+
if (!SCFG_RST && release)
194+
{
195+
CurrentUCodeID = IdentifyUCode(DSi);
196+
}
197+
191198
SCFG_RST = release;
192199
Reset();
193200
DSPTimestamp = DSi.ARM9Timestamp; // only start now!

src/DSi_DSP.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace Teakra { class Teakra; }
3030
namespace melonDS
3131
{
3232
class DSi;
33+
enum class UCodeID;
3334
class DSi_DSP
3435
{
3536
public:
@@ -74,6 +75,7 @@ class DSi_DSP
7475
u16 SNDExCnt;
7576

7677
Teakra::Teakra* TeakraCore;
78+
UCodeID CurrentUCodeID;
7779

7880
bool SCFG_RST;
7981

src/DSi_DSP_UCodes.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2016-2024 melonDS team
3+
4+
This file is part of melonDS.
5+
6+
melonDS is free software: you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License as published by the Free
8+
Software Foundation, either version 3 of the License, or (at your option)
9+
any later version.
10+
11+
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License along
16+
with melonDS. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
#include "DSi.h"
20+
#include "DSi_DSP_UCodes.h"
21+
#include "CRC32.h"
22+
#include "Platform.h"
23+
24+
namespace melonDS
25+
{
26+
using Platform::Log;
27+
using Platform::LogLevel;
28+
29+
// static block of zero'd memory for unmapped DSP memory
30+
static const u8 DSPZeroPage[0x8000] = {};
31+
32+
UCodeID IdentifyUCode(melonDS::DSi& dsi)
33+
{
34+
u32 crc = 0;
35+
36+
// Hash NWRAM B, which contains the DSP program
37+
// The hash should be in the DSP's memory view
38+
for (u32 addr = 0; addr < 0x40000; addr += 0x8000)
39+
{
40+
const u8* ptr = dsi.NWRAMMap_B[2][(addr >> 15) & 0x7];
41+
if (!ptr) ptr = DSPZeroPage;
42+
crc = CRC32(ptr, 0x8000, crc);
43+
}
44+
45+
switch (crc)
46+
{
47+
case 0x7867C94B:
48+
Log(LogLevel::Debug, "Identified AAC Sound App DSP UCode\n");
49+
return UCodeID::AAC_SOUND_APP;
50+
case 0x0CAFEF48:
51+
Log(LogLevel::Debug, "Identified AAC SDK v0 DSP UCode\n");
52+
return UCodeID::AAC_SDK_V0;
53+
case 0xCD2A8B1B:
54+
Log(LogLevel::Debug, "Identified Graphics SDK v0 DSP UCode\n");
55+
return UCodeID::GRAPHICS_SDK_V0;
56+
case 0x7EEE19FE:
57+
Log(LogLevel::Debug, "Identified G711 SDK v1 DSP UCode\n");
58+
return UCodeID::G711_SDK_V1;
59+
case 0x7323B75B:
60+
Log(LogLevel::Debug, "Identified Graphics SDK v1 DSP UCode\n");
61+
return UCodeID::GRAPHICS_SDK_V1;
62+
case 0xBD4B63B6:
63+
Log(LogLevel::Debug, "Identified Graphics SDK v1 Patch DSP UCode\n");
64+
return UCodeID::GRAPHICS_SDK_V1_PATCH;
65+
case 0x6056C6FF:
66+
Log(LogLevel::Debug, "Identified G711 SDK v2 DSP UCode\n");
67+
return UCodeID::G711_SDK_V2;
68+
case 0x448BB6A2:
69+
Log(LogLevel::Debug, "Identified Graphics SDK v2 DSP UCode\n");
70+
return UCodeID::GRAPHICS_SDK_V2;
71+
case 0x2C281DAE:
72+
Log(LogLevel::Debug, "Identified G711 SDK v3 DSP UCode\n");
73+
return UCodeID::G711_SDK_V3;
74+
case 0x63CAEC33:
75+
Log(LogLevel::Debug, "Identified Graphics SDK v3 DSP UCode\n");
76+
return UCodeID::GRAPHICS_SDK_V3;
77+
case 0x2A1D7F94:
78+
Log(LogLevel::Debug, "Identified G711 SDK v4 DSP UCode\n");
79+
return UCodeID::G711_SDK_V4;
80+
case 0x1451EB84:
81+
Log(LogLevel::Debug, "Identified Graphics SDK v4 DSP UCode\n");
82+
return UCodeID::GRAPHICS_SDK_V4;
83+
case 0x4EBEB519:
84+
Log(LogLevel::Debug, "Identified G711 SDK v5 DSP UCode\n");
85+
return UCodeID::G711_SDK_V5;
86+
case 0x2C974FC8:
87+
Log(LogLevel::Debug, "Identified Graphics SDK v5 DSP UCode\n");
88+
return UCodeID::GRAPHICS_SDK_V5;
89+
default:
90+
Log(LogLevel::Debug, "Unknown DSP UCode (CRC = %08X)\n", crc);
91+
return UCodeID::UNKNOWN;
92+
}
93+
}
94+
95+
}

src/DSi_DSP_UCodes.h

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright 2016-2024 melonDS team
3+
4+
This file is part of melonDS.
5+
6+
melonDS is free software: you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License as published by the Free
8+
Software Foundation, either version 3 of the License, or (at your option)
9+
any later version.
10+
11+
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License along
16+
with melonDS. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
19+
#ifndef DSI_DSP_UCODES_H
20+
#define DSI_DSP_UCODES_H
21+
22+
namespace melonDS
23+
{
24+
class DSi;
25+
26+
// DSP ucodes are COFF files embed into the DSi ROM in some fashion
27+
// DSP ucodes all appear to simply be from the DSi's SDK (as evidenced by the build paths in the COFF)
28+
// Presumingly, developers could not actually make their own ucodes, that was reserved for Nintendo
29+
enum class UCodeID
30+
{
31+
// AAC decoder in DSi Sound app
32+
// COFF build timestamp: 8/4/2008
33+
// This appears to be from an extremely early version of the DSi's SDK
34+
// This SDK was presumingly never available to 3rd party developers, as the build timestamp is before the DSi's release
35+
// As such, nothing else appears to use this ucode
36+
AAC_SOUND_APP,
37+
38+
// AAC decoder present in v0 SDK
39+
// COFF build timestamp: 10/21/2008
40+
// At least 1 DSiWare app (Futo Sutando Tsuki - Banbura DX Rajio) is known to contain this
41+
AAC_SDK_V0,
42+
43+
// Graphics ucode present in v0 SDK
44+
// COFF build timestamp: 10/21/2008
45+
// As least 1 DSiWare app (Hobonichi Rosenzu 2010, rev 0) is known to contain this
46+
GRAPHICS_SDK_V0,
47+
48+
// G711 encoder/decoder present in v1 SDK
49+
// COFF build timestamp: 2/13/2009
50+
// Appears to be a replacement for the AAC decoder
51+
G711_SDK_V1,
52+
53+
// Graphics ucode present in v1 SDK
54+
// COFF build timestamp: 2/13/2009
55+
GRAPHICS_SDK_V1,
56+
57+
// Graphics ucode present in v1 SDK
58+
// COFF build timestamp: 4/3/2009
59+
// Appears to be a patch against the previous graphics ucode
60+
// Known to sometimes be present alongside the SDK v1 G711 ucode
61+
GRAPHICS_SDK_V1_PATCH,
62+
63+
// G711 encoder/decoder present in v2 SDK
64+
// COFF build timestamp: 4/8/2009
65+
G711_SDK_V2,
66+
67+
// Graphics ucode present in v2 SDK
68+
// COFF build timestamp: 4/8/2009
69+
GRAPHICS_SDK_V2,
70+
71+
// G711 encoder/decoder present in v3 SDK
72+
// COFF build timestamp: 9/16/2009
73+
G711_SDK_V3,
74+
75+
// Graphics ucode present in v3 SDK
76+
// COFF build timestamp: 9/16/2009
77+
GRAPHICS_SDK_V3,
78+
79+
// G711 encoder/decoder present in v4 SDK
80+
// COFF build timestamp: 11/9/2009
81+
G711_SDK_V4,
82+
83+
// Graphics ucode present in v4 SDK
84+
// COFF build timestamp: 11/9/2009
85+
GRAPHICS_SDK_V4,
86+
87+
// G711 encoder/decoder present in v5 SDK
88+
// COFF build timestamp: 1/13/2010
89+
G711_SDK_V5,
90+
91+
// Graphics ucode present in v5 SDK
92+
// COFF build timestamp: 1/13/2010
93+
GRAPHICS_SDK_V5,
94+
95+
// Unknown ucode...
96+
UNKNOWN = -1,
97+
};
98+
99+
UCodeID IdentifyUCode(melonDS::DSi& dsi);
100+
101+
}
102+
103+
#endif // DSI_DSP_UCODES_H

0 commit comments

Comments
 (0)