Skip to content

Commit

Permalink
Merge pull request #31 from ahezard/card
Browse files Browse the repository at this point in the history
Merge the dsi wram method
  • Loading branch information
ahezard authored Jan 25, 2017
2 parents 6913366 + 492827b commit 707d686
Show file tree
Hide file tree
Showing 32 changed files with 1,401 additions and 171 deletions.
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ endif

export GAME_TITLE := $(TARGET)

.PHONY: cardengine sdengine bootloader bootstub BootStrap clean
.PHONY: cardengine_arm7 cardengine_arm9 sdengine bootloader bootstub BootStrap clean

all: cardengine sdengine bootloader bootstub $(TARGET).nds
all: cardengine_arm7 cardengine_arm9 sdengine bootloader bootstub $(TARGET).nds

dist: all
@rm -fr hbmenu
Expand Down Expand Up @@ -150,8 +150,11 @@ dldi/dsisd.dldi:
sdengine: data
@$(MAKE) -C sdengine

cardengine: data
@$(MAKE) -C cardengine
cardengine_arm7: data
@$(MAKE) -C cardengine_arm7

cardengine_arm9: data
@$(MAKE) -C cardengine_arm9

#---------------------------------------------------------------------------------
#$(BUILD):
Expand All @@ -168,7 +171,8 @@ clean:
@$(MAKE) -C bootstub clean
@$(MAKE) -C arm9 clean
@$(MAKE) -C arm7 clean
@$(MAKE) -C cardengine clean
@$(MAKE) -C cardengine_arm7 clean
@$(MAKE) -C cardengine_arm9 clean
@$(MAKE) -C sdengine clean
@$(MAKE) -C dldi clean

Expand Down
28 changes: 28 additions & 0 deletions arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,38 @@ static u32 quickFind (const unsigned char* data, const unsigned char* search, u3

static const unsigned char dldiMagicString[] = "\xED\xA5\x8D\xBF Chishm"; // Normal DLDI file

void initMBK() {
// give all DSI WRAM to arm7 at boot

// arm7 is master of WRAM-A/B/C
REG_MBK_9=0x3000000F;

// WRAM-A fully mapped to arm7
REG_MBK_1=0x8185898D;

// WRAM-B fully mapped to arm7
REG_MBK_2=0x8185898D;
REG_MBK_3=0x9195999D;

// WRAM-C fully mapped to arm7
REG_MBK_4=0x8185898D;
REG_MBK_5=0x9195999D;

// WRAM mapped to the 0x3700000 - 0x37AFFFF area
// WRAM-A mapped to the 0x3780000 - 0x37BFFFF area : 256k
REG_MBK_6=0x07C03780;
// WRAM-B mapped to the 0x3740000 - 0x377FFFF area : 256k
REG_MBK_7=0x07803740;
// WRAM-C mapped to the 0x3700000 - 0x373FFFF area : 256k
REG_MBK_8=0x07403700;
}

//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

initMBK();

// Find the DLDI reserved space in the file
u32 patchOffset = quickFind (__NDSHeader->arm9destination, dldiMagicString, __NDSHeader->arm9binarySize, sizeof(dldiMagicString));
wordCommandAddr = (u32 *) (((u32)__NDSHeader->arm9destination)+patchOffset+0x80);
Expand Down
27 changes: 27 additions & 0 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,35 @@ static void myFIFOValue32Handler(u32 value,void* data)
dbg_printf( "ARM7 data %x\n", value );
}


void initMBK() {
// default dsiware settings
//REG_MBK_1=0x8185898D;
//REG_MBK_2=0x8084888C;
//REG_MBK_3=0x9094989C;
//REG_MBK_4=0x8084888C;
//REG_MBK_5=0x9094989C;

// WRAM-B fully mapped to arm7
REG_MBK_2=0x8185898D;
REG_MBK_3=0x9195999D;

// WRAM-C fully mapped to arm7
REG_MBK_4=0x8185898D;
REG_MBK_5=0x9195999D;

// WRAM-A not mapped (reserved to arm7)
REG_MBK_6=0x00000000;
// WRAM-B mapped to the 0x3740000 - 0x377FFFF area : 256k
REG_MBK_7=0x07803740;
// WRAM-C mapped to the 0x3700000 - 0x373FFFF area : 256k
REG_MBK_8=0x07403700;
}

int main( int argc, char **argv) {

initMBK();

bool ntrMode = false;

// No! broke no$gba compatibility
Expand Down
11 changes: 8 additions & 3 deletions bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ sdengine.bin.o : sdengine.bin
sdengine.bin:
cp $(CURDIR)/../../data/sdengine.bin sdengine.bin

cardengine.bin.o : cardengine.bin
cardengine_arm7.bin.o : cardengine_arm7.bin

cardengine.bin:
cp $(CURDIR)/../../data/cardengine.bin cardengine.bin
cardengine_arm7.bin:
cp $(CURDIR)/../../data/cardengine_arm7.bin cardengine_arm7.bin

cardengine_arm9.bin.o : cardengine_arm9.bin

cardengine_arm9.bin:
cp $(CURDIR)/../../data/cardengine_arm9.bin cardengine_arm9.bin

-include $(DEPENDS)

Expand Down
21 changes: 15 additions & 6 deletions bootloader/source/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Helpful information:
#include "dldi_patcher.h"
#include "card.h"
#include "card_patcher.h"
#include "cardengine_bin.h"
#include "cardengine_arm7_bin.h"
#include "cardengine_arm9_bin.h"
#include "boot.h"
#include "hook.h"
#include "common.h"
Expand All @@ -69,7 +70,10 @@ void sdmmc_controller_init();

#define CHEAT_ENGINE_LOCATION 0x027FE000
#define CHEAT_DATA_LOCATION 0x06010000
#define SD_ENGINE_LOCATION 0x037C0000
#define ENGINE_LOCATION_ARM7 0x03780000
#define ENGINE_LOCATION_ARM9 0x03700000
#define MARKER_ADDRESS_1 0x03740000
#define MARKER_ADDRESS_2 0x03746004

const char* bootName = "BOOT.NDS";

Expand Down Expand Up @@ -341,25 +345,30 @@ int main (void) {
u32 patchOffset = quickFind ((u8*)((u32*)NDS_HEAD)[0x0A], dldiMagicString, ((u32*)NDS_HEAD)[0x0B], sizeof(dldiMagicString));
u32* wordCommandAddr = (u32 *) (((u32)((u32*)NDS_HEAD)[0x0A])+patchOffset+0x80);

int error = hookNdsHomebrew(NDS_HEAD, (const u32*)CHEAT_DATA_LOCATION, (u32*)CHEAT_ENGINE_LOCATION, (u32*)SD_ENGINE_LOCATION, wordCommandAddr);
int error = hookNdsHomebrew(NDS_HEAD, (const u32*)CHEAT_DATA_LOCATION, (u32*)CHEAT_ENGINE_LOCATION, (u32*)ENGINE_LOCATION_ARM7, wordCommandAddr);
if(error == ERR_NONE) {
nocashMessage("dldi hook Sucessfull");
} else {
nocashMessage("error during dldi hook");
}
} else {
nocashMessage("dldi Patch Unsuccessful try to patch card");
copyLoop (SD_ENGINE_LOCATION, (u32*)cardengine_bin, cardengine_bin_size);
copyLoop (ENGINE_LOCATION_ARM7, (u32*)cardengine_arm7_bin, cardengine_arm7_bin_size);
copyLoop (ENGINE_LOCATION_ARM9, (u32*)cardengine_arm9_bin, cardengine_arm9_bin_size);

// set a synchronisation marker on the WRAM block
*((vu32*)MARKER_ADDRESS_1) = (vu32)0xDEADBABE;
*((vu32*)MARKER_ADDRESS_2) = (vu32)0xDEADBABE;

module_params_t* params = findModuleParams(NDS_HEAD);
if(params)
{
ensureArm9Decompressed(NDS_HEAD, params);
}

patchCardNds(NDS_HEAD,SD_ENGINE_LOCATION,params,saveFileCluster);
patchCardNds(NDS_HEAD,ENGINE_LOCATION_ARM7,ENGINE_LOCATION_ARM9,params,saveFileCluster);

int error = hookNdsRetail(NDS_HEAD, file, (const u32*)CHEAT_DATA_LOCATION, (u32*)CHEAT_ENGINE_LOCATION, (u32*)SD_ENGINE_LOCATION);
int error = hookNdsRetail(NDS_HEAD, file, (const u32*)CHEAT_DATA_LOCATION, (u32*)CHEAT_ENGINE_LOCATION, (u32*)ENGINE_LOCATION_ARM7);
if(error == ERR_NONE) {
nocashMessage("card hook Sucessfull");
} else {
Expand Down
Loading

0 comments on commit 707d686

Please sign in to comment.