Skip to content

Commit

Permalink
Display .md files for Gen/MD ROMs
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Mar 7, 2024
1 parent 805e782 commit 6691b89
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 28 deletions.
8 changes: 4 additions & 4 deletions quickmenu/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ int dsClassicMenu(void) {
} else if (extension(filename[0], ".gg")) {
bnrRomType[0] = 6;
boxArtType[0] = 2;
} else if (extension(filename[0], ".gen")) {
} else if (extension(filename[0], ".gen") || extension(filename[0], ".md")) {
bnrRomType[0] = 7;
boxArtType[0] = 2;
} else if (extension(filename[0], ".smc")) {
Expand Down Expand Up @@ -1547,7 +1547,7 @@ int dsClassicMenu(void) {
} else if (extension(filename[1], ".gg")) {
bnrRomType[1] = 6;
boxArtType[1] = 2;
} else if (extension(filename[1], ".gen")) {
} else if (extension(filename[1], ".gen") || extension(filename[1], ".md")) {
bnrRomType[1] = 7;
boxArtType[1] = 2;
} else if (extension(filename[1], ".smc")) {
Expand Down Expand Up @@ -3265,7 +3265,7 @@ int dsClassicMenu(void) {
ndsToBoot = "fat:/_nds/TWiLightMenu/emulators/S8DS.nds";
boostVram = true;
}
} else if (extension(filename[ms().secondaryDevice], ".gen")) {
} else if (extension(filename[ms().secondaryDevice], ".gen") || extension(filename[ms().secondaryDevice], ".md")) {
bool usePicoDrive = ((isDSiMode() && sdFound() && sys().arm7SCFGLocked())
|| ms().mdEmulator==2 || (ms().mdEmulator==3 && getFileSize(filename[ms().secondaryDevice].c_str()) > 0x300000));
ms().launchType[ms().secondaryDevice] = (usePicoDrive ? TWLSettings::EPicoDriveTWLLaunch : TWLSettings::ESDFlashcardLaunch);
Expand Down Expand Up @@ -3501,7 +3501,7 @@ int dsClassicMenu(void) {
if (access(ms().bootstrapFile ? "sd:/_nds/nds-bootstrap-hb-nightly.nds" : "sd:/_nds/nds-bootstrap-hb-release.nds", F_OK) == 0) {
bool romIsCompressed = false;
if (romToRamDisk == 0) {
romIsCompressed = (extension(ROMpath, ".lz77.gen"));
romIsCompressed = (extension(ROMpath, ".lz77.gen") || extension(ROMpath, ".lz77.md"));
} else if (romToRamDisk == 1) {
romIsCompressed = (extension(ROMpath, ".lz77.smc") || extension(ROMpath, ".lz77.sfc"));
} else if (romToRamDisk == 4) {
Expand Down
42 changes: 33 additions & 9 deletions romsel_dsimenutheme/arm9/source/fileBrowse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,42 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<
if (!ms().showHidden && (attrs & ATTR_HIDDEN || (pent->d_name[0] == '.' && strcmp(pent->d_name, "..") != 0)))
continue;

bool emplaceBackDirContent = false;
if (ms().showDirectories) {
if ((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
emplaceBackDirContent =
((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
&& strcmp(pent->d_name, "saves") != 0 && strcmp(pent->d_name, "ramdisks") != 0)
|| nameEndsWith(pent->d_name, extensionList)) {
dirContents.emplace_back(pent->d_name, pent->d_type == DT_DIR, file_count, false);
file_count++;
}
|| nameEndsWith(pent->d_name, extensionList));
} else {
if (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList)) {
dirContents.emplace_back(pent->d_name, false, file_count, false);
file_count++;
emplaceBackDirContent = (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList));
}
if (emplaceBackDirContent) {
if ((pent->d_type != DT_DIR) && extension(pent->d_name, {".md"})) {
FILE* mdFile = fopen(pent->d_name, "rb");
if (mdFile) {
u8 segaEntryPointReversed[4] = {0};
u8 segaEntryPointU8[4] = {0};
u32 segaEntryPoint = 0;
fseek(mdFile, 4, SEEK_SET);
fread(&segaEntryPointReversed, 1, 4, mdFile);
for (int i = 0; i < 4; i++) {
segaEntryPointU8[3-i] = segaEntryPointReversed[i];
}
tonccpy(&segaEntryPoint, segaEntryPointU8, 4);

char segaString[5] = {0};
fseek(mdFile, 0x100, SEEK_SET);
fread(segaString, 1, 4, mdFile);
fclose(mdFile);

if ((strcmp(segaString, "SEGA") != 0) && ((segaEntryPoint < 8) || (segaEntryPoint >= 0x3FFFFF))) {
// Invalid string or entry point found
continue;
}
}
}
dirContents.emplace_back(pent->d_name, ms().showDirectories ? (pent->d_type == DT_DIR) : false, file_count, false);
file_count++;
}
}

Expand Down Expand Up @@ -2609,7 +2633,7 @@ void getFileInfo(SwitchState scrn, vector<vector<DirEntry>> dirContents, bool re
bnrRomType[i] = 5;
} else if (extension(std_romsel_filename, {".gg"})) {
bnrRomType[i] = 6;
} else if (extension(std_romsel_filename, {".gen"})) {
} else if (extension(std_romsel_filename, {".gen", ".md"})) {
bnrRomType[i] = 7;
} else if (extension(std_romsel_filename, {".smc"})) {
bnrRomType[i] = 8;
Expand Down
7 changes: 4 additions & 3 deletions romsel_dsimenutheme/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,8 @@ int dsiMenuTheme(void) {
}

if (!ms().secondaryDevice) {
extensionList.emplace_back(".gen"); // Sega Mega Drive/Genesis
extensionList.emplace_back(".gen"); // Sega Genesis
extensionList.emplace_back(".md"); // Sega Mega Drive
}

if (!ms().secondaryDevice || ms().newSnesEmuVer) {
Expand Down Expand Up @@ -2364,7 +2365,7 @@ int dsiMenuTheme(void) {
ndsToBoot = "fat:/_nds/TWiLightMenu/emulators/S8DS.nds";
boostVram = true;
}
} else if (extension(filename, {".gen"})) {
} else if (extension(filename, {".gen", ".md"})) {
bool usePicoDrive = ((isDSiMode() && sdFound() && sys().arm7SCFGLocked())
|| ms().mdEmulator==2 || (ms().mdEmulator==3 && getFileSize(filename.c_str()) > 0x300000));
ms().launchType[ms().secondaryDevice] = (usePicoDrive ? Launch::EPicoDriveTWLLaunch : Launch::ESDFlashcardLaunch);
Expand Down Expand Up @@ -2606,7 +2607,7 @@ int dsiMenuTheme(void) {
if (access(ms().bootstrapFile ? "sd:/_nds/nds-bootstrap-hb-nightly.nds" : "sd:/_nds/nds-bootstrap-hb-release.nds", F_OK) == 0) {
bool romIsCompressed = false;
if (romToRamDisk == 0) {
romIsCompressed = (extension(ROMpath, {".lz77.gen"}));
romIsCompressed = (extension(ROMpath, {".lz77.gen", ".lz77.md"}));
} else if (romToRamDisk == 1) {
romIsCompressed = (extension(ROMpath, {".lz77.smc", ".lz77.sfc"}));
} else if (romToRamDisk == 4) {
Expand Down
45 changes: 35 additions & 10 deletions romsel_r4theme/arm9/source/fileBrowse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
#include "date.h"

#include "ndsheaderbanner.h"
#include "common/twlmenusettings.h"
#include "common/bootstrapsettings.h"
#include "common/flashcard.h"
#include "common/systemdetails.h"
#include "common/twlmenusettings.h"
#include "common/tonccpy.h"
#include "iconTitle.h"
#include "graphics/fontHandler.h"
#include "graphics/graphics.h"
Expand Down Expand Up @@ -196,18 +197,42 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<
if (!ms().showHidden && (attrs & ATTR_HIDDEN || (pent->d_name[0] == '.' && strcmp(pent->d_name, "..") != 0)))
continue;

bool emplaceBackDirContent = false;
if (ms().showDirectories) {
if ((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
emplaceBackDirContent =
((pent->d_type == DT_DIR && strcmp(pent->d_name, ".") != 0 && strcmp(pent->d_name, "_nds") != 0
&& strcmp(pent->d_name, "saves") != 0 && strcmp(pent->d_name, "ramdisks") != 0)
|| nameEndsWith(pent->d_name, extensionList)) {
dirContents.emplace_back(pent->d_name, pent->d_type == DT_DIR, file_count, false);
file_count++;
}
|| nameEndsWith(pent->d_name, extensionList));
} else {
if (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList)) {
dirContents.emplace_back(pent->d_name, false, file_count, false);
file_count++;
emplaceBackDirContent = (pent->d_type != DT_DIR && nameEndsWith(pent->d_name, extensionList));
}
if (emplaceBackDirContent) {
if ((pent->d_type != DT_DIR) && extension(pent->d_name, {".md"})) {
FILE* mdFile = fopen(pent->d_name, "rb");
if (mdFile) {
u8 segaEntryPointReversed[4] = {0};
u8 segaEntryPointU8[4] = {0};
u32 segaEntryPoint = 0;
fseek(mdFile, 4, SEEK_SET);
fread(&segaEntryPointReversed, 1, 4, mdFile);
for (int i = 0; i < 4; i++) {
segaEntryPointU8[3-i] = segaEntryPointReversed[i];
}
tonccpy(&segaEntryPoint, segaEntryPointU8, 4);

char segaString[5] = {0};
fseek(mdFile, 0x100, SEEK_SET);
fread(segaString, 1, 4, mdFile);
fclose(mdFile);

if ((strcmp(segaString, "SEGA") != 0) && ((segaEntryPoint < 8) || (segaEntryPoint >= 0x3FFFFF))) {
// Invalid string or entry point found
continue;
}
}
}
dirContents.emplace_back(pent->d_name, ms().showDirectories ? (pent->d_type == DT_DIR) : false, file_count, false);
file_count++;
}
}

Expand Down Expand Up @@ -1104,7 +1129,7 @@ std::string browseForFile(const std::vector<std::string_view> extensionList) {
bnrRomType = 5;
} else if (extension(std_romsel_filename, {".gg"})) {
bnrRomType = 6;
} else if (extension(std_romsel_filename, {".gen"})) {
} else if (extension(std_romsel_filename, {".gen", ".md"})) {
bnrRomType = 7;
} else if (extension(std_romsel_filename, {".smc", ".sfc"})) {
bnrRomType = 8;
Expand Down
5 changes: 3 additions & 2 deletions romsel_r4theme/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,8 @@ int r4Theme(void) {
}

if (!ms().secondaryDevice) {
extensionList.emplace_back(".gen"); // Sega Mega Drive/Genesis
extensionList.emplace_back(".gen"); // Sega Genesis
extensionList.emplace_back(".md"); // Sega Mega Drive
}

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

0 comments on commit 6691b89

Please sign in to comment.