view src/common/movie.h @ 34:6bde5b67a2b8

saving progress
author Robert McIntyre <rlm@mit.edu>
date Mon, 05 Mar 2012 01:58:52 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 #ifndef VBA_MOVIE_H
2 #define VBA_MOVIE_H
4 #if _MSC_VER > 1000
5 #pragma once
6 #endif // _MSC_VER > 1000
8 #include <ctime>
9 #include <string>
11 #include "../Port.h"
13 #define ZLIB
14 ///#ifdef ZLIB
15 #ifndef WIN32
16 #include "zlib.h"
17 #endif
19 #ifndef MOVIE_SUCCESS
20 # define MOVIE_SUCCESS 1
21 # define MOVIE_NOTHING 0
22 # define MOVIE_WRONG_FORMAT (-1)
23 # define MOVIE_WRONG_VERSION (-2)
24 # define MOVIE_FILE_NOT_FOUND (-3)
25 # define MOVIE_NOT_FROM_THIS_MOVIE (-4)
26 # define MOVIE_NOT_FROM_A_MOVIE (-5)
27 # define MOVIE_SNAPSHOT_INCONSISTENT (-6)
28 # define MOVIE_UNKNOWN_ERROR (-7)
29 #endif
31 #define VBM_MAGIC (0x1a4D4256) // VBM0x1a
32 #define VBM_VERSION (1)
33 #define VBM_HEADER_SIZE (64)
34 #define CONTROLLER_DATA_SIZE (2)
35 #define BUFFER_GROWTH_SIZE (4096)
36 #define MOVIE_METADATA_SIZE (192)
37 #define MOVIE_METADATA_AUTHOR_SIZE (64)
39 // revision 1 uses (?) insted of (!) as reset
40 #define VBM_REVISION (1)
42 #define MOVIE_START_FROM_SNAPSHOT (1<<0)
43 #define MOVIE_START_FROM_SRAM (1<<1)
45 #define MOVIE_CONTROLLER(i) (1<<(i))
46 #define MOVIE_CONTROLLERS_ANY_MASK (MOVIE_CONTROLLER(0)|MOVIE_CONTROLLER(1)|MOVIE_CONTROLLER(2)|MOVIE_CONTROLLER(3))
47 #define MOVIE_NUM_OF_POSSIBLE_CONTROLLERS (4)
49 #define MOVIE_TYPE_GBA (1<<0)
50 #define MOVIE_TYPE_GBC (1<<1)
51 #define MOVIE_TYPE_SGB (1<<2)
53 #define MOVIE_SETTING_USEBIOSFILE (1<<0)
54 #define MOVIE_SETTING_SKIPBIOSFILE (1<<1)
55 #define MOVIE_SETTING_RTCENABLE (1<<2)
56 #define MOVIE_SETTING_GBINPUTHACK (1<<3)
57 #define MOVIE_SETTING_LAGHACK (1<<4)
58 #define MOVIE_SETTING_GBCFF55FIX (1<<5)
59 #define MOVIE_SETTING_GBECHORAMFIX (1<<6)
61 #define STREAM gzFile
62 /*#define READ_STREAM(p,l,s) gzread (s,p,l)
63 #define WRITE_STREAM(p,l,s) gzwrite (s,p,l)
64 #define OPEN_STREAM(f,m) gzopen (f,m)
65 #define REOPEN_STREAM(f,m) gzdopen (f,m)
66 #define FIND_STREAM(f) gztell(f)
67 #define REVERT_STREAM(f,o,s) gzseek(f,o,s)
68 #define CLOSE_STREAM(s) gzclose (s)
69 #else
70 #define STREAM FILE *
71 #define READ_STREAM(p,l,s) fread (p,1,l,s)
72 #define WRITE_STREAM(p,l,s) fwrite (p,1,l,s)
73 #define OPEN_STREAM(f,m) fopen (f,m)
74 #define REOPEN_STREAM(f,m) fdopen (f,m)
75 #define FIND_STREAM(f) ftell(f)
76 #define REVERT_STREAM(f,o,s) fseek(f,o,s)
77 #define CLOSE_STREAM(s) fclose (s)
78 #endif*/
80 enum MovieState
81 {
82 MOVIE_STATE_NONE = 0,
83 MOVIE_STATE_PLAY,
84 MOVIE_STATE_RECORD,
85 MOVIE_STATE_END
86 };
88 struct SMovieFileHeader
89 {
90 uint32 magic; // VBM0x1a
91 uint32 version; // 1
92 int32 uid; // used to match savestates to a particular movie
93 uint32 length_frames;
94 uint32 rerecord_count;
95 uint8 startFlags;
96 uint8 controllerFlags;
97 uint8 typeFlags;
98 uint8 optionFlags;
99 uint32 saveType; // emulator setting value
100 uint32 flashSize; // emulator setting value
101 uint32 gbEmulatorType; // emulator setting value
102 char romTitle [12];
103 uint8 minorVersion; // minor version/revision of the current movie version
104 uint8 romCRC; // the CRC of the ROM used while recording
105 uint16 romOrBiosChecksum; // the Checksum of the ROM used while recording, or a CRC of the BIOS if GBA
106 uint32 romGameCode; // the Game Code of the ROM used while recording, or "\0\0\0\0" if not GBA
107 uint32 offset_to_savestate; // offset to the savestate or SRAM inside file, set to 0 if unused
108 uint32 offset_to_controller_data; // offset to the controller data inside file
109 };
111 struct SMovie
112 {
113 enum MovieState state;
114 char filename[/*_MAX_PATH*/ 260]; // FIXME: should use a string instead
115 FILE* file;
116 uint8 readOnly;
117 int32 pauseFrame; // FIXME: byte size
119 SMovieFileHeader header;
120 char authorInfo[MOVIE_METADATA_SIZE];
122 uint32 currentFrame; // should == length_frame when recording, and be < length_frames when playing
123 uint32 bytesPerFrame;
124 uint8* inputBuffer;
125 uint32 inputBufferSize;
126 uint8* inputBufferPtr;
128 // bool8 doesn't make much sense if it is meant to solve any portability problem,
129 // because there's no guarantee that true == 1 and false == 0 (or TRUE == 1 and FALSE == 0) on all platforms.
130 // while using user-defined boolean types might impact on performance.
131 // the more reliable (and faster!) way to maintain cross-platform I/O compatibility is
132 // to manually map from/to built-in boolean types to/from fixed-sized types value by value ONLY when doing I/O
133 // e.g. bool(true) <-> u8(1) and <-> bool(false) <-> u8(0), BOOL(TRUE) <-> s32(-1) and BOOL(FALSE) <-> s32(0) etc.
134 bool8 RecordedThisSession;
135 };
137 // methods used by the user-interface code
138 int VBAMovieOpen(const char *filename, bool8 read_only);
139 int VBAMovieCreate(const char *filename, const char *authorInfo, uint8 startFlags, uint8 controllerFlags, uint8 typeFlags);
140 int VBAMovieGetInfo(const char *filename, SMovie*info);
141 void VBAMovieGetRomInfo(const SMovie &movieInfo, char romTitle[12], uint32 &romGameCode, uint16 &checksum, uint8 &crc);
142 void VBAMovieStop(bool8 suppress_message);
143 const char *VBAChooseMovieFilename(bool8 read_only);
145 // methods used by the emulation
146 void VBAMovieInit();
147 void VBAMovieUpdateState();
148 void VBAMovieRead(int controllerNum = 0, bool sensor = false);
149 void VBAMovieWrite(int controllerNum = 0, bool sensor = false);
150 void VBAUpdateButtonPressDisplay();
151 void VBAUpdateFrameCountDisplay();
152 //bool8 VBAMovieRewind (uint32 at_frame);
153 void VBAMovieFreeze(uint8 **buf, uint32 *size);
154 int VBAMovieUnfreeze(const uint8 *buf, uint32 size);
155 void VBAMovieRestart();
157 // accessor functions
158 bool8 VBAMovieActive();
159 bool8 VBAMovieLoading();
160 bool8 VBAMoviePlaying();
161 bool8 VBAMovieRecording();
162 // the following accessors return 0/false if !VBAMovieActive()
163 uint8 VBAMovieReadOnly();
164 uint32 VBAMovieGetVersion();
165 uint32 VBAMovieGetMinorVersion();
166 uint32 VBAMovieGetId();
167 uint32 VBAMovieGetLength();
168 uint32 VBAMovieGetFrameCounter();
169 uint32 VBAMovieGetState();
170 uint32 VBAMovieGetRerecordCount ();
171 uint32 VBAMovieSetRerecordCount (uint32 newRerecordCount);
172 std::string VBAMovieGetAuthorInfo();
173 std::string VBAMovieGetFilename();
175 uint16 VBAMovieGetCurrentInputOf(int controllerNum, bool normalOnly = true);
176 void VBAMovieSignalReset();
177 void VBAMovieResetIfRequested();
178 void VBAMovieSetMetadata(const char *info);
179 void VBAMovieToggleReadOnly();
180 bool VBAMovieEnded();
181 bool VBAMovieAllowsRerecording();
182 bool VBAMovieSwitchToPlaying();
183 bool VBAMovieSwitchToRecording();
184 int VBAMovieGetPauseAt();
185 void VBAMovieSetPauseAt(int at);
186 int VBAMovieConvertCurrent();
187 bool VBAMovieTuncateAtCurrentFrame();
188 bool VBAMovieFixHeader();
190 #endif // VBA_MOVIE_H