Example #1
0
        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));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Dump raw track data after MFM encoding.
        /// </summary>
        /// <param name="diskStream">Stream for reading the disk image data.</param>
        /// <param name="disk">Disk.</param>
        /// <param name="headId">Head.</param>
        /// <param name="trackId">Track.</param>
        void DumpTrackData(Stream diskStream, HfeDisk disk, int headId, int trackId)
        {
            Console.WriteLine();
            Console.Write("Track data for track {0} side {1}", trackId, headId);
            Console.WriteLine();

            var t = disk.GetTrack(trackId, headId);

            var trackStream = new MfmStream(new HfeRawTrack(diskStream, t.TrackOffset, t.TrackLength, headId));
            var offset      = 0;
            var done        = false;
            var buffer      = new byte[16];

            while (!done)
            {
                Console.Write(String.Format("{0:x4} : ", offset));
                var len = trackStream.Read(buffer, 0, buffer.Length);
                for (var i = 0; i < Math.Min(buffer.Length, len); i++)
                {
                    Console.Write(String.Format("{0:x2} ", buffer[i]));
                }
                Console.WriteLine();
                done    = (len < buffer.Length);
                offset += len;
            }
            trackStream.Dispose();
        }
Example #3
0
        public void Create()
        {
            using (var diskStream = new MemoryStream())
            {
                using (var disk = HfeDisk.Create(diskStream, 1, 40, 18, 256))
                {
                    var diskHeader = disk.DiskHeader;
                    Assert.Equal(0, diskHeader.FileFormatVersion);
                    Assert.Equal(40, diskHeader.Tracks);
                    Assert.Equal(1, diskHeader.Sides);
                    Assert.Equal(HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM, diskHeader.TrackEncoding);
                    Assert.Equal(HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM, diskHeader.TrackEncoding0);

                    var track = disk.GetTrack(0, 0);
                    Assert.NotNull(track);

                    Assert.True(disk.SectorExists(0, 0, 1));
                }
            }
        }
Example #4
0
        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);
                }
            }
        }