コード例 #1
0
ファイル: HfeTrack.cs プロジェクト: rolfmichelsen/dragontools
        /// <summary>
        /// Reads sector data and returns a sector object.  The stream must be positioned at the first byte of the sector payload
        /// data.  On exit the stream will be positioned on the first byte following the sector payload CRC.
        /// </summary>
        /// <param name="info">Sector meta-information.</param>
        /// <returns>A sector object.</returns>
        private HfeSector GetSectorData(HfeSectorInfo info)
        {
            Sync();
            var blockId = trackStream.ReadByte();

            if (blockId == -1)
            {
                return(null);
            }
            if (blockId != DataAddressMark)
            {
                throw new DiskImageFormatException(String.Format("Unexpected block type {0}", blockId));
            }

            var data = new byte[info.Size];

            IOUtils.ReadBlock(trackStream, data, 0, info.Size);
            var crc1 = trackStream.ReadByte();
            var crc2 = trackStream.ReadByte();

            if (crc2 == -1)
            {
                throw new EndOfStreamException();
            }
            var crc = (crc1 << 8) | crc2;

            // TODO Verify disk sector CRC

            return(new HfeSector(info.Head, info.Track, info.Sector, data, 0, data.Length));
        }
コード例 #2
0
 public void EncodeSectorIdRecord()
 {
     var sectorInfo = new HfeSectorInfo(0, 1, 1, 256);
     var idRecord = new byte[] { 0xfe, 0x01, 0x00, 0x01, 0x01, 0x8c, 0xb8 };
     var encoded = sectorInfo.Encode();
     Assert.AreEqual(idRecord.Length, encoded.Length);
     for (var i = 0; i < idRecord.Length; i++ )
         Assert.AreEqual(idRecord[i], encoded[i]);
 }
コード例 #3
0
 public void CalculateCrc()
 {
     var sectorInfo = new HfeSectorInfo(0, 1, 1, 256);
     Assert.AreEqual((uint) 0x8cb8, sectorInfo.Crc);
 }