From cb83ca6688773016927a8cbf4ca3c852b57d2fc0 Mon Sep 17 00:00:00 2001 From: dborth Date: Fri, 3 Oct 2008 06:58:21 +0000 Subject: [PATCH] enable readahead cache for faster file access --- source/ngc/fileop.cpp | 19 +++++++++---------- source/ngc/filesel.h | 2 +- source/ngc/vba.cpp | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 7481913..4f790be 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -60,18 +60,17 @@ bool ChangeFATInterface(int method, bool silent) { devFound = true; fatSetDefaultInterface(PI_INTERNAL_SD); + fatEnableReadAhead (PI_INTERNAL_SD, 6, 64); } #endif if (!devFound && FatIsMounted(PI_SDGECKO_A)) { devFound = true; - fatSetDefaultInterface(PI_SDGECKO_A); } if(!devFound && FatIsMounted(PI_SDGECKO_B)) { devFound = true; - fatSetDefaultInterface(PI_SDGECKO_B); } if(!devFound) { @@ -86,6 +85,7 @@ bool ChangeFATInterface(int method, bool silent) { devFound = true; fatSetDefaultInterface(PI_USBSTORAGE); + fatEnableReadAhead (PI_USBSTORAGE, 6, 64); } else { @@ -222,8 +222,7 @@ int LoadBufferFromFAT (char *filepath, bool silent) { FILE *handle; - int boffset = 0; - int read = 0; + int size = 0; handle = fopen (filepath, "rb"); @@ -238,15 +237,15 @@ LoadBufferFromFAT (char *filepath, bool silent) return 0; } - /*** This is really nice, just load the file and decode it ***/ - while ((read = fread (savebuffer + boffset, 1, 1024, handle)) > 0) - { - boffset += read; - } + fseek(handle, 0, SEEK_END); // go to end of file + size = ftell(handle); // get filesize + fseek(handle, 0, SEEK_SET); // go to start of file + fread (savebuffer, 1, size, handle); + fclose (handle); fclose (handle); - return boffset; + return size; } /**************************************************************************** diff --git a/source/ngc/filesel.h b/source/ngc/filesel.h index 047a678..586a8ce 100644 --- a/source/ngc/filesel.h +++ b/source/ngc/filesel.h @@ -33,7 +33,7 @@ extern int offset; extern int selection; extern char currentdir[MAXPATHLEN]; extern int maxfiles; -extern char romFilename[512]; +extern char ROMFilename[512]; void AllocSaveBuffer(); void FreeSaveBuffer(); diff --git a/source/ngc/vba.cpp b/source/ngc/vba.cpp index 90e9529..00fe09c 100644 --- a/source/ngc/vba.cpp +++ b/source/ngc/vba.cpp @@ -74,7 +74,7 @@ int main() } // Initialize libFAT for SD and USB - fatInitDefault(); + fatInit (8, false); // Initialize DVD subsystem (GameCube only) #ifdef HW_DOL