Mercurial > repos > blastem
annotate serialize.h @ 2354:a773b8f09292
Remove old refresh hack that is causing VDPFifoTesting to have a failed test
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 19 Oct 2023 23:27:57 -0700 |
parents | 9ead0fe69d9b |
children | 64cf80e683aa |
rev | line source |
---|---|
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #ifndef SERIALIZE_H_ |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #define SERIALIZE_H_ |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <stdint.h> |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include <stddef.h> |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 typedef struct { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 size_t size; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 size_t storage; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 size_t current_section_start; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 uint8_t *data; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 } serialize_buffer; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 typedef struct deserialize_buffer deserialize_buffer; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 typedef void (*section_fun)(deserialize_buffer *buf, void *data); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 typedef struct { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 section_fun fun; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 void *data; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 } section_handler; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 struct deserialize_buffer { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 size_t size; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 size_t cur_pos; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 uint8_t *data; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 section_handler *handlers; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 uint16_t max_handler; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 }; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 enum { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 SECTION_HEADER, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 SECTION_68000, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 SECTION_Z80, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 SECTION_VDP, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 SECTION_YM2612, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 SECTION_PSG, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 SECTION_GEN_BUS_ARBITER, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 SECTION_SEGA_IO_1, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 SECTION_SEGA_IO_2, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 SECTION_SEGA_IO_EXT, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 SECTION_MAIN_RAM, |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 SECTION_SOUND_RAM, |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
43 SECTION_MAPPER, |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
44 SECTION_EEPROM, |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
45 SECTION_CART_RAM, |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
46 SECTION_TMSS, |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
47 SECTION_SUB_68000, |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
48 SECTION_GATE_ARRAY, |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
49 SECTION_CDD_MCU, |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
50 SECTION_LC8951, |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
51 SECTION_RF5C164, |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
52 SECTION_CDD_FADER, |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
53 SECTION_CDROM |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 }; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 void init_serialize(serialize_buffer *buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 void save_int32(serialize_buffer *buf, uint32_t val); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 void save_int16(serialize_buffer *buf, uint16_t val); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 void save_int8(serialize_buffer *buf, uint8_t val); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 void save_string(serialize_buffer *buf, char *val); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 void save_buffer8(serialize_buffer *buf, void *val, size_t len); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 void save_buffer16(serialize_buffer *buf, uint16_t *val, size_t len); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 void save_buffer32(serialize_buffer *buf, uint32_t *val, size_t len); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 void start_section(serialize_buffer *buf, uint16_t section_id); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 void end_section(serialize_buffer *buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 void register_section_handler(deserialize_buffer *buf, section_handler handler, uint16_t section_id); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 void init_deserialize(deserialize_buffer *buf, uint8_t *data, size_t size); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 uint32_t load_int32(deserialize_buffer *buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 uint16_t load_int16(deserialize_buffer *buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 uint8_t load_int8(deserialize_buffer *buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 void load_buffer8(deserialize_buffer *buf, void *dst, size_t len); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 void load_buffer16(deserialize_buffer *buf, uint16_t *dst, size_t len); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 void load_buffer32(deserialize_buffer *buf, uint32_t *dst, size_t len); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 void load_section(deserialize_buffer *buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 uint8_t save_to_file(serialize_buffer *buf, char *path); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 uint8_t load_from_file(deserialize_buffer *buf, char *path); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 #endif //SERIALIZE_H |