Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
* Improve Icon UI. "No Icon" is now a seperate banner so that proper
background can be used for valid icons that have alpha pixels.
* Fix issue that could cause hang if using stage2 menu to load a
homebrew SRL that contains DSi Extended binaries.
  • Loading branch information
ApacheThunder committed May 4, 2024
1 parent 82473f4 commit 54734ae
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 315 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ include $(DEVKITARM)/ds_rules
export TARGET := NTR_Launcher
export TOPDIR := $(CURDIR)

export VERSION_MAJOR := 2
export VERSION_MINOR := 9
export VERSION_MAJOR := 3
export VERSION_MINOR := 1
export VERSTRING := $(VERSION_MAJOR).$(VERSION_MINOR)

# specify a directory which contains the nitro filesystem
Expand Down
6 changes: 6 additions & 0 deletions arm9/common/defaultBanners.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.arm
.global dsCardDefault_bin, hbNoIcon_bin

dsCardDefault_bin: .incbin "../include/dsCardDefault.bin"
hbNoIcon_bin: .incbin "../include/hbNoIcon.bin"

6 changes: 3 additions & 3 deletions arm9/common/nds_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
#include <nds.h>
#include "nds_card.h"

void CardReset (bool properReset) {
void CardReset(bool properReset) {
int i;
sysSetCardOwner (BUS_OWNER_ARM9); // Allow arm9 to access NDS cart
if (isDSiMode()) {
// Reset card slot
disableSlot1();
for (i = 0; i < 15; i++) { swiWaitForVBlank(); }
for (i = 0; i < 25; i++) { swiWaitForVBlank(); }
enableSlot1();
for (i = 0; i < 10; i++) { swiWaitForVBlank(); }
for (i = 0; i < 15; i++) { swiWaitForVBlank(); }

if (!properReset) {
// Dummy command sent after card reset
Expand Down
12 changes: 6 additions & 6 deletions arm9/common/read_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ int cardInit (sNDSHeaderExt* ndsHeader) {
// Reset card slot
if(REG_SCFG_MC != 0x11){
disableSlot1();
for(i = 0; i < 30; i++) { swiWaitForVBlank(); }
for(i = 0; i < 15; i++)swiWaitForVBlank();
}
enableSlot1();
for(i = 0; i < 15; i++) { swiWaitForVBlank(); }
for(i = 0; i < 10; i++)swiWaitForVBlank();
// Dummy command sent after card reset
cardParamCommand (CARD_CMD_DUMMY, 0, CARD_ACTIVATE | CARD_nRESET | CARD_CLK_SLOW | CARD_BLK_SIZE(1) | CARD_DELAY1(0x1FFF) | CARD_DELAY2(0x3F), NULL, 0);
}
Expand Down Expand Up @@ -559,14 +559,14 @@ void cardRead (u32 src, void* dest, bool nandSave) {
// Read header
tonccpy (dest, (u8*)headerData + src, 0x200);
return;
} else if ((src < CARD_SECURE_AREA_OFFSET) && !noSlotCrypto) {
} else if (!noSlotCrypto && (src < CARD_SECURE_AREA_OFFSET)) {
toncset (dest, 0, 0x200);
return;
} else if ((src < CARD_DATA_OFFSET) && !noSlotCrypto) {
} else if (!noSlotCrypto && (src < CARD_DATA_OFFSET)) {
// Read data from secure area
tonccpy (dest, (u8*)secureArea + src - CARD_SECURE_AREA_OFFSET, 0x200);
return;
} else if ((ndsHeader->unitCode != 0) && (src >= ndsHeader->arm9iromOffset) && (src < ndsHeader->arm9iromOffset+CARD_SECURE_AREA_SIZE)) {
} else if (!noSlotCrypto && (ndsHeader->unitCode != 0) && (src >= ndsHeader->arm9iromOffset) && (src < ndsHeader->arm9iromOffset+CARD_SECURE_AREA_SIZE)) {
// Read data from secure area
tonccpy (dest, (u8*)secureArea + src - ndsHeader->arm9iromOffset, 0x200);
return;
Expand All @@ -586,7 +586,7 @@ void cardRead (u32 src, void* dest, bool nandSave) {

cardParamCommand (CARD_CMD_DATA_READ, src, portFlags | CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(1), dest, 0x200/sizeof(u32));

if (src > ndsHeader->romSize && !(nandSave && src >= cardNandRwStart) && !noSlotCrypto)switchToTwlBlowfish(ndsHeader);
if (!noSlotCrypto && (src > ndsHeader->romSize) && !(nandSave && src >= cardNandRwStart))switchToTwlBlowfish(ndsHeader);
}

void cardReadAlt (u32 src, void* dest, size_t size) {
Expand Down
Binary file modified arm9/graphics/hbmenu_banner.bmp
Binary file not shown.
Binary file modified arm9/graphics/hbmenu_banner_cartSelected.bmp
Binary file not shown.
Binary file modified arm9/graphics/hbmenu_banner_noCart.bmp
Binary file not shown.
21 changes: 11 additions & 10 deletions arm9/hbmenu/hbmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ static void DoWait(int waitTime = 30) { for (int i = 0; i < waitTime; i++)swiWai

static void DoCardInit() {
switch (REG_SCFG_MC) {
case 0x10: { enableSlot1(); DoWait(10); }break;
case 0x11: { enableSlot1(); DoWait(10); }break;
case 0x10: { enableSlot1(); DoWait(15); }break;
case 0x11: { enableSlot1(); DoWait(15); }break;
}
// Do cart init stuff to wake cart up. DLDI init may fail otherwise!
CardReset(true);
cardReadHeader((u8*)&ntrHeader);
CardReset(false);
// cardInit(&ntrHeader);
tonccpy(gameTitle, ntrHeader.gameTitle, 12);
// tonccpy(gameCode, ntrHeader.gameCode, 4);
DoWait(25);
// DoWait(25);
}


Expand All @@ -110,10 +111,8 @@ static void InitGUI(void) {
}

static int stop(void) {
while (1) {
scanKeys();
while (!keysDown())swiWaitForVBlank();
}
while (keysDown()) { swiWaitForVBlank(); scanKeys(); }
while (!keysDown()) { swiWaitForVBlank(); scanKeys(); }
return 0;
}

Expand Down Expand Up @@ -180,17 +179,19 @@ static int BrowserUI(tLauncherSettings launchdata) {
argarray.clear();
}
if (cartSelected) {
if (cartInsertedOnBoot)DoCardInit(); // Currently required for bootlaoder to succeed with card init.
// DS-Xtreme does not like running in TWL clock speeds.
// (write function likely goes too fast and semi-bricks hidden sector region randomly when using official launcher)
if (!memcmp(gameTitle, "D!S!XTREME", 9)) {
launchdata.scfgUnlock = 0x00;
launchdata.twlMode = 0x00;
launchdata.twlCLK = 0x00;
launchdata.twlVRAM = 0x00;
cardInit(&ntrHeader);
} else {
if (cartInsertedOnBoot)DoCardInit(); // Currently required for bootlaoder to succeed with card init.
// Give launch soundfx time to finish if card Init already occured.
if (!cartInsertedOnBoot)DoWait(29);
}
// Give launch soundfx time to finish if card Init already occured.
if (!cartInsertedOnBoot)DoWait(29);
runLaunchEngine(launchdata);
}
return stop();
Expand Down
42 changes: 35 additions & 7 deletions arm9/hbmenu/iconTitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ static int bg2, bg3;
static u16 *sprite;
static u16 *sprite2;

extern tNDSBanner dsCardDefault_bin;
extern tNDSBanner hbNoIcon_bin;

static tNDSBanner banner;
static tNDSBanner* cartBanner;

Expand Down Expand Up @@ -162,10 +165,15 @@ void iconTitleInit (void) {

cartBanner = (tNDSBanner*)CartBannerBuffer;

// Load Default Icons.
DC_FlushAll();
dmaCopy(hbNoIcon_bin.icon, sprite, sizeof(hbNoIcon_bin.icon));
dmaCopy(hbNoIcon_bin.palette, SPRITE_PALETTE, sizeof(hbNoIcon_bin.palette));
dmaCopy(dsCardDefault_bin.icon, sprite2, 512);
dmaCopy(dsCardDefault_bin.palette, (u16*)((u32)SPRITE_PALETTE + 0x20), 0x20);

// everything's ready :)
writeRow (1,"=====================", false);
writeRow (2,"==>> Loading ... <<==", false);
writeRow (3,"=====================", false);
writeRow (2," Loading ... ", false);
}


Expand All @@ -180,6 +188,9 @@ void iconTitleUpdate (int isdir, const std::string& name) {
writeRow (2, "[directory]", false);
// icon
clearIcon();
DC_FlushAll();
dmaCopy(hbNoIcon_bin.icon, sprite, sizeof(hbNoIcon_bin.icon));
dmaCopy(hbNoIcon_bin.palette, SPRITE_PALETTE, sizeof(hbNoIcon_bin.palette));
} else {
std::string ndsPath;
if (!argsNdsPath(name, ndsPath)) {
Expand All @@ -198,6 +209,9 @@ void iconTitleUpdate (int isdir, const std::string& name) {
writeRow (2,"(can't open file!)", false);
// icon
clearIcon();
DC_FlushAll();
dmaCopy(hbNoIcon_bin.icon, sprite, sizeof(hbNoIcon_bin.icon));
dmaCopy(hbNoIcon_bin.palette, SPRITE_PALETTE, sizeof(hbNoIcon_bin.palette));
fclose (fp);
return;
}
Expand All @@ -208,6 +222,9 @@ void iconTitleUpdate (int isdir, const std::string& name) {
writeRow (2, "(can't read file!)", false);
// icon
clearIcon();
DC_FlushAll();
dmaCopy(hbNoIcon_bin.icon, sprite, sizeof(hbNoIcon_bin.icon));
dmaCopy(hbNoIcon_bin.palette, SPRITE_PALETTE, sizeof(hbNoIcon_bin.palette));
fclose (fp);
return;
}
Expand All @@ -217,6 +234,9 @@ void iconTitleUpdate (int isdir, const std::string& name) {
writeRow (2, "(no title/icon)", false);
// icon
clearIcon();
DC_FlushAll();
dmaCopy(hbNoIcon_bin.icon, sprite, sizeof(hbNoIcon_bin.icon));
dmaCopy(hbNoIcon_bin.palette, SPRITE_PALETTE, sizeof(hbNoIcon_bin.palette));
fclose (fp);
return;
}
Expand All @@ -226,6 +246,9 @@ void iconTitleUpdate (int isdir, const std::string& name) {
writeRow (2,"(can't read icon/title!)", false);
// icon
clearIcon();
DC_FlushAll();
dmaCopy(hbNoIcon_bin.icon, sprite, sizeof(hbNoIcon_bin.icon));
dmaCopy(hbNoIcon_bin.palette, SPRITE_PALETTE, sizeof(hbNoIcon_bin.palette));
fclose (fp);
return;
}
Expand All @@ -235,10 +258,10 @@ void iconTitleUpdate (int isdir, const std::string& name) {

// turn unicode into ascii (kind of)
// and convert 0x0A into 0x00
char *p = (char*)banner.titles[0];
char *p = (char*)banner.titles[1];
int rowOffset = 1;
int lineReturns = 0;
for (size_t i = 0; i < sizeof(banner.titles[0]); i = i+2) {
for (size_t i = 0; i < sizeof(banner.titles[1]); i = i+2) {
if ((p[i] == 0x0A) || (p[i] == 0xFF)) {
p[i/2] = 0;
lineReturns++;
Expand Down Expand Up @@ -273,21 +296,26 @@ void cartIconUpdate (u32 BannerOffset, bool readExistingBanner) {
case 0x0000: {
clearCartIcon(false);
writeRow (1,"(invalid icon/title!)", true);
DC_FlushAll();
dmaCopy(dsCardDefault_bin.icon, sprite2, 512);
dmaCopy(dsCardDefault_bin.palette, (u16*)((u32)SPRITE_PALETTE + 0x20), 0x20);
return;
}break;
case 0xFFFF: {
clearCartIcon(false);
dmaCopy(dsCardDefault_bin.icon, sprite2, 512);
dmaCopy(dsCardDefault_bin.palette, (u16*)((u32)SPRITE_PALETTE + 0x20), 0x20);
writeRow (1,"(invalid icon/title!)", true);
return;
}break;
default: {
clearCartIcon(false);
// turn unicode into ascii (kind of)
// and convert 0x0A into 0x00
char *p = (char*)cartBanner->titles[0];
char *p = (char*)cartBanner->titles[1];
int rowOffset = 0;
int lineReturns = 0;
for (size_t i = 0; i < sizeof(cartBanner->titles[0]); i = i+2) {
for (size_t i = 0; i < sizeof(cartBanner->titles[1]); i = i+2) {
if ((p[i] == 0x0A) || (p[i] == 0xFF)) {
p[i/2] = 0;
lineReturns++;
Expand Down
Binary file added arm9/include/dsCardDefault.bin
Binary file not shown.
Binary file added arm9/include/hbNoIcon.bin
Binary file not shown.
34 changes: 20 additions & 14 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static char gameCode[5] = {0};
static bool nitroFSMounted = false;
static ALIGN(4) sNDSHeaderExt ntrHeader;

const char* PROGVERSION = "3.0";
const char* PROGVERSION = "3.1";

off_t getFileSize(const char *fileName) {
FILE* fp = fopen(fileName, "rb");
Expand All @@ -75,7 +75,7 @@ void DisplayText(const char* text, bool clear = false, bool noText = false){
if (clear)consoleClear();
printf("--------------------------------\n");
printf("----[NTR Launcher Debug Mode]---\n");
printf("----------[Version: 3.0]--------\n");
printf("----------[Version: 3.1]--------\n");
printf("--------------------------------\n\n");
if (!noText)printf(text);
}
Expand Down Expand Up @@ -114,17 +114,18 @@ bool DoCardInit(bool DebugMode, bool fastBoot) {
case 0x11: { enableSlot1(); DoWait(10); FastBoot = false; }break;
}
// Do cart init stuff to wake cart up. DLDI init may fail otherwise!
if (FastBoot) {
/*if (FastBoot) {
cardInitShort(&ntrHeader);
tonccpy(gameTitle, ntrHeader.gameTitle, 12);
tonccpy(gameCode, ntrHeader.gameCode, 4);
} else {
CardReset(true);
cardReadHeader((u8*)&ndsHeader);
CardReset(false);
tonccpy(gameTitle, ndsHeader.header.gameTitle, 12);
tonccpy(gameCode, ndsHeader.header.gameCode, 4);
}
} else {*/
CardReset(true);
cardReadHeader((u8*)&ndsHeader);
CardReset(false);
tonccpy(gameTitle, ndsHeader.header.gameTitle, 12);
tonccpy(gameCode, ndsHeader.header.gameCode, 4);
// cardInit(&ntrHeader);
// }
if (DebugMode) {
DisplayText("CLR", true, true);
iprintf("Detected Cart Name: %12s \n", gameTitle);
Expand Down Expand Up @@ -177,7 +178,7 @@ int main() {
tonccpy ((u32*)CartHeaderCopy, (u32*)InitialCartHeader, 0x200);

int language = -1;
bool scfgunlock = false;
bool scfgunlock = true;
bool twlmode = false;
bool twlclk = false;
bool twlvram = false;
Expand All @@ -190,9 +191,11 @@ int main() {
bool useNTRSplash = true;
bool healthAndSafety_MSG = true;

bool fatInit = fatMountSimple("sd", get_io_dsisd());
bool fatInit = false;
bool nitroInit = false;

#ifndef _NoFATINIT
fatInit = fatMountSimple("sd", get_io_dsisd());
if (fatInit) {
if(access("sd:/NTR_Launcher", F_OK) != 0)mkdir("sd:/NTR_Launcher", 0777);
nitroInit = MountNitroFS();
Expand Down Expand Up @@ -228,6 +231,7 @@ int main() {
language = ntrlauncher_config.GetInt("NTRLAUNCHER", "LANGUAGE", -1);
}
}
#endif

scanKeys();
swiWaitForVBlank();
Expand All @@ -239,7 +243,7 @@ int main() {
if (!autoBoot)stage2Menu = true;
// if (fastBoot)LaunchData.fastBoot = 0x01;

if (keysDown() & KEY_B) {
if ((keysDown() & KEY_B) && fatInit) {
if (stage2Menu) { stage2Menu = false; } else { stage2Menu = true; }
}

Expand All @@ -251,7 +255,7 @@ int main() {
if ((keysHeld() & KEY_L) && (keysHeld() & KEY_R)) {
debugmode = true;
} else if (keysDown() & KEY_L) {
twlclk = false; twlvram = true; scfgunlock = false; twlmode = false;
twlclk = false; twlvram = false; scfgunlock = false; twlmode = false;
} else if (keysDown() & KEY_R) {
twlclk = true; twlvram = true; scfgunlock = true; twlmode = true;
}
Expand Down Expand Up @@ -302,6 +306,8 @@ int main() {
LaunchData.twlCLK = 0x00;
LaunchData.twlVRAM = 0x00;
LaunchData.twlMode = 0x00;
if (!useAnimatedSplash)SimpleSplashInit();
cardInit(&ntrHeader);
}
while(1) {
// If SCFG_MC is returning as zero/null, this means SCFG_EXT registers are locked on arm9 or user attempted to run this while in NTR mode.
Expand Down
4 changes: 2 additions & 2 deletions ndsbootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ SPECS := specs
ARCH := -mthumb -mthumb-interwork

CFLAGS := -g -Wall -Os \
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer \
-ffast-math \
$(ARCH)

CFLAGS += $(INCLUDE) $(EXTRA_CFLAGS) -DARM7
CFLAGS += $(INCLUDE) $(EXTRA_CFLAGS) -DARM7 -DNO_DLDI

ASFLAGS := -g $(ARCH) $(EXTRA_CFLAGS) $(INCLUDE)
LDFLAGS = -nostartfiles -T $(TOPDIR)/load2.ld -Wl,-g $(ARCH) -Wl,-Map,$(TARGET).map
Expand Down
Loading

0 comments on commit 54734ae

Please sign in to comment.