GUI: Load/save states
Jeffrey Pfau jeffrey@endrift.com
Sun, 30 Aug 2015 18:23:01 -0700
5 files changed,
42 insertions(+),
24 deletions(-)
M
src/gba/context/context.c
→
src/gba/context/context.c
@@ -14,6 +14,7 @@ bool GBAContextInit(struct GBAContext* context, const char* port) {
context->gba = anonymousMemoryMap(sizeof(struct GBA)); context->cpu = anonymousMemoryMap(sizeof(struct ARMCore)); context->rom = 0; + context->fname = 0; context->save = 0; context->renderer = 0; memset(context->components, 0, sizeof(context->components));@@ -61,6 +62,7 @@ context->rom = 0;
return false; } + context->fname = path; if (autoloadSave) { context->save = VDirOptionalOpenFile(0, path, 0, ".sav", O_RDWR | O_CREAT); }@@ -123,7 +125,7 @@ if (context->renderer) {
GBAVideoAssociateRenderer(&context->gba->video, context->renderer); } - if (!GBALoadROM(context->gba, context->rom, context->save, 0)) { + if (!GBALoadROM(context->gba, context->rom, context->save, context->fname)) { return false; }
M
src/gba/context/context.h
→
src/gba/context/context.h
@@ -16,6 +16,7 @@ struct GBA* gba;
struct ARMCore* cpu; struct GBAVideoRenderer* renderer; struct VFile* rom; + const char* fname; struct VFile* save; struct VFile* bios; struct ARMComponent* components[GBA_COMPONENT_MAX];
M
src/gba/context/gui-runner.c
→
src/gba/context/gui-runner.c
@@ -5,13 +5,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gui-runner.h" +#include "gba/serialize.h" #include "util/gui/file-select.h" #include "util/gui/font.h" #include "util/gui/menu.h" +#include "util/vfs.h" enum { RUNNER_CONTINUE, - RUNNER_EXIT + RUNNER_EXIT, + RUNNER_SAVE_STATE, + RUNNER_LOAD_STATE, }; void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) {@@ -36,6 +40,11 @@ .index = 0,
}; GUIMenuItemListInit(&pauseMenu.items, 0); *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Unpause", .data = (void*) RUNNER_CONTINUE }; +#if !(defined(__POWERPC__) || defined(__PPC__)) + // PPC doesn't have working savestates yet + *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Save state", .data = (void*) RUNNER_SAVE_STATE }; + *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Load state", .data = (void*) RUNNER_LOAD_STATE }; +#endif *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT }; while (true) {@@ -95,28 +104,36 @@ if (runner->params.guiPrepare) {
runner->params.guiPrepare(); } GUIInvalidateKeys(&runner->params); - while (true) { - struct GUIMenuItem item; - enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item); - if (reason == GUI_MENU_EXIT_ACCEPT) { - if (item.data == (void*) RUNNER_EXIT) { - running = false; - break; + int keys = -1; // Huge hack to avoid an extra variable! + struct GUIMenuItem item; + enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item); + if (reason == GUI_MENU_EXIT_ACCEPT) { + struct VFile* vf; + switch ((int) item.data) { + case RUNNER_EXIT: + running = false; + keys = 0; + break; + case RUNNER_SAVE_STATE: + vf = GBAGetState(runner->context.gba, 0, 1, true); + if (vf) { + GBASaveStateNamed(runner->context.gba, vf, true); + vf->close(vf); } - if (item.data == (void*) RUNNER_CONTINUE) { - int keys = -1; - while (keys) { - GUIPollInput(&runner->params, 0, &keys); - } - break; + break; + case RUNNER_LOAD_STATE: + vf = GBAGetState(runner->context.gba, 0, 1, false); + if (vf) { + GBALoadStateNamed(runner->context.gba, vf); + vf->close(vf); } - } else { - int keys = -1; - while (keys) { - GUIPollInput(&runner->params, 0, &keys); - } + break; + case RUNNER_CONTINUE: break; } + } + while (keys) { + GUIPollInput(&runner->params, 0, &keys); } if (runner->params.guiFinish) { runner->params.guiFinish();
M
src/gba/serialize.c
→
src/gba/serialize.c
@@ -187,13 +187,11 @@ }
return true; } -#ifndef _3DS struct VFile* GBAGetState(struct GBA* gba, struct VDir* dir, int slot, bool write) { char suffix[5] = { '\0' }; snprintf(suffix, sizeof(suffix), ".ss%d", slot); return VDirOptionalOpenFile(dir, gba->activeFile, "savestate", suffix, write ? (O_CREAT | O_TRUNC | O_RDWR) : O_RDONLY); } -#endif #ifdef USE_PNG static bool _savePNGState(struct GBA* gba, struct VFile* vf) {
M
src/platform/3ds/ctru-heap.c
→
src/platform/3ds/ctru-heap.c
@@ -26,8 +26,8 @@ extern char* fake_heap_start;
extern char* fake_heap_end; u32 __linear_heap; u32 __heapBase; -static u32 __heap_size = 0x03000000; -static u32 __linear_heap_size = 0x00800000; +static u32 __heap_size = 0x02800000; +static u32 __linear_heap_size = 0x01000000; extern void (*__system_retAddr)(void);