From 8e07f18eea20b5c5c70aa68490c69fa187b7173c Mon Sep 17 00:00:00 2001 From: Robz8 Date: Thu, 4 Oct 2018 21:40:28 -0600 Subject: [PATCH] Mount flashcard, if supported one is inserted --- arm9/source/driveMenu.cpp | 25 +++++++++++++------------ arm9/source/driveOperations.cpp | 22 +++++++++++++++++----- arm9/source/driveOperations.h | 16 ++++++++++------ arm9/source/main.cpp | 6 +++++- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp index ab81812..a178bfb 100644 --- a/arm9/source/driveMenu.cpp +++ b/arm9/source/driveMenu.cpp @@ -35,17 +35,17 @@ using namespace std; static bool dmTextPrinted = false; static int dmCursorPosition = 0; -static bool sdMounted = false; +static u8 dm_SCFG_MC = 0; void driveMenu (void) { int pressed = 0; int held = 0; - if (isDSiMode()) { - sdMounted = sdFound(); - } - while (true) { + if (isDSiMode() && !pressed) { + flashcardMounted = flashcardMount(); // Try to mount flashcard + } + if (!dmTextPrinted) { consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); if (dmCursorPosition == 0 && isDSiMode()) { @@ -95,6 +95,8 @@ void driveMenu (void) { dmTextPrinted = true; } + + dm_SCFG_MC = REG_SCFG_MC; // Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do do { @@ -107,6 +109,10 @@ void driveMenu (void) { pressed = keysDownRepeat(); held = keysHeld(); swiWaitForVBlank(); + + if (REG_SCFG_MC != dm_SCFG_MC) { + break; + } } while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_A) && !(held & KEY_R)); if ((pressed & KEY_UP) && isDSiMode()) { @@ -130,10 +136,7 @@ void driveMenu (void) { break; } } else { - if (isDSiMode()) { - flashcardMount(); - } - if (flashcardFound()) { + if (flashcardMounted) { dmTextPrinted = false; chdir("fat:/"); screenMode = 1; @@ -144,12 +147,10 @@ void driveMenu (void) { // Unmount/Remount SD card if ((held & KEY_R) && (pressed & KEY_B) && isDSiMode()) { + dmTextPrinted = false; if (sdMounted) { - dmTextPrinted = false; sdUnmount(); - sdMounted = false; } else { - dmTextPrinted = false; sdMounted = sdMount(); } } diff --git a/arm9/source/driveOperations.cpp b/arm9/source/driveOperations.cpp index 3ad994a..0d5ea30 100644 --- a/arm9/source/driveOperations.cpp +++ b/arm9/source/driveOperations.cpp @@ -9,6 +9,9 @@ static sNDSHeader nds; +bool sdMounted = false; +bool flashcardMounted = false; + bool sdFound(void) { if (access("sd:/", F_OK) == 0) { return true; @@ -39,6 +42,7 @@ bool sdMount(void) { void sdUnmount(void) { fatUnmount("sd"); + sdMounted = false; } DLDI_INTERFACE* dldiLoadFromBin (const u8 dldiAddr[]) { @@ -100,8 +104,10 @@ void ShowGameInfo(const char gameid[], const char gamename[]) { iprintf("Game id: %s\nName: %s", gameid, gamename); } -void flashcardMount(void) { - if (!flashcardFound() && REG_SCFG_MC != 0x11) { +bool flashcardMount(void) { + if (flashcardFound()) { + return true; + } else if (REG_SCFG_MC != 0x11) { // Reset Slot-1 to allow reading title name and ID sysSetCardOwner (BUS_OWNER_ARM9); disableSlot1(); @@ -136,10 +142,16 @@ void flashcardMount(void) { // Read a DLDI driver specific to the cart if (!memcmp(gamename, "R4DSULTRA", 9)) { io_dldi_data = dldiLoadFromBin(r4idsn_sd_bin); - fatMountSimple("fat", &io_dldi_data->ioInterface); + return fatMountSimple("fat", &io_dldi_data->ioInterface); } else if (!memcmp(gameid, "YCEP", 4) || !memcmp(gameid, "AHZH", 4)) { io_dldi_data = dldiLoadFromBin(ak2_sd_bin); - fatMountSimple("fat", &io_dldi_data->ioInterface); + return fatMountSimple("fat", &io_dldi_data->ioInterface); } + return false; } -} \ No newline at end of file +} + +void flashcardUnmount(void) { + fatUnmount("fat"); + flashcardMounted = false; +} diff --git a/arm9/source/driveOperations.h b/arm9/source/driveOperations.h index 5107536..0c6faaf 100644 --- a/arm9/source/driveOperations.h +++ b/arm9/source/driveOperations.h @@ -1,11 +1,15 @@ #ifndef FLASHCARD_H #define FLASHCARD_H -bool sdFound(void); -bool flashcardFound(void); -bool bothSDandFlashcard(void); -bool sdMount(void); -void sdUnmount(void); -void flashcardMount(void); +extern bool sdMounted; +extern bool flashcardMounted; + +extern bool sdFound(void); +extern bool flashcardFound(void); +extern bool bothSDandFlashcard(void); +extern bool sdMount(void); +extern void sdUnmount(void); +extern bool flashcardMount(void); +extern void flashcardUnmount(void); #endif //FLASHCARD_H diff --git a/arm9/source/main.cpp b/arm9/source/main.cpp index 612d8e0..236799a 100644 --- a/arm9/source/main.cpp +++ b/arm9/source/main.cpp @@ -30,6 +30,7 @@ #include "nds_loader_arm9.h" #include "driveMenu.h" +#include "driveOperations.h" #include "file_browse.h" #include "gm9i_logo.h" @@ -108,7 +109,10 @@ int main(int argc, char **argv) { stop(); }*/ - fatInitDefault(); + if (isDSiMode()) { + sdMounted = sdMount(); + } + flashcardMounted = flashcardMount(); // Top screen as a console videoSetMode(MODE_0_2D);