Add feature to unmount/remount the SD card

This commit is contained in:
Robz8 2018-10-04 20:45:16 -06:00
parent 78e96a571f
commit 9cfe9e1445
4 changed files with 65 additions and 17 deletions

View File

@ -33,9 +33,16 @@
using namespace std; using namespace std;
static int dmCursorPosition = 0;
static bool sdMounted = false;
void driveMenu (void) { void driveMenu (void) {
int pressed = 0; int pressed = 0;
int dmCursorPosition = 0; int held = 0;
if (isDSiMode()) {
sdMounted = sdFound();
}
while (true) { while (true) {
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
@ -46,39 +53,56 @@ void driveMenu (void) {
printf ("[fat:] GAMECART\n"); printf ("[fat:] GAMECART\n");
printf ("(Flashcart FAT)"); printf ("(Flashcart FAT)");
} }
iprintf ("\x1b[23;0H"); iprintf ("\x1b[%i;0H", 23-isDSiMode());
printf (titleName); printf (titleName);
if (isDSiMode()) {
printf ("\x1b[23;0H");
if (sdMounted) {
printf ("R+B - Unmount SD card");
} else {
printf ("R+B - Remount SD card");
}
}
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true);
iprintf ("[root]"); printf ("[root]");
// Move to 2nd row // Move to 2nd row
iprintf ("\x1b[1;0H"); printf ("\x1b[1;0H");
// Print line of dashes // Print line of dashes
iprintf ("--------------------------------"); printf ("--------------------------------");
// Show cursor // Show cursor
iprintf ("\x1b[%d;0H*", dmCursorPosition + ENTRIES_START_ROW); printf ("\x1b[%d;0H*", dmCursorPosition + ENTRIES_START_ROW);
iprintf ("\x1b[2;1H"); printf ("\x1b[2;1H");
if (isDSiMode()){ if (isDSiMode()){
iprintf ("[sd:] SDCARD"); printf ("[sd:] SDCARD");
iprintf ("\x1b[3;1H"); if (!sdMounted) {
printf ("\x1b[2;29H");
printf ("[x]");
}
printf ("\x1b[3;1H");
}
printf ("[fat:] GAMECART");
if (!flashcardFound()) {
iprintf ("\x1b[%i;29H", 2+isDSiMode());
printf ("[x]");
} }
iprintf ("[fat:] GAMECART");
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do // Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do { do {
// Move to right side of screen // Move to right side of screen
iprintf ("\x1b[0;27H"); printf ("\x1b[0;27H");
// Print time // Print time
printf (RetTime().c_str()); printf (RetTime().c_str());
scanKeys(); scanKeys();
pressed = keysDownRepeat(); pressed = keysDownRepeat();
held = keysHeld();
swiWaitForVBlank(); swiWaitForVBlank();
} while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_A)); } while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_A) && !(held & KEY_R));
if ((pressed & KEY_UP) && isDSiMode()) dmCursorPosition -= 1; if ((pressed & KEY_UP) && isDSiMode()) dmCursorPosition -= 1;
if ((pressed & KEY_DOWN) && isDSiMode()) dmCursorPosition += 1; if ((pressed & KEY_DOWN) && isDSiMode()) dmCursorPosition += 1;
@ -88,9 +112,11 @@ void driveMenu (void) {
if (pressed & KEY_A) { if (pressed & KEY_A) {
if (dmCursorPosition == 0 && isDSiMode()) { if (dmCursorPosition == 0 && isDSiMode()) {
chdir("sd:/"); if (sdMounted) {
screenMode = 1; chdir("sd:/");
break; screenMode = 1;
break;
}
} else { } else {
if (isDSiMode()) { if (isDSiMode()) {
flashcardMount(); flashcardMount();
@ -102,5 +128,15 @@ void driveMenu (void) {
} }
} }
} }
// Unmount/Remount SD card
if ((held & KEY_R) && (pressed & KEY_B) && isDSiMode()) {
if (sdMounted) {
sdUnmount();
sdMounted = false;
} else {
sdMounted = sdMount();
}
}
} }
} }

View File

@ -33,6 +33,14 @@ bool bothSDandFlashcard(void) {
} }
} }
bool sdMount(void) {
return fatMountSimple("sd", get_io_dsisd());
}
void sdUnmount(void) {
fatUnmount("sd");
}
DLDI_INTERFACE* dldiLoadFromBin (const u8 dldiAddr[]) { DLDI_INTERFACE* dldiLoadFromBin (const u8 dldiAddr[]) {
DLDI_INTERFACE* device; DLDI_INTERFACE* device;
size_t dldiSize; size_t dldiSize;

View File

@ -4,6 +4,8 @@
bool sdFound(void); bool sdFound(void);
bool flashcardFound(void); bool flashcardFound(void);
bool bothSDandFlashcard(void); bool bothSDandFlashcard(void);
bool sdMount(void);
void sdUnmount(void);
void flashcardMount(void); void flashcardMount(void);
#endif //FLASHCARD_H #endif //FLASHCARD_H

View File

@ -102,11 +102,13 @@ int main(int argc, char **argv) {
swiWaitForVBlank(); swiWaitForVBlank();
} }
if (!fatInitDefault()) { /*if (!fatInitDefault()) {
consoleClear(); consoleClear();
iprintf ("fatinitDefault failed!\n"); iprintf ("fatinitDefault failed!\n");
stop(); stop();
} }*/
fatInitDefault();
// Top screen as a console // Top screen as a console
videoSetMode(MODE_0_2D); videoSetMode(MODE_0_2D);