From 6fa7430f628d52e480736ff85fd8806bf4aa747d Mon Sep 17 00:00:00 2001 From: ApacheThunder Date: Thu, 11 Apr 2024 23:02:40 -0500 Subject: [PATCH] 1.8 Release Commit ... * Final D2 init command now uses the value from the cart's header (found at offset 0x8) instead of the hardcoded value found with most 16g and 8g carts. --- .gitignore | 2 ++ arm7/Makefile | 2 +- arm9/source/main.cpp | 8 ++++++-- arm9/source/nrio_card.c | 13 +++++++++++-- arm9/source/nrio_card.h | 3 +-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 746b2b7..7c2d8ef 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,8 @@ *.cmd *.nds *.app +*.tmd +*.zip *.arm7 *.arm9 *.elf diff --git a/arm7/Makefile b/arm7/Makefile index ac3a1ad..c8486cd 100644 --- a/arm7/Makefile +++ b/arm7/Makefile @@ -24,7 +24,7 @@ DATA := #--------------------------------------------------------------------------------- ARCH := -mthumb -mthumb-interwork -CFLAGS := -g -Wall -Os \ +CFLAGS := -g -Wall -Oz \ -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\ -ffast-math \ $(ARCH) diff --git a/arm9/source/main.cpp b/arm9/source/main.cpp index 35c27b3..0f06b2c 100644 --- a/arm9/source/main.cpp +++ b/arm9/source/main.cpp @@ -155,12 +155,16 @@ void CardInit(bool Silent = true, bool SkipSlotReset = false) { tonccpy(gameTitle, cartHeader->ndshdr.gameTitle, 12); tonccpy(gameCode, cartHeader->ndshdr.gameCode, 6); ndsHeader = loadHeader(cartHeader); // copy twlHeaderTemp to ndsHeader location - InitCartNandReadMode(); + u32 CardType = *(u32*)(DSI_HEADER + 0x08); + InitCartNandReadMode(CardType); DoWait(); if (!Silent) { if (wasDSi && SCFGUnlocked) { iprintf("SCFG_MC Status: %2x \n\n", REG_SCFG_MC); } iprintf("Detected Cart Name: %12s \n\n", gameTitle); iprintf("Detected Cart Game Id: %6s \n\n", gameCode); + iprintf("Detected Cart Type: %8x \n\n", (unsigned int)CardType); + printf("Press any button to continue..."); + do { swiWaitForVBlank(); scanKeys(); } while (!keysDown()); } } @@ -790,7 +794,7 @@ void DoUdiskDump() { }*/ int UtilityMenu() { - LoadTopScreenUtilitySplash(); + if(!WarningPosted)LoadTopScreenUtilitySplash(); int value = -1; consoleClear(); printf("Press [A] to build update file\n"); diff --git a/arm9/source/nrio_card.c b/arm9/source/nrio_card.c index 319c6ca..3de9e92 100644 --- a/arm9/source/nrio_card.c +++ b/arm9/source/nrio_card.c @@ -43,12 +43,21 @@ void nrioSendCommand(u32 cmdbuffer, u32 cmdData, u8 cmd, u32 cmdflags) { } }*/ +// Final C1 command now reads from 0x08 location of header like origional stage1 main rom does instead of hardcoding. +// Some different capacity cards are known to use different values. 1080 = what most 16g carts use. Some 2G carts also use this value -void InitCartNandReadMode() { +void InitCartNandReadMode(u32 CardType) { + // Only bricked carts would present values like these. Hard Code 1083 if this is the case + switch (CardType) { + case 0x00000000: { CardType = 0x10830000; }break; + case 0xFFFFFFFF: { CardType = 0x10830000; }break; + } + cardParamCommand (0x66, 0, CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(7) | CARD_SEC_CMD | BIT(20) | BIT(19) | BIT(14) | BIT(13), (u32*)INITBUFFER, 128); cardParamCommand (0xC1, 0x0D210000, CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(7) | BIT(17), (u32*)(INITBUFFER + 0x10), 128); cardParamCommand (0xC1, 0x0FB00000, CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(7) | BIT(17), (u32*)(INITBUFFER + 0x10), 128); - cardParamCommand (0xC1, 0x10830000, CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(7) | BIT(17), (u32*)(INITBUFFER + 0x20), 128); + cardParamCommand (0xC1, CardType, CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(7) | BIT(17), (u32*)(INITBUFFER + 0x20), 128); + // cardParamCommand (0xC1, 0x10830000, CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(7) | BIT(17), (u32*)(INITBUFFER + 0x20), 128); // DoWait(8); /**(vu32*)INITBUFFER = nrioInit(0x66, 0xAF586000); nrioSendCommand((u32)(INITBUFFER + 0x10), 0x0D210000, 0xC1, 0xA7020000); diff --git a/arm9/source/nrio_card.h b/arm9/source/nrio_card.h index 8f1a9d5..a1999d8 100644 --- a/arm9/source/nrio_card.h +++ b/arm9/source/nrio_card.h @@ -5,8 +5,7 @@ extern "C" { #endif -void InitCartNandReadMode(void); -void InitCartNandReadModeALT(void); +void InitCartNandReadMode(u32 CardType); ITCM_CODE void nrio_readSectors(void* destination, u32 rom_offset, u32 num_words); ITCM_CODE void nrio_readSector(void* destination, u32 rom_offset); ITCM_CODE void nrio_readSectorB7(void* destination, u32 rom_offset);