From 9cfe9e14457b747449100fdbdef38a6b2ca9e5a7 Mon Sep 17 00:00:00 2001 From: Robz8 Date: Thu, 4 Oct 2018 20:45:16 -0600 Subject: [PATCH] Add feature to unmount/remount the SD card --- arm9/source/driveMenu.cpp | 66 +++++++++++++++++++++++++-------- arm9/source/driveOperations.cpp | 8 ++++ arm9/source/driveOperations.h | 2 + arm9/source/main.cpp | 6 ++- 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp index d4aa415..f4ee3d7 100644 --- a/arm9/source/driveMenu.cpp +++ b/arm9/source/driveMenu.cpp @@ -33,9 +33,16 @@ using namespace std; +static int dmCursorPosition = 0; +static bool sdMounted = false; + void driveMenu (void) { int pressed = 0; - int dmCursorPosition = 0; + int held = 0; + + if (isDSiMode()) { + sdMounted = sdFound(); + } while (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 ("(Flashcart FAT)"); } - iprintf ("\x1b[23;0H"); + iprintf ("\x1b[%i;0H", 23-isDSiMode()); 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); - iprintf ("[root]"); + printf ("[root]"); // Move to 2nd row - iprintf ("\x1b[1;0H"); + printf ("\x1b[1;0H"); // Print line of dashes - iprintf ("--------------------------------"); + printf ("--------------------------------"); // 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()){ - iprintf ("[sd:] SDCARD"); - iprintf ("\x1b[3;1H"); + printf ("[sd:] SDCARD"); + 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 do { // Move to right side of screen - iprintf ("\x1b[0;27H"); + printf ("\x1b[0;27H"); // Print time printf (RetTime().c_str()); scanKeys(); pressed = keysDownRepeat(); + held = keysHeld(); 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_DOWN) && isDSiMode()) dmCursorPosition += 1; @@ -88,9 +112,11 @@ void driveMenu (void) { if (pressed & KEY_A) { if (dmCursorPosition == 0 && isDSiMode()) { - chdir("sd:/"); - screenMode = 1; - break; + if (sdMounted) { + chdir("sd:/"); + screenMode = 1; + break; + } } else { if (isDSiMode()) { 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(); + } + } } } diff --git a/arm9/source/driveOperations.cpp b/arm9/source/driveOperations.cpp index 434fe3a..3ad994a 100644 --- a/arm9/source/driveOperations.cpp +++ b/arm9/source/driveOperations.cpp @@ -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* device; size_t dldiSize; diff --git a/arm9/source/driveOperations.h b/arm9/source/driveOperations.h index 9884d10..5107536 100644 --- a/arm9/source/driveOperations.h +++ b/arm9/source/driveOperations.h @@ -4,6 +4,8 @@ bool sdFound(void); bool flashcardFound(void); bool bothSDandFlashcard(void); +bool sdMount(void); +void sdUnmount(void); void flashcardMount(void); #endif //FLASHCARD_H diff --git a/arm9/source/main.cpp b/arm9/source/main.cpp index c5d41f0..612d8e0 100644 --- a/arm9/source/main.cpp +++ b/arm9/source/main.cpp @@ -102,11 +102,13 @@ int main(int argc, char **argv) { swiWaitForVBlank(); } - if (!fatInitDefault()) { + /*if (!fatInitDefault()) { consoleClear(); iprintf ("fatinitDefault failed!\n"); stop(); - } + }*/ + + fatInitDefault(); // Top screen as a console videoSetMode(MODE_0_2D);