mirror of https://github.com/mgba-emu/mgba.git
Core: Add savedataUpdated callback
This commit is contained in:
parent
65fb61d7e2
commit
f5a1ceb025
|
@ -91,6 +91,7 @@ struct mCoreCallbacks {
|
||||||
void (*coreCrashed)(void* context);
|
void (*coreCrashed)(void* context);
|
||||||
void (*sleep)(void* context);
|
void (*sleep)(void* context);
|
||||||
void (*keysRead)(void* context);
|
void (*keysRead)(void* context);
|
||||||
|
void (*savedataUpdated)(void* context);
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
|
DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
|
||||||
|
|
|
@ -247,6 +247,14 @@ void GBSramClean(struct GB* gb, uint32_t frameCount) {
|
||||||
} else {
|
} else {
|
||||||
mLOG(GB_MEM, INFO, "Savedata failed to sync!");
|
mLOG(GB_MEM, INFO, "Savedata failed to sync!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t c;
|
||||||
|
for (c = 0; c < mCoreCallbacksListSize(&gb->coreCallbacks); ++c) {
|
||||||
|
struct mCoreCallbacks* callbacks = mCoreCallbacksListGetPointer(&gb->coreCallbacks, c);
|
||||||
|
if (callbacks->savedataUpdated) {
|
||||||
|
callbacks->savedataUpdated(callbacks->context);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -816,6 +816,7 @@ void GBAFrameStarted(struct GBA* gba) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAFrameEnded(struct GBA* gba) {
|
void GBAFrameEnded(struct GBA* gba) {
|
||||||
|
int wasDirty = gba->memory.savedata.dirty;
|
||||||
GBASavedataClean(&gba->memory.savedata, gba->video.frameCounter);
|
GBASavedataClean(&gba->memory.savedata, gba->video.frameCounter);
|
||||||
|
|
||||||
if (gba->cpu->components && gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE]) {
|
if (gba->cpu->components && gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE]) {
|
||||||
|
@ -846,6 +847,9 @@ void GBAFrameEnded(struct GBA* gba) {
|
||||||
if (callbacks->videoFrameEnded) {
|
if (callbacks->videoFrameEnded) {
|
||||||
callbacks->videoFrameEnded(callbacks->context);
|
callbacks->videoFrameEnded(callbacks->context);
|
||||||
}
|
}
|
||||||
|
if (callbacks->savedataUpdated && wasDirty && !gba->memory.savedata.dirty) {
|
||||||
|
callbacks->savedataUpdated(callbacks->context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -534,16 +534,14 @@ void GBASavedataClean(struct GBASavedata* savedata, uint32_t frameCount) {
|
||||||
if (savedata->dirty & SAVEDATA_DIRT_NEW) {
|
if (savedata->dirty & SAVEDATA_DIRT_NEW) {
|
||||||
savedata->dirtAge = frameCount;
|
savedata->dirtAge = frameCount;
|
||||||
savedata->dirty &= ~SAVEDATA_DIRT_NEW;
|
savedata->dirty &= ~SAVEDATA_DIRT_NEW;
|
||||||
if (!(savedata->dirty & SAVEDATA_DIRT_SEEN)) {
|
savedata->dirty |= SAVEDATA_DIRT_SEEN;
|
||||||
savedata->dirty |= SAVEDATA_DIRT_SEEN;
|
|
||||||
}
|
|
||||||
} else if ((savedata->dirty & SAVEDATA_DIRT_SEEN) && frameCount - savedata->dirtAge > CLEANUP_THRESHOLD) {
|
} else if ((savedata->dirty & SAVEDATA_DIRT_SEEN) && frameCount - savedata->dirtAge > CLEANUP_THRESHOLD) {
|
||||||
if (savedata->maskWriteback) {
|
if (savedata->maskWriteback) {
|
||||||
GBASavedataUnmask(savedata);
|
GBASavedataUnmask(savedata);
|
||||||
}
|
}
|
||||||
|
savedata->dirty = 0;
|
||||||
if (savedata->mapMode & MAP_WRITE) {
|
if (savedata->mapMode & MAP_WRITE) {
|
||||||
size_t size = GBASavedataSize(savedata);
|
size_t size = GBASavedataSize(savedata);
|
||||||
savedata->dirty = 0;
|
|
||||||
if (savedata->data && savedata->vf->sync(savedata->vf, savedata->data, size)) {
|
if (savedata->data && savedata->vf->sync(savedata->vf, savedata->data, size)) {
|
||||||
mLOG(GBA_SAVE, INFO, "Savedata synced");
|
mLOG(GBA_SAVE, INFO, "Savedata synced");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue