If initsram/initstate points to LSS file, pull the matching member
[lsnes.git] / include / core / moviefile.hpp
blob14d08bc096372a9d41d5b681e3b525735c3f039c
1 #ifndef _moviefile__hpp__included__
2 #define _moviefile__hpp__included__
4 #include <string>
5 #include <vector>
6 #include <stdexcept>
7 #include <map>
8 #include "core/controllerframe.hpp"
9 #include "core/rom-small.hpp"
10 #include "core/subtitles.hpp"
11 #include "interface/romtype.hpp"
12 #include "library/rrdata.hpp"
13 #include "library/zip.hpp"
15 class loaded_rom;
17 /**
18 * This structure gives parsed representationg of movie file, as result of decoding or for encoding.
20 struct moviefile
22 /**
23 * Brief information
25 struct brief_info
27 brief_info() { current_frame = 0; rerecords = 0; }
28 brief_info(const std::string& filename);
29 std::string sysregion;
30 std::string corename;
31 std::string projectid;
32 std::string hash[ROM_SLOT_COUNT];
33 std::string hashxml[ROM_SLOT_COUNT];
34 std::string hint[ROM_SLOT_COUNT];
35 uint64_t current_frame;
36 uint64_t rerecords;
37 private:
38 void load(zip::reader& r);
39 void binary_io(int s);
41 /**
42 * Extract branches.
44 struct branch_extractor
46 branch_extractor(const std::string& filename);
47 virtual ~branch_extractor();
48 virtual std::set<std::string> enumerate() { return real->enumerate(); }
49 virtual void read(const std::string& name, portctrl::frame_vector& v) { real->read(name, v); }
50 protected:
51 branch_extractor() { real = NULL; }
52 private:
53 branch_extractor* real;
55 /**
56 * Extract SRAMs.
58 struct sram_extractor
60 sram_extractor(const std::string& filename);
61 virtual ~sram_extractor();
62 virtual std::set<std::string> enumerate() { return real->enumerate(); }
63 virtual void read(const std::string& name, std::vector<char>& v) { real->read(name, v); }
64 protected:
65 sram_extractor() { real = NULL; }
66 private:
67 sram_extractor* real;
69 /**
70 * Identify if file is movie/savestate file or not.
72 static bool is_movie_or_savestate(const std::string& filename);
73 /**
74 * This constructor construct movie structure with default settings.
76 * throws std::bad_alloc: Not enough memory.
78 moviefile() throw(std::bad_alloc);
80 /**
81 * This constructor loads a movie/savestate file and fills structure accordingly.
83 * parameter filename: The file to load.
84 * parameter romtype: Type of ROM.
85 * throws std::bad_alloc: Not enough memory.
86 * throws std::runtime_error: Can't load the movie file
88 moviefile(const std::string& filename, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
90 /**
91 * Fill a stub movie with specified loaded ROM.
93 * Parameter rom: The rom.
94 * Parameter settings: The settings.
95 * Parameter rtc_sec: The RTC seconds value.
96 * Parameter rtc_subsec: The RTC subseconds value.
98 moviefile(loaded_rom& rom, std::map<std::string, std::string>& c_settings, uint64_t rtc_sec,
99 uint64_t rtc_subsec);
102 * Reads this movie structure and saves it into file.
104 * parameter filename: The file to save to.
105 * parameter compression: The compression level 0-9. 0 is uncompressed.
106 * parameter binary: Save in binary form if true.
107 * parameter rrd: The rerecords data.
108 * throws std::bad_alloc: Not enough memory.
109 * throws std::runtime_error: Can't save the movie file.
111 void save(const std::string& filename, unsigned compression, bool binary, rrdata_set& rrd)
112 throw(std::bad_alloc, std::runtime_error);
114 * Reads this movie structure and saves it to stream (uncompressed ZIP).
116 void save(std::ostream& outstream, rrdata_set& rrd) throw(std::bad_alloc, std::runtime_error);
118 * Force loading as corrupt.
120 bool force_corrupt;
122 * What is the ROM type and region?
124 core_sysregion* gametype;
126 * Settings.
128 std::map<std::string, std::string> settings;
130 * Emulator Core version string.
132 std::string coreversion;
134 * Name of the game
136 std::string gamename;
138 * Project ID (used to identify if two movies are from the same project).
140 std::string projectid;
142 * Rerecord count (only saved).
144 std::string rerecords;
146 * Rerecord count (memory saves only).
148 uint64_t rerecords_mem;
150 * SHA-256 of ROM (empty string if none).
152 std::string romimg_sha256[ROM_SLOT_COUNT];
154 * SHA-256 of ROM XML (empty string if none).
156 std::string romxml_sha256[ROM_SLOT_COUNT];
158 * ROM name hint (empty string if none).
160 std::string namehint[ROM_SLOT_COUNT];
162 * Authors of the run, first in each pair is full name, second is nickname.
164 std::vector<std::pair<std::string, std::string>> authors;
166 * Contents of SRAM on time of initial powerup.
168 std::map<std::string, std::vector<char>> movie_sram;
170 * Contents of RAM on time of initial powerup.
172 std::map<std::string, std::vector<char>> ramcontent;
174 * True if savestate, false if movie.
176 bool is_savestate;
178 * Contents of SRAM on time of savestate (if is_savestate is true).
180 std::map<std::string, std::vector<char>> sram;
182 * Core savestate (if is_savestate is true).
184 std::vector<char> savestate; //Savestate to load (if is_savestate is true).
186 * Anchoring core savestate (if not empty).
188 std::vector<char> anchor_savestate;
190 * Host memory (if is_savestate is true).
192 std::vector<char> host_memory;
194 * Screenshot (if is_savestate is true).
196 std::vector<char> screenshot;
198 * Current frame (if is_savestate is true).
200 uint64_t save_frame;
202 * Number of lagged frames (if is_savestate is true).
204 uint64_t lagged_frames;
206 * Poll counters (if is_savestate is true).
208 std::vector<uint32_t> pollcounters;
210 * Poll flag.
212 unsigned poll_flag;
214 * Compressed rrdata.
216 std::vector<char> c_rrdata;
218 * Input for each (sub)frame (points to active branch).
220 portctrl::frame_vector* input;
222 * Branches.
224 std::map<std::string, portctrl::frame_vector> branches;
226 * Current RTC second.
228 int64_t rtc_second;
230 * Current RTC subsecond.
232 int64_t rtc_subsecond;
234 * Movie starting RTC second.
236 int64_t movie_rtc_second;
238 * Movie starting RTC subsecond.
240 int64_t movie_rtc_subsecond;
242 * Start paused flag.
244 bool start_paused;
246 * Lazy project create flag.
248 bool lazy_project_create;
250 * Subtitles.
252 std::map<moviefile_subtiming, std::string> subtitles;
254 * Active macros at savestate.
256 std::map<std::string, uint64_t> active_macros;
258 * Get number of frames in movie.
260 * returns: Number of frames.
262 uint64_t get_frame_count() throw();
264 * Get length of the movie
266 * returns: Length of the movie in milliseconds.
268 uint64_t get_movie_length() throw();
270 * Return reference to memory slot.
272 static moviefile*& memref(const std::string& slot);
275 * Copy data.
277 void copy_fields(const moviefile& mv);
280 * Create a default branch.
282 void create_default_branch(portctrl::type_set& ports);
284 * Get name of current branch.
286 const std::string& current_branch();
288 * Fork a branch.
290 void fork_branch(const std::string& oldname, const std::string& newname);
292 * Fixup input pointer post-copy.
294 void fixup_current_branch(const moviefile& mv);
295 private:
296 moviefile(const moviefile&);
297 moviefile& operator=(const moviefile&);
298 void binary_io(int stream, rrdata_set& rrd) throw(std::bad_alloc, std::runtime_error);
299 void binary_io(int stream, struct core_type& romtype) throw(std::bad_alloc, std::runtime_error);
300 void save(zip::writer& w, rrdata_set& rrd) throw(std::bad_alloc, std::runtime_error);
301 void load(zip::reader& r, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
304 void emerg_save_movie(const moviefile& mv, rrdata_set& rrd);
306 #endif