From 933d3b6e28e2de5661f5ace70f87a58700800b61 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Sun, 7 Oct 2018 10:12:34 -0600 Subject: [PATCH] Determine ROM size for GBA ROM dump --- arm9/source/driveMenu.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp index 9341215..34d9805 100644 --- a/arm9/source/driveMenu.cpp +++ b/arm9/source/driveMenu.cpp @@ -94,12 +94,20 @@ void gbaCartDump(void) { snprintf(destPath, sizeof(destPath), "fat:/gm9i/out/%s_%s_%s.gba", gbaHeaderGameTitle, gbaHeaderGameCode, gbaHeaderMakerCode); consoleClear(); printf("Dumping...\n"); - printf("This may take a while.\n"); - printf("\n"); printf("Do not remove the GBA cart.\n"); + // Determine ROM size + u32 romSize = 0x02000000; + for (u32 i = 0x09FE0000; i > 0x08000000; i -= 0x20000) { + if (*(u32*)(i) == 0xFFFE0000) { + romSize -= 0x20000; + } else { + break; + } + } + // Dump! remove(destPath); FILE* destinationFile = fopen(destPath, "wb"); - fwrite((void*)0x08000000, 1, 0x400000, destinationFile); + fwrite((void*)0x08000000, 1, romSize, destinationFile); fclose(destinationFile); break; }