Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
emutools_snapshot.h
Go to the documentation of this file.
1 /* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
2  Copyright (C)2016 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17 
18 #ifndef __XEMU_COMMON_EMUTOOLS_SNAPSHOT_H_INCLUDED
19 #define __XEMU_COMMON_EMUTOOLS_SNAPSHOT_H_INCLUDED
20 
21 #ifdef XEMU_SNAPSHOT_SUPPORT
22 
23 #define XEMUSNAP_MAX_IDENT_LENGTH 64
24 #define XEMUSNAP_ERROR_BUFFER_SIZE 256
25 #define XEMUSNAP_FIXED_HEADER_SIZE 21
26 #define XEMUSNAP_FRAMING_VERSION 0
27 
28 #define XSNAPERR_NODATA 1
29 #define XSNAPERR_TRUNCATED 2
30 #define XSNAPERR_FORMAT 3
31 #define XSNAPERR_IO 4
32 #define XSNAPERR_CALLBACK 5
33 
34 #define RETURN_XSNAPERR_USER(...) \
35  do { \
36  snprintf(xemusnap_user_error_buffer, XEMUSNAP_ERROR_BUFFER_SIZE, __VA_ARGS__); \
37  return XSNAPERR_CALLBACK; \
38  } while (0)
39 
40 struct xemu_snapshot_block_st {
41  Uint32 framing_version;
42  Uint32 flags;
43  Uint32 block_version;
44  int header_size;
45  int is_ident;
46  int idlen;
47  char idstr[XEMUSNAP_MAX_IDENT_LENGTH + 1];
48  int counter;
49  int sub_counter;
50  Uint32 sub_size;
51 };
52 
53 struct xemu_snapshot_definition_st;
54 
55 typedef int (*xemu_snapshot_load_callback_t)( const struct xemu_snapshot_definition_st * , struct xemu_snapshot_block_st * );
56 typedef int (*xemu_snapshot_save_callback_t)( const struct xemu_snapshot_definition_st * );
57 
58 struct xemu_snapshot_definition_st {
59  const char *idstr;
60  void *user_data;
61  xemu_snapshot_load_callback_t load;
62  xemu_snapshot_save_callback_t save;
63 };
64 
65 
66 extern char xemusnap_error_buffer[];
67 extern char xemusnap_user_error_buffer[];
68 
69 
70 static inline Uint64 P_AS_BE64 ( const Uint8 *p ) {
71  return ((Uint64)p[0] << 56) | ((Uint64)p[1] << 48) | ((Uint64)p[2] << 40) | ((Uint64)p[3] << 32) | ((Uint64)p[4] << 24) | ((Uint64)p[5] << 16) | ((Uint64)p[6] << 8) | (Uint64)p[7];
72 }
73 static inline Uint32 P_AS_BE32 ( const Uint8 *p ) {
74  return ((Uint32)p[0] << 24) | ((Uint32)p[1] << 16) | ((Uint32)p[2] << 8) | ((Uint32)p[3] ) ;
75 }
76 static inline Uint16 P_AS_BE16 ( const Uint8 *p ) {
77  return ((Uint16)p[0] << 8) | ((Uint16)p[1] ) ;
78 }
79 static inline void U64_AS_BE ( Uint8 *p, Uint64 n ) {
80  p[0] = n >> 56; p[1] = n >> 48; p[2] = n >> 40; p[3] = n >> 32; p[4] = n >> 24; p[5] = n >> 16; p[6] = n >> 8; p[7] = n;
81 }
82 static inline void U32_AS_BE ( Uint8 *p, Uint32 n ) {
83  p[0] = n >> 24; p[1] = n >> 16; p[2] = n >> 8; p[3] = n;
84 }
85 static inline void U16_AS_BE ( Uint8 *p, Uint16 n ) {
86  p[0] = n >> 8; p[1] = n;
87 }
88 
89 extern void xemusnap_init ( const struct xemu_snapshot_definition_st *def );
90 extern int xemusnap_read_file ( void *buffer, size_t size );
91 extern int xemusnap_skip_file_bytes ( off_t size );
92 extern int xemusnap_write_file ( const void *buffer, size_t size );
93 extern int xemusnap_read_block_header ( struct xemu_snapshot_block_st *block );
94 extern int xemusnap_write_block_header ( const char *ident, Uint32 version );
95 extern int xemusnap_read_be32 ( Uint32 *result );
96 extern int xemusnap_skip_sub_blocks ( int num );
97 extern int xemusnap_write_sub_block ( const Uint8 *buffer, Uint32 size );
98 extern int xemusnap_load ( const char *filename );
99 extern int xemusnap_save ( const char *filename );
100 
101 #endif
102 #endif
load
char * load
Definition: rc2014.c:37
flags
Uint8 flags
Definition: z8k1.c:126
Uint32
uint32_t Uint32
Definition: fat32.c:49
Uint8
uint8_t Uint8
Definition: fat32.c:51
block
Uint32 block
Definition: fat32.c:156
size
int size
Definition: inject.c:37
Uint16
uint16_t Uint16
Definition: fat32.c:50