From 93f7433bffe2989068ed35b475496ca8ae06dbdc Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Tue, 9 Oct 2018 08:22:17 -0600 Subject: [PATCH] Show labels of both SD and flashcards --- arm9/source/driveMenu.cpp | 10 +++--- arm9/source/driveOperations.cpp | 55 ++++++++++++++++++++++++++++++--- arm9/source/driveOperations.h | 3 ++ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp index 985cc64..616d97d 100644 --- a/arm9/source/driveMenu.cpp +++ b/arm9/source/driveMenu.cpp @@ -167,11 +167,11 @@ void driveMenu (void) { if (!dmTextPrinted) { consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); if (assignedOp[dmCursorPosition] == 0) { - printf ("[sd:] SDCARD\n"); + iprintf ("[sd:] SDCARD (%s)\n", sdLabel); printf ("(SD FAT)"); } else if (assignedOp[dmCursorPosition] == 1) { - printf ("[fat:] GAMECART\n"); - printf ("(Flashcart FAT)"); + iprintf ("[fat:] FLASHCART (%s)\n", fatLabel); + printf ("(Slot-1 SD FAT)"); } else if (assignedOp[dmCursorPosition] == 2) { printf ("GBA GAMECART\n"); printf ("(GBA Game)"); @@ -209,9 +209,9 @@ void driveMenu (void) { for (int i = 0; i <= maxCursors; i++) { iprintf ("\x1b[%d;1H", i + ENTRIES_START_ROW); if (assignedOp[i] == 0) { - printf ("[sd:] SDCARD"); + iprintf ("[sd:] SDCARD (%s)", sdLabel); } else if (assignedOp[i] == 1) { - printf ("[fat:] GAMECART"); + iprintf ("[fat:] FLASHCART (%s)", fatLabel); } else if (assignedOp[i] == 2) { printf ("GBA GAMECART"); if (gbaFixedValue != 0x96) { diff --git a/arm9/source/driveOperations.cpp b/arm9/source/driveOperations.cpp index ee5a33c..af0e493 100644 --- a/arm9/source/driveOperations.cpp +++ b/arm9/source/driveOperations.cpp @@ -17,6 +17,31 @@ bool nitroMounted = false; bool secondaryDrive = false; // false == SD card, true == Flashcard bool nitroSecondaryDrive = false; // false == SD card, true == Flashcard +char sdLabel[12]; +char fatLabel[12]; + +void fixLabel(bool fat) { + if (fat) { + for (int i = 0; i < 12; i++) { + if (((fatLabel[i] == ' ') && (fatLabel[i+1] == ' ') && (fatLabel[i+2] == ' ')) + || ((fatLabel[i] == ' ') && (fatLabel[i+1] == ' ')) + || (fatLabel[i] == ' ')) { + fatLabel[i] = '\0'; + break; + } + } + } else { + for (int i = 0; i < 12; i++) { + if (((sdLabel[i] == ' ') && (sdLabel[i+1] == ' ') && (sdLabel[i+2] == ' ')) + || ((sdLabel[i] == ' ') && (sdLabel[i+1] == ' ')) + || (sdLabel[i] == ' ')) { + sdLabel[i] = '\0'; + break; + } + } + } +} + bool sdFound(void) { if (access("sd:/", F_OK) == 0) { return true; @@ -42,11 +67,18 @@ bool bothSDandFlashcard(void) { } TWL_CODE bool sdMount(void) { - return fatMountSimple("sd", get_io_dsisd()); + fatMountSimple("sd", get_io_dsisd()); + if (sdFound()) { + fatGetVolumeLabel("sd", sdLabel); + fixLabel(false); + return true; + } + return false; } TWL_CODE void sdUnmount(void) { fatUnmount("sd"); + sdLabel[0] = '\0'; sdMounted = false; } @@ -145,10 +177,16 @@ TWL_CODE bool twl_flashcardMount(void) { // Read a DLDI driver specific to the cart if (!memcmp(gamename, "QMATETRIAL", 9) || !memcmp(gamename, "R4DSULTRA", 9)) { io_dldi_data = dldiLoadFromBin(r4idsn_sd_dldi); - return fatMountSimple("fat", &io_dldi_data->ioInterface); + fatMountSimple("fat", &io_dldi_data->ioInterface); } else if (!memcmp(gameid, "ACEK", 4) || !memcmp(gameid, "YCEP", 4) || !memcmp(gameid, "AHZH", 4)) { io_dldi_data = dldiLoadFromBin(ak2_sd_dldi); - return fatMountSimple("fat", &io_dldi_data->ioInterface); + fatMountSimple("fat", &io_dldi_data->ioInterface); + } + + if (flashcardFound()) { + fatGetVolumeLabel("fat", fatLabel); + fixLabel(true); + return true; } } return false; @@ -156,9 +194,17 @@ TWL_CODE bool twl_flashcardMount(void) { bool flashcardMount(void) { if (flashcardFound()) { + fatGetVolumeLabel("fat", fatLabel); + fixLabel(true); return true; } else if (!isDSiMode()) { - return fatInitDefault(); + fatInitDefault(); + if (flashcardFound()) { + fatGetVolumeLabel("fat", fatLabel); + fixLabel(true); + return true; + } + return false; } else { return twl_flashcardMount(); } @@ -166,5 +212,6 @@ bool flashcardMount(void) { void flashcardUnmount(void) { fatUnmount("fat"); + fatLabel[0] = '\0'; flashcardMounted = false; } diff --git a/arm9/source/driveOperations.h b/arm9/source/driveOperations.h index 1a7fc78..5c9a39f 100644 --- a/arm9/source/driveOperations.h +++ b/arm9/source/driveOperations.h @@ -10,6 +10,9 @@ extern bool nitroMounted; extern bool secondaryDrive; // false == SD card, true == Flashcard extern bool nitroSecondaryDrive; // false == SD card, true == Flashcard +extern char sdLabel[12]; +extern char fatLabel[12]; + extern bool sdFound(void); extern bool flashcardFound(void); extern bool bothSDandFlashcard(void);