|
28 | 28 | #include "ndsheaderbanner.h" |
29 | 29 | #include "gbaswitch.h" |
30 | 30 | #include "common/nds_loader_arm9.h" |
| 31 | +#include "DSpicoLauncher.h" |
31 | 32 | #include "fileBrowse.h" |
32 | 33 | #include "perGameSettings.h" |
33 | 34 | #include "errorScreen.h" |
@@ -1674,7 +1675,101 @@ int akTheme(void) { |
1674 | 1675 |
|
1675 | 1676 | unlaunchRomBoot(argarray[0]); |
1676 | 1677 | } else if (useBackend) { |
1677 | | - if ((((perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap) && !ms().homebrewBootstrap) || !ms().secondaryDevice) || (dsiFeatures() && romUnitCode[cursorPosOnScreen] > 0 && (perGameSettings_dsiMode == -1 ? DEFAULT_DSI_MODE : perGameSettings_dsiMode)) |
| 1678 | + if ((perGameSettings_fcGameLoader == -1 ? (ms().fcGameLoader == TWLSettings::EPicoLoader) : (perGameSettings_fcGameLoader == TWLSettings::EPicoLoader)) && !ms().homebrewBootstrap && ms().secondaryDevice && (dsiFeatures() || romUnitCode[cursorPosOnScreen] < 3)) { |
| 1679 | + std::string path = argarray[0]; |
| 1680 | + std::string savename = replaceAll(filename, typeToReplace, getSavExtension()); |
| 1681 | + std::string ramdiskname = replaceAll(filename, typeToReplace, getImgExtension(perGameSettings_ramDiskNo)); |
| 1682 | + std::string romFolderNoSlash = ms().romfolder[ms().secondaryDevice]; |
| 1683 | + RemoveTrailingSlashes(romFolderNoSlash); |
| 1684 | + std::string savepath = romFolderNoSlash + "/saves/" + savename; |
| 1685 | + std::string ramdiskpath = romFolderNoSlash + "/ramdisks/" + ramdiskname; |
| 1686 | + if (isHomebrew[cursorPosOnScreen]) { |
| 1687 | + // Do nothing |
| 1688 | + } else if (ms().saveLocation == TWLSettings::ETWLMFolder) { |
| 1689 | + std::string twlmSavesFolder = sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/saves" : "fat:/_nds/TWiLightMenu/saves"; |
| 1690 | + mkdir(twlmSavesFolder.c_str(), 0777); |
| 1691 | + savepath = twlmSavesFolder + "/" + savename; |
| 1692 | + } else if (ms().saveLocation == TWLSettings::EGamesFolder) { |
| 1693 | + savepath = romFolderNoSlash + "/" + savename; |
| 1694 | + } else { |
| 1695 | + mkdir("saves", 0777); |
| 1696 | + } |
| 1697 | + |
| 1698 | + if (!isHomebrew[cursorPosOnScreen]) { |
| 1699 | + // Create or expand save if game isn't homebrew |
| 1700 | + u32 orgsavesize = getFileSize(savepath.c_str()); |
| 1701 | + u32 savesize = 524288; // 512KB (default size) |
| 1702 | + |
| 1703 | + u32 gameTidHex = 0; |
| 1704 | + tonccpy(&gameTidHex, gameTid[cursorPosOnScreen], 4); |
| 1705 | + |
| 1706 | + for (int i = 0; i < (int)sizeof(ROMList)/8; i++) { |
| 1707 | + ROMListEntry* curentry = &ROMList[i]; |
| 1708 | + if (gameTidHex == curentry->GameCode) { |
| 1709 | + if (curentry->SaveMemType != 0xFFFFFFFF) savesize = sramlen[curentry->SaveMemType]; |
| 1710 | + break; |
| 1711 | + } |
| 1712 | + } |
| 1713 | + |
| 1714 | + if ((orgsavesize == 0 && savesize > 0) || (orgsavesize < savesize)) { |
| 1715 | + clearText(false); |
| 1716 | + dialogboxHeight = 0; |
| 1717 | + showdialogbox = true; |
| 1718 | + printSmall(false, 0, 74, "Save management", Alignment::center, FontPalette::formTitleText); |
| 1719 | + printSmall(false, 0, 90, (orgsavesize == 0) ? "Creating save file..." : "Expanding save file...", Alignment::center, FontPalette::formText); |
| 1720 | + updateText(false); |
| 1721 | + |
| 1722 | + FILE *pFile = fopen(savepath.c_str(), orgsavesize > 0 ? "r+" : "wb"); |
| 1723 | + if (pFile) { |
| 1724 | + displayDiskIcon(ms().secondaryDevice); |
| 1725 | + fseek(pFile, savesize - 1, SEEK_SET); |
| 1726 | + fputc('\0', pFile); |
| 1727 | + displayDiskIcon(false); |
| 1728 | + fclose(pFile); |
| 1729 | + } |
| 1730 | + clearText(false); |
| 1731 | + printSmall(false, 0, 74, "Save management", Alignment::center, FontPalette::formTitleText); |
| 1732 | + printSmall(false, 0, 90, (orgsavesize == 0) ? "Save file created!" : "Save file expanded!", Alignment::center, FontPalette::formText); |
| 1733 | + updateText(false); |
| 1734 | + for (int i = 0; i < 30; i++) swiWaitForVBlank(); |
| 1735 | + } |
| 1736 | + } |
| 1737 | + |
| 1738 | + if (!isArgv) { |
| 1739 | + ms().romPath[ms().secondaryDevice] = argarray[0]; |
| 1740 | + } |
| 1741 | + ms().launchType[ms().secondaryDevice] = TWLSettings::ESDFlashcardLaunch; |
| 1742 | + ms().previousUsedDevice = ms().secondaryDevice; |
| 1743 | + displayDiskIcon(!sys().isRunFromSD()); |
| 1744 | + ms().saveSettings(); |
| 1745 | + |
| 1746 | + int err = picoLaunchRom(path, savepath); |
| 1747 | + displayDiskIcon(false); |
| 1748 | + |
| 1749 | + char text[32]; |
| 1750 | + snprintf (text, sizeof(text), "Start failed. Error %i", err); |
| 1751 | + clearText(false); |
| 1752 | + dialogboxHeight = (err==1 ? 1 : 0); |
| 1753 | + showdialogbox = true; |
| 1754 | + printSmall(false, 0, 74, "Error!", Alignment::center, FontPalette::formTitleText); |
| 1755 | + printSmall(false, 0, 90, text, Alignment::center, FontPalette::formText); |
| 1756 | + if (err == 1) { |
| 1757 | + printSmall(false, 0, 102, "Pico Loader not found.", Alignment::center, FontPalette::formText); |
| 1758 | + } |
| 1759 | + printSmall(false, 0, (err==1 ? 124 : 108), " Back", Alignment::center, FontPalette::formText); |
| 1760 | + updateText(false); |
| 1761 | + int pressed = 0; |
| 1762 | + do { |
| 1763 | + scanKeys(); |
| 1764 | + pressed = keysDownRepeat(); |
| 1765 | + checkSdEject(); |
| 1766 | + swiWaitForVBlank(); |
| 1767 | + } while (!(pressed & KEY_B)); |
| 1768 | + vector<char *> argarray; |
| 1769 | + argarray.push_back((char*)(sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/akmenu.srldr" : "fat:/_nds/TWiLightMenu/akmenu.srldr")); |
| 1770 | + runNdsFile(argarray[0], argarray.size(), (const char**)&argarray[0], sys().isRunFromSD(), true, false, false, true, true, false, -1); |
| 1771 | + } else |
| 1772 | + if ((((perGameSettings_fcGameLoader == -1 ? (ms().fcGameLoader == TWLSettings::ENdsBootstrap) : (perGameSettings_fcGameLoader == TWLSettings::ENdsBootstrap)) && !ms().homebrewBootstrap) || !ms().secondaryDevice) || (dsiFeatures() && romUnitCode[cursorPosOnScreen] > 0 && (perGameSettings_dsiMode == -1 ? DEFAULT_DSI_MODE : perGameSettings_dsiMode)) |
1678 | 1773 | || (ms().secondaryDevice && !ms().kernelUseable) |
1679 | 1774 | || (romUnitCode[cursorPosOnScreen] == 3 && !ms().homebrewBootstrap)) { |
1680 | 1775 | std::string path = argarray[0]; |
|
0 commit comments