From 2251c974651fbd37096370728cde2fe720a929e6 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Sat, 6 Jan 2024 02:21:00 -0700 Subject: [PATCH] B4DS: Add support for *Defense of the Middle Kingdom* Requires DS Debug console --- .../arm9/include/dsiwaresSetForBootloader.h | 1 + .../bootloader/source/arm7/dsi2ds_patches.c | 27 +++++++++++++++++++ retail/bootloaderi/source/arm7/patch_common.c | 21 +++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/retail/arm9/include/dsiwaresSetForBootloader.h b/retail/arm9/include/dsiwaresSetForBootloader.h index 9b7b4776b..23ede3011 100644 --- a/retail/arm9/include/dsiwaresSetForBootloader.h +++ b/retail/arm9/include/dsiwaresSetForBootloader.h @@ -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 diff --git a/retail/bootloader/source/arm7/dsi2ds_patches.c b/retail/bootloader/source/arm7/dsi2ds_patches.c index 625e59338..c1c8794cb 100644 --- a/retail/bootloader/source/arm7/dsi2ds_patches.c +++ b/retail/bootloader/source/arm7/dsi2ds_patches.c @@ -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) diff --git a/retail/bootloaderi/source/arm7/patch_common.c b/retail/bootloaderi/source/arm7/patch_common.c index 7b27878dd..a75e30080 100644 --- a/retail/bootloaderi/source/arm7/patch_common.c +++ b/retail/bootloaderi/source/arm7/patch_common.c @@ -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)