diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 38dcd858..9f9802d9 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -1238,17 +1238,17 @@ std::fstream* FCEUD_UTF8_fstream(const char *n, const char *m) } std::ios_base::openmode mode = std::ios_base::binary; - if(!strcmp(m,"r")) + if(!strcmp(m,"r") || !strcmp(m,"rb")) mode |= std::ios_base::in; - else if(!strcmp(m,"w")) + else if(!strcmp(m,"w") || !strcmp(m,"wb")) mode |= std::ios_base::out | std::ios_base::trunc; - else if(!strcmp(m,"a")) + else if(!strcmp(m,"a") || !strcmp(m,"ab")) mode |= std::ios_base::out | std::ios_base::app; - else if(!strcmp(m,"r+")) + else if(!strcmp(m,"r+") || !strcmp(m,"r+b")) mode |= std::ios_base::in | std::ios_base::out; - else if(!strcmp(m,"w+")) + else if(!strcmp(m,"w+") || !strcmp(m,"w+b")) mode |= std::ios_base::in | std::ios_base::out | std::ios_base::trunc; - else if(!strcmp(m,"a+")) + else if(!strcmp(m,"a+") || !strcmp(m,"a+b")) mode |= std::ios_base::in | std::ios_base::out | std::ios_base::app; return new std::fstream(n,mode); diff --git a/src/drivers/win/tasedit.cpp b/src/drivers/win/tasedit.cpp index a1b9e4ed..88d24abf 100644 --- a/src/drivers/win/tasedit.cpp +++ b/src/drivers/win/tasedit.cpp @@ -7,6 +7,8 @@ #include "../../movie.h" #include "../../utils/xstring.h" +using namespace std; + //to change header font //http://forums.devx.com/archive/index.php/t-37234.html @@ -306,9 +308,10 @@ static void Export() ofn.lpstrInitialDir=FCEU_GetPath(FCEUMKF_MOVIE); if(GetSaveFileName(&ofn)) { - FILE* outf = fopen(ofn.lpstrFile,"wb"); - currMovieData.dump(outf); - fclose(outf); + fstream* osRecordingMovie = FCEUD_UTF8_fstream(ofn.lpstrFile, "wb"); + currMovieData.dump(osRecordingMovie); + osRecordingMovie->close(); + delete osRecordingMovie; } } diff --git a/src/input.cpp b/src/input.cpp index 785922ad..83f46bdf 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -30,6 +30,7 @@ #include "netplay.h" #include "movie.h" #include "state.h" +#include "input/zapper.h" #include "input.h" #include "vsuni.h" @@ -286,7 +287,7 @@ void FCEU_UpdateInput(void) if(FCEUnetplay) NetplayUpdate(joy); - FCEUMOV_AddJoy(joy, BotMode); + FCEUMOV_AddInputState(ZD, joy, BotMode); if(GameInfo->type==GIT_VSUNI) FCEU_VSUniSwap(&joy[0],&joy[1]); diff --git a/src/input/zapper.cpp b/src/input/zapper.cpp index 2a49b4a9..b3928183 100644 --- a/src/input/zapper.cpp +++ b/src/input/zapper.cpp @@ -18,20 +18,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include +#include +#include -#include "share.h" +#include "share.h" +#include "zapper.h" -typedef struct { - uint32 mzx,mzy,mzb; - int zap_readbit; - int bogo; - int zappo; - uint64 zaphit; -} ZAPPER; - -static ZAPPER ZD[2]; +ZAPPER ZD[2]; static void ZapperFrapper(int w, uint8 *bg, uint8 *spr, uint32 linets, int final) { diff --git a/src/input/zapper.h b/src/input/zapper.h new file mode 100644 index 00000000..7fda3c89 --- /dev/null +++ b/src/input/zapper.h @@ -0,0 +1,15 @@ +#ifndef _ZAPPER_H_ +#define _ZAPPER_H_ + +struct ZAPPER +{ + uint32 mzx,mzy,mzb; + int zap_readbit; + int bogo; + int zappo; + uint64 zaphit; +}; + +extern ZAPPER ZD[2]; + +#endif \ No newline at end of file diff --git a/src/movie.cpp b/src/movie.cpp index 1f36a72c..907c3ddf 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef WIN32 #include @@ -51,7 +52,8 @@ bool suppressMovieStop=false; EMOVIEMODE movieMode = MOVIEMODE_INACTIVE; //this should not be set unless we are in MOVIEMODE_RECORD! -FILE* fpRecordingMovie = 0; +//FILE* fpRecordingMovie = 0; +fstream* osRecordingMovie = 0; int currFrameCounter; uint32 cur_input_display = 0; @@ -120,49 +122,17 @@ void MovieRecord::dump(std::ostream* os, int index) } //separate the joysticks - if(i != 3) os->put('|'); + os->put('|'); } + //write the zapper state + *os << setw(3) << setfill('0') << (int)zappers[0].x << ' ' << setw(3) << setfill('0') << (int)zappers[0].y << setw(1) << ' ' << (int)zappers[0].b << '|'; + *os << setw(3) << setfill('0') << (int)zappers[1].x << ' ' << setw(3) << setfill('0') << (int)zappers[1].y << setw(1) << ' ' << (int)zappers[1].b; + //each frame is on a new line os->put('\n'); } -void MovieRecord::dump(FILE* fp, int index) -{ - //todo: if we want frame numbers in the output (which we dont since we couldnt cut and paste in movies) - //but someone would need to change the parser to ignore it - //fputc('|',fp); - //fprintf(fp,"%08d",index); - - fputc('|',fp); - - //for each joystick - for(int i=0;i<4;i++) - { - //these are mnemonics for each joystick bit. - //since we usually use the regular joypad, these will be more helpful. - //but any character other than ' ' should count as a set bit - //maybe other input types will need to be encoded another way.. - for(int bit=7;bit>=0;bit--) - { - uint8 &joystate = joysticks[i]; - int bitmask = (1<cspecial; - gametype=GameInfo->type; - - InitOtherInput(); -#endif +//#ifdef WIN32 +// extern int UsrInputType[3]; +// UsrInputType[0] = SI_GAMEPAD; +// UsrInputType[1] = SI_GAMEPAD; +// UsrInputType[2] = SIFC_NONE; +// +// ParseGIInput(NULL/*GameInfo*/); +// extern int cspec, gametype; +// cspec=GameInfo->cspecial; +// gametype=GameInfo->type; +// +// InitOtherInput(); +//#endif } @@ -565,14 +533,23 @@ void FCEUI_LoadMovie(char *fname, bool _read_only, int _pauseframe) static void closeRecordingMovie() { - if(fpRecordingMovie) - fclose(fpRecordingMovie); + //if(fpRecordingMovie) + // fclose(fpRecordingMovie); + if(osRecordingMovie) + { + osRecordingMovie->close(); + delete osRecordingMovie; + } } static void openRecordingMovie(const char* fname) { - fpRecordingMovie = FCEUD_UTF8fopen(fname, "wb"); - if(!fpRecordingMovie) + //fpRecordingMovie = FCEUD_UTF8fopen(fname, "wb"); + //if(!fpRecordingMovie) + // FCEU_PrintError("Error opening movie output file: %s",fname); + + osRecordingMovie = FCEUD_UTF8_fstream(fname, "wb"); + if(!osRecordingMovie) FCEU_PrintError("Error opening movie output file: %s",fname); strcpy(curMovieFilename, fname); } @@ -611,7 +588,7 @@ void FCEUI_SaveMovie(char *fname, uint8 flags) } //we are going to go ahead and dump the header. from now on we will only be appending frames - currMovieData.dump(fpRecordingMovie); + currMovieData.dump(osRecordingMovie); //todo - think about this ResetInputTypes(); @@ -631,7 +608,7 @@ void FCEUI_SaveMovie(char *fname, uint8 flags) //the main interaction point between the emulator and the movie system. //either dumps the current joystick state or loads one state from the movie -void FCEUMOV_AddJoy(uint8 *js, int SkipFlush) +void FCEUMOV_AddInputState(ZAPPER (&zappers)[2], uint8 (&js)[4], int SkipFlush) { //todo - for tasedit, either dump or load depending on whether input recording is enabled //or something like that @@ -650,6 +627,13 @@ void FCEUMOV_AddJoy(uint8 *js, int SkipFlush) MovieRecord& mr = currMovieData.records[currFrameCounter]; for(int i=0;i<4;i++) js[i] = mr.joysticks[i]; + + for(int i=0;i<2;i++) + { + zappers[i].mzx = mr.zappers[i].x; + zappers[i].mzy = mr.zappers[i].y; + zappers[i].mzb = mr.zappers[i].b; + } } //if we are on the last frame, then pause the emulator if the player requested it @@ -677,7 +661,16 @@ void FCEUMOV_AddJoy(uint8 *js, int SkipFlush) for(int i=0;i<4;i++) mr.joysticks[i] = js[i]; - mr.dump(fpRecordingMovie,currMovieData.records.size()); + //printf("%d %d %d\n",zappers[1].mzx,zappers[1].mzy,zappers[1].mzb); + + for(int i=0;i<2;i++) + { + mr.zappers[i].x = zappers[i].mzx; + mr.zappers[i].y = zappers[i].mzy; + mr.zappers[i].b = zappers[i].mzb; + } + + mr.dump(osRecordingMovie,currMovieData.records.size()); currMovieData.records.push_back(mr); } @@ -730,22 +723,6 @@ int FCEUMOV_WriteState(std::ostream* os) else return 0; } -int FCEUMOV_WriteState(FILE* st) -{ - //we are supposed to dump the movie data into the savestate - - if(movieMode == MOVIEMODE_RECORD || movieMode == MOVIEMODE_PLAY) - { - int todo = currMovieData.dumpLen(); - - if(st) - currMovieData.dump(st); - - return todo; - } - else return 0; -} - static bool load_successful; bool FCEUMOV_ReadState(FILE* st, uint32 size) @@ -816,7 +793,7 @@ bool FCEUMOV_ReadState(FILE* st, uint32 size) currMovieData.recordCount++; openRecordingMovie(curMovieFilename); - currMovieData.dump(fpRecordingMovie); + currMovieData.dump(osRecordingMovie); movieMode = MOVIEMODE_RECORD; } } diff --git a/src/movie.h b/src/movie.h index 25784744..e6f69319 100644 --- a/src/movie.h +++ b/src/movie.h @@ -6,7 +6,9 @@ #include #include -void FCEUMOV_AddJoy(uint8 *, int SkipFlush); +#include "input/zapper.h" + +void FCEUMOV_AddInputState(ZAPPER (&zappers)[2], uint8 (&js)[4], int SkipFlush); void FCEUMOV_AddCommand(int cmd); void FCEU_DrawMovies(uint8 *); @@ -25,7 +27,7 @@ bool FCEUMOV_Mode(int modemask); bool FCEUMOV_ShouldPause(void); int FCEUMOV_GetFrame(void); -int FCEUMOV_WriteState(FILE* st); +//int FCEUMOV_WriteState(FILE* st); int FCEUMOV_WriteState(std::ostream* os); bool FCEUMOV_ReadState(FILE* st, uint32 size); void FCEUMOV_PreLoad(); @@ -39,6 +41,10 @@ class MovieRecord { public: ValueArray joysticks; + + struct { + uint8 x,y,b; + } zappers[2]; void toggleBit(int joy, int bit) { @@ -73,7 +79,6 @@ public: //a waste of memory in lots of cases.. maybe make it a pointer later? std::vector savestate; - void dump(FILE* fp, int index); void dump(std::ostream* os, int index); static const char mnemonics[8]; @@ -138,7 +143,6 @@ public: void truncateAt(int frame); void installDictionary(TDictionary& dictionary); - void dump(FILE *fp); void dump(std::ostream* os); int dumpLen(); void clearRecordRange(int start, int len);