public virtual object Clone() { DiskImage image = new DiskImage(); image.Data = new byte[Data.Length]; Data.CopyTo(image.Data, 0); image.Sectors = new SectorProcessResult[Sectors.Length]; Sectors.CopyTo(image.Sectors, 0); image.Name = Name; image.FileName = FileName; return(image); }
public void WriteGoodSector(IntPtr memoryHandle, TrackFormat trackF, int sectorIndex) { trackF.Layout.Data[sectorIndex].WriteData(memoryHandle); trackF.Layout.Data[sectorIndex].ProcessResult = SectorProcessResult.Good; Modified = true; // %%% Здесь должен быть вызов Map и функции SectorsChanged(sectorNum, sectorCount); if (DiskImage.AllBytes(trackF.Layout.Data[sectorIndex].Data, 0, trackF.Layout.Data[sectorIndex].SizeBytes, 0)) { trackF.Layout.Data[sectorIndex].MapCellValue = MapCell.Zero; } else { trackF.Layout.Data[sectorIndex].MapCellValue = MapCell.Good; // это наверное надо перенести в Map. } trackF.MapModified = true; }
public void Merge(DiskImage image, out int addedReadSectors) { int size = Math.Max(image.Data.Length, Data.Length); int sizeSectors = size / SectorSize; byte[] newData = new byte[size]; SectorProcessResult[] sectors = new SectorProcessResult[sizeSectors]; addedReadSectors = 0; for (int i = 0; i < sizeSectors; i++) { if (i < Sectors.Length && Sectors[i] == SectorProcessResult.Good) { Array.Copy(Data, i * SectorSize, newData, i * SectorSize, SectorSize); sectors[i] = SectorProcessResult.Good; } else if (i < image.Sectors.Length && image.Sectors[i] == SectorProcessResult.Good) { Array.Copy(image.Data, i * SectorSize, newData, i * SectorSize, SectorSize); sectors[i] = SectorProcessResult.Good; addedReadSectors++; } else if (i < Sectors.Length && Sectors[i] == SectorProcessResult.Bad) { sectors[i] = SectorProcessResult.Bad; } else if (i < image.Sectors.Length && image.Sectors[i] == SectorProcessResult.Bad) { sectors[i] = SectorProcessResult.Bad; } else { sectors[i] = SectorProcessResult.Unprocessed; } } Data = newData; Sectors = sectors; SectorsChanged(0, Sectors.Length); }
/// <summary> /// 0 - Нет ошибок. /// 1 - Размер файла слишком мал. /// 5 - Размер файла слишком мал и содержит не все данные содержимого секторов. /// 6 - Нет сигнатуры FDI. /// </summary> /// <param name="fileName"></param> /// <param name="map"></param> /// <returns></returns> public unsafe int LoadFdi(string fileName, byte[] data, out string text) { Clear(); text = null; if (data.Length < 14) { return(1); } if (data[0] != 'F' || data[1] != 'D' || data[2] != 'I') { return(6); } int cylCount; int textOffset; int dataOffset; fixed(byte *d = &data[0]) { cylCount = *(ushort *)(d + 4); textOffset = *(ushort *)(d + 8); dataOffset = *(ushort *)(d + 10); } int minFileSize = 7 * cylCount * 2 + 14; if (data.Length < minFileSize || data.Length < textOffset + 1) { return(1); } int tt = textOffset; for (; tt < data.Length; tt++) { if (data[tt] == 0) { break; } } int textLen = tt - textOffset; text = textLen > 0 ? Encoding.ASCII.GetString(data, textOffset, tt - textOffset) : null; int index = 14; for (int track = 0; track < cylCount * 2; track++) { int trackOffset; fixed(byte *d = &data[index]) { trackOffset = *((int *)d); } int sectorsOnTrack = data[index + 6]; TrackFormat tf = Tracks.Data[track]; tf.Layout.EnsureCapacity(sectorsOnTrack); tf.Layout.Cnt = sectorsOnTrack; tf.SpinTime = TrackFormat.SpinTimeStandard; tf.MapModified = true; index += 7; double totalTimeMs = 0; for (int sector = 0; sector < sectorsOnTrack; sector++) { tf.Layout.Data[sector].Cylinder = data[index]; tf.Layout.Data[sector].Head = data[index + 1]; tf.Layout.Data[sector].SectorNumber = data[index + 2]; tf.Layout.Data[sector].SizeCode = data[index + 3]; int code = data[index + 4] & 63; tf.Layout.Data[sector].ProcessResult = code == 0 ? SectorProcessResult.Bad : SectorProcessResult.Good; int sectorOffset; fixed(byte *d = &data[index + 5]) { sectorOffset = *((ushort *)d); } int sizeBytes = tf.Layout.Data[sector].SizeBytes; if (data.Length < dataOffset + trackOffset + sectorOffset + sizeBytes) { return(5); } if (tf.Layout.Data[sector].Data == null || tf.Layout.Data[sector].Data.Length < tf.Layout.Data[sector].SizeBytes) { tf.Layout.Data[sector].Data = new byte[tf.Layout.Data[sector].SizeBytes]; } tf.Layout.Data[sector].MapCellValue = tf.Layout.Data[sector].ProcessResult == SectorProcessResult.Good ? MapCell.Good : MapCell.CrcError; Array.Copy(data, dataOffset + trackOffset + sectorOffset, tf.Layout.Data[sector].Data, 0, sizeBytes); if (tf.Layout.Data[sector].ProcessResult == SectorProcessResult.Good && DiskImage.AllBytes(tf.Layout.Data[sector].Data, 0, tf.Layout.Data[sector].SizeBytes, 0)) { tf.Layout.Data[sector].MapCellValue = MapCell.Zero; } index += 7; tf.Layout.Data[sector].TimeCalculated = true; if (sector != 0) { tf.Layout.Data[sector].TimeMs = (tf.Layout.Data[sector - 1].SizeBytes + TrackFormat.NormalSectorHeaderSize + 1) / TrackFormat.BytesPerMsStandard; totalTimeMs += tf.Layout.Data[sector].TimeMs; } } tf.FormatName = tf.GetFormatName(); if (sectorsOnTrack > 0) { tf.Layout.Data[0].TimeMs = Math.Max(0, TrackFormat.SpinTimeStandard - totalTimeMs); } } FileName = fileName; Name = Path.GetFileNameWithoutExtension(fileName); Modified = false; return(0); }
public int LoadTrd(string fileName, byte[] data, bool modifiedTrd) { Clear(); const int sectorSize = 256; int sizeSectors = data.Length / sectorSize; if (sizeSectors * sectorSize != data.Length) { return(1); } int sizeTracks = sizeSectors / 16; FileName = fileName; Name = Path.GetFileNameWithoutExtension(fileName); for (int track = 0; track < sizeTracks; track++) { TrackFormat tf = Tracks[track]; tf.Layout.Cnt = 16; for (int sector = 0; sector < 16; sector++) { tf.Layout.Data[sector].Cylinder = track / 2; tf.Layout.Data[sector].Head = track & 1; tf.Layout.Data[sector].SectorNumber = sector + 1; tf.Layout.Data[sector].SizeCode = 1; tf.Layout.Data[sector].TimeMs = 12.5; tf.FormatName = TrackFormatName.TrDosSequential; tf.Layout.Cnt = 16; tf.SpinTime = TrackFormat.SpinTimeStandard; int adr = track * 16 * 256 + sector * 256; if (tf.Layout.Data[sector].Data == null || tf.Layout.Data[sector].Data.Length < 256) { tf.Layout.Data[sector].Data = new byte[256]; } Array.Copy(data, adr, tf.Layout.Data[sector].Data, 0, 256); tf.Layout.Data[sector].ProcessResult = SectorProcessResult.Good; tf.Layout.Data[sector].MapCellValue = MapCell.Good; if (modifiedTrd) { if (DiskImage.AllBytes(tf.Layout.Data[sector].Data, 0, 256, (byte)'B')) { tf.Layout.Data[sector].ProcessResult = SectorProcessResult.Bad; tf.Layout.Data[sector].MapCellValue = MapCell.CrcError; } else if (DiskImage.AllBytes(tf.Layout.Data[sector].Data, 0, 256, (byte)'N')) { tf.Layout.Data[sector].ProcessResult = SectorProcessResult.Unprocessed; tf.Layout.Data[sector].MapCellValue = MapCell.Unprocessed; } } if (tf.Layout.Data[sector].MapCellValue == MapCell.Good && DiskImage.AllBytes(tf.Layout.Data[sector].Data, 0, 256, 0)) { tf.Layout.Data[sector].MapCellValue = MapCell.Zero; } tf.Layout.Data[sector].TimeCalculated = true; } tf.MapModified = true; } Modified = false; return(0); }