convert movie system to FILE*
This commit is contained in:
parent
c5458e7509
commit
fce7cb2701
|
@ -0,0 +1,47 @@
|
||||||
|
#ifndef EMUFILE_H
|
||||||
|
#define EMUFILE_H
|
||||||
|
|
||||||
|
class EMUFILE{
|
||||||
|
private:
|
||||||
|
FILE* fp;
|
||||||
|
|
||||||
|
public:
|
||||||
|
EMUFILE(const char* fname, const char* mode)
|
||||||
|
{
|
||||||
|
fp = fopen(fname,mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
FILE *get_fp(){
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fprintf(const char *format, ...) {
|
||||||
|
return ::fprintf(fp, format);
|
||||||
|
};
|
||||||
|
|
||||||
|
int fgetc() {
|
||||||
|
return ::fgetc(fp);
|
||||||
|
}
|
||||||
|
int fputc(int c) {
|
||||||
|
return ::fputc(c, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t fread(void *ptr, size_t size, size_t nobj){
|
||||||
|
return ::fread(ptr, size, nobj, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t fwrite(void *ptr, size_t size, size_t nobj){
|
||||||
|
return ::fwrite(ptr, size, nobj, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fseek(long int offset, int origin){
|
||||||
|
return ::fseek(fp, offset, origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
long int ftell() {
|
||||||
|
return ::ftell(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <fstream>
|
|
||||||
#include "utils/guid.h"
|
#include "utils/guid.h"
|
||||||
#include "utils/xstring.h"
|
#include "utils/xstring.h"
|
||||||
#include "movie.h"
|
#include "movie.h"
|
||||||
|
@ -33,8 +32,9 @@
|
||||||
#include "mic.h"
|
#include "mic.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "GPU_osd.h"
|
#include "GPU_osd.h"
|
||||||
#include "memorystream.h"
|
//#include "memorystream.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "emufile.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
bool freshMovie = false; //True when a movie loads, false when movie is altered. Used to determine if a movie has been altered since opening
|
bool freshMovie = false; //True when a movie loads, false when movie is altered. Used to determine if a movie has been altered since opening
|
||||||
|
@ -49,7 +49,7 @@ bool autoMovieBackup = true;
|
||||||
EMOVIEMODE movieMode = MOVIEMODE_INACTIVE;
|
EMOVIEMODE movieMode = MOVIEMODE_INACTIVE;
|
||||||
|
|
||||||
//this should not be set unless we are in MOVIEMODE_RECORD!
|
//this should not be set unless we are in MOVIEMODE_RECORD!
|
||||||
fstream* osRecordingMovie = 0;
|
EMUFILE* osRecordingMovie = 0;
|
||||||
|
|
||||||
int currFrameCounter;
|
int currFrameCounter;
|
||||||
uint32 cur_input_display = 0;
|
uint32 cur_input_display = 0;
|
||||||
|
@ -95,7 +95,7 @@ void MovieRecord::clear()
|
||||||
|
|
||||||
|
|
||||||
const char MovieRecord::mnemonics[13] = {'R','L','D','U','T','S','B','A','Y','X','W','E','G'};
|
const char MovieRecord::mnemonics[13] = {'R','L','D','U','T','S','B','A','Y','X','W','E','G'};
|
||||||
void MovieRecord::dumpPad(std::ostream* os, u16 pad)
|
void MovieRecord::dumpPad(EMUFILE* fp, u16 pad)
|
||||||
{
|
{
|
||||||
//these are mnemonics for each joystick bit.
|
//these are mnemonics for each joystick bit.
|
||||||
//since we usually use the regular joypad, these will be more helpful.
|
//since we usually use the regular joypad, these will be more helpful.
|
||||||
|
@ -107,17 +107,18 @@ void MovieRecord::dumpPad(std::ostream* os, u16 pad)
|
||||||
char mnemonic = mnemonics[bit];
|
char mnemonic = mnemonics[bit];
|
||||||
//if the bit is set write the mnemonic
|
//if the bit is set write the mnemonic
|
||||||
if(pad & bitmask)
|
if(pad & bitmask)
|
||||||
os->put(mnemonic);
|
fp->fputc(mnemonic);
|
||||||
else //otherwise write an unset bit
|
else //otherwise write an unset bit
|
||||||
os->put('.');
|
fp->fputc('.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MovieRecord::parsePad(std::istream* is, u16& pad)
|
void MovieRecord::parsePad(EMUFILE* fp, u16& pad)
|
||||||
{
|
{
|
||||||
|
|
||||||
char buf[13];
|
char buf[13];
|
||||||
is->read(buf,13);
|
fp->fread(buf,13,1);
|
||||||
pad = 0;
|
pad = 0;
|
||||||
for(int i=0;i<13;i++)
|
for(int i=0;i<13;i++)
|
||||||
{
|
{
|
||||||
|
@ -127,42 +128,42 @@ void MovieRecord::parsePad(std::istream* is, u16& pad)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MovieRecord::parse(MovieData* md, std::istream* is)
|
void MovieRecord::parse(MovieData* md, EMUFILE* fp)
|
||||||
{
|
{
|
||||||
//by the time we get in here, the initial pipe has already been extracted
|
//by the time we get in here, the initial pipe has already been extracted
|
||||||
|
|
||||||
//extract the commands
|
//extract the commands
|
||||||
commands = u32DecFromIstream(is);
|
commands = u32DecFromIstream(fp->get_fp());
|
||||||
|
|
||||||
is->get(); //eat the pipe
|
fp->fgetc(); //eat the pipe
|
||||||
|
|
||||||
parsePad(is, pad);
|
parsePad(fp, pad);
|
||||||
touch.x = u32DecFromIstream(is);
|
touch.x = u32DecFromIstream(fp->get_fp());
|
||||||
touch.y = u32DecFromIstream(is);
|
touch.y = u32DecFromIstream(fp->get_fp());
|
||||||
touch.touch = u32DecFromIstream(is);
|
touch.touch = u32DecFromIstream(fp->get_fp());
|
||||||
|
|
||||||
is->get(); //eat the pipe
|
fp->fgetc(); //eat the pipe
|
||||||
|
|
||||||
//should be left at a newline
|
//should be left at a newline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MovieRecord::dump(MovieData* md, std::ostream* os, int index)
|
void MovieRecord::dump(MovieData* md, EMUFILE* fp, int index)
|
||||||
{
|
{
|
||||||
//dump the misc commands
|
//dump the misc commands
|
||||||
//*os << '|' << setw(1) << (int)commands;
|
//*os << '|' << setw(1) << (int)commands;
|
||||||
os->put('|');
|
fp->fputc('|');
|
||||||
putdec<uint8,1,true>(os,commands);
|
putdec<uint8,1,true>(fp->get_fp(),commands);
|
||||||
|
|
||||||
os->put('|');
|
fp->fputc('|');
|
||||||
dumpPad(os, pad);
|
dumpPad(fp, pad);
|
||||||
putdec<u8,3,true>(os,touch.x); os->put(' ');
|
putdec<u8,3,true>(fp->get_fp(),touch.x); fp->fputc(' ');
|
||||||
putdec<u8,3,true>(os,touch.y); os->put(' ');
|
putdec<u8,3,true>(fp->get_fp(),touch.y); fp->fputc(' ');
|
||||||
putdec<u8,1,true>(os,touch.touch);
|
putdec<u8,1,true>(fp->get_fp(),touch.touch);
|
||||||
os->put('|');
|
fp->fputc('|');
|
||||||
|
|
||||||
//each frame is on a new line
|
//each frame is on a new line
|
||||||
os->put('\n');
|
fp->fputc('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
MovieData::MovieData()
|
MovieData::MovieData()
|
||||||
|
@ -224,58 +225,60 @@ void MovieData::installValue(std::string& key, std::string& val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MovieData::dump(std::ostream *os, bool binary)
|
int MovieData::dump(EMUFILE* fp, bool binary)
|
||||||
{
|
{
|
||||||
int start = os->tellp();
|
int start = fp->ftell();
|
||||||
*os << "version " << version << endl;
|
fp->fprintf("version %d\n", version);
|
||||||
*os << "emuVersion " << emuVersion << endl;
|
fp->fprintf("emuVersion %d\n", emuVersion);
|
||||||
*os << "rerecordCount " << rerecordCount << endl;
|
fp->fprintf("rerecordCount %d\n", rerecordCount);
|
||||||
*os << "romFilename " << romFilename << endl;
|
|
||||||
*os << "romChecksum " << u32ToHexString(gameInfo.crc) << endl;
|
fp->fprintf("romFilename %s\n", romFilename.c_str());
|
||||||
*os << "romSerial " << romSerial << endl;
|
fp->fprintf("romChecksum %s\n", u32ToHexString(gameInfo.crc).c_str());
|
||||||
*os << "guid " << guid.toString() << endl;
|
fp->fprintf("romSerial %s\n", romSerial.c_str());
|
||||||
*os << "useExtBios " << CommonSettings.UseExtBIOS << endl;
|
fp->fprintf("guid %s\n", guid.toString().c_str());
|
||||||
|
fp->fprintf("useExtBios %d\n", CommonSettings.UseExtBIOS);
|
||||||
|
|
||||||
if(CommonSettings.UseExtBIOS)
|
if(CommonSettings.UseExtBIOS)
|
||||||
*os << "swiFromBios " << CommonSettings.SWIFromBIOS << endl;
|
fp->fprintf("swiFromBios %d\n", CommonSettings.SWIFromBIOS);
|
||||||
|
|
||||||
for(uint32 i=0;i<comments.size();i++)
|
for(uint32 i=0;i<comments.size();i++)
|
||||||
*os << "comment " << wcstombs(comments[i]) << endl;
|
fp->fprintf("comment %s\n", wcstombs(comments[i]).c_str());
|
||||||
|
|
||||||
if(binary)
|
if(binary)
|
||||||
*os << "binary 1" << endl;
|
fp->fprintf("binary 1\n");
|
||||||
|
|
||||||
if(savestate.size() != 0)
|
if(savestate.size() != 0)
|
||||||
*os << "savestate " << BytesToString(&savestate[0],savestate.size()) << endl;
|
fp->fprintf("savestate %s\n", BytesToString(&savestate[0],savestate.size()).c_str());
|
||||||
if(sram.size() != 0)
|
if(sram.size() != 0)
|
||||||
*os << "sram " << BytesToString(&sram[0],sram.size()) << endl;
|
fp->fprintf("sram %s\n", BytesToString(&sram[0],sram.size()).c_str());
|
||||||
|
|
||||||
if(binary)
|
if(binary)
|
||||||
{
|
{
|
||||||
//put one | to start the binary dump
|
//put one | to start the binary dump
|
||||||
os->put('|');
|
fp->fputc('|');
|
||||||
for(int i=0;i<(int)records.size();i++)
|
for(int i=0;i<(int)records.size();i++)
|
||||||
records[i].dumpBinary(this,os,i);
|
records[i].dumpBinary(this,fp,i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for(int i=0;i<(int)records.size();i++)
|
for(int i=0;i<(int)records.size();i++)
|
||||||
records[i].dump(this,os,i);
|
records[i].dump(this,fp,i);
|
||||||
|
|
||||||
int end = os->tellp();
|
int end = fp->ftell();
|
||||||
return end-start;
|
return end-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
//yuck... another custom text parser.
|
//yuck... another custom text parser.
|
||||||
bool LoadFM2(MovieData& movieData, std::istream* fp, int size, bool stopAfterHeader)
|
bool LoadFM2(MovieData& movieData, EMUFILE* fp, int size, bool stopAfterHeader)
|
||||||
{
|
{
|
||||||
//TODO - start with something different. like 'desmume movie version 1"
|
//TODO - start with something different. like 'desmume movie version 1"
|
||||||
std::ios::pos_type curr = fp->tellg();
|
int curr = fp->ftell();
|
||||||
|
|
||||||
//movie must start with "version 1"
|
//movie must start with "version 1"
|
||||||
char buf[9];
|
char buf[9];
|
||||||
curr = fp->tellg();
|
curr = fp->ftell();
|
||||||
fp->read(buf,9);
|
fp->fread(buf,9,1);
|
||||||
fp->seekg(curr);
|
fp->fseek(curr, SEEK_SET);
|
||||||
if(fp->fail()) return false;
|
// if(fp->fail()) return false;
|
||||||
if(memcmp(buf,"version 1",9))
|
if(memcmp(buf,"version 1",9))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -289,7 +292,7 @@ bool LoadFM2(MovieData& movieData, std::istream* fp, int size, bool stopAfterHea
|
||||||
bool iswhitespace, isrecchar, isnewline;
|
bool iswhitespace, isrecchar, isnewline;
|
||||||
int c;
|
int c;
|
||||||
if(size--<=0) goto bail;
|
if(size--<=0) goto bail;
|
||||||
c = fp->get();
|
c = fp->fgetc();
|
||||||
if(c == -1)
|
if(c == -1)
|
||||||
goto bail;
|
goto bail;
|
||||||
iswhitespace = (c==' '||c=='\t');
|
iswhitespace = (c==' '||c=='\t');
|
||||||
|
@ -318,9 +321,9 @@ bool LoadFM2(MovieData& movieData, std::istream* fp, int size, bool stopAfterHea
|
||||||
if (stopAfterHeader) return true;
|
if (stopAfterHeader) return true;
|
||||||
int currcount = movieData.records.size();
|
int currcount = movieData.records.size();
|
||||||
movieData.records.resize(currcount+1);
|
movieData.records.resize(currcount+1);
|
||||||
int preparse = fp->tellg();
|
int preparse = fp->ftell();
|
||||||
movieData.records[currcount].parse(&movieData, fp);
|
movieData.records[currcount].parse(&movieData, fp);
|
||||||
int postparse = fp->tellg();
|
int postparse = fp->ftell();
|
||||||
size -= (postparse-preparse);
|
size -= (postparse-preparse);
|
||||||
state = NEWLINE;
|
state = NEWLINE;
|
||||||
break;
|
break;
|
||||||
|
@ -370,7 +373,7 @@ static void closeRecordingMovie()
|
||||||
{
|
{
|
||||||
if(osRecordingMovie)
|
if(osRecordingMovie)
|
||||||
{
|
{
|
||||||
delete osRecordingMovie;
|
// delete osRecordingMovie;
|
||||||
osRecordingMovie = 0;
|
osRecordingMovie = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -437,23 +440,24 @@ const char* _CDECL_ FCEUI_LoadMovie(const char *fname, bool _read_only, bool tas
|
||||||
|
|
||||||
//LoadFM2(currMovieData, fp->stream, INT_MAX, false);
|
//LoadFM2(currMovieData, fp->stream, INT_MAX, false);
|
||||||
|
|
||||||
|
|
||||||
bool loadedfm2 = false;
|
bool loadedfm2 = false;
|
||||||
bool opened = false;
|
bool opened = false;
|
||||||
{
|
// {
|
||||||
fstream fs (fname);
|
EMUFILE* fp = new EMUFILE(fname, "rb");
|
||||||
if(fs.is_open())
|
// if(fs.is_open())
|
||||||
{
|
// {
|
||||||
loadedfm2 = LoadFM2(currMovieData, &fs, INT_MAX, false);
|
loadedfm2 = LoadFM2(currMovieData, fp, INT_MAX, false);
|
||||||
opened = true;
|
opened = true;
|
||||||
}
|
// }
|
||||||
fs.close();
|
// fs.close();
|
||||||
}
|
// }
|
||||||
if(!opened)
|
if(!opened)
|
||||||
{
|
{
|
||||||
// for some reason fs.open doesn't work, it has to be a whole new fstream object
|
// for some reason fs.open doesn't work, it has to be a whole new fstream object
|
||||||
fstream fs (fname, std::ios_base::in);
|
// fstream fs (fname, std::ios_base::in);
|
||||||
loadedfm2 = LoadFM2(currMovieData, &fs, INT_MAX, false);
|
loadedfm2 = LoadFM2(currMovieData, fp, INT_MAX, false);
|
||||||
fs.close();
|
// fs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!loadedfm2)
|
if(!loadedfm2)
|
||||||
|
@ -502,16 +506,16 @@ const char* _CDECL_ FCEUI_LoadMovie(const char *fname, bool _read_only, bool tas
|
||||||
static void openRecordingMovie(const char* fname)
|
static void openRecordingMovie(const char* fname)
|
||||||
{
|
{
|
||||||
//osRecordingMovie = FCEUD_UTF8_fstream(fname, "wb");
|
//osRecordingMovie = FCEUD_UTF8_fstream(fname, "wb");
|
||||||
osRecordingMovie = new fstream(fname,std::ios_base::out);
|
osRecordingMovie = new EMUFILE(fname, "wb");
|
||||||
/*if(!osRecordingMovie)
|
/*if(!osRecordingMovie)
|
||||||
FCEU_PrintError("Error opening movie output file: %s",fname);*/
|
FCEU_PrintError("Error opening movie output file: %s",fname);*/
|
||||||
strcpy(curMovieFilename, fname);
|
strcpy(curMovieFilename, fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MovieData::loadSramFrom(std::vector<char>* buf)
|
bool MovieData::loadSramFrom(std::vector<char>* buf)
|
||||||
{
|
{//TODO
|
||||||
memorystream ms(buf);
|
// memorystream ms(buf);
|
||||||
MMU_new.backupDevice.load_movie(&ms);
|
// MMU_new.backupDevice.load_movie(&ms);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,8 +523,8 @@ static bool FCEUSS_SaveSRAM(std::ostream* outstream, std:: string fname)
|
||||||
{
|
{
|
||||||
//a temp memory stream. we'll dump some data here and then compress
|
//a temp memory stream. we'll dump some data here and then compress
|
||||||
//TODO - support dumping directly without compressing to save a buffer copy
|
//TODO - support dumping directly without compressing to save a buffer copy
|
||||||
|
//TODO
|
||||||
memorystream ms;
|
/* memorystream ms;
|
||||||
|
|
||||||
//size it
|
//size it
|
||||||
FILE * fp = fopen( fname.c_str(), "r" );
|
FILE * fp = fopen( fname.c_str(), "r" );
|
||||||
|
@ -542,15 +546,15 @@ static bool FCEUSS_SaveSRAM(std::ostream* outstream, std:: string fname)
|
||||||
outstream->write((char*)buffer,size);
|
outstream->write((char*)buffer,size);
|
||||||
|
|
||||||
fb.close();
|
fb.close();
|
||||||
|
*/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovieData::dumpSramTo(std::vector<char>* buf, std::string sramfname) {
|
void MovieData::dumpSramTo(std::vector<char>* buf, std::string sramfname) {
|
||||||
|
//TODO
|
||||||
memorystream ms(buf);
|
// memorystream ms(buf);
|
||||||
FCEUSS_SaveSRAM(&ms, sramfname);
|
// FCEUSS_SaveSRAM(&ms, sramfname);
|
||||||
ms.trim();
|
// ms.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
//begin recording a new movie
|
//begin recording a new movie
|
||||||
|
@ -754,7 +758,7 @@ static void FCEUMOV_AddCommand(int cmd)
|
||||||
static const int kMOVI = 0x49564F4D;
|
static const int kMOVI = 0x49564F4D;
|
||||||
static const int kNOMO = 0x4F4D4F4E;
|
static const int kNOMO = 0x4F4D4F4E;
|
||||||
|
|
||||||
void mov_savestate(std::ostream* os)
|
void mov_savestate(EMUFILE* fp)
|
||||||
{
|
{
|
||||||
//we are supposed to dump the movie data into the savestate
|
//we are supposed to dump the movie data into the savestate
|
||||||
//if(movieMode == MOVIEMODE_RECORD || movieMode == MOVIEMODE_PLAY)
|
//if(movieMode == MOVIEMODE_RECORD || movieMode == MOVIEMODE_PLAY)
|
||||||
|
@ -762,12 +766,12 @@ void mov_savestate(std::ostream* os)
|
||||||
//else return 0;
|
//else return 0;
|
||||||
if(movieMode == MOVIEMODE_RECORD || movieMode == MOVIEMODE_PLAY)
|
if(movieMode == MOVIEMODE_RECORD || movieMode == MOVIEMODE_PLAY)
|
||||||
{
|
{
|
||||||
write32le(kMOVI,os);
|
write32le(kMOVI,fp->get_fp());
|
||||||
currMovieData.dump(os, true);
|
currMovieData.dump(fp, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
write32le(kNOMO,os);
|
write32le(kNOMO,fp->get_fp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,12 +779,12 @@ void mov_savestate(std::ostream* os)
|
||||||
|
|
||||||
static bool load_successful;
|
static bool load_successful;
|
||||||
|
|
||||||
bool mov_loadstate(std::istream* is, int size)
|
bool mov_loadstate(EMUFILE* fp, int size)
|
||||||
{
|
{
|
||||||
load_successful = false;
|
load_successful = false;
|
||||||
|
|
||||||
int cookie;
|
u32 cookie;
|
||||||
if(read32le(&cookie,is) != 1) return false;
|
if(read32le(&cookie,fp->get_fp()) != 1) return false;
|
||||||
if(cookie == kNOMO)
|
if(cookie == kNOMO)
|
||||||
return true;
|
return true;
|
||||||
else if(cookie != kMOVI)
|
else if(cookie != kMOVI)
|
||||||
|
@ -803,8 +807,8 @@ bool mov_loadstate(std::istream* is, int size)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
MovieData tempMovieData = MovieData();
|
MovieData tempMovieData = MovieData();
|
||||||
std::ios::pos_type curr = is->tellg();
|
int curr = fp->ftell();
|
||||||
if(!LoadFM2(tempMovieData, is, size, false)) {
|
if(!LoadFM2(tempMovieData, fp, size, false)) {
|
||||||
|
|
||||||
// is->seekg((uint32)curr+size);
|
// is->seekg((uint32)curr+size);
|
||||||
/* extern bool FCEU_state_loading_old_format;
|
/* extern bool FCEU_state_loading_old_format;
|
||||||
|
@ -897,7 +901,7 @@ bool mov_loadstate(std::istream* is, int size)
|
||||||
currMovieData.rerecordCount = currRerecordCount;
|
currMovieData.rerecordCount = currRerecordCount;
|
||||||
|
|
||||||
openRecordingMovie(curMovieFilename);
|
openRecordingMovie(curMovieFilename);
|
||||||
if(!osRecordingMovie->is_open())
|
if(!osRecordingMovie->get_fp())
|
||||||
{
|
{
|
||||||
osd->setLineColor(255, 0, 0);
|
osd->setLineColor(255, 0, 0);
|
||||||
osd->addLine("Can't save movie file!");
|
osd->addLine("Can't save movie file!");
|
||||||
|
@ -954,27 +958,27 @@ bool FCEUI_MovieGetInfo(std::istream* fp, MOVIE_INFO& info, bool skipFrameCount)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MovieRecord::parseBinary(MovieData* md, std::istream* is)
|
bool MovieRecord::parseBinary(MovieData* md, EMUFILE* fp)
|
||||||
{
|
{
|
||||||
commands=is->get();
|
commands=fp->fgetc();
|
||||||
is->read((char *) &pad, sizeof pad);
|
fp->fread((char *) &pad, sizeof pad,1);
|
||||||
is->read((char *) &touch.x, sizeof touch.x);
|
fp->fread((char *) &touch.x, sizeof touch.x,1);
|
||||||
is->read((char *) &touch.y, sizeof touch.y);
|
fp->fread((char *) &touch.y, sizeof touch.y,1);
|
||||||
is->read((char *) &touch.touch, sizeof touch.touch);
|
fp->fread((char *) &touch.touch, sizeof touch.touch,1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MovieRecord::dumpBinary(MovieData* md, std::ostream* os, int index)
|
void MovieRecord::dumpBinary(MovieData* md, EMUFILE* fp, int index)
|
||||||
{
|
{
|
||||||
os->put(md->records[index].commands);
|
fp->fputc(md->records[index].commands);
|
||||||
os->write((char *) &md->records[index].pad, sizeof md->records[index].pad);
|
fp->fwrite((char *) &md->records[index].pad, sizeof md->records[index].pad,1);
|
||||||
os->write((char *) &md->records[index].touch.x, sizeof md->records[index].touch.x);
|
fp->fwrite((char *) &md->records[index].touch.x, sizeof md->records[index].touch.x,1);
|
||||||
os->write((char *) &md->records[index].touch.y, sizeof md->records[index].touch.y);
|
fp->fwrite((char *) &md->records[index].touch.y, sizeof md->records[index].touch.y,1);
|
||||||
os->write((char *) &md->records[index].touch.touch, sizeof md->records[index].touch.touch);
|
fp->fwrite((char *) &md->records[index].touch.touch, sizeof md->records[index].touch.touch,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadFM2_binarychunk(MovieData& movieData, std::istream* fp, int size)
|
void LoadFM2_binarychunk(MovieData& movieData, EMUFILE* fp, int size)
|
||||||
{
|
{
|
||||||
int recordsize = 1; //1 for the command
|
int recordsize = 1; //1 for the command
|
||||||
|
|
||||||
|
@ -983,11 +987,11 @@ void LoadFM2_binarychunk(MovieData& movieData, std::istream* fp, int size)
|
||||||
assert(size%6==0);
|
assert(size%6==0);
|
||||||
|
|
||||||
//find out how much remains in the file
|
//find out how much remains in the file
|
||||||
int curr = fp->tellg();
|
int curr = fp->ftell();
|
||||||
fp->seekg(0,std::ios::end);
|
fp->fseek(0,SEEK_END);
|
||||||
int end = fp->tellg();
|
int end = fp->ftell();
|
||||||
int flen = end-curr;
|
int flen = end-curr;
|
||||||
fp->seekg(curr,std::ios::beg);
|
fp->fseek(curr,SEEK_SET);
|
||||||
|
|
||||||
//the amount todo is the min of the limiting size we received and the remaining contents of the file
|
//the amount todo is the min of the limiting size we received and the remaining contents of the file
|
||||||
int todo = std::min(size, flen);
|
int todo = std::min(size, flen);
|
||||||
|
@ -1012,17 +1016,16 @@ static bool CheckFileExists(const char* filename)
|
||||||
checkFilename = filename;
|
checkFilename = filename;
|
||||||
|
|
||||||
//Check if this filename exists
|
//Check if this filename exists
|
||||||
fstream test;
|
FILE* fp = fopen(checkFilename.c_str(), "rb");
|
||||||
test.open(checkFilename.c_str(),fstream::in);
|
|
||||||
|
|
||||||
if (test.fail())
|
if (!fp)
|
||||||
{
|
{
|
||||||
test.close();
|
fclose(fp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
test.close();
|
fclose(fp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1073,9 +1076,9 @@ void FCEUI_MakeBackupMovie(bool dispMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
MovieData md = currMovieData; //Get current movie data
|
MovieData md = currMovieData; //Get current movie data
|
||||||
std::fstream* outf = new fstream(backupFn.c_str(),std::ios_base::out); //FCEUD_UTF8_fstream(backupFn, "wb"); //open/create file
|
EMUFILE* outf = new EMUFILE(backupFn.c_str(),"wb"); //FCEUD_UTF8_fstream(backupFn, "wb"); //open/create file
|
||||||
md.dump(outf,false); //dump movie data
|
md.dump(outf,false); //dump movie data
|
||||||
delete outf; //clean up, delete file object
|
// delete outf; //clean up, delete file object
|
||||||
|
|
||||||
//TODO, decide if fstream successfully opened the file and print error message if it doesn't
|
//TODO, decide if fstream successfully opened the file and print error message if it doesn't
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "emufile.h"
|
||||||
|
|
||||||
#include "utils/guid.h"
|
#include "utils/guid.h"
|
||||||
#include "utils/md5.h"
|
#include "utils/md5.h"
|
||||||
|
@ -93,12 +92,12 @@ public:
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void parse(MovieData* md, std::istream* is);
|
void parse(MovieData* md, EMUFILE* fp);
|
||||||
bool parseBinary(MovieData* md, std::istream* is);
|
bool parseBinary(MovieData* md, EMUFILE* fp);
|
||||||
void dump(MovieData* md, std::ostream* os, int index);
|
void dump(MovieData* md, EMUFILE* fp, int index);
|
||||||
void dumpBinary(MovieData* md, std::ostream* os, int index);
|
void dumpBinary(MovieData* md, EMUFILE* fp, int index);
|
||||||
void parsePad(std::istream* is, u16& pad);
|
void parsePad(EMUFILE* fp, u16& pad);
|
||||||
void dumpPad(std::ostream* os, u16 pad);
|
void dumpPad(EMUFILE* fp, u16 pad);
|
||||||
|
|
||||||
static const char mnemonics[13];
|
static const char mnemonics[13];
|
||||||
|
|
||||||
|
@ -163,7 +162,7 @@ public:
|
||||||
|
|
||||||
void truncateAt(int frame);
|
void truncateAt(int frame);
|
||||||
void installValue(std::string& key, std::string& val);
|
void installValue(std::string& key, std::string& val);
|
||||||
int dump(std::ostream* os, bool binary);
|
int dump(EMUFILE* fp, bool binary);
|
||||||
void clearRecordRange(int start, int len);
|
void clearRecordRange(int start, int len);
|
||||||
void insertEmpty(int at, int frames);
|
void insertEmpty(int at, int frames);
|
||||||
|
|
||||||
|
@ -192,17 +191,17 @@ extern MovieData currMovieData; //adelikat: main needs this for frame counter d
|
||||||
|
|
||||||
extern bool movie_reset_command;
|
extern bool movie_reset_command;
|
||||||
|
|
||||||
bool FCEUI_MovieGetInfo(std::istream* fp, MOVIE_INFO& info, bool skipFrameCount);
|
bool FCEUI_MovieGetInfo(EMUFILE* fp, MOVIE_INFO& info, bool skipFrameCount);
|
||||||
void _CDECL_ FCEUI_SaveMovie(const char *fname, std::wstring author, int flag, std::string sramfname);
|
void _CDECL_ FCEUI_SaveMovie(const char *fname, std::wstring author, int flag, std::string sramfname);
|
||||||
const char* _CDECL_ FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _pauseframe); // returns NULL on success, errmsg on failure
|
const char* _CDECL_ FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _pauseframe); // returns NULL on success, errmsg on failure
|
||||||
void FCEUI_StopMovie();
|
void FCEUI_StopMovie();
|
||||||
void FCEUMOV_AddInputState();
|
void FCEUMOV_AddInputState();
|
||||||
void FCEUMOV_HandlePlayback();
|
void FCEUMOV_HandlePlayback();
|
||||||
void FCEUMOV_HandleRecording();
|
void FCEUMOV_HandleRecording();
|
||||||
void mov_savestate(std::ostream* os);
|
void mov_savestate(EMUFILE* fp);
|
||||||
bool mov_loadstate(std::istream* is, int size);
|
bool mov_loadstate(EMUFILE* fp, int size);
|
||||||
void LoadFM2_binarychunk(MovieData& movieData, std::istream* fp, int size);
|
void LoadFM2_binarychunk(MovieData& movieData, EMUFILE* fp, int size);
|
||||||
bool LoadFM2(MovieData& movieData, std::istream* fp, int size, bool stopAfterHeader);
|
bool LoadFM2(MovieData& movieData, EMUFILE* fp, int size, bool stopAfterHeader);
|
||||||
extern bool movie_readonly;
|
extern bool movie_readonly;
|
||||||
extern bool ShowInputDisplay;
|
extern bool ShowInputDisplay;
|
||||||
void FCEUI_MakeBackupMovie(bool dispMessage);
|
void FCEUI_MakeBackupMovie(bool dispMessage);
|
||||||
|
|
|
@ -98,9 +98,9 @@ static char playfilename[MAX_PATH] = "";
|
||||||
|
|
||||||
void Describe(HWND hwndDlg)
|
void Describe(HWND hwndDlg)
|
||||||
{
|
{
|
||||||
std::fstream fs (playfilename, std::ios_base::in);
|
EMUFILE* fp = new EMUFILE(playfilename,"rb");
|
||||||
MovieData md;
|
MovieData md;
|
||||||
LoadFM2(md, &fs, INT_MAX, false);
|
LoadFM2(md, fp, INT_MAX, false);
|
||||||
fs.close();
|
fs.close();
|
||||||
|
|
||||||
u32 num_frames = md.records.size();
|
u32 num_frames = md.records.size();
|
||||||
|
|
Loading…
Reference in New Issue