diff src/common/movie.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/common/movie.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,190 @@
     1.4 +#ifndef VBA_MOVIE_H
     1.5 +#define VBA_MOVIE_H
     1.6 +
     1.7 +#if _MSC_VER > 1000
     1.8 +#pragma once
     1.9 +#endif // _MSC_VER > 1000
    1.10 +
    1.11 +#include <ctime>
    1.12 +#include <string>
    1.13 +
    1.14 +#include "../Port.h"
    1.15 +
    1.16 +#define ZLIB
    1.17 +///#ifdef ZLIB
    1.18 +#ifndef WIN32
    1.19 +#include "zlib.h"
    1.20 +#endif
    1.21 +
    1.22 +#ifndef MOVIE_SUCCESS
    1.23 +#  define MOVIE_SUCCESS 1
    1.24 +#  define MOVIE_NOTHING 0
    1.25 +#  define MOVIE_WRONG_FORMAT (-1)
    1.26 +#  define MOVIE_WRONG_VERSION (-2)
    1.27 +#  define MOVIE_FILE_NOT_FOUND (-3)
    1.28 +#  define MOVIE_NOT_FROM_THIS_MOVIE (-4)
    1.29 +#  define MOVIE_NOT_FROM_A_MOVIE (-5)
    1.30 +#  define MOVIE_SNAPSHOT_INCONSISTENT (-6)
    1.31 +#  define MOVIE_UNKNOWN_ERROR (-7)
    1.32 +#endif
    1.33 +
    1.34 +#define VBM_MAGIC (0x1a4D4256) // VBM0x1a
    1.35 +#define VBM_VERSION (1)
    1.36 +#define VBM_HEADER_SIZE (64)
    1.37 +#define CONTROLLER_DATA_SIZE (2)
    1.38 +#define BUFFER_GROWTH_SIZE (4096)
    1.39 +#define MOVIE_METADATA_SIZE (192)
    1.40 +#define MOVIE_METADATA_AUTHOR_SIZE (64)
    1.41 +
    1.42 +// revision 1 uses (?) insted of (!) as reset
    1.43 +#define VBM_REVISION   (1)
    1.44 +
    1.45 +#define MOVIE_START_FROM_SNAPSHOT   (1<<0)
    1.46 +#define MOVIE_START_FROM_SRAM       (1<<1)
    1.47 +
    1.48 +#define MOVIE_CONTROLLER(i)         (1<<(i))
    1.49 +#define MOVIE_CONTROLLERS_ANY_MASK  (MOVIE_CONTROLLER(0)|MOVIE_CONTROLLER(1)|MOVIE_CONTROLLER(2)|MOVIE_CONTROLLER(3))
    1.50 +#define MOVIE_NUM_OF_POSSIBLE_CONTROLLERS   (4)
    1.51 +
    1.52 +#define MOVIE_TYPE_GBA              (1<<0)
    1.53 +#define MOVIE_TYPE_GBC              (1<<1)
    1.54 +#define MOVIE_TYPE_SGB              (1<<2)
    1.55 +
    1.56 +#define MOVIE_SETTING_USEBIOSFILE   (1<<0)
    1.57 +#define MOVIE_SETTING_SKIPBIOSFILE  (1<<1)
    1.58 +#define MOVIE_SETTING_RTCENABLE     (1<<2)
    1.59 +#define MOVIE_SETTING_GBINPUTHACK   (1<<3)
    1.60 +#define MOVIE_SETTING_LAGHACK       (1<<4)
    1.61 +#define MOVIE_SETTING_GBCFF55FIX    (1<<5)
    1.62 +#define MOVIE_SETTING_GBECHORAMFIX  (1<<6)
    1.63 +
    1.64 +#define STREAM gzFile
    1.65 +/*#define READ_STREAM(p,l,s) gzread (s,p,l)
    1.66 + #define WRITE_STREAM(p,l,s) gzwrite (s,p,l)
    1.67 + #define OPEN_STREAM(f,m) gzopen (f,m)
    1.68 + #define REOPEN_STREAM(f,m) gzdopen (f,m)
    1.69 + #define FIND_STREAM(f)	gztell(f)
    1.70 + #define REVERT_STREAM(f,o,s)  gzseek(f,o,s)
    1.71 + #define CLOSE_STREAM(s) gzclose (s)
    1.72 + #else
    1.73 + #define STREAM FILE *
    1.74 + #define READ_STREAM(p,l,s) fread (p,1,l,s)
    1.75 + #define WRITE_STREAM(p,l,s) fwrite (p,1,l,s)
    1.76 + #define OPEN_STREAM(f,m) fopen (f,m)
    1.77 + #define REOPEN_STREAM(f,m) fdopen (f,m)
    1.78 + #define FIND_STREAM(f)	ftell(f)
    1.79 + #define REVERT_STREAM(f,o,s)	 fseek(f,o,s)
    1.80 + #define CLOSE_STREAM(s) fclose (s)
    1.81 + #endif*/
    1.82 +
    1.83 +enum MovieState
    1.84 +{
    1.85 +	MOVIE_STATE_NONE = 0,
    1.86 +	MOVIE_STATE_PLAY,
    1.87 +	MOVIE_STATE_RECORD,
    1.88 +	MOVIE_STATE_END
    1.89 +};
    1.90 +
    1.91 +struct SMovieFileHeader
    1.92 +{
    1.93 +	uint32 magic;       // VBM0x1a
    1.94 +	uint32 version;     // 1
    1.95 +	int32  uid;         // used to match savestates to a particular movie
    1.96 +	uint32 length_frames;
    1.97 +	uint32 rerecord_count;
    1.98 +	uint8  startFlags;
    1.99 +	uint8  controllerFlags;
   1.100 +	uint8  typeFlags;
   1.101 +	uint8  optionFlags;
   1.102 +	uint32 saveType;        // emulator setting value
   1.103 +	uint32 flashSize;       // emulator setting value
   1.104 +	uint32 gbEmulatorType;  // emulator setting value
   1.105 +	char   romTitle [12];
   1.106 +	uint8  minorVersion;	// minor version/revision of the current movie version
   1.107 +	uint8  romCRC;						// the CRC of the ROM used while recording
   1.108 +	uint16 romOrBiosChecksum;			// the Checksum of the ROM used while recording, or a CRC of the BIOS if GBA
   1.109 +	uint32 romGameCode;					// the Game Code of the ROM used while recording, or "\0\0\0\0" if not GBA
   1.110 +	uint32 offset_to_savestate;         // offset to the savestate or SRAM inside file, set to 0 if unused
   1.111 +	uint32 offset_to_controller_data;   // offset to the controller data inside file
   1.112 +};
   1.113 +
   1.114 +struct SMovie
   1.115 +{
   1.116 +	enum   MovieState state;
   1.117 +	char   filename[/*_MAX_PATH*/ 260]; // FIXME: should use a string instead
   1.118 +	FILE*  file;
   1.119 +	uint8  readOnly;
   1.120 +	int32  pauseFrame;	// FIXME: byte size
   1.121 +
   1.122 +	SMovieFileHeader header;
   1.123 +	char  authorInfo[MOVIE_METADATA_SIZE];
   1.124 +
   1.125 +	uint32 currentFrame;    // should == length_frame when recording, and be < length_frames when playing
   1.126 +	uint32 bytesPerFrame;
   1.127 +	uint8* inputBuffer;
   1.128 +	uint32 inputBufferSize;
   1.129 +	uint8* inputBufferPtr;
   1.130 +
   1.131 +	// bool8 doesn't make much sense if it is meant to solve any portability problem,
   1.132 +	//   because there's no guarantee that true == 1 and false == 0 (or TRUE == 1 and FALSE == 0) on all platforms.
   1.133 +	//   while using user-defined boolean types might impact on performance.
   1.134 +	//   the more reliable (and faster!) way to maintain cross-platform I/O compatibility is
   1.135 +	//   to manually map from/to built-in boolean types to/from fixed-sized types value by value ONLY when doing I/O
   1.136 +	//   e.g. bool(true) <-> u8(1) and <-> bool(false) <-> u8(0), BOOL(TRUE) <-> s32(-1) and BOOL(FALSE) <-> s32(0) etc.
   1.137 +	bool8 RecordedThisSession;
   1.138 +};
   1.139 +
   1.140 +// methods used by the user-interface code
   1.141 +int VBAMovieOpen(const char *filename, bool8 read_only);
   1.142 +int VBAMovieCreate(const char *filename, const char *authorInfo, uint8 startFlags, uint8 controllerFlags, uint8 typeFlags);
   1.143 +int VBAMovieGetInfo(const char *filename, SMovie*info);
   1.144 +void VBAMovieGetRomInfo(const SMovie &movieInfo, char romTitle[12], uint32 &romGameCode, uint16 &checksum, uint8 &crc);
   1.145 +void VBAMovieStop(bool8 suppress_message);
   1.146 +const char *VBAChooseMovieFilename(bool8 read_only);
   1.147 +
   1.148 +// methods used by the emulation
   1.149 +void VBAMovieInit();
   1.150 +void VBAMovieUpdateState();
   1.151 +void VBAMovieRead(int controllerNum = 0, bool sensor = false);
   1.152 +void VBAMovieWrite(int controllerNum = 0, bool sensor = false);
   1.153 +void VBAUpdateButtonPressDisplay();
   1.154 +void VBAUpdateFrameCountDisplay();
   1.155 +//bool8 VBAMovieRewind (uint32 at_frame);
   1.156 +void VBAMovieFreeze(uint8 **buf, uint32 *size);
   1.157 +int VBAMovieUnfreeze(const uint8 *buf, uint32 size);
   1.158 +void VBAMovieRestart();
   1.159 +
   1.160 +// accessor functions
   1.161 +bool8 VBAMovieActive();
   1.162 +bool8 VBAMovieLoading();
   1.163 +bool8 VBAMoviePlaying();
   1.164 +bool8 VBAMovieRecording();
   1.165 +// the following accessors return 0/false if !VBAMovieActive()
   1.166 +uint8 VBAMovieReadOnly();
   1.167 +uint32 VBAMovieGetVersion();
   1.168 +uint32 VBAMovieGetMinorVersion();
   1.169 +uint32 VBAMovieGetId();
   1.170 +uint32 VBAMovieGetLength();
   1.171 +uint32 VBAMovieGetFrameCounter();
   1.172 +uint32 VBAMovieGetState();
   1.173 +uint32 VBAMovieGetRerecordCount ();
   1.174 +uint32 VBAMovieSetRerecordCount (uint32 newRerecordCount);
   1.175 +std::string VBAMovieGetAuthorInfo();
   1.176 +std::string VBAMovieGetFilename();
   1.177 +
   1.178 +uint16 VBAMovieGetCurrentInputOf(int controllerNum, bool normalOnly = true);
   1.179 +void VBAMovieSignalReset();
   1.180 +void VBAMovieResetIfRequested();
   1.181 +void VBAMovieSetMetadata(const char *info);
   1.182 +void VBAMovieToggleReadOnly();
   1.183 +bool VBAMovieEnded();
   1.184 +bool VBAMovieAllowsRerecording();
   1.185 +bool VBAMovieSwitchToPlaying();
   1.186 +bool VBAMovieSwitchToRecording();
   1.187 +int  VBAMovieGetPauseAt();
   1.188 +void VBAMovieSetPauseAt(int at);
   1.189 +int  VBAMovieConvertCurrent();
   1.190 +bool VBAMovieTuncateAtCurrentFrame();
   1.191 +bool VBAMovieFixHeader();
   1.192 +
   1.193 +#endif // VBA_MOVIE_H