Skip to content

Commit

Permalink
Do not initialize the screens in the very common case where the user …
Browse files Browse the repository at this point in the history
…has only one payload, etc.
  • Loading branch information
TuxSH committed Jan 26, 2021
1 parent bd2b012 commit 487c2a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions arm9/source/firm.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadF
void loadHomebrewFirm(u32 pressed)
{
char path[10 + 255];
bool found = !pressed ? payloadMenu(path) : findPayload(path, pressed);
bool hasDisplayedMenu = false;
bool found = !pressed ? payloadMenu(path, &hasDisplayedMenu) : findPayload(path, pressed);

if(!found) return;

Expand All @@ -254,10 +255,12 @@ void loadHomebrewFirm(u32 pressed)
else sprintf(absPath, "nand:/rw/luma/%s", path);

char *argv[2] = {absPath, (char *)fbs};
bool wantsScreenInit = (firm->reserved2[0] & 1) != 0;

initScreens();
if(!hasDisplayedMenu && wantsScreenInit)
initScreens(); // Don't init the screens unless we have to, if not already done

launchFirm((firm->reserved2[0] & 1) ? 2 : 1, argv);
launchFirm(wantsScreenInit ? 2 : 1, argv);
}

static inline void mergeSection0(FirmwareType firmType, u32 firmVersion, bool loadFromStorage)
Expand Down
4 changes: 3 additions & 1 deletion arm9/source/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@ bool findPayload(char *path, u32 pressed)
return true;
}

bool payloadMenu(char *path)
bool payloadMenu(char *path, bool *hasDisplayedMenu)
{
DIR dir;

*hasDisplayedMenu = false;
if(f_opendir(&dir, "payloads") != FR_OK) return false;

FILINFO info;
Expand Down Expand Up @@ -189,6 +190,7 @@ bool payloadMenu(char *path)
if(payloadNum != 1)
{
initScreens();
*hasDisplayedMenu = true;

drawString(true, 10, 10, COLOR_TITLE, "Luma3DS chainloader");
drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, "Press A to select, START to quit");
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ u32 getFileSize(const char *path);
bool fileWrite(const void *buffer, const char *path, u32 size);
bool fileDelete(const char *path);
bool findPayload(char *path, u32 pressed);
bool payloadMenu(char *path);
bool payloadMenu(char *path, bool *hasDisplayedMenu);
u32 firmRead(void *dest, u32 firmType);
void findDumpFile(const char *folderPath, char *fileName);

0 comments on commit 487c2a0

Please sign in to comment.