Skip to content

Commit 2cc7adc

Browse files
committed
GBA: Added save state support
1 parent 06433c1 commit 2cc7adc

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

gbsp/components/gbsp-libretro/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ typedef u32 fixed8_24;
157157
#define read_dmareg(regnum, dmachan) (eswap16(io_registers[(regnum) + (dmachan) * 6]))
158158
#define write_dmareg(regnum, dmachan, val) io_registers[(regnum) + (dmachan) * 6] = eswap16(val)
159159

160+
#ifdef RETRO_GO
160161
#include <rg_system.h>
161-
#include <esp_attr.h>
162+
#endif
162163
#include <unistd.h>
163164
#include <time.h>
164165
#include <stdlib.h>

gbsp/main/main.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,26 @@ static bool screenshot_handler(const char *filename, int width, int height)
4444

4545
static bool save_state_handler(const char *filename)
4646
{
47-
return false;
47+
size_t buffer_len = GBA_STATE_MEM_SIZE;
48+
void *buffer = malloc(buffer_len);
49+
if (!buffer)
50+
return false;
51+
gba_save_state(buffer);
52+
bool success = rg_storage_write_file(filename, buffer, buffer_len, 0);
53+
free(buffer);
54+
return success;
4855
}
4956

5057
static bool load_state_handler(const char *filename)
5158
{
52-
return false;
59+
size_t buffer_len = GBA_STATE_MEM_SIZE;
60+
void *buffer = malloc(buffer_len);
61+
if (!buffer)
62+
return false;
63+
bool success = rg_storage_read_file(filename, &buffer, &buffer_len, RG_FILE_USER_BUFFER)
64+
&& gba_load_state(buffer);
65+
free(buffer);
66+
return success;
5367
}
5468

5569
static bool reset_handler(bool hard)
@@ -150,6 +164,12 @@ void app_main(void)
150164
RG_LOGI("reset_gba");
151165
reset_gba();
152166

167+
if (app->bootFlags & RG_BOOT_RESUME)
168+
{
169+
RG_LOGI("load_state");
170+
rg_emu_load_state(app->saveSlot);
171+
}
172+
153173
RG_LOGI("emulation loop");
154174

155175
rg_audio_sample_t mixbuffer[AUDIO_BUFFER_LENGTH] = {0};

0 commit comments

Comments
 (0)