IPF Image-File Reader-Writer  1.0
IPF File information
BufferWindow.xaml.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using System.Windows;
7 using System.Windows.Controls;
8 using System.Windows.Data;
9 using System.Windows.Documents;
10 using System.Windows.Input;
11 using System.Windows.Media;
12 using System.Windows.Media.Imaging;
13 using System.Windows.Shapes;
14 
15 namespace ipf {
19  public partial class BufferWindow : Window {
20  public BufferWindow() {
21  InitializeComponent();
22  }
23 
30  public void displayBlocksBuffer(Floppy floppy, int track, int side) {
31  displayBuffer.FontFamily = new FontFamily("Consolas");
32  displayBuffer.FontSize = 16;
33  displayBuffer.FontStyle = FontStyles.Normal;
34  displayBuffer.FontWeight = FontWeights.Normal;
35 
36  Track t = floppy.tracks[track, side];
37  displayBuffer.AppendText(String.Format("Track {0:D2}.{1} has {2} blocks\n", track, side, t.blockCount));
38  uint trackGapSum = 0;
39  uint trackDataSum = 0;
40 
41  for (int sect = 0; sect < t.blockCount; sect++) {
42  uint gapSum = 0;
43  uint dataSum = 0;
44  Sector s = t.sectors[sect];
45  foreach (GapElement gap in s.gapElems)
46  gapSum += gap.gapBytes;
47  foreach (DataElem data in s.dataElems)
48  dataSum += (data.type == DataType.Sync) ? (data.dataBytes / 2) : data.dataBytes;
49  displayBuffer.AppendText(String.Format("Sector {0} Total={1} bytes (Gap={2} Data={3}) in Block Descriptor: (Gap={4} Data={5})\n",
50  sect, gapSum + dataSum, gapSum, dataSum, s.gapBits * 8, s.dataBits * 8));
51 
52  foreach (GapElement gap in s.gapElems) {
53  displayBuffer.AppendText(String.Format(" - {0} Gap {1} Value={2:X2}\n",
54  (gap.type == GapType.Forward) ? "Forward" : "Backward", (gap.gapBytes == 0) ? "Repeat" : gap.gapBytes.ToString() + " bytes", gap.value));
55  }
56  if (gapSum != (s.gapBits * 8))
57  displayBuffer.AppendText(String.Format(" = Gap filling required: only {0} bytes specified out of {1}\n", gapSum, s.gapBits * 8));
58 
59  foreach (DataElem data in s.dataElems) {
60  displayBuffer.AppendText(String.Format(" + {0} {1} bytes\n",
61  data.type.ToString(), (data.type == DataType.Sync) ? (data.dataBytes / 2) : data.dataBytes));
62  drawBuffer(data.value, data.type == DataType.Sync);
63  }
64  trackDataSum += dataSum;
65  trackGapSum += gapSum;
66  }
67  displayBuffer.AppendText(String.Format("Track {0:D2}.{1} Specified Bytes={2} ({3}) Data={4} ({5}) Gap={6} ({7})\n", track, side,
68  trackDataSum + trackGapSum, (trackDataSum+trackGapSum)*8, trackDataSum, trackDataSum*8, trackGapSum, trackGapSum*8));
69  }
70 
71 
72 
73 
78  public void drawBuffer(List<byte> buffer, bool sync) {
79  displayBuffer.FontFamily = new FontFamily("Consolas");
80  displayBuffer.FontSize = 16;
81  displayBuffer.FontStyle = FontStyles.Normal;
82  displayBuffer.FontWeight = FontWeights.Normal;
83 
84  for (int i = 0; i < buffer.Count(); i += 16) {
85  displayBuffer.AppendText(String.Format(" {0:D4} ", i));
86 
87  string ascii = " ";
88  for (int j = 0; j < 16; j++) {
89  if ((i + j) < buffer.Count()) {
90  displayBuffer.AppendText(String.Format("{0:X2}{1}", buffer[i + j], (sync && (j % 2 == 0)) ? "" : " "));
91  char ch = Convert.ToChar(buffer[i + j]);
92  ascii += Char.IsControl(ch) ? "." : ch.ToString();
93  }
94  else
95  displayBuffer.AppendText(String.Format(" "));
96  } // one more line
97  displayBuffer.AppendText(ascii);
98  displayBuffer.AppendText(String.Format("\n"));
99  } // all lines
100  }
101 
102  }
103 }
Interaction logic for BufferWindow.xaml
DataType
Type of Data in data element
Definition: IPFStruct.cs:68
Store information about all tracks of a FD
Definition: Floppy.cs:56
void drawBuffer(List< byte > buffer, bool sync)
Display the content of TrackBuffer buffer in the displayBuffer TextBox
Store the sector/bloc information
Definition: Floppy.cs:30
GapType
Type of a gap element
Definition: IPFStruct.cs:71
Definition: App.xaml.cs:9
void displayBlocksBuffer(Floppy floppy, int track, int side)
Draw the content of the buffer
Store the content of a data element.
Definition: Floppy.cs:21
Store the content of a gap element including the gap value
Definition: Floppy.cs:12
Store information about one track
Definition: Floppy.cs:41