Skip to content

Commit 6691b89

Browse files
committed
Display .md files for Gen/MD ROMs
1 parent 805e782 commit 6691b89

File tree

5 files changed

+79
-28
lines changed

5 files changed

+79
-28
lines changed

quickmenu/arm9/source/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ int dsClassicMenu(void) {
14011401
} else if (extension(filename[0], ".gg")) {
14021402
bnrRomType[0] = 6;
14031403
boxArtType[0] = 2;
1404-
} else if (extension(filename[0], ".gen")) {
1404+
} else if (extension(filename[0], ".gen") || extension(filename[0], ".md")) {
14051405
bnrRomType[0] = 7;
14061406
boxArtType[0] = 2;
14071407
} else if (extension(filename[0], ".smc")) {
@@ -1547,7 +1547,7 @@ int dsClassicMenu(void) {
15471547
} else if (extension(filename[1], ".gg")) {
15481548
bnrRomType[1] = 6;
15491549
boxArtType[1] = 2;
1550-
} else if (extension(filename[1], ".gen")) {
1550+
} else if (extension(filename[1], ".gen") || extension(filename[1], ".md")) {
15511551
bnrRomType[1] = 7;
15521552
boxArtType[1] = 2;
15531553
} else if (extension(filename[1], ".smc")) {
@@ -3265,7 +3265,7 @@ int dsClassicMenu(void) {
32653265
ndsToBoot = "fat:/_nds/TWiLightMenu/emulators/S8DS.nds";
32663266
boostVram = true;
32673267
}
3268-
} else if (extension(filename[ms().secondaryDevice], ".gen")) {
3268+
} else if (extension(filename[ms().secondaryDevice], ".gen") || extension(filename[ms().secondaryDevice], ".md")) {
32693269
bool usePicoDrive = ((isDSiMode() && sdFound() && sys().arm7SCFGLocked())
32703270
|| ms().mdEmulator==2 || (ms().mdEmulator==3 && getFileSize(filename[ms().secondaryDevice].c_str()) > 0x300000));
32713271
ms().launchType[ms().secondaryDevice] = (usePicoDrive ? TWLSettings::EPicoDriveTWLLaunch : TWLSettings::ESDFlashcardLaunch);
@@ -3501,7 +3501,7 @@ int dsClassicMenu(void) {
35013501
if (access(ms().bootstrapFile ? "sd:/_nds/nds-bootstrap-hb-nightly.nds" : "sd:/_nds/nds-bootstrap-hb-release.nds", F_OK) == 0) {
35023502
bool romIsCompressed = false;
35033503
if (romToRamDisk == 0) {
3504-
romIsCompressed = (extension(ROMpath, ".lz77.gen"));
3504+
romIsCompressed = (extension(ROMpath, ".lz77.gen") || extension(ROMpath, ".lz77.md"));
35053505
} else if (romToRamDisk == 1) {
35063506
romIsCompressed = (extension(ROMpath, ".lz77.smc") || extension(ROMpath, ".lz77.sfc"));
35073507
} else if (romToRamDisk == 4) {

romsel_dsimenutheme/arm9/source/fileBrowse.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,42 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<
305305
if (!ms().showHidden && (attrs & ATTR_HIDDEN || (pent->d_name[0] == '.' && strcmp(pent->d_name, "..") != 0)))
306306
continue;
307307

308+
bool emplaceBackDirContent = false;
308309
if (ms().showDirectories) {
309-
if ((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
310+
emplaceBackDirContent =
311+
((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
310312
&& strcmp(pent->d_name, "saves") != 0 && strcmp(pent->d_name, "ramdisks") != 0)
311-
|| nameEndsWith(pent->d_name, extensionList)) {
312-
dirContents.emplace_back(pent->d_name, pent->d_type == DT_DIR, file_count, false);
313-
file_count++;
314-
}
313+
|| nameEndsWith(pent->d_name, extensionList));
315314
} else {
316-
if (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList)) {
317-
dirContents.emplace_back(pent->d_name, false, file_count, false);
318-
file_count++;
315+
emplaceBackDirContent = (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList));
316+
}
317+
if (emplaceBackDirContent) {
318+
if ((pent->d_type != DT_DIR) && extension(pent->d_name, {".md"})) {
319+
FILE* mdFile = fopen(pent->d_name, "rb");
320+
if (mdFile) {
321+
u8 segaEntryPointReversed[4] = {0};
322+
u8 segaEntryPointU8[4] = {0};
323+
u32 segaEntryPoint = 0;
324+
fseek(mdFile, 4, SEEK_SET);
325+
fread(&segaEntryPointReversed, 1, 4, mdFile);
326+
for (int i = 0; i < 4; i++) {
327+
segaEntryPointU8[3-i] = segaEntryPointReversed[i];
328+
}
329+
tonccpy(&segaEntryPoint, segaEntryPointU8, 4);
330+
331+
char segaString[5] = {0};
332+
fseek(mdFile, 0x100, SEEK_SET);
333+
fread(segaString, 1, 4, mdFile);
334+
fclose(mdFile);
335+
336+
if ((strcmp(segaString, "SEGA") != 0) && ((segaEntryPoint < 8) || (segaEntryPoint >= 0x3FFFFF))) {
337+
// Invalid string or entry point found
338+
continue;
339+
}
340+
}
319341
}
342+
dirContents.emplace_back(pent->d_name, ms().showDirectories ? (pent->d_type == DT_DIR) : false, file_count, false);
343+
file_count++;
320344
}
321345
}
322346

@@ -2609,7 +2633,7 @@ void getFileInfo(SwitchState scrn, vector<vector<DirEntry>> dirContents, bool re
26092633
bnrRomType[i] = 5;
26102634
} else if (extension(std_romsel_filename, {".gg"})) {
26112635
bnrRomType[i] = 6;
2612-
} else if (extension(std_romsel_filename, {".gen"})) {
2636+
} else if (extension(std_romsel_filename, {".gen", ".md"})) {
26132637
bnrRomType[i] = 7;
26142638
} else if (extension(std_romsel_filename, {".smc"})) {
26152639
bnrRomType[i] = 8;

romsel_dsimenutheme/arm9/source/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,8 @@ int dsiMenuTheme(void) {
12121212
}
12131213

12141214
if (!ms().secondaryDevice) {
1215-
extensionList.emplace_back(".gen"); // Sega Mega Drive/Genesis
1215+
extensionList.emplace_back(".gen"); // Sega Genesis
1216+
extensionList.emplace_back(".md"); // Sega Mega Drive
12161217
}
12171218

12181219
if (!ms().secondaryDevice || ms().newSnesEmuVer) {
@@ -2364,7 +2365,7 @@ int dsiMenuTheme(void) {
23642365
ndsToBoot = "fat:/_nds/TWiLightMenu/emulators/S8DS.nds";
23652366
boostVram = true;
23662367
}
2367-
} else if (extension(filename, {".gen"})) {
2368+
} else if (extension(filename, {".gen", ".md"})) {
23682369
bool usePicoDrive = ((isDSiMode() && sdFound() && sys().arm7SCFGLocked())
23692370
|| ms().mdEmulator==2 || (ms().mdEmulator==3 && getFileSize(filename.c_str()) > 0x300000));
23702371
ms().launchType[ms().secondaryDevice] = (usePicoDrive ? Launch::EPicoDriveTWLLaunch : Launch::ESDFlashcardLaunch);
@@ -2606,7 +2607,7 @@ int dsiMenuTheme(void) {
26062607
if (access(ms().bootstrapFile ? "sd:/_nds/nds-bootstrap-hb-nightly.nds" : "sd:/_nds/nds-bootstrap-hb-release.nds", F_OK) == 0) {
26072608
bool romIsCompressed = false;
26082609
if (romToRamDisk == 0) {
2609-
romIsCompressed = (extension(ROMpath, {".lz77.gen"}));
2610+
romIsCompressed = (extension(ROMpath, {".lz77.gen", ".lz77.md"}));
26102611
} else if (romToRamDisk == 1) {
26112612
romIsCompressed = (extension(ROMpath, {".lz77.smc", ".lz77.sfc"}));
26122613
} else if (romToRamDisk == 4) {

romsel_r4theme/arm9/source/fileBrowse.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
#include "date.h"
3939

4040
#include "ndsheaderbanner.h"
41+
#include "common/twlmenusettings.h"
4142
#include "common/bootstrapsettings.h"
4243
#include "common/flashcard.h"
4344
#include "common/systemdetails.h"
44-
#include "common/twlmenusettings.h"
45+
#include "common/tonccpy.h"
4546
#include "iconTitle.h"
4647
#include "graphics/fontHandler.h"
4748
#include "graphics/graphics.h"
@@ -196,18 +197,42 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<
196197
if (!ms().showHidden && (attrs & ATTR_HIDDEN || (pent->d_name[0] == '.' && strcmp(pent->d_name, "..") != 0)))
197198
continue;
198199

200+
bool emplaceBackDirContent = false;
199201
if (ms().showDirectories) {
200-
if ((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
202+
emplaceBackDirContent =
203+
((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
201204
&& strcmp(pent->d_name, "saves") != 0 && strcmp(pent->d_name, "ramdisks") != 0)
202-
|| nameEndsWith(pent->d_name, extensionList)) {
203-
dirContents.emplace_back(pent->d_name, pent->d_type == DT_DIR, file_count, false);
204-
file_count++;
205-
}
205+
|| nameEndsWith(pent->d_name, extensionList));
206206
} else {
207-
if (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList)) {
208-
dirContents.emplace_back(pent->d_name, false, file_count, false);
209-
file_count++;
207+
emplaceBackDirContent = (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList));
208+
}
209+
if (emplaceBackDirContent) {
210+
if ((pent->d_type != DT_DIR) && extension(pent->d_name, {".md"})) {
211+
FILE* mdFile = fopen(pent->d_name, "rb");
212+
if (mdFile) {
213+
u8 segaEntryPointReversed[4] = {0};
214+
u8 segaEntryPointU8[4] = {0};
215+
u32 segaEntryPoint = 0;
216+
fseek(mdFile, 4, SEEK_SET);
217+
fread(&segaEntryPointReversed, 1, 4, mdFile);
218+
for (int i = 0; i < 4; i++) {
219+
segaEntryPointU8[3-i] = segaEntryPointReversed[i];
220+
}
221+
tonccpy(&segaEntryPoint, segaEntryPointU8, 4);
222+
223+
char segaString[5] = {0};
224+
fseek(mdFile, 0x100, SEEK_SET);
225+
fread(segaString, 1, 4, mdFile);
226+
fclose(mdFile);
227+
228+
if ((strcmp(segaString, "SEGA") != 0) && ((segaEntryPoint < 8) || (segaEntryPoint >= 0x3FFFFF))) {
229+
// Invalid string or entry point found
230+
continue;
231+
}
232+
}
210233
}
234+
dirContents.emplace_back(pent->d_name, ms().showDirectories ? (pent->d_type == DT_DIR) : false, file_count, false);
235+
file_count++;
211236
}
212237
}
213238

@@ -1104,7 +1129,7 @@ std::string browseForFile(const std::vector<std::string_view> extensionList) {
11041129
bnrRomType = 5;
11051130
} else if (extension(std_romsel_filename, {".gg"})) {
11061131
bnrRomType = 6;
1107-
} else if (extension(std_romsel_filename, {".gen"})) {
1132+
} else if (extension(std_romsel_filename, {".gen", ".md"})) {
11081133
bnrRomType = 7;
11091134
} else if (extension(std_romsel_filename, {".smc", ".sfc"})) {
11101135
bnrRomType = 8;

romsel_r4theme/arm9/source/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,8 @@ int r4Theme(void) {
14031403
}
14041404

14051405
if (!ms().secondaryDevice) {
1406-
extensionList.emplace_back(".gen"); // Sega Mega Drive/Genesis
1406+
extensionList.emplace_back(".gen"); // Sega Genesis
1407+
extensionList.emplace_back(".md"); // Sega Mega Drive
14071408
}
14081409

14091410
if (!ms().secondaryDevice || ms().newSnesEmuVer) {
@@ -2373,7 +2374,7 @@ int r4Theme(void) {
23732374
ndsToBoot = "fat:/_nds/TWiLightMenu/emulators/S8DS.nds";
23742375
boostVram = true;
23752376
}
2376-
} else if (extension(filename, {".gen"})) {
2377+
} else if (extension(filename, {".gen", ".md"})) {
23772378
bool usePicoDrive = ((isDSiMode() && sdFound() && sys().arm7SCFGLocked())
23782379
|| ms().mdEmulator==2 || (ms().mdEmulator==3 && getFileSize(filename.c_str()) > 0x300000));
23792380
ms().launchType[ms().secondaryDevice] = (usePicoDrive ? TWLSettings::EPicoDriveTWLLaunch : TWLSettings::ESDFlashcardLaunch);

0 commit comments

Comments
 (0)