Debian Codegraph @

mednafen/state.h

raw symbols SCIP
1 #ifndef _STATE_H
2 #define _STATE_H
3
4 typedef struct
5 {
6 uint8 *data;
7 uint32 loc;
8 uint32 len;
9 uint32 malloced;
10 uint32 initial_malloc; // A setting!
11 } StateMem;
12
13 // Eh, we abuse the smem_* in-memory stream code
14 // in a few other places. :)
15 int32 smem_read(StateMem *st, void *buffer, uint32 len);
16 int32 smem_write(StateMem *st, void *buffer, uint32 len);
17 int32 smem_putc(StateMem *st, int value);
18 int32 smem_tell(StateMem *st);
19 int32 smem_seek(StateMem *st, uint32 offset, int whence);
20 int smem_write32le(StateMem *st, uint32 b);
21 int smem_read32le(StateMem *st, uint32 *b);
22
23 int MDFNSS_SaveSM(void *st, int, int, const void*, const void*, const void*);
24 int MDFNSS_LoadSM(void *st, int, int);
25
26 // Flag for a single, >= 1 byte native-endian variable
27 #define MDFNSTATE_RLSB 0x80000000
28
29 // 32-bit native-endian elements
30 #define MDFNSTATE_RLSB32 0x40000000
31
32 // 16-bit native-endian elements
33 #define MDFNSTATE_RLSB16 0x20000000
34
35 // 64-bit native-endian elements
36 #define MDFNSTATE_RLSB64 0x10000000
37
38 #define MDFNSTATE_BOOL 0x08000000
39
40 typedef struct {
41 void *v; // Pointer to the variable/array
42 uint32 size; // Length, in bytes, of the data to be saved EXCEPT:
43 // In the case of MDFNSTATE_BOOL, it is the number of bool elements to save(bool is not always 1-byte).
44 // If 0, the subchunk isn't saved.
45 uint32 flags; // Flags
46 const char *name; // Name
47 //uint32 struct_size; // Only used for MDFNSTATE_ARRAYOFS, sizeof(struct) that members of the linked SFORMAT struct are in.
48 } SFORMAT;
49
50 INLINE bool SF_IS_BOOL(bool *) { return(1); }
51 INLINE bool SF_IS_BOOL(void *) { return(0); }
52
53 INLINE uint32 SF_FORCE_AB(bool *) { return(0); }
54
55 INLINE uint32 SF_FORCE_A8(int8 *) { return(0); }
56 INLINE uint32 SF_FORCE_A8(uint8 *) { return(0); }
57
58 INLINE uint32 SF_FORCE_A16(int16 *) { return(0); }
59 INLINE uint32 SF_FORCE_A16(uint16 *) { return(0); }
60
61 INLINE uint32 SF_FORCE_A32(int32 *) { return(0); }
62 INLINE uint32 SF_FORCE_A32(uint32 *) { return(0); }
63
64 INLINE uint32 SF_FORCE_A64(int64 *) { return(0); }
65 INLINE uint32 SF_FORCE_A64(uint64 *) { return(0); }
66
67 INLINE uint32 SF_FORCE_D(double *) { return(0); }
68
69 #define SFVARN(x, n) { &(x), SF_IS_BOOL(&(x)) ? 1 : (uint32_t)sizeof(x), MDFNSTATE_RLSB | (SF_IS_BOOL(&(x)) ? MDFNSTATE_BOOL : 0), n }
70 #define SFVAR(x) SFVARN((x), #x)
71
72 #define SFARRAYN(x, l, n) { (x), (uint32)(l), 0 | SF_FORCE_A8(x), n }
73 #define SFARRAY(x, l) SFARRAYN((x), (l), #x)
74
75 #define SFARRAYBN(x, l, n) { (x), (uint32)(l), MDFNSTATE_BOOL | SF_FORCE_AB(x), n }
76 #define SFARRAYB(x, l) SFARRAYBN((x), (l), #x)
77
78 #define SFARRAY16N(x, l, n) { (x), (uint32)((l) * sizeof(uint16)), MDFNSTATE_RLSB16 | SF_FORCE_A16(x), n }
79 #define SFARRAY16(x, l) SFARRAY16N((x), (l), #x)
80
81 #define SFARRAY32N(x, l, n) { (x), (uint32)((l) * sizeof(uint32)), MDFNSTATE_RLSB32 | SF_FORCE_A32(x), n }
82 #define SFARRAY32(x, l) SFARRAY32N((x), (l), #x)
83
84 #define SFARRAY64N(x, l, n) { (x), (uint32)((l) * sizeof(uint64)), MDFNSTATE_RLSB64 | SF_FORCE_A64(x), n }
85 #define SFARRAY64(x, l) SFARRAY64N((x), (l), #x)
86
87 #if SIZEOF_DOUBLE != 8
88 #error "sizeof(double) != 8"
89 #endif
90
91 #define SFARRAYDN(x, l, n) { (x), (uint32)((l) * 8), MDFNSTATE_RLSB64 | SF_FORCE_D(x), n }
92 #define SFARRAYD(x, l) SFARRAYDN((x), (l), #x)
93
94 #define SFEND { 0, 0, 0, 0 }
95
96 #include <vector>
97
98 // State-Section Descriptor
99 class SSDescriptor
100 {
101 public:
102 SSDescriptor(SFORMAT *n_sf, const char *n_name, bool n_optional = 0)
103 {
104 sf = n_sf;
105 name = n_name;
106 optional = n_optional;
107 }
108 ~SSDescriptor(void)
109 {
110
111 }
112
113 SFORMAT *sf;
114 const char *name;
115 bool optional;
116 };
117
118 int MDFNSS_StateAction(void *st, int load, int data_only, std::vector <SSDescriptor> &sections);
119 int MDFNSS_StateAction(void *st, int load, int data_only, SFORMAT *sf, const char *name, bool optional = 0);
120
121 #endif