From 3bf8f17b7c7b0c59bb368788e61e30299f5d13b5 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Fri, 4 Sep 2020 00:39:08 -0600 Subject: [PATCH] Dump last 32MB from certain GBA Video ROMs --- README.md | 1 + arm9/source/dumpOperations.cpp | 38 +++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d8718d..48ac6e9 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Once everything is downloaded and installed, `git clone` this repository, naviga * [Evie/Pk11](https://github.com/Epicpkmn11): Contributor. * [zacchi4k](https://github.com/zacchi4k): Logo designer. * [Edo9300](https://github.com/edo9300): Save reading code from his save manager tool. +* [endrift](https://github.com/endrift): GBA ROM dumping code from [duplo](https://github.com/endrift/duplo), used for 64MB ROMs. * [JimmyZ](https://github.com/JimmyZ): NAND code from twlnf (with writing code stripped for safety reasons). * [zoogie](https://github.com/zoogie): ConsoleID code (originating from dumpTool). * [devkitPro](https://github.com/devkitPro): devkitARM, libnds, original nds-hb-menu code, and screenshot code. diff --git a/arm9/source/dumpOperations.cpp b/arm9/source/dumpOperations.cpp index 15fbbc8..4eb4531 100644 --- a/arm9/source/dumpOperations.cpp +++ b/arm9/source/dumpOperations.cpp @@ -466,6 +466,21 @@ void ndsCardDump(void) { } } + +void writeChange(const u32* buffer) { + // Input registers are at 0x08800000 - 0x088001FF + *(vu32*) 0x08800184 = buffer[1]; + *(vu32*) 0x08800188 = buffer[2]; + *(vu32*) 0x0880018C = buffer[3]; + + *(vu32*) 0x08800180 = buffer[0]; +} + +void readChange(void) { + // Output registers are at 0x08800100 - 0x088001FF + while (*(vu32*) 0x08000180 & 0x1000); // Busy bit +} + void gbaCartDump(void) { int pressed = 0; @@ -553,8 +568,29 @@ void gbaCartDump(void) { // Dump! remove(destPath); FILE* destinationFile = fopen(destPath, "wb"); - fwrite((void*)0x08000000, 1, romSize, destinationFile); + fwrite(GBAROM, 1, romSize, destinationFile); fclose(destinationFile); + // Check for 64MB GBA Video ROM + if (strncmp((char*)0x080000AC, "MSAE", 4)==0 // Shark Tale + || strncmp((char*)0x080000AC, "MSKE", 4)==0 // Shrek + || strncmp((char*)0x080000AC, "M2SE", 4)==0 // Shrek 2 + ) { + // Dump last 32MB + u32 cmd[4] = { + 0x11, // Command + 0, // ROM address + 0x08001000, // Virtual address + 0x8, // Size (in 0x200 byte blocks) + }; + + size_t i; + for (i = 0x02000000; i < 0x04000000; i += 0x1000) { + cmd[1] = i, + writeChange(cmd); + readChange(); + fwrite(GBAROM + (0x1000 >> 1), 0x1000, 1, destinationFile); + } + } // Save file remove(destSavPath); destinationFile = fopen(destSavPath, "wb");