Core: Add state manipulation back
Jeffrey Pfau jeffrey@endrift.com
Thu, 04 Feb 2016 02:31:50 -0800
6 files changed,
128 insertions(+),
1 deletions(-)
M
src/core/core.h
→
src/core/core.h
@@ -58,6 +58,9 @@ void (*runFrame)(struct mCore*);
void (*runLoop)(struct mCore*); void (*step)(struct mCore*); + bool (*loadState)(struct mCore*, struct VFile*, int flags); + bool (*saveState)(struct mCore*, struct VFile*, int flags); + void (*setKeys)(struct mCore*, uint32_t keys); void (*addKeys)(struct mCore*, uint32_t keys); void (*clearKeys)(struct mCore*, uint32_t keys);@@ -70,7 +73,15 @@ void (*setRTC)(struct mCore*, struct mRTCSource*);
}; bool mCoreLoadFile(struct mCore* core, const char* path); + +#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 bool mCoreAutoloadSave(struct mCore* core); bool mCoreAutoloadPatch(struct mCore* core); + +bool mCoreSaveState(struct mCore* core, int slot, int flags); +bool mCoreLoadState(struct mCore* core, int slot, int flags); +struct VFile* mCoreGetState(struct mCore* core, int slot, bool write); +void mCoreDeleteState(struct mCore* core, int slot); +#endif #endif
M
src/core/log.c
→
src/core/log.c
@@ -34,3 +34,5 @@ return _categoryNames[category];
} return 0; } + +mLOG_DEFINE_CATEGORY(STATUS, "Status")
M
src/core/log.h
→
src/core/log.h
@@ -53,4 +53,6 @@ } \
return category; \ } +mLOG_DECLARE_CATEGORY(STATUS) + #endif
M
src/gb/core.c
→
src/gb/core.c
@@ -124,6 +124,22 @@ static void _GBCoreStep(struct mCore* core) {
LR35902Tick(core->cpu); } +static bool _GBCoreLoadState(struct mCore* core, struct VFile* vf, int flags) { + UNUSED(core); + UNUSED(vf); + UNUSED(flags); + // TODO + return false; +} + +static bool _GBCoreSaveState(struct mCore* core, struct VFile* vf, int flags) { + UNUSED(core); + UNUSED(vf); + UNUSED(flags); + // TODO + return false; +} + static void _GBCoreSetKeys(struct mCore* core, uint32_t keys) { struct GBCore* gbcore = (struct GBCore*) core; gbcore->keys = keys;@@ -180,6 +196,8 @@ core->reset = _GBCoreReset;
core->runFrame = _GBCoreRunFrame; core->runLoop = _GBCoreRunLoop; core->step = _GBCoreStep; + core->loadState = _GBCoreLoadState; + core->saveState = _GBCoreSaveState; core->setKeys = _GBCoreSetKeys; core->addKeys = _GBCoreAddKeys; core->clearKeys = _GBCoreClearKeys;
M
src/gba/core.c
→
src/gba/core.c
@@ -9,6 +9,7 @@ #include "core/core.h"
#include "core/log.h" #include "gba/gba.h" #include "gba/renderers/video-software.h" +#include "gba/serialize.h" #include "util/memory.h" struct GBACore {@@ -126,6 +127,14 @@ static void _GBACoreStep(struct mCore* core) {
ARMRun(core->cpu); } +static bool _GBACoreLoadState(struct mCore* core, struct VFile* vf, int flags) { + return GBALoadStateNamed(core->board, vf, flags); +} + +static bool _GBACoreSaveState(struct mCore* core, struct VFile* vf, int flags) { + return GBASaveStateNamed(core->board, vf, flags); +} + static void _GBACoreSetKeys(struct mCore* core, uint32_t keys) { struct GBACore* gbacore = (struct GBACore*) core; gbacore->keys = keys;@@ -181,6 +190,8 @@ core->reset = _GBACoreReset;
core->runFrame = _GBACoreRunFrame; core->runLoop = _GBACoreRunLoop; core->step = _GBACoreStep; + core->loadState = _GBACoreLoadState; + core->saveState = _GBACoreSaveState; core->setKeys = _GBACoreSetKeys; core->addKeys = _GBACoreAddKeys; core->clearKeys = _GBACoreClearKeys;
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -564,7 +564,90 @@ if (event->keysym.sym == SDLK_TAB) {
context->sync.audioWait = event->type != SDL_KEYDOWN; return; } - // TODO: Put back events + if (event->type == SDL_KEYDOWN) { + switch (event->keysym.sym) { + case SDLK_F11: + // TODO: Put back debugger + return; +#ifdef USE_PNG + case SDLK_F12: + // TODO: Put back screenshots + return; +#endif + case SDLK_BACKSLASH: + // TODO: Put back frame advance + return; + case SDLK_BACKQUOTE: + // TODO: Put back rewind + return; +#ifdef BUILD_PANDORA + case SDLK_ESCAPE: + mCoreThreadEnd(context); + return; +#endif + default: + if ((event->keysym.mod & GUI_MOD) && (event->keysym.mod & GUI_MOD) == event->keysym.mod) { + switch (event->keysym.sym) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + case SDLK_f: + SDL_SetWindowFullscreen(sdlContext->window, sdlContext->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); + sdlContext->fullscreen = !sdlContext->fullscreen; + sdlContext->windowUpdated = 1; + break; +#endif + case SDLK_p: + mCoreThreadTogglePause(context); + break; + case SDLK_n: + // TODO: Put back frame advance + break; + case SDLK_r: + mCoreThreadReset(context); + break; + default: + break; + } + } + if (event->keysym.mod & KMOD_SHIFT) { + switch (event->keysym.sym) { + case SDLK_F1: + case SDLK_F2: + case SDLK_F3: + case SDLK_F4: + case SDLK_F5: + case SDLK_F6: + case SDLK_F7: + case SDLK_F8: + case SDLK_F9: + mCoreThreadInterrupt(context); + mCoreSaveState(context->core, event->keysym.sym - SDLK_F1 + 1, SAVESTATE_SCREENSHOT); + mCoreThreadContinue(context); + break; + default: + break; + } + } else { + switch (event->keysym.sym) { + case SDLK_F1: + case SDLK_F2: + case SDLK_F3: + case SDLK_F4: + case SDLK_F5: + case SDLK_F6: + case SDLK_F7: + case SDLK_F8: + case SDLK_F9: + mCoreThreadInterrupt(context); + mCoreLoadState(context->core, event->keysym.sym - SDLK_F1 + 1, SAVESTATE_SCREENSHOT); + mCoreThreadContinue(context); + break; + default: + break; + } + } + return; + } + } } static void _mSDLHandleJoyButton(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_JoyButtonEvent* event) {