From c5ff18b2ffab19d9cfe13d80b524caaa738a4bac Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Mon, 18 Dec 2023 02:53:06 -0700 Subject: [PATCH] Patch apps received via Download Play to read save from SD instead of cartridge Currently makes the received app not boot --- retail/Makefile | 9 +- retail/arm9/source/conf_sd.cpp | 10 +- retail/bootloaderi/source/arm7/hook_arm7.c | 4 + retail/bootloaderi/source/arm7/hook_arm9.c | 4 + retail/bootloaderi/source/arm7/main.arm7.c | 6 + retail/cardenginei/arm7/source/cardengine.c | 75 +++++-- .../arm7/source/patcher/hook_arm9.c | 10 + .../arm7/source/patcher/patch_arm9.c | 4 +- retail/cardenginei/arm9/source/misc.c | 11 +- retail/cardenginei/arm9_dlp/Makefile | 144 +++++++++++++ retail/cardenginei/arm9_dlp/cardengine.ld.in | 201 ++++++++++++++++++ .../common/include/cardengine_header_arm7.h | 1 + .../common/include/cardengine_header_arm9.h | 1 + retail/common/include/locations.h | 1 + 14 files changed, 453 insertions(+), 28 deletions(-) create mode 100644 retail/cardenginei/arm9_dlp/Makefile create mode 100644 retail/cardenginei/arm9_dlp/cardengine.ld.in diff --git a/retail/Makefile b/retail/Makefile index 8ea669720..96cb5cd76 100644 --- a/retail/Makefile +++ b/retail/Makefile @@ -128,7 +128,7 @@ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) export GAME_ICON := $(CURDIR)/$(ASSETS)/icon.bmp #.PHONY: cardengine_arm7 cardengine_arm9 bootloader BootStrap clean -.PHONY: all dist release nightly bootloader bootloader2 bootloaderi bootloaderi2 cardengine_arm7 cardengine_arm9_igm cardengine_arm9_igm_extmem cardengine_arm9 cardengine_arm9_start cardengine_arm9_alt cardengine_arm9_alt2 cardengine_arm9_extmem cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3 arm7/$(TARGET).elf arm9/$(TARGET).elf clean +.PHONY: all dist release nightly bootloader bootloader2 bootloaderi bootloaderi2 cardengine_arm7 cardengine_arm9_igm cardengine_arm9_igm_extmem cardengine_arm9 cardengine_arm9_start cardengine_arm9_alt cardengine_arm9_alt2 cardengine_arm9_extmem cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_dlp cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3 arm7/$(TARGET).elf arm9/$(TARGET).elf clean all: $(OUTPUT) @@ -169,7 +169,7 @@ bootloader2: $(DATA) @$(MAKE) -C bootloader2 #--------------------------------------------------------------------------------- -bootloaderi: $(DATA) cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3 +bootloaderi: $(DATA) cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_dlp cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3 @$(MAKE) -C bootloaderi #--------------------------------------------------------------------------------- @@ -252,6 +252,10 @@ cardenginei_arm9_alt: $(DATA) cardenginei_arm9_alt2: $(DATA) @$(MAKE) -C cardenginei/arm9_alt2 +#--------------------------------------------------------------------------------- +cardenginei_arm9_dlp: $(DATA) + @$(MAKE) -C cardenginei/arm9_dlp + #--------------------------------------------------------------------------------- cardenginei_arm9_gsdd: $(DATA) @$(MAKE) -C cardenginei/arm9_gsdd @@ -323,6 +327,7 @@ clean: @$(MAKE) -C cardenginei/arm9 clean @$(MAKE) -C cardenginei/arm9_alt clean @$(MAKE) -C cardenginei/arm9_alt2 clean + @$(MAKE) -C cardenginei/arm9_dlp clean @$(MAKE) -C cardenginei/arm9_gsdd clean @$(MAKE) -C cardenginei/arm9_gsdd_alt clean @$(MAKE) -C cardenginei/arm9_dldi clean diff --git a/retail/arm9/source/conf_sd.cpp b/retail/arm9/source/conf_sd.cpp index e0c1514a9..fdf533d24 100644 --- a/retail/arm9/source/conf_sd.cpp +++ b/retail/arm9/source/conf_sd.cpp @@ -1166,7 +1166,8 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) { conf->dsiWramAccess = true; } if (conf->dsiWramAccess) { - if (strncmp(romTid, "ADA", 3) == 0 // Diamond + if (strncmp(romTid, "HND", 3) == 0 // DS Download Play + || strncmp(romTid, "ADA", 3) == 0 // Diamond || strncmp(romTid, "APA", 3) == 0 // Pearl || strncmp(romTid, "Y3E", 3) == 0 // 2006-Nen 10-Gatsu Taikenban Soft || strncmp(romTid, "CPU", 3) == 0 // Platinum @@ -1235,6 +1236,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) { } fclose(cebin); + const bool dlp = (memcmp(romTid, "HND", 3) == 0); const bool gsdd = (memcmp(romTid, "BO5", 3) == 0); if (conf->gameOnFlashcard) { @@ -1252,7 +1254,9 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) { fclose(cebin); } else { const char* ce9Path = conf->dsiWramAccess ? "nitro:/cardenginei_arm9.lz77" : "nitro:/cardenginei_arm9_alt.lz77"; - if (gsdd) { + if (dlp) { + ce9Path = "nitro:/cardenginei_arm9_dlp.lz77"; + } else if (gsdd) { ce9Path = conf->dsiWramAccess ? "nitro:/cardenginei_arm9_gsdd.lz77" : "nitro:/cardenginei_arm9_gsdd_alt.lz77"; } @@ -1264,7 +1268,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) { } fclose(cebin); - if (!conf->dsiWramAccess && !gsdd) { + if (!conf->dsiWramAccess && !dlp && !gsdd) { // Load ce9 binary (alt 2) cebin = fopen("nitro:/cardenginei_arm9_alt2.lz77", "rb"); if (cebin) { diff --git a/retail/bootloaderi/source/arm7/hook_arm7.c b/retail/bootloaderi/source/arm7/hook_arm7.c index a5ae47bb9..8836c4a39 100644 --- a/retail/bootloaderi/source/arm7/hook_arm7.c +++ b/retail/bootloaderi/source/arm7/hook_arm7.c @@ -54,6 +54,7 @@ #define b_dsiBios BIT(18) #define b_bootstrapOnFlashcard BIT(19) #define b_ndmaDisabled BIT(20) +#define b_isDlp BIT(21) #define b_scfgLocked BIT(31) extern u32 newArm7binarySize; @@ -399,6 +400,9 @@ int hookNdsRetailArm7( if (ndmaDisabled) { ce7->valueBits |= b_ndmaDisabled; } + if (strncmp(romTid, "HND", 3) == 0) { + ce7->valueBits |= b_isDlp; + } if (REG_SCFG_EXT == 0) { ce7->valueBits |= b_scfgLocked; } diff --git a/retail/bootloaderi/source/arm7/hook_arm9.c b/retail/bootloaderi/source/arm7/hook_arm9.c index 8239d50d3..20d6c397a 100644 --- a/retail/bootloaderi/source/arm7/hook_arm9.c +++ b/retail/bootloaderi/source/arm7/hook_arm9.c @@ -26,6 +26,7 @@ #define b_asyncCardRead BIT(12) #define b_softResetMb BIT(13) #define b_cloneboot BIT(14) +#define b_isDlp BIT(15) static const int MAX_HANDLER_LEN = 50; @@ -329,6 +330,9 @@ int hookNdsRetailArm9( if (usesCloneboot) { ce9->valueBits |= b_cloneboot; } + if (strncmp(romTid, "HND", 3) == 0) { + ce9->valueBits |= b_isDlp; + } ce9->mainScreen = mainScreen; ce9->overlaysSize = overlaysSize; ce9->romPaddingSize = romPaddingSize; diff --git a/retail/bootloaderi/source/arm7/main.arm7.c b/retail/bootloaderi/source/arm7/main.arm7.c index 0602f0aea..83542643f 100644 --- a/retail/bootloaderi/source/arm7/main.arm7.c +++ b/retail/bootloaderi/source/arm7/main.arm7.c @@ -1588,6 +1588,9 @@ int arm7_main(void) { extern u32 clusterCache; u32 add = (moduleParams->sdk_version >= 0x2008000 || moduleParams->sdk_version == 0x20029A8) ? 0xC8000 : 0xE8000; // 0x027C8000 : 0x027E8000 + if (memcmp(romTid, "HND", 3) == 0) { + add = 0x108000; // 0x02808000 + } tonccpy((char*)0x02700000+add, (char*)0x02700000, 0x10000); // Move FAT table cache elsewhere romFile->fatTableCache = (u32*)((u32)romFile->fatTableCache+add); savFile->fatTableCache = (u32*)((u32)savFile->fatTableCache+add); @@ -2011,6 +2014,9 @@ int arm7_main(void) { } else { const bool laterSdk = (moduleParams->sdk_version >= 0x2008000 || moduleParams->sdk_version == 0x20029A8); ce9Location = dsiWramAccess ? CARDENGINEI_ARM9_LOCATION_DSI_WRAM : (!laterSdk ? CARDENGINEI_ARM9_LOCATION2 : CARDENGINEI_ARM9_LOCATION); + if (memcmp(romTid, "HND", 3) == 0) { + ce9Location = CARDENGINEI_ARM9_LOCATION_DLP; + } ce9size = 0x5000; tonccpy((u32*)ce9Location, (u32*)((!dsiWramAccess && !laterSdk) ? CARDENGINEI_ARM9_BUFFERED_LOCATION2 : CARDENGINEI_ARM9_BUFFERED_LOCATION), ce9size); } diff --git a/retail/cardenginei/arm7/source/cardengine.c b/retail/cardenginei/arm7/source/cardengine.c index 908fdbaf7..139876c24 100644 --- a/retail/cardenginei/arm7/source/cardengine.c +++ b/retail/cardenginei/arm7/source/cardengine.c @@ -75,6 +75,7 @@ #define dsiBios BIT(18) #define bootstrapOnFlashcard BIT(19) #define ndmaDisabled BIT(20) +#define isDlp BIT(21) #define scfgLocked BIT(31) #define REG_EXTKEYINPUT (*(vuint16*)0x04000136) @@ -367,6 +368,10 @@ static void initialize(void) { sharedAddr = (vu32*)CARDENGINE_SHARED_ADDRESS_SDK5; ndsHeader = (tNDSHeader*)NDS_HEADER_SDK5; personalData = (PERSONAL_DATA*)((u8*)NDS_HEADER_SDK5-0x180); + } else { + sharedAddr = (vu32*)CARDENGINE_SHARED_ADDRESS_SDK1; + ndsHeader = (tNDSHeader*)NDS_HEADER; + personalData = (PERSONAL_DATA*)((u8*)NDS_HEADER-0x180); } #endif @@ -451,9 +456,11 @@ static void cardReadRAM(u8* dst, u32 src, u32 len/*, int romPartNo*/) { } void reset(void) { + register int i, reg; + #ifndef TWLSDK u32 resetParam = ((valueBits & isSdk5) ? RESET_PARAM_SDK5 : RESET_PARAM); - if ((valueBits & slowSoftReset) || (*(u32*)(resetParam+0xC) > 0 && (*(u32*)CARDENGINEI_ARM9_LOCATION == 0 || (valueBits & isSdk5)))) { + if (((valueBits & isDlp) && *(u32*)(NDS_HEADER_SDK5+0xC) == 0) || (valueBits & slowSoftReset) || (*(u32*)(resetParam+0xC) > 0 && (*(u32*)CARDENGINEI_ARM9_LOCATION == 0 || (valueBits & isSdk5)))) { REG_MASTER_VOLUME = 0; int oldIME = enterCriticalSection(); //driveInitialize(); @@ -480,10 +487,10 @@ void reset(void) { leaveCriticalSection(oldIME); while (1); } + + if (!(valueBits & isDlp)) { #endif - register int i, reg; - REG_IME = 0; for (i = 0; i < 16; i++) { @@ -522,37 +529,52 @@ void reset(void) { *(vu32*)0x0380FFF8 = 0; // VBLANK_INTR_WAIT_FLAGS, ARM7 version REG_POWERCNT = 1; // Turn off power to stuff - initialized = false; funcsUnpatched = false; + +#ifndef TWLSDK + } +#endif + + initialized = false; //ipcSyncHooked = false; languageTimer = 0; #ifndef TWLSDK - if (currentSrlAddr != *(u32*)(resetParam+0xC) || *(u32*)(resetParam+8) == 0x44414F4C) { + if ((valueBits & isDlp) || currentSrlAddr != *(u32*)(resetParam+0xC) || *(u32*)(resetParam+8) == 0x44414F4C) { currentSrlAddr = *(u32*)(resetParam+0xC); - if (*(u32*)(resetParam+8) == 0x44414F4C) { + if (valueBits & isDlp) { ndmaCopyWordsAsynch(1, (u32*)0x022C0000, ndsHeader->arm7destination, ndsHeader->arm7binarySize); - *((u16*)(/*isSdk5(moduleParams) ? 0x02fffc40 :*/ 0x027ffc40)) = 2; // Boot Indicator (Cloneboot/Multiboot) - // tonccpy((u32*)0x027FFC40, (u32*)0x02344820, 0x40); // Multiboot info? - } else if (valueBits & ROMinRAM) { - cardReadRAM((u8*)ndsHeader, currentSrlAddr, 0x160); - cardReadRAM((u8*)ndsHeader->arm9destination, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); - cardReadRAM((u8*)ndsHeader->arm7destination, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); + *(u16*)0x02fffc40 = 2; // Boot Indicator (Cloneboot/Multiboot) } else { - fileRead((char*)ndsHeader, romFile, currentSrlAddr, 0x160); - fileRead((char*)ndsHeader->arm9destination, romFile, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); - fileRead((char*)ndsHeader->arm7destination, romFile, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); + if (*(u32*)(resetParam+8) == 0x44414F4C) { + ndmaCopyWordsAsynch(1, (u32*)0x022C0000, ndsHeader->arm7destination, ndsHeader->arm7binarySize); + *((u16*)(/*isSdk5(moduleParams) ? 0x02fffc40 :*/ 0x027ffc40)) = 2; // Boot Indicator (Cloneboot/Multiboot) + // tonccpy((u32*)0x027FFC40, (u32*)0x02344820, 0x40); // Multiboot info? + } else if (valueBits & ROMinRAM) { + cardReadRAM((u8*)ndsHeader, currentSrlAddr, 0x160); + cardReadRAM((u8*)ndsHeader->arm9destination, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); + cardReadRAM((u8*)ndsHeader->arm7destination, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); + } else { + fileRead((char*)ndsHeader, romFile, currentSrlAddr, 0x160); + fileRead((char*)ndsHeader->arm9destination, romFile, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); + fileRead((char*)ndsHeader->arm7destination, romFile, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); + } } moduleParams = getModuleParams(ndsHeader); /*dbg_printf("sdk_version: "); dbg_hexa(moduleParams->sdk_version); dbg_printf("\n");*/ + if (moduleParams->sdk_version > 0x5000000) { + valueBits |= isSdk5; + } else { + valueBits &= ~isSdk5; + } - ensureBinaryDecompressed(ndsHeader, moduleParams, resetParam); + ensureBinaryDecompressed(ndsHeader, moduleParams, (valueBits & isDlp) ? 0x44414F4 : resetParam); patchCardNdsArm9( - (cardengineArm9*)CARDENGINEI_ARM9_LOCATION, + (cardengineArm9*)((valueBits & isDlp) ? CARDENGINEI_ARM9_LOCATION_DLP : CARDENGINEI_ARM9_LOCATION), ndsHeader, moduleParams, 1 @@ -582,7 +604,15 @@ void reset(void) { ndmaCopyWordsAsynch(1, ndsHeader->arm7destination, (char*)DONOR_ROM_ARM7_LOCATION, ndsHeader->arm7binarySize); while (ndmaBusy(0) || ndmaBusy(1)); } */ - *(u32*)(resetParam+8) = 0; + if (valueBits & isDlp) { + toncset((u32*)0x022C0000, 0, ndsHeader->arm7binarySize); + if (!(valueBits & isSdk5)) { + tonccpy((u8*)0x027FF000, (u8*)0x02FFF000, 0x1000); + } + } else { + *(u32*)(resetParam+8) = 0; + } + valueBits &= ~isDlp; } else { //driveInitialize(); @@ -1574,6 +1604,15 @@ void myIrqHandlerVBlank(void) { i2cWriteRegister(0x4A, 0x11, 0x01); // Reboot into error screen if SD card is removed } +#ifndef TWLSDK + if (valueBits & isDlp) { + if (!(REG_EXTKEYINPUT & KEY_A) && *(u32*)(NDS_HEADER_SDK5+0xC) != 0 && !wifiIrq) { + IPC_SendSync(0x5); + reset(); + } + } +#endif + if ((0 == (REG_KEYINPUT & igmHotkey) && 0 == (REG_EXTKEYINPUT & (((igmHotkey >> 10) & 3) | ((igmHotkey >> 6) & 0xC0))) && (valueBits & igmAccessible) && !wifiIrq) || returnToMenu || sharedAddr[5] == 0x4C4D4749 /* IGML */) { #ifdef TWLSDK igmText = (struct IgmText *)INGAME_MENU_LOCATION; diff --git a/retail/cardenginei/arm7/source/patcher/hook_arm9.c b/retail/cardenginei/arm7/source/patcher/hook_arm9.c index 613cc214f..6d725bb4e 100644 --- a/retail/cardenginei/arm7/source/patcher/hook_arm9.c +++ b/retail/cardenginei/arm7/source/patcher/hook_arm9.c @@ -9,8 +9,12 @@ #include "nds_header.h" #include "cardengine_header_arm9.h" +#define isSdk5_9 BIT(5) +#define isSdk5_7 BIT(13) #define b_softResetMb BIT(13) +#define b_isDlp BIT(15) +extern u32 valueBits; extern vu32* volatile sharedAddr; @@ -122,11 +126,17 @@ int hookNdsRetailArm9( extern u32 iUncompressedSize; extern bool softResetMb; + if (valueBits & isSdk5_7) { + sharedAddr[1] |= isSdk5_9; + } else { + sharedAddr[1] &= ~isSdk5_9; + } if (softResetMb) { sharedAddr[1] |= b_softResetMb; } else { sharedAddr[1] &= ~b_softResetMb; } + sharedAddr[1] &= ~b_isDlp; u32* tableAddr = hookInterruptHandler((u32*)ndsHeader->arm9destination, iUncompressedSize); diff --git a/retail/cardenginei/arm7/source/patcher/patch_arm9.c b/retail/cardenginei/arm7/source/patcher/patch_arm9.c index 465e66748..ab26120ea 100644 --- a/retail/cardenginei/arm7/source/patcher/patch_arm9.c +++ b/retail/cardenginei/arm7/source/patcher/patch_arm9.c @@ -479,7 +479,7 @@ static void patchMpu(const tNDSHeader* ndsHeader, const module_params_t* moduleP } static void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { - if (moduleParams->sdk_version < 0x2008000 || moduleParams->sdk_version > 0x5000000) { + if (moduleParams->sdk_version > 0x5000000) { return; } @@ -522,7 +522,7 @@ static void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* module //Original code made loading slow, so new code is used unpatchedFuncs->mpuDataOffset2 = mpuDataOffset; unpatchedFuncs->mpuInitRegionOldData2 = *mpuDataOffset; - *mpuDataOffset = PAGE_128K | 0x027E0000 | 1; + *mpuDataOffset = 0; //} /*u32 mpuInitRegionNewData = PAGE_32M | 0x02000000 | 1; diff --git a/retail/cardenginei/arm9/source/misc.c b/retail/cardenginei/arm9/source/misc.c index 3fc2a88a7..2af4a9d49 100644 --- a/retail/cardenginei/arm9/source/misc.c +++ b/retail/cardenginei/arm9/source/misc.c @@ -40,6 +40,7 @@ #define slowSoftReset BIT(10) #define softResetMb BIT(13) #define cloneboot BIT(14) +#define isDlp BIT(15) #include "my_fat.h" @@ -131,9 +132,9 @@ void enableIPC_SYNC(void) { } #ifndef TWLSDK -void initialize(void) { - static bool initialized = false; +static bool initialized = false; +void initialize(void) { if (initialized) { return; } @@ -150,6 +151,9 @@ void initialize(void) { cacheAddressTable = (u32*)CACHE_ADDRESS_TABLE_LOCATION_TWLSDK; #endif } + } else { + sharedAddr = (vu32*)CARDENGINE_SHARED_ADDRESS_SDK1; + ndsHeader = (tNDSHeader*)NDS_HEADER; } #endif initialized = true; @@ -335,12 +339,13 @@ void reset(u32 param, u32 tid2) { while (REG_VCOUNT == 191); } - if (*(u32*)(RESET_PARAM+0xC) > 0) { + if ((ce9->valueBits & isDlp) || *(u32*)(RESET_PARAM+0xC) > 0) { u32 newIrqTable = sharedAddr[2]; ce9->valueBits = sharedAddr[1]; ce9->irqTable = (u32*)newIrqTable; ce9->cardStruct0 = sharedAddr[4]; sharedAddr[4] = 0; + initialized = false; } #endif diff --git a/retail/cardenginei/arm9_dlp/Makefile b/retail/cardenginei/arm9_dlp/Makefile new file mode 100644 index 000000000..eceea2570 --- /dev/null +++ b/retail/cardenginei/arm9_dlp/Makefile @@ -0,0 +1,144 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +include $(DEVKITARM)/ds_rules + +ifeq ($(OS),Windows_NT) +LZSS ?= ../../../lzss.exe + +else + +LZSS ?= lzss + +endif +#--------------------------------------------------------------------------------- +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +# DATA is a list of directories containing binary files +# all directories are relative to this makefile +#--------------------------------------------------------------------------------- +BUILD := build +SOURCES := ../arm9/source ../arm9/source_ext ../../common/source_general +INCLUDES := ../arm9/include ../arm9/include_ext ../../common/include +DATA := data + + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -march=armv5te -mtune=arm946e-s + +CFLAGS := -g -Wall -O2\ + -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\ + -ffast-math \ + $(ARCH) + +# ADD -DDEBUG here for logging/debug +CFLAGS += $(INCLUDE) -DARM9 -DNO_CARDID +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) $(INCLUDE) + +LDFLAGS = -nostartfiles -T cardengine.ld -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project (order is important) +#--------------------------------------------------------------------------------- +LIBS := + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBNDS) + + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export TARGET := cardenginei_arm9_dlp +export OUTPUT := $(CURDIR)/../../nitrofiles_dec/$(TARGET) +export OUTPUT_CMP := $(CURDIR)/../../nitrofiles/$(TARGET) +export DEPSDIR := $(CURDIR)/$(BUILD) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + @cp $(OUTPUT).bin $(OUTPUT_CMP).lz77 + @$(LZSS) -ewf $(OUTPUT_CMP).lz77 + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf + + +#--------------------------------------------------------------------------------- +else + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).bin: $(DEPSDIR)/$(TARGET).elf +$(DEPSDIR)/$(TARGET).elf: cardengine.ld $(OFILES) +# @echo linking $(notdir $@) +# @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ + +cardengine.ld: $(CURDIR)/../cardengine.ld.in + $(CPP) -P $(INCLUDE) $< $@ + + +#--------------------------------------------------------------------------------- +%.bin : %.elf +#--------------------------------------------------------------------------------- + @$(OBJCOPY) -O binary $< $@ + @echo built ... $(notdir $@) + +-include $(DEPSDIR)/*.d + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/retail/cardenginei/arm9_dlp/cardengine.ld.in b/retail/cardenginei/arm9_dlp/cardengine.ld.in new file mode 100644 index 000000000..419864840 --- /dev/null +++ b/retail/cardenginei/arm9_dlp/cardengine.ld.in @@ -0,0 +1,201 @@ +#include "locations.h" + +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") +OUTPUT_ARCH(arm) +/*ENTRY(_start)*/ + +MEMORY { + + vram : ORIGIN = CARDENGINEI_ARM9_LOCATION_DLP, LENGTH = 29K /* Main RAM */ +} + +__vram_start = ORIGIN(vram); +__vram_top = ORIGIN(vram)+ LENGTH(vram); +__sp_irq = __vram_top - 0x60; +__sp_svc = __sp_irq - 0x100; +__sp_usr = __sp_svc - 0x100; + +__irq_flags = __vram_top - 8; +__irq_flagsaux = __vram_top - 0x40; /*__irq_flagsaux = 0x04000000 - 0x40;*/ +__irq_vector = __vram_top - 4; + +SECTIONS +{ + .init : + { + __text_start = . ; + KEEP (*(.init)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram = 0xff + + .plt : + { + *(.plt) + } >vram = 0xff + + .text : /* ALIGN (4): */ + { + + *(.text*) + *(.stub) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t*) + *(.glue_7) + *(.glue_7t) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram = 0xff + + .fini : + { + KEEP (*(.fini)) + } >vram =0xff + + __text_end = . ; + + .rodata : + { + *(.rodata) + *all.rodata*(*) + *(.roda) + *(.rodata.*) + *(.gnu.linkonce.r*) + SORT(CONSTRUCTORS) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram = 0xff + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >vram + __exidx_start = .; + .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >vram + __exidx_end = .; + +/* Ensure the __preinit_array_start label is properly aligned. We + could instead move the label definition inside the section, but + the linker would then create the section even if it turns out to + be empty, which isn't pretty. */ + . = ALIGN(32 / 8); + PROVIDE (__preinit_array_start = .); + .preinit_array : { KEEP (*(.preinit_array)) } >vram = 0xff + PROVIDE (__preinit_array_end = .); + PROVIDE (__init_array_start = .); + .init_array : { KEEP (*(.init_array)) } >vram = 0xff + PROVIDE (__init_array_end = .); + PROVIDE (__fini_array_start = .); + .fini_array : { KEEP (*(.fini_array)) } >vram = 0xff + PROVIDE (__fini_array_end = .); + + .ctors : + { + /* gcc uses crtbegin.o to find the start of the constructors, so + we make sure it is first. Because this is a wildcard, it + doesn't matter if the user does not actually link against + crtbegin.o; the linker won't look for a file to match a + wildcard. The wildcard also means that it doesn't matter which + directory crtbegin.o is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram = 0xff + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram = 0xff + + .eh_frame : + { + KEEP (*(.eh_frame)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram = 0xff + + .gcc_except_table : + { + *(.gcc_except_table) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram = 0xff + .jcr : { KEEP (*(.jcr)) } >vram = 0 + .got : { *(.got.plt) *(.got) } >vram = 0 + + + .vram ALIGN(4) : + { + __vram_start = ABSOLUTE(.) ; + *(.vram) + *vram.*(.text) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + __vram_end = ABSOLUTE(.) ; + } >vram = 0xff + + + .data ALIGN(4) : { + __data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + CONSTRUCTORS + . = ALIGN(4); + __data_end = ABSOLUTE(.) ; + } >vram = 0xff + + + + .bss ALIGN(4) : + { + __bss_start = ABSOLUTE(.); + __bss_start__ = ABSOLUTE(.); + *(.dynbss) + *(.gnu.linkonce.b*) + *(.bss*) + *(COMMON) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >vram + + __bss_end = . ; + __bss_end__ = . ; + + _end = . ; + __end__ = . ; + PROVIDE (end = _end); + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + .stack 0x80000 : { _stack = .; *(.stack) } + /* These must appear regardless of . */ +} diff --git a/retail/common/include/cardengine_header_arm7.h b/retail/common/include/cardengine_header_arm7.h index 4b32917aa..4c94a2bfa 100644 --- a/retail/common/include/cardengine_header_arm7.h +++ b/retail/common/include/cardengine_header_arm7.h @@ -101,6 +101,7 @@ typedef struct cardengineArm7 { 18: dsiBios 19: bootstrapOnFlashcard 20: ndmaDisabled + 21: isDlp 31: scfgLocked */ s32 mainScreen; diff --git a/retail/common/include/cardengine_header_arm9.h b/retail/common/include/cardengine_header_arm9.h index 68e843c0a..9f9961e01 100644 --- a/retail/common/include/cardengine_header_arm9.h +++ b/retail/common/include/cardengine_header_arm9.h @@ -100,6 +100,7 @@ typedef struct cardengineArm9 { 12: asyncCardRead 13: softResetMb 14: cloneboot + 15: isDlp */ s32 mainScreen; u32 overlaysSize; diff --git a/retail/common/include/locations.h b/retail/common/include/locations.h index 0b6a1c3e3..5f7c51416 100644 --- a/retail/common/include/locations.h +++ b/retail/common/include/locations.h @@ -86,6 +86,7 @@ #define CARDENGINEI_ARM7_DSIWARE_LOCATION3 0x03807400 #define CARDENGINEI_ARM9_LOCATION 0x027D8000 #define CARDENGINEI_ARM9_LOCATION2 0x027E0000 +#define CARDENGINEI_ARM9_LOCATION_DLP 0x02800000 #define CARDENGINEI_ARM9_LOCATION_DSI_WRAM 0x03700000 #define CARDENGINEI_ARM9_TWLSDK_LOCATION 0x02FD6C00 // Used for DSi-Enhanced games in DSi mode #define CARDENGINEI_ARM9_TWLSDK_LOCATION3 0x02F80000 // Used for DSi-Exclusive games