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
+ }
0 commit comments