protected virtual void SaveToStream(Stream stream) { // save at least 80 cylinders var cylCount = m_diskImage.CylynderCount < 80 ? 80 : m_diskImage.CylynderCount; var secSize = 128 << (SectorSizeCode & 3); for (var c = 0; c < cylCount; c++) { for (var h = 0; h < 2; h++) { var il = GetSectorMap(c, h); for (var s = 0; s < il.Length; s++) { var buffer = new byte[secSize]; if (c < m_diskImage.CylynderCount) { if (m_diskImage.GetLogicalSectorSizeCode(c, h, il[s]) != (SectorSizeCode & 3)) { throw new NotSupportedException( string.Format( "Cannot save because disk contains data which is not supported by {0}", FormatName)); } m_diskImage .ReadLogicalSector(c, h, il[s], buffer); } stream.Write(buffer, 0, buffer.Length); } } } }