From 94998adbaafdb7cb541ad2087057949bc0dc2b33 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Mon, 1 Jan 2024 02:43:57 -0700 Subject: [PATCH] B4DS: Add POC-state support for *Flipnote Studio* - Requires DS Debug console - Attempting to create a flipnote causes a crash --- .../arm9/include/dsiwaresSetForBootloader.h | 1 + .../bootloader/source/arm7/dsi2ds_patches.c | 56 +++++++++++++++++++ retail/bootloader/source/arm7/patch_arm9.c | 32 +++++++++-- retail/bootloaderi/source/arm7/patch_common.c | 14 +++++ 4 files changed, 97 insertions(+), 6 deletions(-) diff --git a/retail/arm9/include/dsiwaresSetForBootloader.h b/retail/arm9/include/dsiwaresSetForBootloader.h index ecf7a01fb..9b7b4776b 100644 --- a/retail/arm9/include/dsiwaresSetForBootloader.h +++ b/retail/arm9/include/dsiwaresSetForBootloader.h @@ -194,6 +194,7 @@ static const char dsiWareForBootloader1[][4] = { // "K4K", // Flametail "KFS", // Flashlight "KKR", // Flip the Core + "KGU", // Flipnote Studio "KFP", // Flipper "KKN", // Flipper 2: Flush the Goldfish "KFU", // Flips: The Bubonic Builders diff --git a/retail/bootloader/source/arm7/dsi2ds_patches.c b/retail/bootloader/source/arm7/dsi2ds_patches.c index e8f3d66ab..1e2f73ce8 100644 --- a/retail/bootloader/source/arm7/dsi2ds_patches.c +++ b/retail/bootloader/source/arm7/dsi2ds_patches.c @@ -10837,6 +10837,62 @@ void patchDSiModeToDSMode(cardengineArm9* ce9, const tNDSHeader* ndsHeader) { *(u16*)0x020D86B8 = nopT; } + // Flipnote Studio (USA) + // Requires 8MB of RAM + // Proof-of-Concept stage (Crashes when attempting to create a flipnote) + else if (strcmp(romTid, "KGUE") == 0 && extendedMemory) { + *(u32*)0x020051E8 = 0xE1A00000; // nop + *(u32*)0x020051F4 = 0xE1A00000; // nop + *(u32*)0x02005200 = 0xE1A00000; // nop + *(u32*)0x0200520C = 0xE1A00000; // nop + *(u32*)0x0200521C = 0xE3A0079E; // mov r0, #0x02780000 + *(u32*)0x02005234 = 0xE3A0079D; // mov r0, #0x02740000 + *(u32*)0x0200526C = 0xE1A00000; // nop + *(u32*)0x020052F4 = 0xE1A00000; // nop + *(u32*)0x02005C7C = 0xE1A00000; // nop + *(u32*)0x02006844 = 0xE3A00001; // mov r0, #1 + *(u32*)0x02006898 = 0xE3A00001; // mov r0, #1 + *(u32*)0x02006930 = 0xE1A00000; // nop + *(u32*)0x02006950 = 0xE1A00000; // nop + *(u32*)0x020069A4 = 0xE1A00000; // nop + *(u32*)0x020069D8 = 0xE1A00000; // nop + *(u32*)0x02010048 = 0xE1A00000; // nop + *(u32*)0x02011B68 = 0xE3A00000; // mov r0, #0 + *(u32*)0x02018474 = 0xE3A00000; // mov r0, #0 + *(u32*)0x02018478 = 0xE12FFF1E; // bx lr + *(u32*)0x0201BA3C = 0xE12FFF1E; // bx lr + *(u32*)0x0201D584 = 0xE3A00000; // mov r0, #0 + *(u32*)0x02022FD8 = 0xE12FFF1E; // bx lr + *(u32*)0x02028BBC = 0xE12FFF1E; // bx lr (Skip loading SampleData .ash files) + *(u32*)0x0203202C = 0xE1A00000; // nop + *(u32*)0x02032160 = 0xE3A00000; // mov r0, #0 + *(u32*)0x0203218C = 0xE1A00000; // nop + *(u32*)0x020325AC = 0xE1A00000; // nop + *(u32*)0x02058C10 = 0xE12FFF1E; // bx lr + *(u32*)0x0206D698 = 0xE3A00000; // mov r0, #0 + *(u32*)0x02070180 = 0xE1A00000; // nop + *(u32*)0x020B41A4 = 0xE1A00000; // nop + *(u32*)0x020B820C = 0xE1A00000; // nop + patchInitDSiWare(0x020C1418, heapEnd_512KBFreeForDebug); + *(u32*)0x020C1788 = *(u32*)0x02004FC0; + patchUserSettingsReadDSiWare(0x020C2998); + // *(u32*)0x020C29C0 = wirelessReturnCodeArm; + *(u32*)0x020C29C0 = 0xE3A00000; // mov r0, #0 + *(u32*)0x020C29C4 = 0xE12FFF1E; // bx lr + *(u32*)0x020C29CC = 0xE3A00001; // mov r0, #1 + *(u32*)0x020C29D0 = 0xE12FFF1E; // bx lr + *(u32*)0x020C29F0 = 0xE3A00001; // mov r0, #1 + *(u32*)0x020C29F4 = 0xE12FFF1E; // bx lr + *(u32*)0x020C2A04 = 0xE3A00001; // mov r0, #1 + *(u32*)0x020C2A08 = 0xE12FFF1E; // bx lr + *(u32*)0x020C2A28 = 0xE3A00000; // mov r0, #0 + *(u32*)0x020C2A2C = 0xE12FFF1E; // bx lr + *(u32*)0x020C2EF8 = 0xE1A00000; // nop + *(u32*)0x020C2EFC = 0xE1A00000; // nop + *(u32*)0x020C2F00 = 0xE1A00000; // nop + *(u32*)0x020C2F04 = 0xE1A00000; // nop + } + // Flipper (USA) // Saving not supported due to using more than one file in filesystem else if (strcmp(romTid, "KFPE") == 0) { diff --git a/retail/bootloader/source/arm7/patch_arm9.c b/retail/bootloader/source/arm7/patch_arm9.c index bd63bd460..e9e91ca2e 100644 --- a/retail/bootloader/source/arm7/patch_arm9.c +++ b/retail/bootloader/source/arm7/patch_arm9.c @@ -814,11 +814,21 @@ void patchHiHeapDSiWare(u32 addr, u32 heapEnd) { *(u32*)(addr+0x28) = 0xE3560001; // cmp r6, #1 *(u32*)(addr+0x30) = 0xE3A00627; // mov r0, #0x2700000 - *(u32*)(addr+0x58) = 0xE3A00C00; // mov r0, #*(u32*)(addr+0x13C) + // Convert ldr to mov instruction if (*(u32*)(addr+0x13C) != 0) { - for (u32 i = 0; i < *(u32*)(addr+0x13C); i += 0x100) { - *(u32*)(addr+0x58) += 1; + if (*(u8*)(addr+0x13C) != 0) { + *(u32*)(addr+0x58) = 0xE3A00D00; // mov r0, #*(u32*)(addr+0x13C) + for (u32 i = 0; i < *(u32*)(addr+0x13C); i += 0x40) { + *(u32*)(addr+0x58) += 1; + } + } else { + *(u32*)(addr+0x58) = 0xE3A00C00; // mov r0, #*(u32*)(addr+0x13C) + for (u32 i = 0; i < *(u32*)(addr+0x13C); i += 0x100) { + *(u32*)(addr+0x58) += 1; + } } + } else { + *(u32*)(addr+0x58) = 0xE3A00000; // mov r0, #*(u32*)(addr+0x13C) } *(u32*)(addr+0x13C) = heapEnd; @@ -829,11 +839,21 @@ void patchHiHeapDSiWare(u32 addr, u32 heapEnd) { *(u32*)(addr+0x24) = 0xE3500001; // cmp r0, #1 *(u32*)(addr+0x2C) = 0x13A00627; // movne r0, #0x2700000 - *(u32*)(addr+0x40) = 0xE3A01C00; // mov r1, #*(u32*)(addr+0x9C) + // Convert ldr to mov instruction if (*(u32*)(addr+0x9C) != 0) { - for (u32 i = 0; i < *(u32*)(addr+0x9C); i += 0x100) { - *(u32*)(addr+0x40) += 1; + if (*(u8*)(addr+0x9C) != 0) { + *(u32*)(addr+0x40) = 0xE3A01D00; // mov r1, #*(u32*)(addr+0x9C) + for (u32 i = 0; i < *(u32*)(addr+0x9C); i += 0x40) { + *(u32*)(addr+0x40) += 1; + } + } else { + *(u32*)(addr+0x40) = 0xE3A01C00; // mov r1, #*(u32*)(addr+0x9C) + for (u32 i = 0; i < *(u32*)(addr+0x9C); i += 0x100) { + *(u32*)(addr+0x40) += 1; + } } + } else { + *(u32*)(addr+0x40) = 0xE3A01000; // mov r1, #*(u32*)(addr+0x9C) } /*if (*(u32*)(addr+0x9C) == 0) { diff --git a/retail/bootloaderi/source/arm7/patch_common.c b/retail/bootloaderi/source/arm7/patch_common.c index 69e9abf12..8d0294c2a 100644 --- a/retail/bootloaderi/source/arm7/patch_common.c +++ b/retail/bootloaderi/source/arm7/patch_common.c @@ -6151,6 +6151,20 @@ void dsiWarePatch(cardengineArm9* ce9, const tNDSHeader* ndsHeader) { setBLThumb(0x0204A478, dsiSaveSeekT); } + // Flipnote Studio (USA) + else if (strcmp(romTid, "KGUE") == 0 && saveOnFlashcard) { + *(u32*)0x02006844 = 0xE3A00001; // mov r0, #1 + *(u32*)0x02006898 = 0xE3A00001; // mov r0, #1 + *(u32*)0x0201D584 = 0xE3A00000; // mov r0, #0 + } + + // Flipnote Studio (Europe, Australia) + else if (strcmp(romTid, "KGUV") == 0 && saveOnFlashcard) { + *(u32*)0x02006748 = 0xE3A00001; // mov r0, #1 + *(u32*)0x02006784 = 0xE3A00001; // mov r0, #1 + *(u32*)0x0201D6CC = 0xE3A00000; // mov r0, #0 + } + // Flips: The Bubonic Builders (USA) // Flips: The Bubonic Builders (Europe, Australia) // Flips: Silent But Deadly (USA)