2016-06-11 11:52:09 +00:00
|
|
|
/* Macros to make the GB_gameboy_t struct more future compatible when state saving */
|
2017-06-13 21:23:34 +00:00
|
|
|
#ifndef save_state_h
|
|
|
|
#define save_state_h
|
|
|
|
#include <stddef.h>
|
2016-06-11 11:52:09 +00:00
|
|
|
|
|
|
|
#define GB_PADDING(type, old_usage) type old_usage##__do_not_use
|
|
|
|
|
2020-10-09 13:39:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
/* For bsnes integration. C++ code does not need section information, and throws a fit over certain types such
|
|
|
|
as anonymous enums inside unions */
|
|
|
|
#define GB_SECTION(name, ...) __attribute__ ((aligned (8))) __VA_ARGS__
|
|
|
|
#else
|
2021-09-29 18:57:39 +00:00
|
|
|
#define GB_SECTION(name, ...) union __attribute__ ((aligned (8))) {uint8_t name##_section_start; struct {__VA_ARGS__};}; uint8_t name##_section_end[0]
|
2016-06-11 11:52:09 +00:00
|
|
|
#define GB_SECTION_OFFSET(name) (offsetof(GB_gameboy_t, name##_section_start))
|
|
|
|
#define GB_SECTION_SIZE(name) (offsetof(GB_gameboy_t, name##_section_end) - offsetof(GB_gameboy_t, name##_section_start))
|
|
|
|
#define GB_GET_SECTION(gb, name) ((void*)&((gb)->name##_section_start))
|
2020-10-09 13:39:23 +00:00
|
|
|
#endif
|
2016-06-11 11:52:09 +00:00
|
|
|
|
2016-06-18 17:29:11 +00:00
|
|
|
#define GB_aligned_double __attribute__ ((aligned (8))) double
|
|
|
|
|
2017-06-13 21:23:34 +00:00
|
|
|
|
|
|
|
/* Public calls related to save states */
|
|
|
|
int GB_save_state(GB_gameboy_t *gb, const char *path);
|
|
|
|
size_t GB_get_save_state_size(GB_gameboy_t *gb);
|
|
|
|
/* Assumes buffer is big enough to contain the save state. Use with GB_get_save_state_size(). */
|
|
|
|
void GB_save_state_to_buffer(GB_gameboy_t *gb, uint8_t *buffer);
|
|
|
|
|
|
|
|
int GB_load_state(GB_gameboy_t *gb, const char *path);
|
|
|
|
int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t length);
|
2021-04-14 12:20:01 +00:00
|
|
|
bool GB_is_stave_state(const char *path);
|
2021-04-13 17:35:07 +00:00
|
|
|
#ifdef GB_INTERNAL
|
2021-04-14 12:20:01 +00:00
|
|
|
static inline uint32_t state_magic(void)
|
|
|
|
{
|
|
|
|
if (sizeof(bool) == 1) return 'SAME';
|
|
|
|
return 'S4ME';
|
|
|
|
}
|
|
|
|
|
2021-04-13 17:35:07 +00:00
|
|
|
/* For internal in-memory save states (rewind, debugger) that do not need BESS */
|
|
|
|
size_t GB_get_save_state_size_no_bess(GB_gameboy_t *gb);
|
|
|
|
void GB_save_state_to_buffer_no_bess(GB_gameboy_t *gb, uint8_t *buffer);
|
|
|
|
#endif
|
|
|
|
|
2017-06-13 21:23:34 +00:00
|
|
|
#endif /* save_state_h */
|