From 23515b11d60dd17f5b0913f143624b1774205669 Mon Sep 17 00:00:00 2001 From: Robz8 Date: Thu, 4 Oct 2018 22:27:18 -0600 Subject: [PATCH] Unmount flashcard and return to [root] menu, if directory listing of flashcard is shown --- arm9/source/driveMenu.cpp | 9 ++++----- arm9/source/driveMenu.h | 2 ++ arm9/source/driveOperations.cpp | 2 ++ arm9/source/driveOperations.h | 2 ++ arm9/source/file_browse.cpp | 24 ++++++++++++++++++------ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp index 0f9f4b9..b5f4351 100644 --- a/arm9/source/driveMenu.cpp +++ b/arm9/source/driveMenu.cpp @@ -34,8 +34,7 @@ using namespace std; static bool dmTextPrinted = false; -static int dmCursorPosition = 0; -static u8 dm_SCFG_MC = 0; +int dmCursorPosition = 0; void driveMenu (void) { int pressed = 0; @@ -101,8 +100,8 @@ void driveMenu (void) { dmTextPrinted = true; } - - dm_SCFG_MC = REG_SCFG_MC; + + stored_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 { @@ -116,7 +115,7 @@ void driveMenu (void) { held = keysHeld(); swiWaitForVBlank(); - if (REG_SCFG_MC != dm_SCFG_MC) { + if (REG_SCFG_MC != stored_SCFG_MC) { dmTextPrinted = false; break; } diff --git a/arm9/source/driveMenu.h b/arm9/source/driveMenu.h index 2ccd88f..c53434d 100644 --- a/arm9/source/driveMenu.h +++ b/arm9/source/driveMenu.h @@ -4,6 +4,8 @@ #include #include +extern int dmCursorPosition; + extern void driveMenu (void); diff --git a/arm9/source/driveOperations.cpp b/arm9/source/driveOperations.cpp index bf2241e..1fc4a4b 100644 --- a/arm9/source/driveOperations.cpp +++ b/arm9/source/driveOperations.cpp @@ -9,6 +9,8 @@ static sNDSHeader nds; +u8 stored_SCFG_MC = 0; + bool sdMounted = false; bool flashcardMounted = false; diff --git a/arm9/source/driveOperations.h b/arm9/source/driveOperations.h index 0c6faaf..6f24162 100644 --- a/arm9/source/driveOperations.h +++ b/arm9/source/driveOperations.h @@ -1,6 +1,8 @@ #ifndef FLASHCARD_H #define FLASHCARD_H +extern u8 stored_SCFG_MC; + extern bool sdMounted; extern bool flashcardMounted; diff --git a/arm9/source/file_browse.cpp b/arm9/source/file_browse.cpp index bc966ba..ff529e3 100644 --- a/arm9/source/file_browse.cpp +++ b/arm9/source/file_browse.cpp @@ -33,6 +33,8 @@ #include "main.h" #include "date.h" #include "fileOperations.h" +#include "driveMenu.h" +#include "driveOperations.h" #define SCREEN_COLS 32 #define ENTRIES_PER_SCREEN 22 @@ -148,8 +150,15 @@ string browseForFile (void) { getDirectoryContents (dirContents); while (true) { + if (isDSiMode() && !pressed && dmCursorPosition == 1 && REG_SCFG_MC == 0x11) { + if (flashcardMounted) { + flashcardUnmount(); + screenMode = 0; + return "null"; + } + } + consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); - //consoleClear(); DirEntry* entry = &dirContents.at(fileOffset); printf (entry->name.c_str()); printf ("\n"); @@ -157,13 +166,12 @@ string browseForFile (void) { printf ("(dir)"); } else { fileSize = getFileSize(entry->name.c_str()); - iprintf ("%i Bytes", (int)fileSize); + printf ("%i Bytes", (int)fileSize); } - iprintf ("\x1b[23;0H"); + printf ("\x1b[23;0H"); printf (titleName); consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); - //consoleClear(); showDirectoryContents (dirContents, screenOffset); // Clear old cursors @@ -173,18 +181,22 @@ string browseForFile (void) { // Show cursor iprintf ("\x1b[%d;0H*", fileOffset - screenOffset + ENTRIES_START_ROW); - //iconTitleUpdate (dirContents.at(fileOffset).isDirectory,dirContents.at(fileOffset).name.c_str()); + stored_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 { // Move to right side of screen - iprintf ("\x1b[0;27H"); + printf ("\x1b[0;27H"); // Print time printf (RetTime().c_str()); scanKeys(); pressed = keysDownRepeat(); swiWaitForVBlank(); + + if (REG_SCFG_MC != stored_SCFG_MC) { + break; + } } while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_LEFT) && !(pressed & KEY_RIGHT) && !(pressed & KEY_A) && !(pressed & KEY_B));