public FamicomDiskSystem_Side(Stream Image, uint Offset) { this.Image = Image; this.StartOffset = Offset; // Step 1: confirm the data contains valid FDS file system data this.Image.Position = this.StartOffset; // read first byte, confirm it is 0x01 // read the next 14 bytes, confirm it is ASCII for "*NINTENDO-HVC*" byte[] verify = new byte[15]; this.Image.Read(verify, 0, 15); if (verify[0] != 1 || Encoding.ASCII.GetString(verify, 1, 14) != "*NINTENDO-HVC*") throw new InvalidDataException("Not a valid Famicom Disk System file system (invalid hardware identifier in header)"); //next byte should be the manufacturer code this.ManufacturerCode = (byte)Image.ReadByte(); verify = new byte[3]; this.Image.Read(verify, 0, 3); this.GameName = Encoding.ASCII.GetString(verify); this.GameType = (byte)this.Image.ReadByte(); this.GameVersion = (byte)this.Image.ReadByte(); this.SideNumber = (byte)this.Image.ReadByte(); this.DiskNumber = (byte)this.Image.ReadByte(); // Step 2: set up files // check number of files this.Image.Position = this.StartOffset + 0x38; if (this.Image.ReadByte() != 2) throw new InvalidDataException("Not a valid Famicom Disk System file system (invalid file count block)"); int numfiles = this.Image.ReadByte(); if (numfiles == 0) Console.WriteLine("File count value is zero; may be invalid data or 'copy protection'"); this.Root = new Directory(); this.Root.Contents = new FamicomDiskSystem_File[numfiles]; byte[] filename = new byte[8]; byte[] size = new byte[2]; for (int allfiles = 0; allfiles < numfiles; allfiles++) { // assume the stream pointer is set properly... if (this.Image.ReadByte() != 3) if (this.Image.ReadByte() != 2) throw new InvalidDataException("Not a valid Famicom Disk System file system (invalid beginning of file metadata byte while trying file #" + allfiles + ")"); var props = new FamicomDiskSystem_File.Properties(); props.Number = (byte)this.Image.ReadByte(); props.ID = (byte)this.Image.ReadByte(); this.Image.Read(filename, 0, 8); props.Name = String.Format("{0}:{1}", props.ID.ToString(), Encoding.ASCII.GetString(filename)); string test = Text.Transcode.UsingSJIS(filename); //ignore the destination address for now.. this.Image.ReadByte(); this.Image.ReadByte(); this.Image.Read(size, 0, 2); if (!BitConverter.IsLittleEndian) Array.Reverse(size); props.Length = (ushort)BitConverter.ToInt16(size, 0); props.Type = (FamicomDiskSystem_File.FileTypes)this.Image.ReadByte(); if (this.Image.ReadByte() != 4) throw new InvalidDataException("Not a valid Famicom Disk System file system (invalid beginning of file data byte while trying file #" + allfiles + ")"); props.Offset = (ulong)this.Image.Position; //this.objects.Add(props.Name, new FamicomDiskSystem_File(props)); this.Root.Contents[allfiles] = new FamicomDiskSystem_File(props); this.Image.Seek(props.Length, SeekOrigin.Current); } }