Skip to content

Commit

Permalink
B4DS: Add POC-state support for *Flipnote Studio*
Browse files Browse the repository at this point in the history
- Requires DS Debug console
- Attempting to create a flipnote causes a crash
  • Loading branch information
RocketRobz committed Jan 1, 2024
1 parent ea7ea71 commit 94998ad
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 6 deletions.
1 change: 1 addition & 0 deletions retail/arm9/include/dsiwaresSetForBootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions retail/bootloader/source/arm7/dsi2ds_patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 26 additions & 6 deletions retail/bootloader/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions retail/bootloaderi/source/arm7/patch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 94998ad

Please sign in to comment.