Skip to content

Commit

Permalink
B4DS: Add support for *Defense of the Middle Kingdom*
Browse files Browse the repository at this point in the history
Requires DS Debug console
  • Loading branch information
RocketRobz committed Jan 6, 2024
1 parent 56e79c9 commit 2251c97
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions retail/arm9/include/dsiwaresSetForBootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ static const char dsiWareForBootloader1[][4] = {
"KDV", // Dark Void Zero
"KUI", // Decathlon 2012
"K6B", // Deep Sea Creatures
"K35", // Defense of the Middle Kingdom
"KWT", // GO Series: Defense Wars
"KCP", // Dekisugi Tingle Pack
"KN2", // Devil Band: Rock the Underworld
Expand Down
27 changes: 27 additions & 0 deletions retail/bootloader/source/arm7/dsi2ds_patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -8383,6 +8383,33 @@ void patchDSiModeToDSMode(cardengineArm9* ce9, const tNDSHeader* ndsHeader) {
*(u32*)0x02072780 = 0xE1A00000; // nop (Skip Manual screen)
}

// Defense of the Middle Kingdom (USA)
// Sangoku Tower Defense: Doushou Teppeki (Japan)
// Requires 8MB of RAM
else if (strncmp(romTid, "K35", 3) == 0 && extendedMemory) {
const u32 newCodeAddr = 0x0205EE58;

codeCopy((u32*)newCodeAddr, (u32*)0x0200B390, 0xC0);
setBL(newCodeAddr+0x28, (u32)dsiSaveOpen);
setBL(newCodeAddr+0x40, (u32)dsiSaveGetLength);
setBL(newCodeAddr+0x5C, (u32)dsiSaveRead);
setBL(newCodeAddr+0x8C, (u32)dsiSaveClose);

*(u32*)0x0200B1E0 = 0xE1A00000; // nop
setBL(0x0200B240, newCodeAddr);
*(u32*)0x0200B27C = 0xE1A00000; // nop
setBL(0x0200B478, (u32)dsiSaveCreate); // dsiSaveCreateAuto
setBL(0x0200B488, (u32)dsiSaveOpen);
setBL(0x0200B4A8, (u32)dsiSaveWrite);
setBL(0x0200B4C0, (u32)dsiSaveClose);
*(u32*)0x0205CE4C = 0xE1A00000; // nop
tonccpy((u32*)0x0205D9D0, dsiSaveGetResultCode, 0xC);
*(u32*)0x02061130 = 0xE1A00000; // nop
patchInitDSiWare(0x02068918, heapEnd);
*(u32*)0x02068CA4 -= 0x39000;
patchUserSettingsReadDSiWare(0x02069DA4);
}

// GO Series: Defense Wars (USA)
// GO Series: Defence Wars (Europe)
// Uchi Makure!: Touch Pen Wars (Japan)
Expand Down
21 changes: 21 additions & 0 deletions retail/bootloaderi/source/arm7/patch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5004,6 +5004,27 @@ void dsiWarePatch(cardengineArm9* ce9, const tNDSHeader* ndsHeader) {
}
}

// Defense of the Middle Kingdom (USA)
// Sangoku Tower Defense: Doushou Teppeki (Japan)
else if (strncmp(romTid, "K35", 3) == 0 && saveOnFlashcard) {
const u32 newCodeAddr = 0x0205EE58;

codeCopy((u32*)newCodeAddr, (u32*)0x0200B390, 0xC0);
setBL(newCodeAddr+0x28, (u32)dsiSaveOpen);
setBL(newCodeAddr+0x40, (u32)dsiSaveGetLength);
setBL(newCodeAddr+0x5C, (u32)dsiSaveRead);
setBL(newCodeAddr+0x8C, (u32)dsiSaveClose);

*(u32*)0x0200B1E0 = 0xE1A00000; // nop
setBL(0x0200B240, newCodeAddr);
*(u32*)0x0200B27C = 0xE1A00000; // nop
setBL(0x0200B478, (u32)dsiSaveCreate); // dsiSaveCreateAuto
setBL(0x0200B488, (u32)dsiSaveOpen);
setBL(0x0200B4A8, (u32)dsiSaveWrite);
setBL(0x0200B4C0, (u32)dsiSaveClose);
tonccpy((u32*)0x0205D9D0, dsiSaveGetResultCode, 0xC);
}

// GO Series: Defense Wars (USA)
// GO Series: Defence Wars (Europe)
// Uchi Makure!: Touch Pen Wars (Japan)
Expand Down

0 comments on commit 2251c97

Please sign in to comment.