From 5ad6e0b6023923938bf44f7b094683a248149030 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Sun, 5 Jun 2011 02:50:50 +0000 Subject: [PATCH] Begin Convert FCM tool. Reads most header stuff, no input log yet. Only hooked up to Drag & Drop atm --- BizHawk.MultiClient/MainForm.cs | 4 + BizHawk.MultiClient/movie/MovieConvert.cs | 125 ++++++++++++++++++++-- 2 files changed, 118 insertions(+), 11 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index ccf43a5500..0f710b382d 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -554,6 +554,10 @@ namespace BizHawk.MultiClient RamWatch1.LoadWatchFile(filePaths[0], false); RamWatch1.DisplayWatchList(); } + else if (Path.GetExtension(filePaths[0]).ToUpper() == ".FCM") + { + UserMovie = MovieConvert.ConvertFCM(filePaths[0]); + } else LoadRom(filePaths[0]); } diff --git a/BizHawk.MultiClient/movie/MovieConvert.cs b/BizHawk.MultiClient/movie/MovieConvert.cs index cda25a13df..43ab8c9eca 100644 --- a/BizHawk.MultiClient/movie/MovieConvert.cs +++ b/BizHawk.MultiClient/movie/MovieConvert.cs @@ -2,39 +2,142 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.IO; -namespace BizHawk.MultiClient.movie +namespace BizHawk.MultiClient { public static class MovieConvert { - public static void ConvertFCM(string path) + public static Movie ConvertFCM(string path) { + Movie m = new Movie(Path.ChangeExtension(path, ".tas"), MOVIEMODE.PLAY); + + FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); + BinaryReader r = new BinaryReader(fs); + //TODO: if fail to open...do some kind of error + UInt32 magic = r.ReadUInt32(); + + UInt32 version = r.ReadUInt32(); + m.SetHeaderLine(MovieHeader.MovieVersion, "FCEU movie version " + version.ToString() + " (.fcm)"); + + byte[] flags = new byte[4]; + for (int x = 0; x < 4; x++) + flags[x] = r.ReadByte(); + + UInt32 length = r.ReadUInt32(); + + UInt32 rerecords = r.ReadUInt32(); + m.SetHeaderLine(MovieHeader.RERECORDS, rerecords.ToString()); + + UInt32 movieDataSize = r.ReadUInt32(); + UInt32 savestateOffset = r.ReadUInt32(); + UInt32 firstFrameOffset = r.ReadUInt32(); + + //TODO: ROM checksum movie header line + byte[] romCheckSum = r.ReadBytes(16); + + UInt32 EmuVersion = r.ReadUInt32(); + m.SetHeaderLine(MovieHeader.EMULATIONVERSION, "FCEU " + EmuVersion.ToString()); + + //rom Filename + + + + List romBytes = new List(); + while (true) + { + if (r.PeekChar() == 0) + break; + else + romBytes.Add(r.ReadByte()); + } + string rom = System.Text.Encoding.UTF8.GetString(romBytes.ToArray()); + m.SetHeaderLine(MovieHeader.GAMENAME, rom); + + r.ReadByte(); //Advance past null byte + + List authorBytes = new List(); + while (true) + { + if (r.PeekChar() == 0) + break; + else + authorBytes.Add(r.ReadByte()); + } + string author = System.Text.Encoding.UTF8.GetString(authorBytes.ToArray()); + m.SetHeaderLine(MovieHeader.AUTHOR, author); + + r.ReadByte(); //Advance past null byte + + int xx = 0; + + //synchack + //flags[0] & 16 + + //pal + //flags[0] & 4 + + //Power on vs reset + //flags[0] & 8 = power on + + + //flags[0] & 2 = reset + + + //else starts from savestate so freak out, this isn't supported + + + //moviedatasize stuff + + //read frame data + byte joopcmd = 0; + for (int x = 0; x < length; x++) + { + joopcmd = 0; + //Check for reset or power-on on first frame + + } + + + //set 4 score flag if necessary + + return m; } - public static void ConvertMMV(string path) + public static string ConvertMMV(string path) { - + string converted = Path.ChangeExtension(path, ".tas"); + + return converted; } - public static void ConvertMCM(string path) + public static string ConvertMCM(string path) { + string converted = Path.ChangeExtension(path, ".tas"); + return converted; } - public static void ConvertSMV(string path) + public static string ConvertSMV(string path) { - + string converted = Path.ChangeExtension(path, ".tas"); + + return converted; } - public static void ConvertGMV(string path) + public static string ConvertGMV(string path) { - + string converted = Path.ChangeExtension(path, ".tas"); + + return converted; } - public static void ConvertVBM(string path) + public static string ConvertVBM(string path) { - + string converted = Path.ChangeExtension(path, ".tas"); + + return converted; } } }