From 370be5352862211fdf45cb092d16d9969a25c75d Mon Sep 17 00:00:00 2001 From: JeffRuLz Date: Wed, 7 Nov 2018 21:23:37 -0600 Subject: [PATCH] store SD card size in an unsigned long long Fixes compatibility with >64GB cards? --- src/installmenu.c | 2 +- src/main.c | 15 ++++++++++++--- src/storage.c | 26 +++++++++++++------------- src/storage.h | 12 ++++++------ src/testmenu.c | 14 +++++++------- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/installmenu.c b/src/installmenu.c index 4f58e0a..0c7efa4 100644 --- a/src/installmenu.c +++ b/src/installmenu.c @@ -307,7 +307,7 @@ void install(Menu* m) } //Print file size - int fileSize = -1; + unsigned long long fileSize = 0; { iprintf("File Size: "); diff --git a/src/main.c b/src/main.c index 96c06a6..d1ff63f 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ #include "menu.h" #include -#define VERSION "0.5.1" +#define VERSION "0.5.2" enum { MAIN_MENU_INSTALL, @@ -18,6 +18,10 @@ int main(int argc, char **argv) { srand(time(0)); + //Setup top screen + REG_DISPCNT = MODE_FB0; + VRAM_A_CR = VRAM_ENABLE; + videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); @@ -30,13 +34,18 @@ int main(int argc, char **argv) consoleSelect(&bottomScreen); consoleClear(); + VRAM_A[100] = 0xFFFF; + if (!fatInitDefault()) { consoleSelect(&bottomScreen); consoleClear(); - iprintf("fatInitDefault...Failed\n"); - iprintf("\nPress B to exit.\n"); + //iprintf("fatInitDefault...Failed\n"); + //iprintf("\nPress B to exit.\n"); + + for (int i = 0; i < 32*24; i++) + iprintf("%c", i); keyWait(KEY_B | KEY_A | KEY_START); } diff --git a/src/storage.c b/src/storage.c index 7f13836..832819e 100644 --- a/src/storage.c +++ b/src/storage.c @@ -8,15 +8,15 @@ #define TITLE_LIMIT 39 //Printing -void printBytes(int bytes) +void printBytes(unsigned long long bytes) { - if (abs(bytes) < 1024) - iprintf("%dB", bytes); + if (bytes < 1024) + iprintf("%dB", (unsigned int)bytes); - else if (abs(bytes) < 1024 * 1024) + else if (bytes < 1024 * 1024) printf("%.2fKB", (float)bytes / 1024); - else if (abs(bytes) < 1024 * 1024 * 1024) + else if (bytes < 1024 * 1024 * 1024) printf("%.2fMB", (float)bytes / 1024 / 1024); else @@ -209,25 +209,25 @@ int copyFile(const char* in, char* out) return result; } -int getFileSize(FILE* f) +unsigned long long getFileSize(FILE* f) { if (!f) return 0; fseek(f, 0, SEEK_END); - int size = ftell(f); + unsigned long long size = ftell(f); fseek(f, 0, SEEK_SET); return size; } -int getFileSizePath(const char* path) +unsigned long long getFileSizePath(const char* path) { if (path == NULL) return -1; FILE* f = fopen(path, "rb"); - int size = getFileSize(f); + unsigned long long size = getFileSize(f); fclose(f); return size; @@ -372,12 +372,12 @@ int deleteDir(const char* path) return 1; } -int getDirSize(const char* path) +unsigned long long getDirSize(const char* path) { if (path == NULL) return 0; - int size = 0; + unsigned long long size = 0; DIR* dir; struct dirent *ent; @@ -472,7 +472,7 @@ int sdIsInserted() return 1; } -int getSDCardSize() +unsigned long long getSDCardSize() { if (sdIsInserted()) { @@ -484,7 +484,7 @@ int getSDCardSize() return 0; } -int getSDCardFree() +unsigned long long getSDCardFree() { if (sdIsInserted()) { diff --git a/src/storage.h b/src/storage.h index 486fb22..e8bb417 100644 --- a/src/storage.h +++ b/src/storage.h @@ -9,7 +9,7 @@ #define BYTES_PER_BLOCK (1024*128) //Printing -void printBytes(int bytes); +void printBytes(unsigned long long bytes); void printFileInfo(const char* path); //Progress bar @@ -18,15 +18,15 @@ void clearProgressBar(); //Files int copyFile(const char* in, char* out); -int getFileSize(FILE* f); -int getFileSizePath(const char* path); +unsigned long long getFileSize(FILE* f); +unsigned long long getFileSizePath(const char* path); int padFile(const char* path, int size); //Directories int dirExists(const char* path); //int copyDir(const char* in, char* out); int deleteDir(const char* path); -int getDirSize(const char* path); +unsigned long long getDirSize(const char* path); //Home menu int getMenuSlots(); @@ -36,8 +36,8 @@ int getMenuSlotsFree(); //SD Card int sdIsInserted(); -int getSDCardSize(); -int getSDCardFree(); +unsigned long long getSDCardSize(); +unsigned long long getSDCardFree(); #define getSDCardUsedSpace() (getSDCardSize() - getSDCardFree()) //Internal storage diff --git a/src/testmenu.c b/src/testmenu.c index 3983690..fdd370e 100644 --- a/src/testmenu.c +++ b/src/testmenu.c @@ -12,8 +12,8 @@ void testMenu() consoleSelect(&bottomScreen); consoleClear(); - int free = -1; - int size = -1; + unsigned int free = 0; + unsigned int size = 0; //Home menu slots { @@ -30,15 +30,15 @@ void testMenu() { iprintf("\nFree SD Space:\n\t"); swiWaitForVBlank(); - free = getSDCardFree(); - printBytes(free); + unsigned long long sdfree = getSDCardFree(); + printBytes(sdfree); iprintf(" / "); swiWaitForVBlank(); - size = getSDCardSize(); - printBytes(size); + unsigned long long sdsize = getSDCardSize(); + printBytes(sdsize); iprintf("\n"); swiWaitForVBlank(); - printf("\t%.0f / %.0f blocks\n", (float)free / BYTES_PER_BLOCK, (float)size / BYTES_PER_BLOCK); + printf("\t%d / %d blocks\n", (unsigned int)(sdfree / BYTES_PER_BLOCK), (unsigned int)(sdsize / BYTES_PER_BLOCK)); } //Emunand