public void ModifySectors(int index, int length, byte[] data, SectorProcessResult[] sectors) { int last = Math.Min(index + length, sectors.Length); for (int sectorNum = index; sectorNum < last; sectorNum++) { MapCell cell = WorkMap[sectorNum] & (MapCell.Highlighted | MapCell.Hover); switch (sectors[sectorNum]) { case SectorProcessResult.Unprocessed: WorkMap[sectorNum] = cell | MapCell.Unprocessed; break; case SectorProcessResult.Good: WorkMap[sectorNum] = cell | (DiskImage.AllBytes(data, sectorNum * SectorSize, SectorSize, ZeroByte) ? MapCell.Zero : MapCell.Good); break; case SectorProcessResult.Bad: WorkMap[sectorNum] = cell | MapCell.CrcError; break; case SectorProcessResult.NoHeader: WorkMap[sectorNum] = cell | MapCell.NoHeader; break; } } for (int i = sectors.Length; i < oldSectorArraySize; i++) { WorkMap[i] = 0; } oldSectorArraySize = sectors.Length; }
public void BuildMap(byte[] data, SectorProcessResult[] sectors) { int i; for (i = 0; i < sectors.Length; i++) { switch (sectors[i]) { case SectorProcessResult.Unprocessed: WorkMap[i] = MapCell.Unprocessed; break; case SectorProcessResult.Good: WorkMap[i] = DiskImage.AllBytes(data, i * SectorSize, SectorSize, ZeroByte) ? MapCell.Zero : MapCell.Good; break; case SectorProcessResult.Bad: WorkMap[i] = MapCell.CrcError; break; case SectorProcessResult.NoHeader: WorkMap[i] = MapCell.NoHeader; break; } } for (; i < WorkMap.Length; i++) { WorkMap[i] = 0; } oldSectorArraySize = sectors.Length; }
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; }
/// <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); }