26 using System.Collections.Generic;
 
   31 using System.Threading.Tasks;
 
   32 using System.Windows.Controls;
 
   33 using System.Windows.Media;
 
   75             List<byte> sbuf = 
new List<byte>();
 
   80                 fs = 
new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read);
 
   82             catch (Exception exc) {
 
   83                 Console.WriteLine(
"Error: {0}", exc.Message);
 
   86             fs.Write(sbuf.ToArray(), 0 , sbuf.Count);
 
  104             for (
int track = 0; track < 84; track++)
 
  105                 for (
int side = 0; side < 2; side++)
 
  106                     if (floppy.
tracks[track, side] != null) trackCount++;
 
  114             writeByte(buffer, (byte)
'R');           
 
  115             writeByte(buffer, (byte)
'S');
 
  116             writeByte(buffer, (byte)
'Y');
 
  117             writeByte(buffer, 0);
 
  119             writeInt16(buffer, fd.
version);         
 
  120             writeInt16(buffer, fd.
tool);            
 
  121             writeInt16(buffer, 0);                  
 
  124             writeInt32(buffer, 0);                  
 
  127             _infoBox.ScrollToHome();
 
  128             _infoBox.FontFamily = 
new FontFamily(
"Consolas");
 
  129             _infoBox.FontSize = 14;
 
  131             _infoBox.AppendText(String.Format(
" - ({0}-{1})\n", start, buffer.Count-1));
 
  135             for (
int track = 0; track < 84; track++)
 
  136                 for (
int side = 0; side < 2; side++) {
 
  137                     if (floppy.
tracks[track, side] == null) 
continue;
 
  138                     int startTrackRecord = buffer.Count;
 
  150                     if (trackNeedSectorDesc(floppy.
tracks[track, side])) {
 
  156                     for (
int sect = 0; sect < floppy.
tracks[track, side].
sectors.Count(); sect++)
 
  161                     bool trkSync = 
false;
 
  163                     if (trackNeedTrackData(floppy.
tracks[track, side])) {
 
  165                             td.
trackFlags |= TrackDesc.TRK_IMAGE | TrackDesc.TRK_SYNC;
 
  178                     int timingEntries = 0;
 
  179                     for (
int sect = 0; sect < floppy.
tracks[track, side].
sectors.Count(); sect++)
 
  183                     if (timingEntries > 0)
 
  184                         td.
recordSize += (uint)((2 * timingEntries) + 4);
 
  187                     for (
int sect = 0; sect < floppy.
tracks[track, side].
sectors.Count(); sect++)
 
  195                     start = buffer.Count;
 
  205                     _infoBox.AppendText(String.Format(
" ({0}-{1})\n", start, buffer.Count - 1));
 
  208                     if (trackNeedSectorDesc(floppy.
tracks[track, side])) {
 
  210                         if (trackNeedTrackData(floppy.
tracks[track, side]))
 
  213                             SectorDesc sd = 
new SectorDesc();
 
  214                             sd.dataOffset = offset;
 
  223                             start = buffer.Count;
 
  224                             writeInt32(buffer, sd.dataOffset);
 
  225                             writeInt16(buffer, sd.bitPosition);
 
  226                             writeInt16(buffer, sd.readTime);
 
  228                             writeByte(buffer, sd.id.track);
 
  229                             writeByte(buffer, sd.id.side);
 
  230                             writeByte(buffer, sd.id.number);
 
  231                             writeByte(buffer, sd.id.size);
 
  232                             writeInt16(buffer, sd.id.crc);
 
  234                             writeByte(buffer, sd.fdcFlags);
 
  235                             writeByte(buffer, sd.reserved);
 
  237                             _infoBox.AppendText(sd.ToString());
 
  238                             _infoBox.AppendText(String.Format(
" ({0}-{1})\n", start, buffer.Count - 1));
 
  245                             start = buffer.Count;
 
  248                             _infoBox.AppendText(String.Format(
"   Writing Fuzzy {0} bytes for sector {1} ({2}-{3})\n",
 
  255                     int track_data_start = buffer.Count; 
 
  256                     _infoBox.AppendText(String.Format(
"   Start of Track data {0}\n", track_data_start));
 
  259                     if (trackNeedTrackData(floppy.
tracks[track, side])) {
 
  260                         start = buffer.Count;
 
  268                             writeByte(buffer, 0xFF);
 
  270                         _infoBox.AppendText(String.Format(
"      Writing Track {0}{1} bytes SyncPos={2} ({3}-{4})\n",
 
  277                         start = buffer.Count;
 
  281                             _infoBox.AppendText(String.Format(
"      Writing Sector {0} {1} bytes ({2}-{3})\n",
 
  287                     if (timingEntries > 0) {
 
  289                         start = buffer.Count;
 
  290                         writeInt16(buffer, 0x05);
 
  291                         writeInt16(buffer, (ushort)(2 * timingEntries + 4));
 
  292                         _infoBox.AppendText(String.Format(
"   Writing Timing header Flag=5 size={0} ({1}-{2})\n", 2 * timingEntries + 4, start, buffer.Count - 1));
 
  296                                 start = buffer.Count;
 
  302                                 _infoBox.AppendText(String.Format(
"   Writing Timing {0} values for sector {1} ({2}-{3})\n",
 
  308                     if (buffer.Count % 2 != 0) {
 
  309                         writeByte(buffer, 0xFF);    
 
  312                     Debug.Assert(buffer.Count == startTrackRecord + td.
recordSize, 
"Invalid Track Size",
 
  313                         String.Format(
"Track {0} Current pointer position = {1} next track = {2}", td.
trackNumber, buffer.Count, startTrackRecord + td.
recordSize));
 
  321         private static void writeInt32(List<byte> buffer, uint val) {
 
  322             buffer.Add((byte)(val & 0xFF));
 
  323             buffer.Add((byte)((val >> 8) & 0xFF));
 
  324             buffer.Add((byte)((val >> 16) & 0xFF));
 
  325             buffer.Add((byte)((val >> 24) & 0xFF));
 
  329         private static void writeInt16(List<byte> buffer, ushort val) {
 
  330             buffer.Add((byte)(val & 0xFF));
 
  331             buffer.Add((byte)(val >> 8));
 
  334         private static void writeByte(List<byte> buffer, byte val) {
 
  339         private bool trackNeedSectorDesc(Track track) {
 
  349             for (
int sect = 0; sect < track.sectorCount; sect++) {
 
  351                 if (track.sectors[sect].id.number != secnum++) 
 
  352                     track.standardSectors = 
false;
 
  355                 for (
int j = sect + 1; j < track.sectorCount; j++)
 
  356                     if (track.sectors[sect].id.number == track.sectors[j].id.number)
 
  357                         track.standardSectors = 
false;
 
  360                 if ((track.sectors[sect].id.number >= 0xF5) && (track.sectors[sect].id.number <= 0xF7))
 
  361                     track.standardSectors = 
false;
 
  364                 if (track.sectors[sect].id.track != track.number)
 
  365                     track.standardSectors = 
false;
 
  368                 if (track.sectors[sect].id.side != track.side)
 
  369                     track.standardSectors = 
false;
 
  372                 if (track.sectors[sect].id.size > 3)
 
  373                     track.standardSectors = 
false;
 
  376                 if (track.sectors[sect].readTime != 0)
 
  377                     track.standardSectors = 
false;
 
  383                 if (track.sectors[sect].sectorData == null)
 
  384                     track.standardSectors = 
false;
 
  387                 if ((track.sectors[sect].fdcFlags & SectorDesc.CRC_ERR) != 0)
 
  388                     track.standardSectors = 
false;
 
  391                 if ((track.sectors[sect].fdcFlags & SectorDesc.REC_TYPE) != 0)
 
  392                     track.standardSectors = 
false;
 
  395                 if (track.sectors[sect].fuzzyData != null)
 
  396                     track.standardSectors = 
false;
 
  399                 if (track.sectors[sect].timmingData != null)
 
  400                     track.standardSectors = 
false;
 
  402             if (trackNeedTrackData(track))
 
  404             return !track.standardSectors;
 
  408         private bool trackNeedTrackData(Track track) {
 
  421             return !track.standardTrack;
 
Pasti File Track Descriptor
Track[,] tracks
Array of Tracks
Pasti File Header Descriptor
override string ToString()
Override ToString() to display Track header information 
ushort trackFlags
This field contain bit-mask flags that provide information about the content of the track record as f...
override string ToString()
Override ToString() to display File header information 
byte trackType
track image type (not used)
uint sectorCount
Number of sectors for this track
ushort sectorCount
number of sectors in the track
uint fuzzyCount
number of bytes in the fuzzy mask
ushort bitPosition
position in the track of the sector address field in bits
const byte TRK_SECT_DESC
The track record contains sectorCount SectDesc
byte size
Size value from address field
byte[] trackData
buffer for the track data if necessary
byte trackCount
Number of track records
ushort trackLength
length of the track in number of bytes. Usually around 6250 bytes.
ushort version
File version number: Should be equal to 3.
Contains information about a complete Floppy disk
byte trackNumber
Bit 7 contains the side (0 or 1) and bits 6-0 contain the track number (usually 0 to 79)...
IDField id
Address field content
PastiWriter(TextBox tb)
The Pasti Writer Constructor 
ushort firstSyncOffset
First sync byte offset: This is the offset in byte of the first 0xA1 sync byte found in the track...
byte number
Sector number from address field
uint byteCount
Number of bytes in the track
Sector[] sectors
Array of Sectors
ushort readTime
read time of the track in ms or 0 if standard sector
byte[] sectorData
buffer for the sector data
WriteStatus
Status returned when reading Pasti file 
ushort tool
Tool used to create image
uint recordSize
Total size of this track record. 
byte revision
revision number of the file. 
ushort[] timmingData
buffer for timing bytes if necessary
Could not open file for reading or file not found
WriteStatus writePasti(string fileName, Floppy fd)
Read a Pasti file and fills the Floppy structure 
byte[] fuzzyData
buffer for fuzzy mask bytes if necessary
The header in the file is not RSY
byte fdcFlags
Status returned by the FDC