public void CreateAndOpen() { byte[] diskImage; /* Create a HFE disk image and keep the image in the diskImage buffer. */ using (var diskStream = new MemoryStream()) { using (var disk = HfeDisk.Create(diskStream, 1, 40, 18, 256)) { } diskImage = diskStream.GetBuffer(); } /* Now open the disk image in diskImage and verify that it is correct. */ using (var diskStream = new MemoryStream(diskImage, false)) { using (var disk = HfeDisk.Open(diskStream, false)) { var header = disk.DiskHeader; Assert.Equal(0, header.FileFormatVersion); Assert.Equal(40, header.Tracks); Assert.Equal(1, header.Sides); Assert.Equal(HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM, header.TrackEncoding); Assert.Equal(HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM, header.TrackEncoding0); var track = disk.GetTrack(0, 0); Assert.NotNull(track); Assert.True(disk.SectorExists(0, 0, 1)); Assert.True(disk.SectorExists(0, 0, 3)); Assert.True(disk.SectorExists(0, 0, 2)); Assert.True(disk.SectorExists(0, 0, 17)); Assert.True(disk.SectorExists(0, 0, 18)); Assert.True(disk.SectorExists(0, 39, 1)); Assert.True(disk.SectorExists(0, 39, 18)); } } }
void DumpDiskInfo(string diskFilename) { using (var diskStream = new FileStream(diskFilename, FileMode.Open, FileAccess.Read)) { using (var disk = HfeDisk.Open(diskStream, false)) { Console.WriteLine(diskFilename); Console.WriteLine(); var diskHeader = disk.DiskHeader; Console.WriteLine("File format version : {0}", diskHeader.FileFormatVersion); Console.WriteLine("Number of disk sides : {0}", diskHeader.Sides); Console.WriteLine("Number of tracks per side : {0}", diskHeader.Tracks); Console.WriteLine("Track encoding : {0}", diskHeader.TrackEncoding); Console.WriteLine("Track encoding (track 0, side 0) : {0}", diskHeader.TrackEncoding0); Console.WriteLine("Track encoding (track 0, side 1) : {0}", diskHeader.TrackEncoding1); Console.WriteLine("Floppy interface mode : {0}", diskHeader.FloppyInterface); Console.WriteLine("Disk bit rate : {0}", diskHeader.DiskBitRate); Console.WriteLine("Disk rotation speed : {0}", diskHeader.DiskRotationSpeed); Console.WriteLine("Disk write protected : {0}", diskHeader.IsDiskWriteProtected); Console.WriteLine("Track list block : {0}", diskHeader.TrackListBlock); Console.WriteLine(); for (int track = 0; track < diskHeader.Tracks; track++) { for (int head = 0; head < diskHeader.Sides; head++) { var t = disk.GetTrack(track, head); Console.WriteLine("Track {0,2} Offset={1} Length={2}", track, t.TrackOffset, t.TrackLength); foreach (var s in t) { Console.WriteLine(" Sector Head={0} Track={1,-2} Sector={2,-2} Size={3}", s.Head, s.Track, s.Sector, s.Size); } } } // DumpTrackData(diskStream, disk, 0, 0); } } }