Fixing savestate and adding load keys.

This commit is contained in:
Sergiotarxz 2023-03-24 22:28:30 +01:00
parent 05fff066ef
commit 72677feab5
4 changed files with 47 additions and 4 deletions

View File

@ -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 *

View File

@ -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

View File

@ -14,6 +14,8 @@
#include <msgba/global.h>
#include <msgba/core_controller.h>
#include <mgba/core/input.h>
#include <mgba/internal/gba/input.h>
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

View File

@ -3,6 +3,8 @@
#include <sys/signal.h>
#include <mgba/core/serialize.h>
#include <msgba/packet/send_frame.h>
#include <msgba/packet.h>
#include <msgba/packet/hello.h>
@ -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) {