From 4c0b428cde4d9e590d0873cdcdd96d006502e0be Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 14 May 2015 04:27:30 -0300 Subject: [PATCH] Remove pointless casts and fix variable types. --- source/main.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/source/main.c b/source/main.c index 599d43d..9807b3e 100644 --- a/source/main.c +++ b/source/main.c @@ -37,19 +37,19 @@ int main() { wait_key(); u32 bytes_written = 0; - u8 String[21]; + char filename_buf[21]; // Arbitrary target buffer // TODO: This should be done in a nicer way ;) - volatile u8* target = (vu8*)0x22000000; - volatile u8* header = (vu8*)0x23000000; + u8* target = (u8*)0x22000000; + u8* header = (u8*)0x23000000; Debug("ROM dump tool v0.2", 1, 1, 0xFF); - memset((u8*)target, 0x00, 0x100000); // Clear our 1 MB buffer + memset(target, 0x00, 0x100000); // Clear our 1 MB buffer // clear_screens(0x00); - *(u32*)0x10000020 = 0; // InitFS stuff - *(u32*)0x10000020 = 0x340; // InitFS stuff + *(vu32*)0x10000020 = 0; // InitFS stuff + *(vu32*)0x10000020 = 0x340; // InitFS stuff unsigned ret = f_mount(&fs, "0:", 0) == FR_OK; if (!ret) { Debug("Failed to f_mount..."); @@ -65,11 +65,11 @@ int main() { Debug("Done! Cart id is %08x, press A...", (u32)Cart_GetID()); - while((*((vu16*)0x10146000) & 1)); // Wait for button A + InputWait(); Debug("Done waiting :)...", 1, 1, 0xFF); CTR_CmdReadHeader(header); - Debug("Done reading header: %08x :)...", *(u32*)&header[0x100]); + Debug("Done reading header: %08X :)...", *(u32*)&header[0x100]); // TODO: Check first header bytes for "NCSD" or other magic words which should be there for valid NCCHs u32 sec_keys[4]; @@ -82,16 +82,16 @@ int main() { u32 blocks = dumpSize / mediaUnit; //1MB of blocks // Read out the header 0x0000-0x1000 - CTR_CmdReadData(0, mediaUnit, 8, (void*)(target)); + CTR_CmdReadData(0, mediaUnit, 8, target); // Create output file - TODO: Put actual information in the file name (game id/name/..?), to have a standardized naming scheme - memcpy(String, "/dump.3ds\0", 10); + snprintf(filename_buf, sizeof(filename_buf), "%s", "/dump.3ds"); wait_key(); - Debug("File name: \"%s\"", String); + Debug("File name: \"%s\"", filename_buf); unsigned flags = FA_READ | FA_WRITE | FA_CREATE_ALWAYS; - if (f_open(&file, String, flags) != FR_OK) { + if (f_open(&file, filename_buf, flags) != FR_OK) { Debug("Failed to create file..."); wait_key(); return 0; @@ -103,15 +103,14 @@ int main() { wait_key(); // Write header to file - u32 written = 0; + unsigned int written = 0; f_write(&file, target, 0x4000, &written); f_sync(&file); Debug("Wrote header"); wait_key(); - u32 cartSize = *(u32*)(&target[0x104]); - Debug("Cart size: %d MB", cartSize * 0x200 / 1024/1024); + Debug("Cart size: %llu MB", (u64)cartSize * 0x200ull / 1024ull / 1024ull); wait_key(); // Dump remaining data @@ -137,12 +136,11 @@ int main() { f_lseek(&file, 0x1000); f_write(&file, header, 0x200, &written); f_sync(&file); - Debug("Wrote 0x%x header bytes", written); + Debug("Wrote 0x%X header bytes", written); wait_key(); // Done, clean up... f_close(&file); - wait_key(); f_mount(NULL, "0:", 0); return 0;