diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp new file mode 100644 index 0000000..41f1268 --- /dev/null +++ b/arm9/source/driveMenu.cpp @@ -0,0 +1,86 @@ +/*----------------------------------------------------------------- + Copyright (C) 2005 - 2013 + Michael "Chishm" Chisholm + Dave "WinterMute" Murphy + Claudio "sverx" + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +------------------------------------------------------------------*/ + +#include + +#include "main.h" +#include "date.h" + +#define SCREEN_COLS 32 +#define ENTRIES_PER_SCREEN 22 +#define ENTRIES_START_ROW 2 +#define ENTRY_PAGE_LENGTH 10 + +using namespace std; + +void driveMenu (void) { + int pressed = 0; + int dmCursorPosition = 0; + + while (true) { + consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); + iprintf ("\x1b[23;0H"); + printf (titleName); + + consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); + + iprintf ("[root]"); + + // Move to 2nd row + iprintf ("\x1b[1;0H"); + // Print line of dashes + iprintf ("--------------------------------"); + + // Show cursor + iprintf ("\x1b[%d;0H*", dmCursorPosition + ENTRIES_START_ROW); + + iprintf ("\x1b[2;1H"); + if (isDSiMode()){ + iprintf ("[sd:] SDCARD"); + iprintf ("\x1b[3;1H"); + } + iprintf ("[fat:] GAMECART"); + + // Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do + do { + // Move to right side of screen + iprintf ("\x1b[0;27H"); + // Print time + printf (RetTime().c_str()); + + scanKeys(); + pressed = keysDownRepeat(); + swiWaitForVBlank(); + } while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_A)); + + if (pressed & KEY_UP) dmCursorPosition -= 1; + if (pressed & KEY_DOWN) dmCursorPosition += 1; + + if (dmCursorPosition < 0) dmCursorPosition = 1; // Wrap around to bottom of list + if (dmCursorPosition > 1) dmCursorPosition = 0; // Wrap around to top of list + + if (pressed & KEY_A) { + screenMode = 1; + break; + } + } +} diff --git a/arm9/source/driveMenu.h b/arm9/source/driveMenu.h new file mode 100644 index 0000000..2ccd88f --- /dev/null +++ b/arm9/source/driveMenu.h @@ -0,0 +1,11 @@ +#ifndef DRIVE_MENU_H +#define DRIVE_MENU_H + +#include +#include + +extern void driveMenu (void); + + + +#endif //DRIVE_MENU_H diff --git a/arm9/source/file_browse.cpp b/arm9/source/file_browse.cpp index 5618965..bc966ba 100644 --- a/arm9/source/file_browse.cpp +++ b/arm9/source/file_browse.cpp @@ -30,6 +30,7 @@ #include +#include "main.h" #include "date.h" #include "fileOperations.h" @@ -45,17 +46,11 @@ struct DirEntry { bool isDirectory; } ; -bool nameEndsWith (const string& name, const vector extensionList) { +bool nameEndsWith (const string& name) { if (name.size() == 0) return false; - if (extensionList.size() == 0) return true; - - for (int i = 0; i < (int)extensionList.size(); i++) { - const string ext = extensionList.at(i); - if ( strcasecmp (name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true; - } - return false; + return true; } bool dirEntryPredicate (const DirEntry& lhs, const DirEntry& rhs) { @@ -69,7 +64,7 @@ bool dirEntryPredicate (const DirEntry& lhs, const DirEntry& rhs) { return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0; } -void getDirectoryContents (vector& dirContents, const vector extensionList) { +void getDirectoryContents (vector& dirContents) { struct stat st; dirContents.clear(); @@ -90,7 +85,7 @@ void getDirectoryContents (vector& dirContents, const vector e dirEntry.name = pent->d_name; dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false; - if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) { + if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name))) { dirContents.push_back (dirEntry); } @@ -102,11 +97,6 @@ void getDirectoryContents (vector& dirContents, const vector e sort(dirContents.begin(), dirContents.end(), dirEntryPredicate); } -void getDirectoryContents (vector& dirContents) { - vector extensionList; - getDirectoryContents (dirContents, extensionList); -} - void showDirectoryContents (const vector& dirContents, int startRow) { char path[PATH_MAX]; @@ -148,14 +138,14 @@ void showDirectoryContents (const vector& dirContents, int startRow) { } } -string browseForFile (const vector extensionList) { +string browseForFile (void) { int pressed = 0; int screenOffset = 0; int fileOffset = 0; off_t fileSize = 0; vector dirContents; - getDirectoryContents (dirContents, extensionList); + getDirectoryContents (dirContents); while (true) { consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); @@ -170,7 +160,7 @@ string browseForFile (const vector extensionList) { iprintf ("%i Bytes", (int)fileSize); } iprintf ("\x1b[23;0H"); - printf ("GodMode9i v0.1.0"); + printf (titleName); consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); //consoleClear(); @@ -195,7 +185,8 @@ string browseForFile (const vector extensionList) { scanKeys(); pressed = keysDownRepeat(); swiWaitForVBlank(); - } while (!pressed); + } while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_LEFT) && !(pressed & KEY_RIGHT) + && !(pressed & KEY_A) && !(pressed & KEY_B)); if (pressed & KEY_UP) fileOffset -= 1; if (pressed & KEY_DOWN) fileOffset += 1; @@ -221,11 +212,12 @@ string browseForFile (const vector extensionList) { iprintf("Entering directory\n"); // Enter selected directory chdir (entry->name.c_str()); - getDirectoryContents (dirContents, extensionList); + getDirectoryContents (dirContents); screenOffset = 0; fileOffset = 0; showDirectoryContents (dirContents, screenOffset); } else { + applaunch = true; // Clear the screen iprintf ("\x1b[2J"); // Return the chosen file @@ -234,9 +226,15 @@ string browseForFile (const vector extensionList) { } if (pressed & KEY_B) { + char path[PATH_MAX]; + getcwd(path, PATH_MAX); + if ((strcmp (path, "sd:/") == 0) || (strcmp (path, "fat:/") == 0)) { + screenMode = 0; + return "null"; + } // Go up a directory chdir (".."); - getDirectoryContents (dirContents, extensionList); + getDirectoryContents (dirContents); screenOffset = 0; fileOffset = 0; showDirectoryContents (dirContents, screenOffset); diff --git a/arm9/source/file_browse.h b/arm9/source/file_browse.h index d811c40..58993a7 100644 --- a/arm9/source/file_browse.h +++ b/arm9/source/file_browse.h @@ -25,7 +25,7 @@ #include #include -std::string browseForFile (const std::vector extensionList); +std::string browseForFile (void); diff --git a/arm9/source/main.cpp b/arm9/source/main.cpp index d79d767..a65be89 100644 --- a/arm9/source/main.cpp +++ b/arm9/source/main.cpp @@ -29,10 +29,17 @@ #include #include "nds_loader_arm9.h" +#include "driveMenu.h" #include "file_browse.h" //#include "iconTitle.h" +char titleName[32]; + +int screenMode = 0; + +bool applaunch = false; + using namespace std; //--------------------------------------------------------------------------------- @@ -59,6 +66,8 @@ int main(int argc, char **argv) { std::string filename; //iconTitleInit(); + + snprintf(titleName, sizeof(titleName), "GodMode9i v%i.%i.%i", 0, 1, 0); // Subscreen as a console videoSetMode(MODE_0_2D); @@ -74,69 +83,68 @@ int main(int argc, char **argv) { keysSetRepeat(25,5); - vector extensionList; - extensionList.push_back(".nds"); - extensionList.push_back(".firm"); - //extensionList.push_back(".argv"); - - chdir("/nds"); - while(1) { - filename = browseForFile(extensionList); + if (screenMode == 0) { + driveMenu(); + } else { + filename = browseForFile(); + } - // Construct a command line - getcwd (filePath, PATH_MAX); - pathLen = strlen (filePath); - vector argarray; + if (applaunch) { + // Construct a command line + getcwd (filePath, PATH_MAX); + pathLen = strlen (filePath); + vector argarray; - if ( strcasecmp (filename.c_str() + filename.size() - 5, ".argv") == 0) { + if ( strcasecmp (filename.c_str() + filename.size() - 5, ".argv") == 0) { - FILE *argfile = fopen(filename.c_str(),"rb"); - char str[PATH_MAX], *pstr; - const char seps[]= "\n\r\t "; + FILE *argfile = fopen(filename.c_str(),"rb"); + char str[PATH_MAX], *pstr; + const char seps[]= "\n\r\t "; - while( fgets(str, PATH_MAX, argfile) ) { - // Find comment and end string there - if( (pstr = strchr(str, '#')) ) - *pstr= '\0'; + while( fgets(str, PATH_MAX, argfile) ) { + // Find comment and end string there + if( (pstr = strchr(str, '#')) ) + *pstr= '\0'; - // Tokenize arguments - pstr= strtok(str, seps); + // Tokenize arguments + pstr= strtok(str, seps); - while( pstr != NULL ) { - argarray.push_back(strdup(pstr)); - pstr= strtok(NULL, seps); + while( pstr != NULL ) { + argarray.push_back(strdup(pstr)); + pstr= strtok(NULL, seps); + } } + fclose(argfile); + filename = argarray.at(0); + } else { + argarray.push_back(strdup(filename.c_str())); } - fclose(argfile); - filename = argarray.at(0); - } else { - argarray.push_back(strdup(filename.c_str())); - } - if ( strcasecmp (filename.c_str() + filename.size() - 4, ".nds") != 0 || argarray.size() == 0 ) { - iprintf("no nds file specified\n"); - } else { - char *name = argarray.at(0); - strcpy (filePath + pathLen, name); - free(argarray.at(0)); - argarray.at(0) = filePath; - iprintf ("Running %s with %d parameters\n", argarray[0], argarray.size()); - int err = runNdsFile (argarray[0], argarray.size(), (const char **)&argarray[0]); - iprintf ("Start failed. Error %i\n", err); + if ( strcasecmp (filename.c_str() + filename.size() - 4, ".nds") != 0 || argarray.size() == 0 ) { + iprintf("no nds file specified\n"); + } else { + char *name = argarray.at(0); + strcpy (filePath + pathLen, name); + free(argarray.at(0)); + argarray.at(0) = filePath; + iprintf ("Running %s with %d parameters\n", argarray[0], argarray.size()); + int err = runNdsFile (argarray[0], argarray.size(), (const char **)&argarray[0]); + iprintf ("Start failed. Error %i\n", err); - } + } - while(argarray.size() !=0 ) { - free(argarray.at(0)); - argarray.erase(argarray.begin()); - } + while(argarray.size() !=0 ) { + free(argarray.at(0)); + argarray.erase(argarray.begin()); + } - while (1) { - swiWaitForVBlank(); - scanKeys(); - if (!(keysHeld() & KEY_A)) break; + while (1) { + swiWaitForVBlank(); + scanKeys(); + if (!(keysHeld() & KEY_A)) break; + } } } diff --git a/arm9/source/main.h b/arm9/source/main.h new file mode 100644 index 0000000..aa79e53 --- /dev/null +++ b/arm9/source/main.h @@ -0,0 +1,12 @@ +#ifndef MAIN_H +#define MAIN_H + +extern char titleName[32]; + +extern int screenMode; + +extern bool applaunch; + + + +#endif //MAIN_H