From 72677feab5449321862471745861a7c3cb7f00e3 Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Fri, 24 Mar 2023 22:28:30 +0100 Subject: [PATCH] Fixing savestate and adding load keys. --- include/msgba/core_controller.h | 5 +++-- include/msgba/global.h | 10 ++++++++++ src/core_controller.c | 28 ++++++++++++++++++++++++++-- src/packet/hello.c | 8 ++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/include/msgba/core_controller.h b/include/msgba/core_controller.h index 46f77ab..bdede58 100644 --- a/include/msgba/core_controller.h +++ b/include/msgba/core_controller.h @@ -10,10 +10,11 @@ struct msMultiplayerController; struct msCoreController { - struct msMultiplayerController *multiplayer; - struct mCoreThread threadContext; + struct msMultiplayerController *multiplayer; + struct mCoreThread threadContext; color_t *outputBuffer; unsigned int stride; + struct VFile *saveState; }; struct msCoreController * diff --git a/include/msgba/global.h b/include/msgba/global.h index 81f4aec..787ecff 100644 --- a/include/msgba/global.h +++ b/include/msgba/global.h @@ -6,3 +6,13 @@ extern char *ms_last_error; #endif +#define MSGBA_KEY_A 0 +#define MSGBA_KEY_B 1 +#define MSGBA_KEY_L 2 +#define MSGBA_KEY_R 3 +#define MSGBA_KEY_START 4 +#define MSGBA_KEY_SELECT 5 +#define MSGBA_KEY_UP 6 +#define MSGBA_KEY_DOWN 7 +#define MSGBA_KEY_LEFT 8 +#define MSGBA_KEY_RIGHT 9 diff --git a/src/core_controller.c b/src/core_controller.c index bd0aedd..6167aee 100644 --- a/src/core_controller.c +++ b/src/core_controller.c @@ -14,6 +14,8 @@ #include #include +#include +#include struct msCoreController * @@ -35,6 +37,17 @@ msCoreControllerLoadGame (const unsigned char *rom, size_t rom_len, goto loadGameReturn; } core->init(core); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_A, GBA_KEY_A); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_B, GBA_KEY_B); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_L, GBA_KEY_L); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_R, GBA_KEY_R); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_START, GBA_KEY_START); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_SELECT, GBA_KEY_SELECT); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_UP, GBA_KEY_UP); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_DOWN, GBA_KEY_DOWN); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_LEFT, GBA_KEY_LEFT); + mInputBindKey(&core->inputMap, 0, MSGBA_KEY_RIGHT, GBA_KEY_RIGHT); + unsigned int width; unsigned int height; mCoreInitConfig(core, NULL); @@ -47,11 +60,11 @@ msCoreControllerLoadGame (const unsigned char *rom, size_t rom_len, printf("controller->outputBuffer width: %u\n", width); core->setVideoBuffer(core, outputBuffer, width); core->loadROM (core, file_rom); - mCoreLoadStateNamed (core, file_state, SAVESTATE_SAVEDATA & SAVESTATE_RTC); - + controller = msCoreControllerNew (core, data); controller->outputBuffer = outputBuffer; controller->stride = width; + controller->saveState = file_state; loadGameReturn: return controller; } @@ -65,10 +78,21 @@ msCoreControllerSetStartCallback(struct msCoreController *const self, void(*call self->threadContext.startCallback = callback; } +void +mCoreThreadAfterStart(struct mCoreThread *threadContext) { + struct msClientConnectionData *data = (struct msClientConnectionData *)threadContext->userData; + struct msCoreController *coreController = data->coreController; + struct mCore *core = coreController->threadContext.core; + if (!mCoreLoadStateNamed (core, coreController->saveState, 0)) { // SAVESTATE_SAVEDATA & SAVESTATE_RTC)) { + fprintf(stderr, "Unable to load save state\n"); + } +} + void msCoreControllerThreadStart (struct msCoreController *const core_controller) { struct mCoreThread *thread = &core_controller->threadContext; mCoreThreadStart(thread); + mCoreThreadRunFunction(thread, &mCoreThreadAfterStart); } void diff --git a/src/packet/hello.c b/src/packet/hello.c index e0b9874..21a0969 100644 --- a/src/packet/hello.c +++ b/src/packet/hello.c @@ -3,6 +3,8 @@ #include +#include + #include #include #include @@ -28,6 +30,12 @@ msThreadCallbackStart(struct mCoreThread *threadContext) { sigemptyset(&set); sigaddset(&set, SIGPIPE); pthread_sigmask(SIG_BLOCK, &set, NULL); + struct msClientConnectionData *data = (struct msClientConnectionData *)threadContext->userData; + struct msCoreController *coreController = data->coreController; + struct mCore *core = coreController->threadContext.core; + if (!mCoreLoadStateNamed (core, coreController->saveState, 0)) { // SAVESTATE_SAVEDATA & SAVESTATE_RTC)) { + fprintf(stderr, "Unable to load save state\n"); + } } void msThreadCallbackSetFrame(struct mCoreThread *threadContext) {