all repos — mgba @ 916d14cd780a90cd8d712bb7932755c65b555b08

mGBA Game Boy Advance Emulator

Core: Unify duplicated loading functionality, make loads always preload with fixed ROM buffer
Vicki Pfau vi@endrift.com
Thu, 04 Jul 2019 14:18:30 -0700
commit

916d14cd780a90cd8d712bb7932755c65b555b08

parent

ca8559549c2b77b5adb958557c3a6c9d6ebc5d47

1 files changed, 9 insertions(+), 32 deletions(-)

jump to
M src/core/core.csrc/core/core.c

@@ -114,6 +114,9 @@ return NULL;

} bool mCoreLoadFile(struct mCore* core, const char* path) { +#ifdef FIXED_ROM_BUFFER + return mCorePreloadFile(core, path); +#else struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM); if (!rom) { return false;

@@ -124,43 +127,15 @@ if (!ret) {

rom->close(rom); } return ret; +#endif } bool mCorePreloadVF(struct mCore* core, struct VFile* vf) { - struct VFile* vfm; -#ifdef FIXED_ROM_BUFFER - extern uint32_t* romBuffer; - extern size_t romBufferSize; - vfm = VFileFromMemory(romBuffer, romBufferSize); -#else - vfm = VFileMemChunk(NULL, vf->size(vf)); -#endif - - uint8_t buffer[2048]; - ssize_t read; - vf->seek(vf, 0, SEEK_SET); - while ((read = vf->read(vf, buffer, sizeof(buffer))) > 0) { - vfm->write(vfm, buffer, read); - } - vf->close(vf); - bool ret = core->loadROM(core, vfm); - if (!ret) { - vfm->close(vfm); - } - return ret; + return mCorePreloadVFCB(core, vf, NULL, NULL); } bool mCorePreloadFile(struct mCore* core, const char* path) { - struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM); - if (!rom) { - return false; - } - - bool ret = mCorePreloadVF(core, rom); - if (!ret) { - rom->close(rom); - } - return ret; + return mCorePreloadFileCB(core, path, NULL, NULL); } bool mCorePreloadVFCB(struct mCore* core, struct VFile* vf, void (cb)(size_t, size_t, void*), void* context) {

@@ -182,7 +157,9 @@ vf->seek(vf, 0, SEEK_SET);

while ((read = vf->read(vf, buffer, sizeof(buffer))) > 0) { vfm->write(vfm, buffer, read); total += read; - cb(total, size, context); + if (cb) { + cb(total, size, context); + } } vf->close(vf); bool ret = core->loadROM(core, vfm);