1 /*  RetroArch - A frontend for libretro.
2  *  Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3  *  Copyright (C) 2011-2017 - Daniel De Matteis
4  *  Copyright (C) 2014-2017 - Alfred Agrell
5  *
6  *  RetroArch is free software: you can redistribute it and/or modify it under the terms
7  *  of the GNU General Public License as published by the Free Software Found-
8  *  ation, either version 3 of the License, or (at your option) any later version.
9  *
10  *  RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  *  PURPOSE.  See the GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along with RetroArch.
15  *  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __STATE_MANAGER_H
19 #define __STATE_MANAGER_H
20 
21 #include <stdint.h>
22 #include <stddef.h>
23 
24 #include <boolean.h>
25 #include <retro_common_api.h>
26 
27 RETRO_BEGIN_DECLS
28 
29 struct state_manager
30 {
31    uint8_t *data;
32    /* Reading and writing is done here here. */
33    uint8_t *head;
34    /* If head comes close to this, discard a frame. */
35    uint8_t *tail;
36 
37    uint8_t *thisblock;
38    uint8_t *nextblock;
39 #if STRICT_BUF_SIZE
40    uint8_t *debugblock;
41    size_t debugsize;
42 #endif
43 
44    size_t capacity;
45    /* This one is rounded up from reset::blocksize. */
46    size_t blocksize;
47    /* size_t + (blocksize + 131071) / 131072 *
48     * (blocksize + u16 + u16) + u16 + u32 + size_t
49     * (yes, the math is a bit ugly). */
50    size_t maxcompsize;
51 
52    unsigned entries;
53    bool thisblock_valid;
54 };
55 
56 typedef struct state_manager state_manager_t;
57 
58 struct state_manager_rewind_state
59 {
60    /* Rewind support. */
61    state_manager_t *state;
62    size_t size;
63    bool frame_is_reversed;
64 };
65 
66 bool state_manager_frame_is_reversed(void);
67 
68 void state_manager_event_deinit(
69       struct state_manager_rewind_state *rewind_st);
70 
71 void state_manager_event_init(struct state_manager_rewind_state *rewind_st,
72       unsigned rewind_buffer_size);
73 
74 /**
75  * check_rewind:
76  * @pressed              : was rewind key pressed or held?
77  *
78  * Checks if rewind toggle/hold was being pressed and/or held.
79  **/
80 bool state_manager_check_rewind(
81       struct state_manager_rewind_state *rewind_st,
82       bool pressed,
83       unsigned rewind_granularity, bool is_paused,
84       char *s, size_t len, unsigned *time);
85 
86 RETRO_END_DECLS
87 
88 #endif
89