annotate src/common/movie.h @ 291:c8b0db518de3

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