all repos — mgba @ 981a8bcb7d253835c334e7b6671ce5a523917bd3

mGBA Game Boy Advance Emulator

mGUI: Refactor fixed ROM buffer code out of cores, add loading progress
Vicki Pfau vi@endrift.com
Sun, 30 Jun 2019 17:49:44 -0700
commit

981a8bcb7d253835c334e7b6671ce5a523917bd3

parent

1a6d5ad7e3f28e01e747f634384e3775c562e119

5 files changed, 73 insertions(+), 21 deletions(-)

jump to
M include/mgba/core/core.hinclude/mgba/core/core.h

@@ -173,6 +173,9 @@

bool mCorePreloadVF(struct mCore* core, struct VFile* vf); bool mCorePreloadFile(struct mCore* core, const char* path); +bool mCorePreloadVFCB(struct mCore* core, struct VFile* vf, void (cb)(size_t, size_t, void*), void* context); +bool mCorePreloadFileCB(struct mCore* core, const char* path, void (cb)(size_t, size_t, void*), void* context); + bool mCoreAutoloadSave(struct mCore* core); bool mCoreAutoloadPatch(struct mCore* core); bool mCoreAutoloadCheats(struct mCore* core);
M src/core/core.csrc/core/core.c

@@ -127,7 +127,15 @@ return ret;

} bool mCorePreloadVF(struct mCore* core, struct VFile* vf) { - struct VFile* vfm = VFileMemChunk(NULL, vf->size(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);

@@ -149,6 +157,48 @@ return false;

} bool ret = mCorePreloadVF(core, rom); + if (!ret) { + rom->close(rom); + } + return ret; +} + +bool mCorePreloadVFCB(struct mCore* core, struct VFile* vf, void (cb)(size_t, size_t, void*), void* context) { + struct VFile* vfm; + size_t size = vf->size(vf); + +#ifdef FIXED_ROM_BUFFER + extern uint32_t* romBuffer; + extern size_t romBufferSize; + vfm = VFileFromMemory(romBuffer, romBufferSize); +#else + vfm = VFileMemChunk(NULL, size); +#endif + + uint8_t buffer[2048]; + ssize_t read; + size_t total = 0; + 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); + } + vf->close(vf); + bool ret = core->loadROM(core, vfm); + if (!ret) { + vfm->close(vfm); + } + return ret; +} + +bool mCorePreloadFileCB(struct mCore* core, const char* path, void (cb)(size_t, size_t, void*), void* context) { + struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM); + if (!rom) { + return false; + } + + bool ret = mCorePreloadVFCB(core, rom, cb, context); if (!ret) { rom->close(rom); }
M src/feature/gui/gui-runner.csrc/feature/gui/gui-runner.c

@@ -289,6 +289,23 @@ }

} } +static void _updateLoading(size_t read, size_t size, void* context) { + struct mGUIRunner* runner = context; + if (read & 0x3FFFF) { + return; + } + + runner->params.drawStart(); + if (runner->params.guiPrepare) { + runner->params.guiPrepare(); + } + GUIFontPrintf(runner->params.font, runner->params.width / 2, (GUIFontHeight(runner->params.font) + runner->params.height) / 2, GUI_ALIGN_HCENTER, 0xFFFFFFFF, "Loading...%i%%", 100 * read / size); + if (runner->params.guiFinish) { + runner->params.guiFinish(); + } + runner->params.drawEnd(); +} + void mGUIRun(struct mGUIRunner* runner, const char* path) { struct mGUIBackground drawState = { .d = {

@@ -364,7 +381,8 @@ mLOG(GUI_RUNNER, INFO, "Found core");

runner->core->init(runner->core); mCoreInitConfig(runner->core, runner->port); mInputMapInit(&runner->core->inputMap, &GBAInputInfo); - found = mCoreLoadFile(runner->core, path); + + found = mCorePreloadFileCB(runner->core, path, _updateLoading, runner); if (!found) { mLOG(GUI_RUNNER, WARN, "Failed to load %s!", path); mCoreConfigDeinit(&runner->core->config);
M src/gb/gb.csrc/gb/gb.c

@@ -46,11 +46,6 @@ static void GBStop(struct LR35902Core* cpu);

static void _enableInterrupts(struct mTiming* timing, void* user, uint32_t cyclesLate); -#ifdef FIXED_ROM_BUFFER -extern uint32_t* romBuffer; -extern size_t romBufferSize; -#endif - void GBCreate(struct GB* gb) { gb->d.id = GB_COMPONENT_MAGIC; gb->d.init = GBInit;

@@ -113,14 +108,7 @@ gb->romVf = vf;

gb->pristineRomSize = vf->size(vf); vf->seek(vf, 0, SEEK_SET); gb->isPristine = true; -#ifdef FIXED_ROM_BUFFER - if (gb->pristineRomSize <= romBufferSize) { - gb->memory.rom = romBuffer; - vf->read(vf, romBuffer, gb->pristineRomSize); - } -#else gb->memory.rom = vf->map(vf, gb->pristineRomSize, MAP_READ); -#endif if (!gb->memory.rom) { return false; }
M src/gba/gba.csrc/gba/gba.c

@@ -383,14 +383,7 @@ gba->memory.rom = anonymousMemoryMap(SIZE_CART0);

#endif } else { gba->isPristine = true; -#ifdef FIXED_ROM_BUFFER - if (gba->pristineRomSize <= romBufferSize) { - gba->memory.rom = romBuffer; - vf->read(vf, romBuffer, gba->pristineRomSize); - } -#else gba->memory.rom = vf->map(vf, gba->pristineRomSize, MAP_READ); -#endif gba->memory.romSize = gba->pristineRomSize; } if (!gba->memory.rom) {