mGUI: Refactor fixed ROM buffer code out of cores, add loading progress

This commit is contained in:
Vicki Pfau 2019-06-30 17:49:44 -07:00
parent 1a6d5ad7e3
commit 981a8bcb7d
5 changed files with 73 additions and 21 deletions

View File

@ -173,6 +173,9 @@ bool mCoreLoadFile(struct mCore* core, const char* path);
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);

View File

@ -127,7 +127,15 @@ bool mCoreLoadFile(struct mCore* core, const char* path) {
}
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);
@ -155,6 +163,48 @@ bool mCorePreloadFile(struct mCore* core, const char* path) {
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);
}
return ret;
}
bool mCoreAutoloadSave(struct mCore* core) {
if (!core->dirs.save) {
return false;

View File

@ -289,6 +289,23 @@ static void _log(struct mLogger* logger, int category, enum mLogLevel level, con
}
}
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 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) {
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);

View File

@ -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 @@ bool GBLoadROM(struct GB* gb, struct VFile* 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;
}

View File

@ -383,14 +383,7 @@ bool GBALoadROM(struct GBA* gba, struct VFile* vf) {
#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) {