~ubuntu-branches/ubuntu/lucid/fceux/lucid

« back to all changes in this revision

Viewing changes to fceu/src/movie.h

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-12-14 08:05:17 UTC
  • Revision ID: james.westby@ubuntu.com-20091214080517-abi5tj8avthfan7c
Tags: upstream-2.1.2+repack
ImportĀ upstreamĀ versionĀ 2.1.2+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __MOVIE_H_
 
2
#define __MOVIE_H_
 
3
 
 
4
#include <vector>
 
5
#include <map>
 
6
#include <string>
 
7
#include <ostream>
 
8
#include <stdlib.h>
 
9
 
 
10
#include "input/zapper.h"
 
11
#include "utils/guid.h"
 
12
 
 
13
struct FCEUFILE;
 
14
 
 
15
enum EMOVIE_FLAG
 
16
{
 
17
        MOVIE_FLAG_NONE = 0,
 
18
 
 
19
        //an ARCHAIC flag which means the movie was recorded from a soft reset.
 
20
        //WHY would you do this?? do not create any new movies with this flag
 
21
        MOVIE_FLAG_FROM_RESET = (1<<1),
 
22
        
 
23
        MOVIE_FLAG_PAL = (1<<2),
 
24
 
 
25
        //movie was recorded from poweron. the alternative is from a savestate (or from reset)
 
26
        MOVIE_FLAG_FROM_POWERON = (1<<3),
 
27
 
 
28
        // set in newer version, used for old movie compatibility
 
29
        //TODO - only use this flag to print a warning that the sync might be bad
 
30
        //so that we can get rid of the sync hack code
 
31
        MOVIE_FLAG_NOSYNCHACK = (1<<4)
 
32
};
 
33
 
 
34
typedef struct
 
35
{
 
36
        int movie_version;                                      // version of the movie format in the file
 
37
        uint32 num_frames;
 
38
        uint32 rerecord_count;
 
39
        bool poweron, pal, nosynchack;
 
40
        bool reset; //mbg 6/21/08 - this flag isnt used anymore.. but maybe one day we can scan it out of the first record in the movie file
 
41
        uint32 emu_version_used;                                // 9813 = 0.98.13
 
42
        MD5DATA md5_of_rom_used;
 
43
        std::string name_of_rom_used;
 
44
 
 
45
        std::vector<std::wstring> comments;
 
46
        std::vector<std::string> subtitles;
 
47
} MOVIE_INFO;
 
48
 
 
49
 
 
50
void FCEUMOV_AddInputState();
 
51
void FCEUMOV_AddCommand(int cmd);
 
52
void FCEU_DrawMovies(uint8 *);
 
53
void FCEU_DrawLagCounter(uint8 *);
 
54
 
 
55
enum EMOVIEMODE
 
56
{
 
57
        MOVIEMODE_INACTIVE = 1,
 
58
        MOVIEMODE_RECORD = 2,
 
59
        MOVIEMODE_PLAY = 4,
 
60
        MOVIEMODE_TASEDIT = 8
 
61
};
 
62
 
 
63
enum EMOVIECMD
 
64
{
 
65
        MOVIECMD_RESET = 1,
 
66
        MOVIECMD_POWER = 2,
 
67
        MOVIECMD_FDS_INSERT = 4,
 
68
        MOVIECMD_FDS_SELECT = 8
 
69
};
 
70
 
 
71
EMOVIEMODE FCEUMOV_Mode();
 
72
bool FCEUMOV_Mode(EMOVIEMODE modemask);
 
73
bool FCEUMOV_Mode(int modemask);
 
74
inline bool FCEUMOV_IsPlaying() { return FCEUMOV_Mode(MOVIEMODE_PLAY); }
 
75
inline bool FCEUMOV_IsRecording() { return FCEUMOV_Mode(MOVIEMODE_RECORD); }
 
76
 
 
77
bool FCEUMOV_ShouldPause(void);
 
78
int FCEUMOV_GetFrame(void);
 
79
int FCEUI_GetLagCount(void);
 
80
bool FCEUI_GetLagged(void);
 
81
 
 
82
int FCEUMOV_WriteState(std::ostream* os);
 
83
bool FCEUMOV_ReadState(std::istream* is, uint32 size);
 
84
void FCEUMOV_PreLoad();
 
85
bool FCEUMOV_PostLoad();
 
86
 
 
87
void FCEUMOV_EnterTasEdit();
 
88
void FCEUMOV_ExitTasEdit();
 
89
 
 
90
class MovieData;
 
91
class MovieRecord
 
92
{
 
93
 
 
94
public:
 
95
        ValueArray<uint8,4> joysticks;
 
96
        
 
97
        struct {
 
98
                uint8 x,y,b,bogo;
 
99
                uint64 zaphit;
 
100
        } zappers[2];
 
101
 
 
102
        //misc commands like reset, etc.
 
103
        //small now to save space; we might need to support more commands later.
 
104
        //the disk format will support up to 64bit if necessary
 
105
        uint8 commands;
 
106
        bool command_reset() { return (commands&MOVIECMD_RESET)!=0; }
 
107
        bool command_power() { return (commands&MOVIECMD_POWER)!=0; }
 
108
        bool command_fds_insert() { return (commands&MOVIECMD_FDS_INSERT)!=0; }
 
109
        bool command_fds_select() { return (commands&MOVIECMD_FDS_SELECT)!=0; }
 
110
 
 
111
        void toggleBit(int joy, int bit)
 
112
        {
 
113
                joysticks[joy] ^= mask(bit);
 
114
        }
 
115
 
 
116
        void setBit(int joy, int bit)
 
117
        {
 
118
                joysticks[joy] |= mask(bit);
 
119
        }
 
120
 
 
121
        void clearBit(int joy, int bit)
 
122
        {
 
123
                joysticks[joy] &= ~mask(bit);
 
124
        }
 
125
 
 
126
        void setBitValue(int joy, int bit, bool val)
 
127
        {
 
128
                if(val) setBit(joy,bit);
 
129
                else clearBit(joy,bit);
 
130
        }
 
131
 
 
132
        bool checkBit(int joy, int bit)
 
133
        {
 
134
                return (joysticks[joy] & mask(bit))!=0;
 
135
        }
 
136
 
 
137
        void clear();
 
138
        
 
139
        //a waste of memory in lots of cases..  maybe make it a pointer later?
 
140
        std::vector<char> savestate;
 
141
 
 
142
        void parse(MovieData* md, std::istream* is);
 
143
        bool parseBinary(MovieData* md, std::istream* is);
 
144
        void dump(MovieData* md, std::ostream* os, int index);
 
145
        void dumpBinary(MovieData* md, std::ostream* os, int index);
 
146
        void parseJoy(std::istream* is, uint8& joystate);
 
147
        void dumpJoy(std::ostream* os, uint8 joystate);
 
148
        
 
149
        static const char mnemonics[8];
 
150
 
 
151
private:
 
152
        int mask(int bit) { return 1<<bit; }
 
153
};
 
154
 
 
155
class MovieData
 
156
{
 
157
public:
 
158
        MovieData();
 
159
        
 
160
 
 
161
        int version;
 
162
        int emuVersion;
 
163
        //todo - somehow force mutual exclusion for poweron and reset (with an error in the parser)
 
164
        bool palFlag;
 
165
        MD5DATA romChecksum;
 
166
        std::string romFilename;
 
167
        std::vector<char> savestate;
 
168
        std::vector<MovieRecord> records;
 
169
        std::vector<std::wstring> comments;
 
170
        std::vector<std::string> subtitles;
 
171
        //this is the RERECORD COUNT. please rename variable.
 
172
        int rerecordCount;
 
173
        FCEU_Guid guid;
 
174
 
 
175
        //was the frame data stored in binary?
 
176
        bool binaryFlag;
 
177
 
 
178
        //which ports are defined for the movie
 
179
        int ports[3];
 
180
        //whether fourscore is enabled
 
181
        bool fourscore;
 
182
        
 
183
        //----TasEdit stuff---
 
184
        int greenZoneCount;
 
185
        //----
 
186
 
 
187
        int getNumRecords() { return records.size(); }
 
188
 
 
189
        class TDictionary : public std::map<std::string,std::string>
 
190
        {
 
191
        public:
 
192
                bool containsKey(std::string key)
 
193
                {
 
194
                        return find(key) != end();
 
195
                }
 
196
 
 
197
                void tryInstallBool(std::string key, bool& val)
 
198
                {
 
199
                        if(containsKey(key))
 
200
                                val = atoi(operator [](key).c_str())!=0;
 
201
                }
 
202
 
 
203
                void tryInstallString(std::string key, std::string& val)
 
204
                {
 
205
                        if(containsKey(key))
 
206
                                val = operator [](key);
 
207
                }
 
208
 
 
209
                void tryInstallInt(std::string key, int& val)
 
210
                {
 
211
                        if(containsKey(key))
 
212
                                val = atoi(operator [](key).c_str());
 
213
                }
 
214
 
 
215
        };
 
216
 
 
217
        void truncateAt(int frame);
 
218
        void installValue(std::string& key, std::string& val);
 
219
        int dump(std::ostream* os, bool binary);
 
220
        void clearRecordRange(int start, int len);
 
221
        void insertEmpty(int at, int frames);
 
222
        
 
223
        static bool loadSavestateFrom(std::vector<char>* buf);
 
224
        static void dumpSavestateTo(std::vector<char>* buf, int compressionLevel);
 
225
        void TryDumpIncremental();
 
226
 
 
227
private:
 
228
        void installInt(std::string& val, int& var)
 
229
        {
 
230
                var = atoi(val.c_str());
 
231
        }
 
232
 
 
233
        void installBool(std::string& val, bool& var)
 
234
        {
 
235
                var = atoi(val.c_str())!=0;
 
236
        }
 
237
};
 
238
 
 
239
extern MovieData currMovieData;
 
240
extern int currFrameCounter;
 
241
extern char curMovieFilename[512];
 
242
extern bool subtitlesOnAVI;
 
243
extern bool freshMovie;
 
244
extern bool movie_readonly;
 
245
extern bool autoMovieBackup;
 
246
//--------------------------------------------------
 
247
bool CheckFileExists(const char* filename);     //Receives a filename (fullpath) and checks to see if that file exists
 
248
void FCEUI_MakeBackupMovie(bool dispMessage);
 
249
void FCEUI_CreateMovieFile(std::string fn);
 
250
void FCEUI_SaveMovie(const char *fname, EMOVIE_FLAG flags, std::wstring author);
 
251
bool FCEUI_LoadMovie(const char *fname, bool read_only, bool tasedit, int _stopframe);
 
252
void FCEUI_MoviePlayFromBeginning(void);
 
253
void FCEUI_StopMovie(void);
 
254
bool FCEUI_MovieGetInfo(FCEUFILE* fp, MOVIE_INFO& info, bool skipFrameCount = false);
 
255
char* FCEUI_MovieGetCurrentName(int addSlotNumber);
 
256
void FCEUI_MovieToggleReadOnly(void);
 
257
bool FCEUI_GetMovieToggleReadOnly();
 
258
void FCEUI_SetMovieToggleReadOnly(bool which);
 
259
int FCEUI_GetMovieLength();
 
260
int FCEUI_GetMovieRerecordCount();
 
261
std::string FCEUI_GetMovieName(void);
 
262
void FCEUI_MovieToggleFrameDisplay();
 
263
void FCEUI_ToggleInputDisplay(void);
 
264
 
 
265
void LoadSubtitles(MovieData);
 
266
void ProcessSubtitles(void);
 
267
void FCEU_DisplaySubtitles(char *format, ...);
 
268
 
 
269
#endif //__MOVIE_H_