From 3d3ca0abf789ff06638859b46ee1eb16a0c35e72 Mon Sep 17 00:00:00 2001 From: Kei <7037851+coderkei@users.noreply.github.com> Date: Fri, 28 Feb 2025 19:34:12 +0000 Subject: [PATCH] Start DSiWare Support - Added DSiWare detection - Start INI Work for DSiWare. PUB and PRV save creation not added yet. - Only modify VRAM if running on a flashcart (resolved Giana Sisters DS regression) - Remove Card DMA configuration to align with nds-bootstrap removing it as a configurable value - Show a message to the user if using akmenu-next for the first time --- .vscode/settings.json | 4 +- arm9/source/dsrom.cpp | 10 +++++ arm9/source/dsrom.h | 5 ++- arm9/source/globalsettings.cpp | 3 -- arm9/source/globalsettings.h | 1 - arm9/source/launcher/NdsBootstrapLauncher.cpp | 37 ++++++++++++++++--- arm9/source/launcher/NdsBootstrapLauncher.h | 1 + arm9/source/launcher/nds_loader_arm9.c | 8 +++- arm9/source/mainwnd.cpp | 9 +---- arm9/source/romlauncher.cpp | 12 ++++-- 10 files changed, 68 insertions(+), 22 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 95ad162..e53ee82 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -53,6 +53,8 @@ "format": "cpp", "span": "cpp", "text_encoding": "cpp", - "variant": "cpp" + "variant": "cpp", + "nds.h": "c", + "maxmod9.h": "c" } } \ No newline at end of file diff --git a/arm9/source/dsrom.cpp b/arm9/source/dsrom.cpp index 45195f6..000280e 100644 --- a/arm9/source/dsrom.cpp +++ b/arm9/source/dsrom.cpp @@ -47,6 +47,10 @@ bool DSRomInfo::loadDSRomInfo(const std::string& filename, bool loadBanner) { return false; } + if (header.unitCode == 0x03) { + _isDSiWare = ETrue; + } + ///////// ROM Header ///////// u16 crc = swiCRC16(0xFFFF, &header, 0x15E); if (crc != header.headerCRC16) // 锟侥硷拷头 CRC 锟斤拷锟襟,诧拷锟斤拷nds锟斤拷戏 @@ -204,6 +208,7 @@ bool DSRomInfo::loadGbaRomInfo(const std::string& filename) { void DSRomInfo::load(void) { if (_isDSRom == EMayBe) loadDSRomInfo(_fileName, true); if (_isGbaRom == EMayBe) loadGbaRomInfo(_fileName); + if (_isDSiWare == EMayBe) loadDSRomInfo(_fileName, true); } tNDSBanner& DSRomInfo::banner(void) { @@ -226,6 +231,11 @@ bool DSRomInfo::isDSRom(void) { return (_isDSRom == ETrue) ? true : false; } +bool DSRomInfo::isDSiWare(void) { + load(); + return (_isDSiWare == ETrue) ? true : false; +} + bool DSRomInfo::isHomebrew(void) { load(); return (_isHomebrew == ETrue) ? true : false; diff --git a/arm9/source/dsrom.h b/arm9/source/dsrom.h index 5fbe3e3..ead5c96 100644 --- a/arm9/source/dsrom.h +++ b/arm9/source/dsrom.h @@ -22,6 +22,7 @@ class DSRomInfo { tNDSBanner _banner; SAVE_INFO_EX _saveInfo; TBool _isDSRom; + TBool _isDSiWare; TBool _isHomebrew; TBool _isGbaRom; std::string _fileName; @@ -35,7 +36,7 @@ class DSRomInfo { public: DSRomInfo() - : _isDSRom(EFalse), _isHomebrew(EFalse), _isGbaRom(EFalse), _extIcon(-1), _romVersion(0) { + : _isDSRom(EFalse), _isDSiWare(EFalse), _isHomebrew(EFalse), _isGbaRom(EFalse), _extIcon(-1), _romVersion(0) { // memcpy(&_banner,unknown_banner_bin,unknown_banner_bin_size); memset(&_banner, 0, sizeof(_banner)); memset(&_saveInfo, 0, sizeof(_saveInfo)); @@ -50,12 +51,14 @@ class DSRomInfo { void setExtIcon(const std::string& aValue); inline bool isExtIcon(void) { return _extIcon >= 0; }; bool isDSRom(void); + bool isDSiWare(void); bool isHomebrew(void); bool isGbaRom(void); DSRomInfo& operator=(const DSRomInfo& src); void MayBeDSRom(const std::string& filename) { _isDSRom = EMayBe; _isHomebrew = EMayBe; + _isDSiWare = EMayBe; _fileName = filename; }; void MayBeGbaRom(const std::string& filename) { diff --git a/arm9/source/globalsettings.cpp b/arm9/source/globalsettings.cpp index a23aa7c..c0c0015 100644 --- a/arm9/source/globalsettings.cpp +++ b/arm9/source/globalsettings.cpp @@ -40,7 +40,6 @@ cGlobalSettings::cGlobalSettings() { saveExt = true; saveDir = false; nightly = false; - cardDma = true; safeMode = false; show12hrClock = false; autorunWithLastRom = false; @@ -72,7 +71,6 @@ void cGlobalSettings::loadSettings() { saveDir = ini.GetInt("system", "savedir", saveDir); nightly = ini.GetInt("system", "nightly", nightly); dma = ini.GetInt("system", "dma", dma); - cardDma = ini.GetInt("system", "carddma", cardDma); sdsave = ini.GetInt("system", "sdsave", sdsave); safeMode = ini.GetInt("system", "safemode", safeMode); show12hrClock = ini.GetInt("system", "Show12hrClock", show12hrClock); @@ -121,7 +119,6 @@ void cGlobalSettings::saveSettings() { ini.SetInt("system", "cheats", cheats); ini.SetInt("system", "softreset", softreset); ini.SetInt("system", "dma", dma); - ini.SetInt("system", "carddma", cardDma); ini.SetInt("system", "sdsave", sdsave); ini.SetInt("system", "safemode", safeMode); ini.SetInt("system", "savedir", saveDir); diff --git a/arm9/source/globalsettings.h b/arm9/source/globalsettings.h index 6c91b7e..70f4dc6 100644 --- a/arm9/source/globalsettings.h +++ b/arm9/source/globalsettings.h @@ -53,7 +53,6 @@ class cGlobalSettings { bool Animation; bool cheats; bool softreset; - bool cardDma; bool sdsave; bool cheatDB; int slot2mode; diff --git a/arm9/source/launcher/NdsBootstrapLauncher.cpp b/arm9/source/launcher/NdsBootstrapLauncher.cpp index 7ada945..fb17c5a 100644 --- a/arm9/source/launcher/NdsBootstrapLauncher.cpp +++ b/arm9/source/launcher/NdsBootstrapLauncher.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -25,6 +26,7 @@ #include "ILauncher.h" #include "NdsBootstrapLauncher.h" #include "nds_loader_arm9.h" +#include "fat_ext.h" bool NdsBootstrapLauncher::prepareCheats() { u32 gameCode, crc32; @@ -67,16 +69,34 @@ cheat_failed: bool NdsBootstrapLauncher::prepareIni() { CIniFile ini; + tDSiHeader header; + char sfnSrl[62]; + char sfnPub[62]; + char sfnPrv[62]; + _romInfo.MayBeDSRom(mRomPath); + bool dsiWare = _romInfo.isDSiWare(); + ini.SetString("NDS-BOOTSTRAP", "NDS_PATH", mRomPath); - ini.SetString("NDS-BOOTSTRAP", "SAV_PATH", mSavePath); - if(gs().cardDma){ - ini.SetInt("NDS-BOOTSTRAP", "CARD_READ_DMA", 1); + // check for DSiWare + if(dsiWare){ + //TODO create pub & prv savwe + #ifdef __DSIMODE__ + fatGetAliasPath("sd:/", mRomPath, sfnSrl); + fatGetAliasPath("sd:/", pubPath, sfnPub); + fatGetAliasPath("sd:/", prvPath, sfnPrv); + ini.SetString("NDS-BOOTSTRAP", "APP_PATH", sfnSrl); + ini.SetString("NDS-BOOTSTRAP", "SAV_PATH", sfnPub); + ini.SetString("NDS-BOOTSTRAP", "PRV_PATH", sfnPrv); + #else + //TODO flashcart + #endif } else{ - ini.SetInt("NDS-BOOTSTRAP", "CARD_READ_DMA", 0); + ini.SetString("NDS-BOOTSTRAP", "SAV_PATH", mSavePath); } - + ini.SaveIniFile("/_nds/nds-bootstrap.ini"); + return true; } @@ -84,7 +104,14 @@ bool NdsBootstrapLauncher::launchRom(std::string romPath, std::string savePath, u32 cheatOffset, u32 cheatSize) { const char ndsBootstrapPath[] = SD_ROOT_0 "/_nds/nds-bootstrap-release.nds"; const char ndsBootstrapPathNightly[] = SD_ROOT_0 "/_nds/nds-bootstrap-nightly.nds"; + const char ndsBootstrapCheck[] = SD_ROOT_0 "/_nds/pagefile.sys"; bool useNightly = false; + + //has the user used nds-bootstrap before? + if(access(ndsBootstrapCheck, F_OK) != 0){ + akui::messageBox(NULL, LANG("nds bootstrap", "firsttimetitle"), LANG("nds bootstrap", "firsttime"), MB_OK); + } + progressWnd().setTipText("Initializing nds-bootstrap..."); progressWnd().show(); progressWnd().setPercent(0); diff --git a/arm9/source/launcher/NdsBootstrapLauncher.h b/arm9/source/launcher/NdsBootstrapLauncher.h index ad3a471..7e0219a 100644 --- a/arm9/source/launcher/NdsBootstrapLauncher.h +++ b/arm9/source/launcher/NdsBootstrapLauncher.h @@ -22,4 +22,5 @@ class NdsBootstrapLauncher : public ILauncher { std::string mRomPath; std::string mSavePath; u32 mFlags; + DSRomInfo _romInfo; }; diff --git a/arm9/source/launcher/nds_loader_arm9.c b/arm9/source/launcher/nds_loader_arm9.c index 613262f..3111edb 100644 --- a/arm9/source/launcher/nds_loader_arm9.c +++ b/arm9/source/launcher/nds_loader_arm9.c @@ -281,8 +281,14 @@ eRunNdsRetCode runNds (const void* loader, u32 loaderSize, u32 cluster, bool ini // Direct CPU access to VRAM bank C VRAM_C_CR = VRAM_ENABLE | VRAM_C_LCD; + //Fix VRAM because for some reason some homebrew screws up without it - memset (LCDC_BANK_C, 0x00, 128 * 1024); + #ifdef __DSIMODE__ + //do nothing because this breaks on DSi/3DS mode + #else + memset (LCDC_BANK_C, 0x00, 128 * 1024); + #endif + // Load the loader/patcher into the correct address vramcpy (LCDC_BANK_C, loader, loaderSize); diff --git a/arm9/source/mainwnd.cpp b/arm9/source/mainwnd.cpp index c2825b2..ab79e4b 100644 --- a/arm9/source/mainwnd.cpp +++ b/arm9/source/mainwnd.cpp @@ -550,10 +550,6 @@ void cMainWnd::setParam(void) { _values.push_back(LANG("switches", "Disable")); _values.push_back(LANG("switches", "Enable")); settingWnd.addSettingItem(LANG("patches", "cheating system"), _values, gs().cheats); - _values.clear(); - _values.push_back(LANG("switches", "Disable")); - _values.push_back(LANG("switches", "Enable")); - settingWnd.addSettingItem(LANG("patches", "carddma"), _values, gs().cardDma); #ifdef __KERNEL_LAUNCHER_SUPPORT__ _values.clear(); _values.push_back("Kernel"); @@ -607,9 +603,8 @@ void cMainWnd::setParam(void) { // page 4: patches gs().cheats = settingWnd.getItemSelection(3, 0); - gs().cardDma = settingWnd.getItemSelection(3, 1); - gs().softreset = settingWnd.getItemSelection(3, 2); - gs().homebrewreset = settingWnd.getItemSelection(3, 3); + gs().softreset = settingWnd.getItemSelection(3, 1); + gs().homebrewreset = settingWnd.getItemSelection(3, 2); // page 5: gba gs().gbaSleepHack = settingWnd.getItemSelection(4, 0); diff --git a/arm9/source/romlauncher.cpp b/arm9/source/romlauncher.cpp index 10e36cc..7c0fd0f 100644 --- a/arm9/source/romlauncher.cpp +++ b/arm9/source/romlauncher.cpp @@ -140,12 +140,15 @@ TLaunchResult launchRom(const std::string& aFullPath, DSRomInfo& aRomInfo, bool std::string saveName; std::string useSavesPath; ILauncher* launcher = nullptr; + bool isDsiWare; if (!aRomInfo.isHomebrew()) { u32 gameCode; memcpy(&gameCode, aRomInfo.saveInfo().gameCode, sizeof(gameCode)); // because alignment bool isBigSave = false; u32 bigSaveSize = 8 * 1024 * 1024; u32 bigSaveMask = 14; + // check for DSiWare + isDsiWare = aRomInfo.isDSiWare(); // reading speed setting std::string disk = aFullPath.substr(0, 5); // bool dma = false, protection = aRomInfo.saveInfo().isProtection(); @@ -209,13 +212,16 @@ TLaunchResult launchRom(const std::string& aFullPath, DSRomInfo& aRomInfo, bool saveManager().updateCustomSaveList(aRomInfo.saveInfo()); } } - if (cSaveManager::initializeSaveFile(useSavesPath, aRomInfo.saveInfo().getSlot(), - SaveSize(st))) { + if(!isDsiWare){ + if (cSaveManager::initializeSaveFile(useSavesPath, aRomInfo.saveInfo().getSlot(), + SaveSize(st))) { flags |= PATCH_SD_SAVE | (SaveMask(st) << PATCH_SAVE_SHIFT); saveManager().saveLastInfo(aFullPath); - } else { + } else { return ELaunchNoFreeSpace; + } } + } __NDSHeader->cardControl13 = 0x00406000 | speed;