From d27f4fcc8261ce8ba82125537a5f4bec57058420 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sat, 11 Apr 2020 19:47:33 +0800 Subject: [PATCH] common large load buffer. --- file_io.cpp | 1 + file_io.h | 1 + support/arcade/romutils.cpp | 8 ++++---- support/neogeo/loader.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/file_io.cpp b/file_io.cpp index 58fe595..3511f73 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -41,6 +41,7 @@ static int iSelectedEntry = 0; // selected entry index static int iFirstEntry = 0; static char full_path[2100]; +uint8_t loadbuf[LOADBUF_SZ]; fileTYPE::fileTYPE() { diff --git a/file_io.h b/file_io.h index bcaef24..70c171f 100644 --- a/file_io.h +++ b/file_io.h @@ -113,6 +113,7 @@ const char *getFullPath(const char *name); uint32_t getFileType(const char *name); bool isMraName(char *path); +#define LOADBUF_SZ (1024*1024) #define COEFF_DIR "filters" #define GAMMA_DIR "gamma" diff --git a/support/arcade/romutils.cpp b/support/arcade/romutils.cpp index 0718481..8d61667 100644 --- a/support/arcade/romutils.cpp +++ b/support/arcade/romutils.cpp @@ -191,10 +191,10 @@ static int rom_data(const uint8_t *buf, int chunk, int map, struct MD5Context *m return 1; } +extern uint8_t loadbuf[]; static int rom_file(const char *name, uint32_t crc32, int start, int len, int map, struct MD5Context *md5context) { fileTYPE f = {}; - static uint8_t buf[4096]; if (!FileOpenZip(&f, name, crc32)) return 0; if (start) FileSeek(&f, start, SEEK_SET); unsigned long bytes2send = f.size - f.offset; @@ -202,10 +202,10 @@ static int rom_file(const char *name, uint32_t crc32, int start, int len, int ma while (bytes2send) { - uint16_t chunk = (bytes2send > sizeof(buf)) ? sizeof(buf) : bytes2send; + uint32_t chunk = (bytes2send > LOADBUF_SZ) ? LOADBUF_SZ : bytes2send; - FileReadAdv(&f, buf, chunk); - if (!rom_data(buf, chunk, map, md5context)) + FileReadAdv(&f, loadbuf, chunk); + if (!rom_data(loadbuf, chunk, map, md5context)) { FileClose(&f); return 0; diff --git a/support/neogeo/loader.cpp b/support/neogeo/loader.cpp index 28de896..8417421 100644 --- a/support/neogeo/loader.cpp +++ b/support/neogeo/loader.cpp @@ -223,7 +223,7 @@ static void make_path(const char *root, const char *name, char *path) strcat(path, name); } -static uint8_t loadbuf[1024 * 1024]; +extern uint8_t loadbuf[]; static uint32_t load_crom_to_mem(const char* path, const char* name, uint8_t index, uint32_t offset, uint32_t size) { fileTYPE f = {}; @@ -260,7 +260,7 @@ static uint32_t load_crom_to_mem(const char* path, const char* name, uint8_t ind while (remain) { uint32_t partsz = remain; - if (partsz > 1024 * 1024) partsz = 1024 * 1024; + if (partsz > LOADBUF_SZ) partsz = LOADBUF_SZ; //printf("partsz=%d, map_addr=0x%X\n", partsz, map_addr); void *base = mmap(0, partsz, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, map_addr); @@ -335,10 +335,10 @@ static uint32_t load_rom_to_mem(const char* path, const char* name, uint8_t neo_ while (remain) { uint32_t partsz = remain; - if (partsz > 1024 * 1024) partsz = 1024 * 1024; + if (partsz > LOADBUF_SZ) partsz = LOADBUF_SZ; uint32_t partszf = remainf; - if (partszf > 1024 * 1024) partszf = 1024 * 1024; + if (partszf > LOADBUF_SZ) partszf = LOADBUF_SZ; //printf("partsz=%d, map_addr=0x%X\n", partsz, map_addr); void *base = mmap(0, partsz, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, map_addr);