Mount flashcard, if supported one is inserted

This commit is contained in:
Robz8 2018-10-04 21:40:28 -06:00
parent 0a3d3b5e13
commit 8e07f18eea
4 changed files with 45 additions and 24 deletions

View File

@ -35,17 +35,17 @@ using namespace std;
static bool dmTextPrinted = false; static bool dmTextPrinted = false;
static int dmCursorPosition = 0; static int dmCursorPosition = 0;
static bool sdMounted = false; static u8 dm_SCFG_MC = 0;
void driveMenu (void) { void driveMenu (void) {
int pressed = 0; int pressed = 0;
int held = 0; int held = 0;
if (isDSiMode()) { while (true) {
sdMounted = sdFound(); if (isDSiMode() && !pressed) {
flashcardMounted = flashcardMount(); // Try to mount flashcard
} }
while (true) {
if (!dmTextPrinted) { if (!dmTextPrinted) {
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
if (dmCursorPosition == 0 && isDSiMode()) { if (dmCursorPosition == 0 && isDSiMode()) {
@ -96,6 +96,8 @@ void driveMenu (void) {
dmTextPrinted = true; 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 // 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
@ -107,6 +109,10 @@ void driveMenu (void) {
pressed = keysDownRepeat(); pressed = keysDownRepeat();
held = keysHeld(); held = keysHeld();
swiWaitForVBlank(); swiWaitForVBlank();
if (REG_SCFG_MC != dm_SCFG_MC) {
break;
}
} while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_A) && !(held & KEY_R)); } while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_A) && !(held & KEY_R));
if ((pressed & KEY_UP) && isDSiMode()) { if ((pressed & KEY_UP) && isDSiMode()) {
@ -130,10 +136,7 @@ void driveMenu (void) {
break; break;
} }
} else { } else {
if (isDSiMode()) { if (flashcardMounted) {
flashcardMount();
}
if (flashcardFound()) {
dmTextPrinted = false; dmTextPrinted = false;
chdir("fat:/"); chdir("fat:/");
screenMode = 1; screenMode = 1;
@ -144,12 +147,10 @@ void driveMenu (void) {
// Unmount/Remount SD card // Unmount/Remount SD card
if ((held & KEY_R) && (pressed & KEY_B) && isDSiMode()) { if ((held & KEY_R) && (pressed & KEY_B) && isDSiMode()) {
dmTextPrinted = false;
if (sdMounted) { if (sdMounted) {
dmTextPrinted = false;
sdUnmount(); sdUnmount();
sdMounted = false;
} else { } else {
dmTextPrinted = false;
sdMounted = sdMount(); sdMounted = sdMount();
} }
} }

View File

@ -9,6 +9,9 @@
static sNDSHeader nds; static sNDSHeader nds;
bool sdMounted = false;
bool flashcardMounted = false;
bool sdFound(void) { bool sdFound(void) {
if (access("sd:/", F_OK) == 0) { if (access("sd:/", F_OK) == 0) {
return true; return true;
@ -39,6 +42,7 @@ bool sdMount(void) {
void sdUnmount(void) { void sdUnmount(void) {
fatUnmount("sd"); fatUnmount("sd");
sdMounted = false;
} }
DLDI_INTERFACE* dldiLoadFromBin (const u8 dldiAddr[]) { 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); iprintf("Game id: %s\nName: %s", gameid, gamename);
} }
void flashcardMount(void) { bool flashcardMount(void) {
if (!flashcardFound() && REG_SCFG_MC != 0x11) { if (flashcardFound()) {
return true;
} else if (REG_SCFG_MC != 0x11) {
// Reset Slot-1 to allow reading title name and ID // Reset Slot-1 to allow reading title name and ID
sysSetCardOwner (BUS_OWNER_ARM9); sysSetCardOwner (BUS_OWNER_ARM9);
disableSlot1(); disableSlot1();
@ -136,10 +142,16 @@ void flashcardMount(void) {
// Read a DLDI driver specific to the cart // Read a DLDI driver specific to the cart
if (!memcmp(gamename, "R4DSULTRA", 9)) { if (!memcmp(gamename, "R4DSULTRA", 9)) {
io_dldi_data = dldiLoadFromBin(r4idsn_sd_bin); 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)) { } else if (!memcmp(gameid, "YCEP", 4) || !memcmp(gameid, "AHZH", 4)) {
io_dldi_data = dldiLoadFromBin(ak2_sd_bin); io_dldi_data = dldiLoadFromBin(ak2_sd_bin);
fatMountSimple("fat", &io_dldi_data->ioInterface); return fatMountSimple("fat", &io_dldi_data->ioInterface);
} }
return false;
} }
} }
void flashcardUnmount(void) {
fatUnmount("fat");
flashcardMounted = false;
}

View File

@ -1,11 +1,15 @@
#ifndef FLASHCARD_H #ifndef FLASHCARD_H
#define FLASHCARD_H #define FLASHCARD_H
bool sdFound(void); extern bool sdMounted;
bool flashcardFound(void); extern bool flashcardMounted;
bool bothSDandFlashcard(void);
bool sdMount(void); extern bool sdFound(void);
void sdUnmount(void); extern bool flashcardFound(void);
void flashcardMount(void); extern bool bothSDandFlashcard(void);
extern bool sdMount(void);
extern void sdUnmount(void);
extern bool flashcardMount(void);
extern void flashcardUnmount(void);
#endif //FLASHCARD_H #endif //FLASHCARD_H

View File

@ -30,6 +30,7 @@
#include "nds_loader_arm9.h" #include "nds_loader_arm9.h"
#include "driveMenu.h" #include "driveMenu.h"
#include "driveOperations.h"
#include "file_browse.h" #include "file_browse.h"
#include "gm9i_logo.h" #include "gm9i_logo.h"
@ -108,7 +109,10 @@ int main(int argc, char **argv) {
stop(); stop();
}*/ }*/
fatInitDefault(); if (isDSiMode()) {
sdMounted = sdMount();
}
flashcardMounted = flashcardMount();
// Top screen as a console // Top screen as a console
videoSetMode(MODE_0_2D); videoSetMode(MODE_0_2D);