Skip to content

Commit

Permalink
Merge 3DS version into DSi version.
Browse files Browse the repository at this point in the history
The 3DS branch will be retired. The DSi branch is now the default. The
animated bootsplash has been integrated and is off by default. If you
intend to use on 3DS, enable the splash via the NTR_Launcher.ini file.
  • Loading branch information
ApacheThunder committed Apr 5, 2020
1 parent 33b0918 commit 77161eb
Show file tree
Hide file tree
Showing 251 changed files with 3,141 additions and 99 deletions.
48 changes: 23 additions & 25 deletions BootLoader/source/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,20 @@ static void my_readUserSettings(tNDSHeader* ndsHeader) {
short calc2CRC = swiCRC16(0xFFFF, &slot2, sizeof(PERSONAL_DATA));

// Bail out if neither slot is valid
if (calc1CRC != slot1CRC && calc2CRC != slot2CRC) {
return;
}
if (calc1CRC != slot1CRC && calc2CRC != slot2CRC) { return; }

// If both slots are valid pick the most recent
if (calc1CRC == slot1CRC && calc2CRC == slot2CRC) {
currentSettings = (slot2count == ((slot1count + 1) & 0x7f) ? &slot2 : &slot1); //if ((slot1count & 0x7F) == ((slot2count + 1) & 0x7F)) {
} else {
if (calc2CRC == slot2CRC) {
currentSettings = &slot2;
}
if (calc2CRC == slot2CRC) { currentSettings = &slot2; }
}

PERSONAL_DATA* personalData = (PERSONAL_DATA*)((u32)__NDSHeader - (u32)ndsHeader + (u32)PersonalData); //(u8*)((u32)ndsHeader - 0x180)

tonccpy(PersonalData, currentSettings, sizeof(PERSONAL_DATA));

if (useTwlCfg && (language == 0xFF || language == -1)) {
language = twlCfgLang;
}
if (useTwlCfg && (language == 0xFF || language == -1)) { language = twlCfgLang; }

if (language >= 0 && language <= 7) {
// Change language
Expand Down Expand Up @@ -428,15 +422,13 @@ static void NDSTouchscreenMode(void) {
}

// SDK 5
static bool ROMsupportsDsiMode(const tNDSHeader* ndsHeader) {
return (ndsHeader->unitCode > 0);
}
static bool ROMsupportsDSiMode(const tNDSHeader* ndsHeader) { return (ndsHeader->unitCode > 0); }

// SDK 5
// static bool ROMisDsiEnhanced(const tNDSHeader* ndsHeader) { return (ndsHeader->unitCode == 0x02); }
static bool ROMisDSiEnhanced(const tNDSHeader* ndsHeader) { return (ndsHeader->unitCode == 0x02); }

// SDK 5
// static bool ROMisDsiExclusive(const tNDSHeader* ndsHeader) { return (ndsHeader->unitCode == 0x03); }
static bool ROMisDSiExclusive(const tNDSHeader* ndsHeader) { return (ndsHeader->unitCode == 0x03); }

int arm7_loadBinary (const tDSiHeader* dsiHeaderTemp) {
u32 errorCode;
Expand Down Expand Up @@ -601,7 +593,7 @@ void fixDSBrowser(void) {


static void setMemoryAddress(const tNDSHeader* ndsHeader) {
if (ROMsupportsDsiMode(ndsHeader)) {
if (ROMsupportsDSiMode(ndsHeader)) {
// u8* deviceListAddr = (u8*)((u8*)0x02FFE1D4);
// tonccpy(deviceListAddr, deviceList_bin, deviceList_bin_len);

Expand Down Expand Up @@ -659,15 +651,23 @@ void arm7_main (void) {

// Load the NDS file
errorCode = arm7_loadBinary(dsiHeaderTemp);
if (errorCode) {
debugOutput(errorCode);
}
if (errorCode) { debugOutput(errorCode); }

// Override some settings depending on if DSi Enhanced cart or DSi Exclusive cart is inserted
if (ROMisDSiEnhanced(&dsiHeaderTemp->ndshdr)) { extendRam = true; } // Required for TWL carts to boot properly. Disabled by default for NTR carts to allow WoodR4 to operate correctly.

if (ROMisDSiExclusive(&dsiHeaderTemp->ndshdr)) {
twlClock = true;
extendRam = true;
boostVram = true;
dsiMode = true;
}

if (dsiMode) {
if (twlMode == 2) {
dsiModeConfirmed = twlMode;
} else {
dsiModeConfirmed = twlMode && ROMsupportsDsiMode(&dsiHeaderTemp->ndshdr);
dsiModeConfirmed = twlMode && ROMsupportsDSiMode(&dsiHeaderTemp->ndshdr);
}
}

Expand Down Expand Up @@ -696,14 +696,10 @@ void arm7_main (void) {
} else {
REG_SCFG_CLK = 0x0180;
}
if (!sdAccess) {
REG_SCFG_EXT = 0x93FBFB06;
}
if (!sdAccess) { REG_SCFG_EXT = 0x93FBFB06; }
}

if (*(u32*)(NDS_HEADER+0xC) == 0x50524255) {
fixDSBrowser();
}
if (*(u32*)(NDS_HEADER+0xC) == 0x50524255) { fixDSBrowser(); }

if ((*(u32*)(NDS_HEADER+0xC) & 0x00FFFFFF) == 0x52544E // Download Play ROMs
|| (*(u32*)(NDS_HEADER+0xC) & 0x00FFFFFF) == 0x4D5341 // Super Mario 64 DS
Expand All @@ -720,13 +716,15 @@ void arm7_main (void) {
toncset ((void*)0x023F0000, 0, 0x8000); // Clear cheat data from main memory

debugOutput (ERR_STS_START);

arm9_TWLClockSpeeds = twlClock;
arm9_boostVram = boostVram;
arm9_scfgUnlock = scfgUnlock;
arm9_dsiModeConfirmed = dsiModeConfirmed;
arm9_ExtendRam = extendRam;
//arm9_isSdk5 = isSdk5(moduleParams);


if (dsiModeConfirmed) {
REG_SCFG_EXT = 0x93FBFB06;
if (!scfgUnlock) { REG_SCFG_EXT &= ~(1UL << 31); }
Expand Down
40 changes: 4 additions & 36 deletions BootLoader/source/main.arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,40 +292,9 @@ void __attribute__((target("arm"))) arm9_main (void) {
// arm9_errorOutput (arm9_errorCode, arm9_errorClearBG);
if ( arm9_stateFlag == ARM9_DISPERR) { arm9_stateFlag = ARM9_READY; }
}
if (arm9_stateFlag == ARM9_SETSCFG) {
/*if (arm9_dsiModeConfirmed) {
REG_SCFG_EXT = 0x8307F100;
// REG_SCFG_CLK = 0x84;
if (arm9_TWLClockSpeeds) {
REG_SCFG_CLK = 0x85;
} else {
REG_SCFG_CLK = 0x84;
}
} else {
// REG_SCFG_EXT = 0x8300C000;
// REG_SCFG_EXT=0x83000000;
REG_SCFG_EXT=0x83000000;
if (arm9_ExtendRam) {
REG_SCFG_EXT |= BIT(14);
REG_SCFG_EXT |= BIT(15);
}
if (arm9_TWLClockSpeeds) {
// REG_SCFG_EXT=0x8300C000;
} else {
// REG_SCFG_EXT=0x83000000;
}
if (arm9_boostVram) {
REG_SCFG_EXT |= BIT(13); // Extended VRAM Access
}
if (!arm9_scfgUnlock) {
// lock SCFG
REG_SCFG_EXT &= ~(1UL << 31);
}
}*/
arm9_stateFlag = ARM9_READY;
}

// I don't set SCFG_EXT here anymore. The required changes to make WoodR4 work would crash Bootloader if set here.
if (arm9_stateFlag == ARM9_SETSCFG) { arm9_stateFlag = ARM9_READY; }
}

VoidFn arm9code = (VoidFn)ndsHeader->arm9executeAddress;
Expand All @@ -347,8 +316,7 @@ void __attribute__((target("arm"))) arm9_main (void) {
if (arm9_ExtendRam) {
REG_SCFG_EXT |= BIT(14);
REG_SCFG_EXT |= BIT(15);
}

}
// Extended VRAM Access
if (arm9_boostVram) { REG_SCFG_EXT |= BIT(13); }

Expand Down
22 changes: 9 additions & 13 deletions BootLoader/source/read_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ static u32 getRandomNumber(void) {
// guaranteed to be random.
}

static void decryptSecureArea (u32 gameCode, u32* secureArea, int iCardDevice)
{
static void decryptSecureArea (u32 gameCode, u32* secureArea, int iCardDevice) {
init_keycode (gameCode, 2, 8, iCardDevice);
crypt_64bit_down (secureArea);

init_keycode (gameCode, 3, 8, iCardDevice);

for (int i = 0; i < 0x200; i+= 2) {
crypt_64bit_down (secureArea + i);
}
for (int i = 0; i < 0x200; i+= 2) { crypt_64bit_down (secureArea + i); }
}

static struct {
Expand All @@ -77,11 +74,12 @@ static void initKey1Encryption (u8* cmdData, int iCardDevice) {
key1data.mmm = getRandomNumber() & 0x00000fff;
key1data.nnn = getRandomNumber() & 0x00000fff;

if(iCardDevice) //DSi
cmdData[7]=0x3D; // CARD_CMD_ACTIVATE_BF2
else
cmdData[7]=CARD_CMD_ACTIVATE_BF;

if(iCardDevice) {
cmdData[7]=0x3D; //DSi // CARD_CMD_ACTIVATE_BF2
} else {
cmdData[7]=CARD_CMD_ACTIVATE_BF;
}

cmdData[6] = (u8) (key1data.iii >> 4);
cmdData[5] = (u8) ((key1data.iii << 4) | (key1data.jjj >> 8));
cmdData[4] = (u8) key1data.jjj;
Expand All @@ -95,9 +93,7 @@ static void initKey1Encryption (u8* cmdData, int iCardDevice) {
static void createEncryptedCommand (u8 command, u8* cmdData, u32 block) {
unsigned long iii, jjj;

if (command != CARD_CMD_SECURE_READ) {
block = key1data.llll;
}
if (command != CARD_CMD_SECURE_READ) { block = key1data.llll; }

if (command == CARD_CMD_ACTIVATE_SEC) {
iii = key1data.mmm;
Expand Down
3 changes: 3 additions & 0 deletions NTR_Launcher.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[NTRLAUNCHER]
ANIMATEDSPLASH = 0
NTRSPLASH = 0
HEALTHSAFETYSPLASH = 1
TWLMODE = 0
TWLCLOCK = 0
TWLVRAM = 0
Expand Down
2 changes: 1 addition & 1 deletion arm7/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti
ASFLAGS := -g $(ARCH) $(INCLUDE)
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,-Map,$(notdir $*).map

LIBS := -lnds7
LIBS := -lmm7 -lnds7

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
5 changes: 5 additions & 0 deletions arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <nds/arm7/input.h>
#include <nds/system.h>

#include <maxmod7.h>

void VcountHandler() { inputGetAndSend(); }
void VblankHandler(void) { }

Expand Down Expand Up @@ -58,9 +60,12 @@ int main(void) {
// Start the RTC tracking IRQ
initClockIRQ();
fifoInit();

mmInstall(FIFO_MAXMOD);

SetYtrigger(80);

installSoundFIFO();
installSystemFIFO();

irqSet(IRQ_VCOUNT, VcountHandler);
Expand Down
Loading

0 comments on commit 77161eb

Please sign in to comment.