From a91d2c414ee57910fb8173822e224c08c053c71b Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 22 Jun 2008 22:25:30 +0000 Subject: [PATCH] better movie conversion --- src/drivers/win/res.rc | 3 +- src/drivers/win/window.cpp | 20 ++++++++++-- src/movie.cpp | 3 ++ src/movie.h | 1 + src/oldmovie.cpp | 66 +++++++++++++++++++++----------------- src/oldmovie.h | 14 ++++++++ src/utils/xstring.cpp | 13 ++++++++ src/utils/xstring.h | 2 ++ 8 files changed, 89 insertions(+), 33 deletions(-) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 5deef8fe..29605c07 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -49,7 +49,6 @@ BEGIN MENUITEM "Record Movie...", MENU_RECORD_MOVIE MENUITEM "Replay Movie...", MENU_REPLAY_MOVIE MENUITEM "Stop Movie", MENU_STOP_MOVIE - MENUITEM "Convert FCM...", MENU_CONVERT_MOVIE MENUITEM SEPARATOR MENUITEM "Record AVI...", MENU_RECORD_AVI MENUITEM "Stop AVI", MENU_STOP_AVI @@ -132,6 +131,8 @@ BEGIN MENUITEM "&Alternate A and B", MENU_ALTERNATE_AB MENUITEM SEPARATOR MENUITEM "Use &External Input", MENU_EXTERNAL_INPUT + MENUITEM SEPARATOR + MENUITEM "Convert FCM...", MENU_CONVERT_MOVIE END POPUP "&Debug" BEGIN diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 694cef71..d8aa9f3f 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -29,8 +29,8 @@ #include "wave.h" #include "input.h" #include "video.h" -#include "../../input.h" -#include "../../fceu.h" +#include "input.h" +#include "fceu.h" #include "memwatch.h" #include "ppuview.h" @@ -55,6 +55,7 @@ #include "gui.h" #include "help.h" #include "movie.h" +#include "utils/xstring.h" #include @@ -133,6 +134,7 @@ static void ConvertFCM(HWND hwndOwner) { std::vector todo; + //build a list of movies to convert. this might be one, or it might be many, depending on what the user selected if(ofn.nFileExtension==0) { //multiselect @@ -150,17 +152,29 @@ static void ConvertFCM(HWND hwndOwner) todo.push_back(ofn.lpstrFile); } + SetCursor(LoadCursor(0,IDC_WAIT)); + + //convert each movie + int okcount = 0; for(uint32 i=0;i savestate; std::vector records; + std::vector comments; //this is the RERECORD COUNT. please rename variable. int rerecordCount; FCEU_Guid guid; diff --git a/src/oldmovie.cpp b/src/oldmovie.cpp index a9db0c24..f55959c4 100644 --- a/src/oldmovie.cpp +++ b/src/oldmovie.cpp @@ -1,9 +1,11 @@ #include "types.h" #include "fceu.h" #include "driver.h" +#include "netplay.h" #include "oldmovie.h" #include "movie.h" +#include "utils/xstring.h" #include @@ -42,6 +44,7 @@ using namespace std; //------- static uint8 joop[4]; +static uint8 joopcmd; static uint32 framets = 0; static uint32 frameptr = 0; static uint8* moviedata = NULL; @@ -54,8 +57,6 @@ static uint32 nextts = 0; static int32 nextd = 0; -static int movieConvertOffset1=0, movieConvertOffset2=0,movieSyncHackOn=0; - //backwards compat static void FCEUI_LoadMovie_v1(char *fname, int _read_only); @@ -442,7 +443,7 @@ static int movie_readchar() } -static void FCEUMOV_AddJoy() +static void _addjoy() { while(nextts == framets || nextd == -1) { @@ -453,8 +454,10 @@ static void FCEUMOV_AddJoy() { if(nextd&0x80) { - //puts("Egads"); //FCEU_DoSimpleCommand(nextd&0x1F); + int command = nextd&0x1F; + if(command = FCEUNPCMD_RESET) + joopcmd = MOVIECMD_RESET; } else joop[(nextd >> 3)&0x3] ^= 1 << (nextd&0x7); @@ -500,6 +503,7 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname) uint32 framecount; uint32 rerecord_count; + int movieConvertOffset1=0, movieConvertOffset2=0,movieSyncHackOn=0; ifstream* fp = (ifstream*)FCEUD_UTF8_fstream(fname, "rb"); @@ -543,35 +547,35 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname) read32le(&savestate_offset, fp); read32le(&firstframeoffset, fp); + //read header values + fp->read((char*)&md.romChecksum,16); + read32le((uint32*)&md.emuVersion,fp); + + md.romFilename = readNullTerminatedAscii(fp); + md.comments.push_back("author " + readNullTerminatedAscii(fp)); + // FCEU_PrintError("flags[0] & MOVIE_FLAG_NOSYNCHACK=%d",flags[0] & MOVIE_FLAG_NOSYNCHACK); if(flags[0] & MOVIE_FLAG_NOSYNCHACK) movieSyncHackOn=0; else movieSyncHackOn=1; - //if(flags[0] & MOVIE_FLAG_PAL) - //if(flags[0] & MOVIE_FLAG_FROM_POWERON) - //{ - // //don't need to load a savestate - // //there shouldn't be a savestate! - // if(savestate_offset != 0xFFFFFFFF) - // FCEU_PrintError("Savestate found in a start-from-poweron movie!"); - //} - //else - //{ - // if(savestate_offset == 0xFFFFFFFF) - // FCEU_PrintError("No savestate found in a start-from-savestate movie!"); - - // if(fseek(fp, savestate_offset, SEEK_SET)) - // { - // fclose(fp); - // return; - // } - - // if(!FCEUSS_LoadFP(fp,SSLOADPARAM_BACKUP)) - // return; - //} + if(flags[0] & MOVIE_FLAG_PAL) + md.palFlag = true; + bool initreset = false; + if(flags[0] & MOVIE_FLAG_FROM_POWERON) + { + //don't need to load a savestate + } + else if(flags[0] & MOVIE_FLAG_FROM_RESET) + { + initreset = true; + } + else + { + return FCM_CONVERTRESULT_STARTFROMSAVESTATENOTSUPPORTED; + } //analyze input types? //ResetInputTypes(); @@ -589,6 +593,7 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname) //prepare output structure md.rerecordCount = rerecord_count; md.records.resize(framecount); + md.guid.newGuid(); //begin decoding. //joymask is used to look for any joystick that has input. @@ -596,8 +601,11 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname) uint8 joymask[4] = {0,0,0,0}; for(uint32 i=0;iget(); + if(c == 0) break; + else ret += (char)c; + } + return ret; +} \ No newline at end of file diff --git a/src/utils/xstring.h b/src/utils/xstring.h index 58442604..19563cef 100644 --- a/src/utils/xstring.h +++ b/src/utils/xstring.h @@ -57,6 +57,8 @@ char *U16ToHexStr(uint16 a); std::string stditoa(int n); +std::string readNullTerminatedAscii(std::istream* is); + //extracts a decimal uint from an istream template T templateIntegerDecFromIstream(std::istream* is) {