当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadStringFixedAscii方法代码示例

本文整理汇总了C#中System.IO.BinaryReader.ReadStringFixedAscii方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadStringFixedAscii方法的具体用法?C# BinaryReader.ReadStringFixedAscii怎么用?C# BinaryReader.ReadStringFixedAscii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadStringFixedAscii方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WrapByteArray

		public void WrapByteArray(byte[] data)
		{
			NSFData = data;

			var ms = new MemoryStream(data);
			var br = new BinaryReader(ms);
			br.BaseStream.Position += 5;
			
			Version = br.ReadByte();
			TotalSongs = br.ReadByte();
			StartingSong = br.ReadByte();
			LoadAddress = br.ReadUInt16();
			InitAddress = br.ReadUInt16();
			PlayAddress = br.ReadUInt16();
			SongName = br.ReadStringFixedAscii(32);
			ArtistName = br.ReadStringFixedAscii(32);
			CopyrightHolder = br.ReadStringFixedAscii(32);
			SpeedNTSC = br.ReadUInt16();
			br.Read(BankswitchInitValues, 0, 8);
			SpeedPAL = br.ReadUInt16();
			byte temp = br.ReadByte();
			if ((temp & 2) != 0) IsNTSC = IsPAL = true;
			else if ((temp & 1) != 0) IsPAL = true; else IsNTSC = true;
			ExtraChips = (eExtraChips)br.ReadByte();
		}
开发者ID:CadeLaRen,项目名称:BizHawk,代码行数:25,代码来源:NSFFormat.cs

示例2: Load

		public bool Load(string fpPSF, Func<Stream,int,byte[]> cbDeflater)
		{
			using(var fs = File.OpenRead(fpPSF))
			{
				//not endian safe
				var br = new BinaryReader(fs);
				var sig = br.ReadStringFixedAscii(4);
				if (sig != "PSF\x1")
					return false;

				int reserved_size = br.ReadInt32();
				int compressed_size = br.ReadInt32();
				int compressed_crc32 = br.ReadInt32();
				
				//load tags
				//tags run until the end of the file
				fs.Position = 16 + reserved_size + compressed_size;
				if (fs.Position + 5 > fs.Length)
				{
					//theres no space for tags, probably just no tags in the file
				}
				else
				{
					if (br.ReadStringFixedAscii(5) == "[TAG]")
					{
						var tagstring = br.ReadStringFixedAscii((int)(fs.Length - fs.Position)).Replace("\r\n", "\n");
						foreach (var tag in tagstring.Split('\n', '\x0'))
						{
							if (tag.Trim() == "")
								continue;
							int eq = tag.IndexOf('=');
							if (eq != -1)
								TagsDictionary[tag.Substring(0, eq)] = tag.Substring(eq + 1);
							else
								LooseTags.Add(tag);
						}
					}
				}

				//load compressed section buffer
				fs.Position = 16 + reserved_size;
				Data = cbDeflater(fs, compressed_size);

				//load lib if needed
				if (TagsDictionary.ContainsKey("_lib"))
				{
					var fpLib = Path.Combine(Path.GetDirectoryName(fpPSF), TagsDictionary["_lib"]);
					if (!File.Exists(fpLib))
						return false;
					PSF lib = new PSF();
					if (!lib.Load(fpLib,cbDeflater))
						return false;
					LibData = lib.Data;
				}
			}

			return true;
		}
开发者ID:CadeLaRen,项目名称:BizHawk,代码行数:58,代码来源:PSF.cs

示例3: Run

		public void Run()
		{
			using (var fs = File.OpenRead(IN_Path))
			{
				BinaryReader br = new BinaryReader(fs);
				string sig = br.ReadStringFixedAscii(4);
				if (sig != "SBI\0")
					throw new SBIParseException("Missing magic number");

				SubQPatchData ret = new SubQPatchData();
				List<short> bytes = new List<short>();

				//read records until done
				for (; ; )
				{
					//graceful end
					if (fs.Position == fs.Length)
						break;

					if (fs.Position + 4 > fs.Length) throw new SBIParseException("Broken record");
					var m = BCD2.BCDToInt(br.ReadByte());
					var s = BCD2.BCDToInt(br.ReadByte());
					var f = BCD2.BCDToInt(br.ReadByte());
					var ts = new Timestamp(m, s, f);
					ret.ABAs.Add(ts.Sector);
					int type = br.ReadByte();
					switch (type)
					{
						case 1: //Q0..Q9
							if (fs.Position + 10 > fs.Length) throw new SBIParseException("Broken record");
							for (int i = 0; i <= 9; i++) bytes.Add(br.ReadByte());
							for (int i = 10; i <= 11; i++) bytes.Add(-1);
							break;
						case 2: //Q3..Q5
							if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
							for (int i = 0; i <= 2; i++) bytes.Add(-1);
							for (int i = 3; i <= 5; i++) bytes.Add(br.ReadByte());
							for (int i = 6; i <= 11; i++) bytes.Add(-1);
							break;
						case 3: //Q7..Q9
							if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
							for (int i = 0; i <= 6; i++) bytes.Add(-1);
							for (int i = 7; i <= 9; i++) bytes.Add(br.ReadByte());
							for (int i = 10; i <= 11; i++) bytes.Add(-1);
							break;
						default:
							throw new SBIParseException("Broken record");
					}
				}

				ret.subq = bytes.ToArray();

				OUT_Data = ret;
			}
		}
开发者ID:CadeLaRen,项目名称:BizHawk,代码行数:55,代码来源:LoadSBIJob.cs

示例4: QuickCheckISSBI

		/// <summary>
		/// Does a cursory check to see if the file looks like an SBI
		/// </summary>
		public static bool QuickCheckISSBI(string path)
		{
			using (var fs = File.OpenRead(path))
			{
				BinaryReader br = new BinaryReader(fs);
				string sig = br.ReadStringFixedAscii(4);
				if (sig != "SBI\0")
					return false;
			}
			return true;
		}
开发者ID:CadeLaRen,项目名称:BizHawk,代码行数:14,代码来源:SBI_format.cs

示例5: ImportGMV

		// GMV file format: http://code.google.com/p/gens-rerecording/wiki/GMV
		private static BkmMovie ImportGMV(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 16-byte signature and format version: "Gens Movie TEST9"
			string signature = r.ReadStringFixedAscii(15);
			if (signature != "Gens Movie TEST")
			{
				errorMsg = "This is not a valid .GMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			m.Header[HeaderKeys.PLATFORM] = "GEN";
			// 00F ASCII-encoded GMV file format version. The most recent is 'A'. (?)
			string version = r.ReadStringFixedAscii(1);
			m.Comments.Add(MOVIEORIGIN + " .GMV version " + version);
			m.Comments.Add(EMULATIONORIGIN + " Gens");
			// 010 4-byte little-endian unsigned int: rerecord count
			uint rerecordCount = r.ReadUInt32();
			m.Rerecords = rerecordCount;
			// 014 ASCII-encoded controller config for player 1. '3' or '6'.
			string player1Config = r.ReadStringFixedAscii(1);
			// 015 ASCII-encoded controller config for player 2. '3' or '6'.
			string player2Config = r.ReadStringFixedAscii(1);
			SimpleController controllers = new SimpleController { Type = new ControllerDefinition() };
			if (player1Config == "6" || player2Config == "6")
			{
				controllers.Type.Name = "GPGX Genesis Controller";
			}
			else
			{
				controllers.Type.Name = "GPGX 3-Button Controller";
			}
			// 016 special flags (Version A and up only)
			byte flags = r.ReadByte();
			/*
			 bit 7 (most significant): if "1", movie runs at 50 frames per second; if "0", movie runs at 60 frames per
			 second The file format has no means of identifying NTSC/"PAL", but the FPS can still be derived from the
			 header.
			*/
			bool pal = (((flags >> 7) & 0x1) != 0);
			m.Header[HeaderKeys.PAL] = pal.ToString();
			// bit 6: if "1", movie requires a savestate.
			if (((flags >> 6) & 0x1) != 0)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			// bit 5: if "1", movie is 3-player movie; if "0", movie is 2-player movie
			bool threePlayers = (((flags >> 5) & 0x1) != 0);
			// Unknown.
			r.ReadByte();
			// 018 40-byte zero-terminated ASCII movie name string
			string description = NullTerminated(r.ReadStringFixedAscii(40));
			m.Comments.Add(COMMENT + " " + description);
			/*
			 040 frame data
			 For controller bytes, each value is determined by OR-ing together values for whichever of the following are
			 left unpressed:
			 * 0x01 Up
			 * 0x02 Down
			 * 0x04 Left
			 * 0x08 Right
			 * 0x10 A
			 * 0x20 B
			 * 0x40 C
			 * 0x80 Start
			*/
			string[] buttons = { "Up", "Down", "Left", "Right", "A", "B", "C", "Start" };
			/*
			 For XYZ-mode, each value is determined by OR-ing together values for whichever of the following are left
			 unpressed:
			 * 0x01 Controller 1 X
			 * 0x02 Controller 1 Y
			 * 0x04 Controller 1 Z
			 * 0x08 Controller 1 Mode
			 * 0x10 Controller 2 X
			 * 0x20 Controller 2 Y
			 * 0x40 Controller 2 Z
			 * 0x80 Controller 2 Mode
			*/
			string[] other = { "X", "Y", "Z", "Mode" };
			// The file has no terminator byte or frame count. The number of frames is the <filesize minus 64> divided by 3.
			long frameCount = (fs.Length - 64) / 3;
			for (long frame = 1; frame <= frameCount; frame++)
			{
				// Each frame consists of 3 bytes.
				for (int player = 1; player <= 3; player++)
				{
					byte controllerState = r.ReadByte();
					// * is controller 3 if a 3-player movie, or XYZ-mode if a 2-player movie.
					if (player != 3 || threePlayers)
					{
						for (int button = 0; button < buttons.Length; button++)
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例6: ImportFMV

		// FMV file format: http://tasvideos.org/FMV.html
		private static BkmMovie ImportFMV(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 4-byte signature: 46 4D 56 1A "FMV\x1A"
			string signature = r.ReadStringFixedAscii(4);
			if (signature != "FMV\x1A")
			{
				errorMsg = "This is not a valid .FMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			// 004 1-byte flags:
			byte flags = r.ReadByte();
			// bit 7: 0=reset-based, 1=savestate-based
			if (((flags >> 2) & 0x1) != 0)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			// other bits: unknown, set to 0
			// 005 1-byte flags:
			flags = r.ReadByte();
			// bit 5: is a FDS recording
			bool FDS;
			if (((flags >> 5) & 0x1) != 0)
			{
				FDS = true;
				m.Header[HeaderKeys.BOARDNAME] = "FDS";
			}
			else
			{
				FDS = false;

			}

			m.Header[HeaderKeys.PLATFORM] = "NES";

			// bit 6: uses controller 2
			bool controller2 = (((flags >> 6) & 0x1) != 0);
			// bit 7: uses controller 1
			bool controller1 = (((flags >> 7) & 0x1) != 0);
			// other bits: unknown, set to 0
			// 006 4-byte little-endian unsigned int: unknown, set to 00000000
			r.ReadInt32();
			// 00A 4-byte little-endian unsigned int: rerecord count minus 1
			uint rerecordCount = r.ReadUInt32();
			/*
			 The rerecord count stored in the file is the number of times a savestate was loaded. If a savestate was never
			 loaded, the number is 0. Famtasia however displays "1" in such case. It always adds 1 to the number found in
			 the file.
			*/
			m.Rerecords = rerecordCount + 1;
			// 00E 2-byte little-endian unsigned int: unknown, set to 0000
			r.ReadInt16();
			// 010 64-byte zero-terminated emulator identifier string
			string emuVersion = NullTerminated(r.ReadStringFixedAscii(64));
			m.Comments.Add(EMULATIONORIGIN + " Famtasia version " + emuVersion);
			m.Comments.Add(MOVIEORIGIN + " .FMV");
			// 050 64-byte zero-terminated movie title string
			string description = NullTerminated(r.ReadStringFixedAscii(64));
			m.Comments.Add(COMMENT + " " + description);
			if (!controller1 && !controller2 && !FDS)
			{
				warningMsg = "No input recorded.";
				r.Close();
				fs.Close();
				return m;
			}
			/*
			 The file format has no means of identifying NTSC/"PAL". It is always assumed that the game is NTSC - that is,
			 60 fps.
			*/
			m.Header[HeaderKeys.PAL] = "False";
			// 090 frame data begins here
			SimpleController controllers = new SimpleController { Type = new ControllerDefinition { Name = "NES Controller" } };
			/*
			 * 01 Right
			 * 02 Left
			 * 04 Up
			 * 08 Down
			 * 10 B
			 * 20 A
			 * 40 Select
			 * 80 Start
			*/
			string[] buttons = { "Right", "Left", "Up", "Down", "B", "A", "Select", "Start" };
			bool[] masks = { controller1, controller2, FDS };
			/*
			 The file has no terminator byte or frame count. The number of frames is the <filesize minus 144> divided by
			 <number of bytes per frame>.
			*/
			int bytesPerFrame = 0;
			for (int player = 1; player <= masks.Length; player++)
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例7: ImportFCM

		// FCM file format: http://code.google.com/p/fceu/wiki/FCM
		private static BkmMovie ImportFCM(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 4-byte signature: 46 43 4D 1A "FCM\x1A"
			string signature = r.ReadStringFixedAscii(4);
			if (signature != "FCM\x1A")
			{
				errorMsg = "This is not a valid .FCM file.";
				r.Close();
				fs.Close();
				return null;
			}
			// 004 4-byte little-endian unsigned int: version number, must be 2
			uint version = r.ReadUInt32();
			if (version != 2)
			{
				errorMsg = ".FCM movie version must always be 2.";
				r.Close();
				fs.Close();
				return null;
			}
			m.Comments.Add(MOVIEORIGIN + " .FCM version " + version);
			// 008 1-byte flags
			byte flags = r.ReadByte();
			// bit 0: reserved, set to 0
			/*
			 bit 1:
			 * if "0", movie begins from an embedded "quicksave" snapshot
			 * if "1", movie begins from reset or power-on[1]
			*/
			if (((flags >> 1) & 0x1) == 0)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			/*
			 bit 2:
			 * if "0", NTSC timing
			 * if "1", "PAL" timing
			 Starting with version 0.98.12 released on September 19, 2004, a "PAL" flag was added to the header but
			 unfortunately it is not reliable - the emulator does not take the "PAL" setting from the ROM, but from a user
			 preference. This means that this site cannot calculate movie lengths reliably.
			*/
			bool pal = (((flags >> 2) & 0x1) != 0);
			m.Header[HeaderKeys.PAL] = pal.ToString();
			// other: reserved, set to 0
			bool syncHack = (((flags >> 4) & 0x1) != 0);
			m.Comments.Add(SYNCHACK + " " + syncHack);
			// 009 1-byte flags: reserved, set to 0
			r.ReadByte();
			// 00A 1-byte flags: reserved, set to 0
			r.ReadByte();
			// 00B 1-byte flags: reserved, set to 0
			r.ReadByte();
			// 00C 4-byte little-endian unsigned int: number of frames
			uint frameCount = r.ReadUInt32();
			// 010 4-byte little-endian unsigned int: rerecord count
			uint rerecordCount = r.ReadUInt32();
			m.Rerecords = rerecordCount;
			/*
			 018 4-byte little-endian unsigned int: offset to the savestate inside file
			 The savestate offset is <header_size + length_of_metadata_in_bytes + padding>. The savestate offset should be
			 4-byte aligned. At the savestate offset there is a savestate file. The savestate exists even if the movie is
			 reset-based.
			*/
			r.ReadUInt32();
			// 01C 4-byte little-endian unsigned int: offset to the controller data inside file
			uint firstFrameOffset = r.ReadUInt32();
			// 020 16-byte md5sum of the ROM used
			byte[] md5 = r.ReadBytes(16);
			m.Header[MD5] = md5.BytesToHexString().ToLower();
			// 030 4-byte little-endian unsigned int: version of the emulator used
			uint emuVersion = r.ReadUInt32();
			m.Comments.Add(EMULATIONORIGIN + " FCEU " + emuVersion);
			// 034 name of the ROM used - UTF8 encoded nul-terminated string.
			List<byte> gameBytes = new List<byte>();
			while (r.PeekChar() != 0)
				gameBytes.Add(r.ReadByte());
			// Advance past null byte.
			r.ReadByte();
			string gameName = Encoding.UTF8.GetString(gameBytes.ToArray());
			m.Header[HeaderKeys.GAMENAME] = gameName;
			/*
			 After the header comes "metadata", which is UTF8-coded movie title string. The metadata begins after the ROM
			 name and ends at the savestate offset. This string is displayed as "Author Info" in the Windows version of the
			 emulator.
			*/
			List<byte> authorBytes = new List<byte>();
			while (r.PeekChar() != 0)
				authorBytes.Add(r.ReadByte());
			// Advance past null byte.
			r.ReadByte();
			string author = Encoding.UTF8.GetString(authorBytes.ToArray());
			m.Header[HeaderKeys.AUTHOR] = author;
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例8: ImportZMV

		// ZMV file format: http://tasvideos.org/ZMV.html
		private static BkmMovie ImportZMV(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 3-byte signature: 5A 4D 56 "ZMV"
			string signature = r.ReadStringFixedAscii(3);
			if (signature != "ZMV")
			{
				errorMsg = "This is not a valid .ZMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			m.Header[HeaderKeys.PLATFORM] = "SNES";
			// 003 2-byte little-endian unsigned int: zsnes version number
			short version = r.ReadInt16();
			m.Comments.Add(EMULATIONORIGIN + " ZSNES version " + version);
			m.Comments.Add(MOVIEORIGIN + " .ZMV");
			// 005 4-byte little-endian integer: CRC32 of the ROM
			int crc32 = r.ReadInt32();
			m.Header[CRC32] = crc32.ToString();
			// 009 4-byte little-endian unsigned int: number of frames
			uint frameCount = r.ReadUInt32();
			// 00D 4-byte little-endian unsigned int: number of rerecords
			uint rerecordCount = r.ReadUInt32();
			m.Rerecords = rerecordCount;
			// 011 4-byte little-endian unsigned int: number of frames removed by rerecord
			r.ReadBytes(4);
			// 015 4-byte little-endian unsigned int: number of frames advanced step by step
			r.ReadBytes(4);
			// 019 1-byte: average recording frames per second
			r.ReadByte();
			// 01A 4-byte little-endian unsigned int: number of key combos
			r.ReadBytes(4);
			// 01E 2-byte little-endian unsigned int: number of internal chapters
			ushort internalChaptersCount = r.ReadUInt16();
			// 020 2-byte little-endian unsigned int: length of the author name field in bytes
			ushort authorSize = r.ReadUInt16();
			// 022 3-byte little-endian unsigned int: size of an uncompressed save state in bytes
			r.ReadBytes(3);
			// 025 1-byte: reserved
			r.ReadByte();
			/*
			 026 1-byte flags: initial input configuration
				 bit 7: first input enabled
				 bit 6: second input enabled
				 bit 5: third input enabled
				 bit 4: fourth input enabled
				 bit 3: fifth input enabled
				 bit 2: mouse in first port
				 bit 1: mouse in second port
				 bit 0: super scope in second port
			*/
			byte controllerFlags = r.ReadByte();
			string peripheral = "";
			bool superScope = ((controllerFlags & 0x1) != 0);
			if (superScope)
			{
				peripheral = "Super Scope";
			}
			controllerFlags >>= 1;
			bool secondMouse = ((controllerFlags & 0x1) != 0);
			if (secondMouse && peripheral == "")
			{
				peripheral = "Second Mouse";
			}
			controllerFlags >>= 1;
			bool firstMouse = ((controllerFlags & 0x1) != 0);
			if (firstMouse && peripheral == "")
			{
				peripheral = "First Mouse";
			}
			if (peripheral != "")
			{
				warningMsg = "Unable to import " + peripheral + ".";
			}
			// 027 1-byte flags:
			byte movieFlags = r.ReadByte();
			byte begins = (byte)(movieFlags & 0xC0);
			/*
			 bits 7,6:
				 if "00", movie begins from savestate
			*/
			if (begins == 0x00)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			// if "10", movie begins from reset
			// if "01", movie begins from power-on
			if (begins == 0x40)
			{
				errorMsg = "Movies that begin with SRAM are not supported.";
				r.Close();
				fs.Close();
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例9: ImportVMV

		// VMV file format: http://tasvideos.org/VMV.html
		private static BkmMovie ImportVMV(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 12-byte signature: "VirtuaNES MV"
			string signature = r.ReadStringFixedAscii(12);
			if (signature != "VirtuaNES MV")
			{
				errorMsg = "This is not a valid .VMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			m.Header[HeaderKeys.PLATFORM] = "NES";
			// 00C 2-byte little-endian integer: movie version 0x0400
			ushort version = r.ReadUInt16();
			m.Comments.Add(MOVIEORIGIN + " .VMV version " + version);
			m.Comments.Add(EMULATIONORIGIN + " VirtuaNES");
			// 00E 2-byte little-endian integer: record version
			ushort recordVersion = r.ReadUInt16();
			m.Comments.Add(COMMENT + " Record version " + recordVersion);
			// 010 4-byte flags (control byte)
			uint flags = r.ReadUInt32();
			/*
			 * bit 0: controller 1 in use
			 * bit 1: controller 2 in use
			 * bit 2: controller 3 in use
			 * bit 3: controller 4 in use
			*/
			bool[] controllersUsed = new bool[4];
			for (int controller = 1; controller <= controllersUsed.Length; controller++)
			{
				controllersUsed[controller - 1] = (((flags >> (controller - 1)) & 0x1) != 0);
			}
			bool fourscore = (controllersUsed[2] || controllersUsed[3]);
			m.Header[HeaderKeys.FOURSCORE] = fourscore.ToString();
			/*
			 bit 6: 1=reset-based, 0=savestate-based (movie version <= 0x300 is always savestate-based)
			 If the movie version is < 0x400, or the "from-reset" flag is not set, a savestate is loaded from the movie.
			 Otherwise, the savestate is ignored.
			*/
			if (version < 0x400 || ((flags >> 6) & 0x1) == 0)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			/*
			 bit 7: disable rerecording
			 For the other control bytes, if a key from 1P to 4P (whichever one) is entirely ON, the following 4 bytes
			 becomes the controller data. TODO: Figure out what this means.
			 Other bits: reserved, set to 0
			*/
			// 014 DWORD   Ext0;				   // ROM:program CRC  FDS:program ID
			r.ReadBytes(4);
			// 018 WORD	Ext1;				   // ROM:unused,0	 FDS:maker ID
			r.ReadBytes(2);
			// 01A WORD	Ext2;				   // ROM:unused,0	 FDS:disk no.
			r.ReadBytes(2);
			// 01C 4-byte little-endian integer: rerecord count
			uint rerecordCount = r.ReadUInt32();
			m.Rerecords = rerecordCount;
			/*
			020 BYTE	RenderMethod
			0=POST_ALL,1=PRE_ALL
			2=POST_RENDER,3=PRE_RENDER
			4=TILE_RENDER
			*/
			r.ReadByte();
			// 021 BYTE	IRQtype				 // IRQ type
			r.ReadByte();
			// 022 BYTE	FrameIRQ				// FrameIRQ not allowed
			r.ReadByte();
			// 023 1-byte flag: 0=NTSC (60 Hz), 1="PAL" (50 Hz)
			bool pal = (r.ReadByte() == 1);
			m.Header[HeaderKeys.PAL] = pal.ToString();
			// 024 8-bytes: reserved, set to 0
			r.ReadBytes(8);
			// 02C 4-byte little-endian integer: save state start offset
			r.ReadBytes(4);
			// 030 4-byte little-endian integer: save state end offset
			r.ReadBytes(4);
			// 034 4-byte little-endian integer: movie data offset
			uint firstFrameOffset = r.ReadUInt32();
			// 038 4-byte little-endian integer: movie frame count
			uint frameCount = r.ReadUInt32();
			// 03C 4-byte little-endian integer: CRC (CRC excluding this data(to prevent cheating))
			int crc32 = r.ReadInt32();
			m.Header[CRC32] = crc32.ToString();
			if (!controllersUsed[0] && !controllersUsed[1] && !controllersUsed[2] && !controllersUsed[3])
			{
				warningMsg = "No input recorded.";
				r.Close();
				fs.Close();
				return m;
			}
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例10: ImportVBM

		// VBM file format: http://code.google.com/p/vba-rerecording/wiki/VBM
		private static BkmMovie ImportVBM(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 4-byte signature: 56 42 4D 1A "VBM\x1A"
			string signature = r.ReadStringFixedAscii(4);
			if (signature != "VBM\x1A")
			{
				errorMsg = "This is not a valid .VBM file.";
				r.Close();
				fs.Close();
				return null;
			}
			// 004 4-byte little-endian unsigned int: major version number, must be "1"
			uint majorVersion = r.ReadUInt32();
			if (majorVersion != 1)
			{
				errorMsg = ".VBM major movie version must be 1.";
				r.Close();
				fs.Close();
				return null;
			}
			/*
			 008 4-byte little-endian integer: movie "uid" - identifies the movie-savestate relationship, also used as the
			 recording time in Unix epoch format
			*/
			uint uid = r.ReadUInt32();

			// 00C 4-byte little-endian unsigned int: number of frames
			uint frameCount = r.ReadUInt32();
			// 010 4-byte little-endian unsigned int: rerecord count
			uint rerecordCount = r.ReadUInt32();
			m.Rerecords = rerecordCount;
			// 014 1-byte flags: (movie start flags)
			byte flags = r.ReadByte();
			// bit 0: if "1", movie starts from an embedded "quicksave" snapshot
			bool startfromquicksave = ((flags & 0x1) != 0);
			// bit 1: if "1", movie starts from reset with an embedded SRAM
			bool startfromsram = (((flags >> 1) & 0x1) != 0);
			// other: reserved, set to 0
			// (If both bits 0 and 1 are "1", the movie file is invalid)
			if (startfromquicksave && startfromsram)
			{
				errorMsg = "This is not a valid .VBM file.";
				r.Close();
				fs.Close();
				return null;
			}
			if (startfromquicksave)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			if (startfromsram)
			{
				errorMsg = "Movies that begin with SRAM are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			// 015 1-byte flags: controller flags
			byte controllerFlags = r.ReadByte();
			/*
			 * bit 0: controller 1 in use
			 * bit 1: controller 2 in use (SGB games can be 2-player multiplayer)
			 * bit 2: controller 3 in use (SGB games can be 3- or 4-player multiplayer with multitap)
			 * bit 3: controller 4 in use (SGB games can be 3- or 4-player multiplayer with multitap)
			*/
			bool[] controllersUsed = new bool[4];
			for (int controller = 1; controller <= controllersUsed.Length; controller++)
			{
				controllersUsed[controller - 1] = (((controllerFlags >> (controller - 1)) & 0x1) != 0);
			}
			if (!controllersUsed[0])
			{
				errorMsg = "Controller 1 must be in use.";
				r.Close();
				fs.Close();
				return null;
			}
			// other: reserved
			// 016 1-byte flags: system flags (game always runs at 60 frames/sec)
			flags = r.ReadByte();
			// bit 0: if "1", movie is for the GBA system
			bool is_gba = ((flags & 0x1) != 0);
			// bit 1: if "1", movie is for the GBC system
			bool is_gbc = (((flags >> 1) & 0x1) != 0);
			// bit 2: if "1", movie is for the SGB system
			bool is_sgb = (((flags >> 2) & 0x1) != 0);
			// other: reserved, set to 0

			// (At most one of bits 0, 1, 2 can be "1")
			//if (!(is_gba ^ is_gbc ^ is_sgb) && (is_gba || is_gbc || is_sgb)) //TODO: adelikat: this doesn't do what the comment above suggests it is trying to check for, it is always false!
			//{
			//errorMsg = "This is not a valid .VBM file.";
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例11: ImportSMV

		private static BkmMovie ImportSMV(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 4-byte signature: 53 4D 56 1A "SMV\x1A"
			string signature = r.ReadStringFixedAscii(4);
			if (signature != "SMV\x1A")
			{
				errorMsg = "This is not a valid .SMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			m.Header[HeaderKeys.PLATFORM] = "SNES";
			// 004 4-byte little-endian unsigned int: version number
			uint versionNumber = r.ReadUInt32();
			string version;
			switch (versionNumber)
			{
				case 1:
					version = "1.43";
					break;
				case 4:
					version = "1.51";
					break;
				case 5:
					version = "1.52";
					break;
				default:
					errorMsg = "SMV version not recognized. 1.43, 1.51, and 1.52 are currently supported.";
					r.Close();
					fs.Close();
					return null;
			}
			m.Comments.Add(EMULATIONORIGIN + " Snes9x version " + version);
			m.Comments.Add(MOVIEORIGIN + " .SMV");
			/*
			 008 4-byte little-endian integer: movie "uid" - identifies the movie-savestate relationship, also used as the
			 recording time in Unix epoch format
			*/
			uint uid = r.ReadUInt32();

			// 00C 4-byte little-endian unsigned int: rerecord count
			m.Rerecords = r.ReadUInt32();
			// 010 4-byte little-endian unsigned int: number of frames
			uint frameCount = r.ReadUInt32();
			// 014 1-byte flags "controller mask"
			byte controllerFlags = r.ReadByte();
			/*
			 * bit 0: controller 1 in use
			 * bit 1: controller 2 in use
			 * bit 2: controller 3 in use
			 * bit 3: controller 4 in use
			 * bit 4: controller 5 in use
			 * other: reserved, set to 0
			*/
			SimpleController controllers = new SimpleController { Type = new ControllerDefinition { Name = "SNES Controller" } };
			bool[] controllersUsed = new bool[5];
			for (int controller = 1; controller <= controllersUsed.Length; controller++)
			{
				controllersUsed[controller - 1] = (((controllerFlags >> (controller - 1)) & 0x1) != 0);
			}
			// 015 1-byte flags "movie options"
			byte movieFlags = r.ReadByte();
			/*
				 bit 0:
					 if "0", movie begins from an embedded "quicksave" snapshot
					 if "1", a SRAM is included instead of a quicksave; movie begins from reset
			*/
			if ((movieFlags & 0x1) == 0)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			// bit 1: if "0", movie is NTSC (60 fps); if "1", movie is PAL (50 fps)
			bool pal = (((movieFlags >> 1) & 0x1) != 0);
			m.Header[HeaderKeys.PAL] = pal.ToString();
			// other: reserved, set to 0
			/*
			 016 1-byte flags "sync options":
				 bit 0: MOVIE_SYNC2_INIT_FASTROM
				 other: reserved, set to 0
			*/
			r.ReadByte();
			/*
			 017 1-byte flags "sync options":
				 bit 0: MOVIE_SYNC_DATA_EXISTS
					 if "1", all sync options flags are defined.
					 if "0", all sync options flags have no meaning.
				 bit 1: MOVIE_SYNC_WIP1TIMING
				 bit 2: MOVIE_SYNC_LEFTRIGHT
				 bit 3: MOVIE_SYNC_VOLUMEENVX
				 bit 4: MOVIE_SYNC_FAKEMUTE
				 bit 5: MOVIE_SYNC_SYNCSOUND
				 bit 6: MOVIE_SYNC_HASROMINFO
					 if "1", there is extra ROM info located right in between of the metadata and the savestate.
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例12: ImportNMV

		// NMV file format: http://tasvideos.org/NMV.html
		private static BkmMovie ImportNMV(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 4-byte signature: 4E 53 53 1A "NSS\x1A"
			string signature = r.ReadStringFixedAscii(4);
			if (signature != "NSS\x1A")
			{
				errorMsg = "This is not a valid .NMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			// 004 4-byte version string (example "0960")
			string emuVersion = r.ReadStringFixedAscii(4);
			m.Comments.Add(EMULATIONORIGIN + " Nintendulator version " + emuVersion);
			m.Comments.Add(MOVIEORIGIN + " .NMV");
			// 008 4-byte file size, not including the 16-byte header
			r.ReadUInt32();
			/*
			 00C 4-byte file type string
			 * "NSAV" - standard savestate
			 * "NREC" - savestate saved during movie recording
			 * "NMOV" - standalone movie file
			*/
			string type = r.ReadStringFixedAscii(4);
			if (type != "NMOV")
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			/*
			 Individual blocks begin with an 8-byte header, consisting of a 4-byte signature and a 4-byte length (which
			 does not include the length of the block header).
			 The final block in the file is of type "NMOV"
			*/
			string header = r.ReadStringFixedAscii(4);
			if (header != "NMOV")
			{
				errorMsg = "This is not a valid .NMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			r.ReadUInt32();
			// 000 1-byte controller #1 type (see below)
			byte controller1 = r.ReadByte();
			// 001 1-byte controller #2 type (or four-score mask, see below)
			byte controller2 = r.ReadByte();
			/*
			 Controller data is variant, depending on which controllers are attached at the time of recording. The
			 following controllers are implemented:
			 * 0 - Unconnected
			 * 1 - Standard Controller (1 byte)
			 * 2 - Zapper (3 bytes)
			 * 3 - Arkanoid Paddle (2 bytes)
			 * 4 - Power Pad (2 bytes)
			 * 5 - Four-Score (special)
			 * 6 - SNES controller (2 bytes) - A/B become B/Y, adds A/X and L/R shoulder buttons
			 * 7 - Vs Unisystem Zapper (3 bytes)
			*/
			bool fourscore = (controller1 == 5);
			m.Header[HeaderKeys.FOURSCORE] = fourscore.ToString();
			bool[] masks = new[] { false, false, false, false, false };
			if (fourscore)
			{
				/*
				 When a Four-Score is indicated for Controller #1, the Controller #2 byte becomes a bit mask to indicate
				 which ports on the Four-Score have controllers connected to them. Each connected controller stores 1 byte
				 per frame. Nintendulator's Four-Score recording is seemingly broken.
				*/
				for (int controller = 1; controller < masks.Length; controller++)
				{
					masks[controller - 1] = (((controller2 >> (controller - 1)) & 0x1) != 0);
				}
				warningMsg = "Nintendulator's Four Score recording is seemingly broken.";
			}
			else
			{
				byte[] types = new[] { controller1, controller2 };
				for (int controller = 1; controller <= types.Length; controller++)
				{
					masks[controller - 1] = (types[controller - 1] == 1);
					// Get the first unsupported controller warning message that arises.
					if (warningMsg == "")
					{
						switch (types[controller - 1])
						{
							case 0:
								break;
							case 2:
								warningMsg = "Zapper";
								break;
							case 3:
								warningMsg = "Arkanoid Paddle";
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例13: ImportMMV

		// MMV file format: http://tasvideos.org/MMV.html
		private static BkmMovie ImportMMV(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 0000: 4-byte signature: "MMV\0"
			string signature = r.ReadStringFixedAscii(4);
			if (signature != "MMV\0")
			{
				errorMsg = "This is not a valid .MMV file.";
				r.Close();
				fs.Close();
				return null;
			}
			// 0004: 4-byte little endian unsigned int: dega version
			uint emuVersion = r.ReadUInt32();
			m.Comments.Add(EMULATIONORIGIN + " Dega version " + emuVersion);
			m.Comments.Add(MOVIEORIGIN + " .MMV");
			// 0008: 4-byte little endian unsigned int: frame count
			uint frameCount = r.ReadUInt32();
			// 000c: 4-byte little endian unsigned int: rerecord count
			uint rerecordCount = r.ReadUInt32();
			m.Rerecords = rerecordCount;
			// 0010: 4-byte little endian flag: begin from reset?
			uint reset = r.ReadUInt32();
			if (reset == 0)
			{
				errorMsg = "Movies that begin with a savestate are not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			// 0014: 4-byte little endian unsigned int: offset of state information
			r.ReadUInt32();
			// 0018: 4-byte little endian unsigned int: offset of input data
			r.ReadUInt32();
			// 001c: 4-byte little endian unsigned int: size of input packet
			r.ReadUInt32();
			// 0020-005f: string: author info (UTF-8)
			string author = NullTerminated(r.ReadStringFixedAscii(64));
			m.Header[HeaderKeys.AUTHOR] = author;
			// 0060: 4-byte little endian flags
			byte flags = r.ReadByte();
			// bit 0: unused
			// bit 1: "PAL"
			bool pal = (((flags >> 1) & 0x1) != 0);
			m.Header[HeaderKeys.PAL] = pal.ToString();
			// bit 2: Japan
			bool japan = (((flags >> 2) & 0x1) != 0);
			m.Header[JAPAN] = japan.ToString();
			// bit 3: Game Gear (version 1.16+)
			bool gamegear;
			if (((flags >> 3) & 0x1) != 0)
			{
				gamegear = true;
				m.Header[HeaderKeys.PLATFORM] = "GG";
			}
			else
			{
				gamegear = false;
				m.Header[HeaderKeys.PLATFORM] = "SMS";
			}
			// bits 4-31: unused
			r.ReadBytes(3);
			// 0064-00e3: string: rom name (ASCII)
			string gameName = NullTerminated(r.ReadStringFixedAscii(128));
			m.Header[HeaderKeys.GAMENAME] = gameName;
			// 00e4-00f3: binary: rom MD5 digest
			byte[] md5 = r.ReadBytes(16);
			m.Header[MD5] = string.Format("{0:x8}", md5.BytesToHexString().ToLower());
			var controllers = new SimpleController { Type = new ControllerDefinition { Name = "SMS Controller" } };
			/*
			 76543210
			 * bit 0 (0x01): up
			 * bit 1 (0x02): down
			 * bit 2 (0x04): left
			 * bit 3 (0x08): right
			 * bit 4 (0x10): 1
			 * bit 5 (0x20): 2
			 * bit 6 (0x40): start (Master System)
			 * bit 7 (0x80): start (Game Gear)
			*/
			string[] buttons = { "Up", "Down", "Left", "Right", "B1", "B2" };
			for (int frame = 1; frame <= frameCount; frame++)
			{
				/*
				 Controller data is made up of one input packet per frame. Each packet currently consists of 2 bytes. The
				 first byte is for controller 1 and the second controller 2. The Game Gear only uses the controller 1 input
				 however both bytes are still present.
				*/
				for (int player = 1; player <= 2; player++)
				{
					byte controllerState = r.ReadByte();
					for (int button = 0; button < buttons.Length; button++)
					{
						controllers["P" + player + " " + buttons[button]] = (((controllerState >> button) & 0x1) != 0);
					}
					if (player == 1)
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs

示例14: ImportMCM

		/*
		 MCM file format: http://code.google.com/p/mednafen-rr/wiki/MCM
		 Mednafen-rr switched to MC2 from r261, so see r260 for details.
		*/
		private static BkmMovie ImportMCM(string path, out string errorMsg, out string warningMsg)
		{
			errorMsg = warningMsg = string.Empty;
			BkmMovie m = new BkmMovie(path);
			FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
			BinaryReader r = new BinaryReader(fs);
			// 000 8-byte	"MDFNMOVI" signature
			var signature = r.ReadStringFixedAscii(8);
			if (signature != "MDFNMOVI")
			{
				errorMsg = "This is not a valid .MCM file.";
				r.Close();
				fs.Close();
				return null;
			}
			// 008 uint32	 Mednafen Version (Current is 0A 08)
			uint emuVersion = r.ReadUInt32();
			m.Comments.Add(EMULATIONORIGIN + " Mednafen " + emuVersion);
			// 00C uint32	 Movie Format Version (Current is 01)
			uint version = r.ReadUInt32();
			m.Comments.Add(MOVIEORIGIN + " .MCM version " + version);
			// 010 32-byte	MD5 of the ROM used
			byte[] md5 = r.ReadBytes(16);
			// Discard the second 16 bytes.
			r.ReadBytes(16);
			m.Header[MD5] = md5.BytesToHexString().ToLower();
			// 030 64-byte	Filename of the ROM used (with extension)
			string gameName = NullTerminated(r.ReadStringFixedAscii(64));
			m.Header[HeaderKeys.GAMENAME] = gameName;
			// 070 uint32	 Re-record Count
			uint rerecordCount = r.ReadUInt32();
			m.Rerecords = (ulong)rerecordCount;
			// 074 5-byte	 Console indicator (pce, ngp, pcfx, wswan)
			string platform = NullTerminated(r.ReadStringFixedAscii(5));
			Dictionary<string, Dictionary<string, object>> platforms = new Dictionary<string, Dictionary<string, object>>
			{
				{
					/*
					 Normally, NES receives from 5 input ports, where the first 4 have a length of 1 byte, and the last has
					 a length of 0. For the sake of simplicity, it is interpreted as 4 ports of 1 byte length for
					 re-recording.
					*/
					"nes", new Dictionary<string, object>
					{
						{"name", "NES"}, {"ports", 4}, {"bytesPerPort", 1},
						{"buttons", new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" }}
					}
				},
				{
					"pce", new Dictionary<string, object>
					{
						{"name", "PC Engine"}, {"ports", 5}, {"bytesPerPort", 2},
						{"buttons", new[] { "B1", "B2", "Select", "Run", "Up", "Right", "Down", "Left" }}
					}
				},
				{
					"lynx", new Dictionary<string, object>
					{
						{ "name", "Lynx" }, { "ports", 2 }, { "bytesPerPort", 1 },
						{ "buttons", new[] { "A", "B", "Up", "Down", "Left", "Right" }}
					}
				}
			};
			if (!platforms.ContainsKey(platform))
			{
				errorMsg = "Platform " + platform + " not supported.";
				r.Close();
				fs.Close();
				return null;
			}
			string name = (string)platforms[platform]["name"];

			string systemID = name.ToUpper(); // Hack

			m.Header[HeaderKeys.PLATFORM] = systemID;
			// 079 32-byte	Author name
			string author = NullTerminated(r.ReadStringFixedAscii(32));
			m.Header[HeaderKeys.AUTHOR] = author;
			// 099 103-byte   Padding 0s
			r.ReadBytes(103);
			// TODO: Verify if NTSC/"PAL" mode used for the movie can be detected or not.
			// 100 variable   Input data
			SimpleController controllers = new SimpleController { Type = new ControllerDefinition { Name = name + " Controller" } };
			int bytes = 256;
			// The input stream consists of 1 byte for power-on and reset, and then X bytes per each input port per frame.
			if (platform == "nes")
			{
				// Power-on.
				r.ReadByte();
				bytes++;
			}
			string[] buttons = (string[])platforms[platform]["buttons"];
			int ports = (int)platforms[platform]["ports"];
			int bytesPerPort = (int)platforms[platform]["bytesPerPort"];
			// Frame Size (with Control Byte)
			int size = (ports * bytesPerPort) + 1;
//.........这里部分代码省略.........
开发者ID:henke37,项目名称:BizHawk,代码行数:101,代码来源:MovieImport.cs


注:本文中的System.IO.BinaryReader.ReadStringFixedAscii方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。