29 using System.Windows.Controls;
30 using System.Windows.Media;
71 fs =
new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
73 catch (Exception exc) {
74 Console.WriteLine(
"Error: {0}", exc.Message);
79 byte[] sbuf =
new byte[fs.Length];
80 int bytes = fs.Read(sbuf, 0, (
int)fs.Length);
81 Debug.Assert(bytes == fs.Length);
106 file.
version = readUInt16(buffer, ref bpos);
107 file.
tool = readUInt16(buffer, ref bpos);
108 file.
reserved_1 = readUInt16(buffer, ref bpos);
110 file.
revision = readByte(buffer, ref bpos);
111 file.
reserved_2 = readUInt32(buffer, ref bpos);
119 _infoBox.FontFamily =
new FontFamily(
"Consolas");
120 _infoBox.FontSize = 14;
121 _infoBox.AppendText(file.
ToString());
122 _infoBox.AppendText(String.Format(
" - ({0}-{1})\n", startPos, bpos - 1));
123 _infoBox.ScrollToHome();
132 for (
int tnum = 0; tnum < file.
trackCount; tnum++) {
133 uint track_record_start = bpos;
135 Debug.Assert((startPos % 2) == 0,
"Track Descriptor not word aligned", String.Format(
"Address = {0}", startPos));
143 td.
trackType = readByte(buffer, ref bpos);
149 _infoBox.AppendText(String.Format(
" ({0}-{1})\n", startPos, bpos - 1));
163 for (
int snum = 0; snum < td.
sectorCount; snum++) {
168 sectors[snum].
dataOffset = readUInt32(buffer, ref bpos);
169 sectors[snum].
bitPosition = readUInt16(buffer, ref bpos);
170 sectors[snum].
readTime = readUInt16(buffer, ref bpos);
171 sectors[snum].
id.
track = readByte(buffer, ref bpos);
172 sectors[snum].
id.
side = readByte(buffer, ref bpos);
173 sectors[snum].
id.
number = readByte(buffer, ref bpos);
174 sectors[snum].
id.
size = readByte(buffer, ref bpos);
175 sectors[snum].
id.
crc = readUInt16(buffer, ref bpos);
176 sectors[snum].
fdcFlags = readByte(buffer, ref bpos);
177 sectors[snum].
reserved = readByte(buffer, ref bpos);
179 _infoBox.AppendText(sectors[snum].ToString());
180 _infoBox.AppendText(String.Format(
" ({0}-{1})\n", startPos, bpos - 1));
190 byte[] fuzzyMask = null;
196 fuzzyMask[i] = readByte(buffer, ref bpos);
197 _infoBox.AppendText(String.Format(
" Reading Fuzzy {0} bytes ({1}-{2})\n", td.
fuzzyCount, startPos, bpos - 1));
201 uint track_data_start = bpos;
202 _infoBox.AppendText(String.Format(
" Start of Track data {0}\n", track_data_start));
205 if ((td.
trackFlags & TrackDesc.TRK_IMAGE) != 0) {
209 if ((td.
trackFlags & TrackDesc.TRK_SYNC) != 0)
220 maxBufPos = Math.Max(maxBufPos, bpos + bpos % 2);
222 _infoBox.AppendText(String.Format(
" Reading Track Image {0}{1} bytes SyncPos={2} ({3}-{4})\n",
228 bool bitWidth =
false;
229 for (
int snum = 0; snum < td.
sectorCount; snum++) {
230 if (((sectors[snum].fdcFlags & SectorDesc.
BIT_WIDTH) != 0) && (file.
revision == 2))
234 if ((sectors[snum].fdcFlags & SectorDesc.
SECT_RNF) == 0) {
236 bpos = track_data_start + sectors[snum].dataOffset;
238 for (
int i = 0; i < 128 << sectors[snum].id.size; i++)
240 maxBufPos = Math.Max(maxBufPos, bpos);
241 _infoBox.AppendText(String.Format(
" Reading Sector {0} {1} bytes ({2}-{3}) {4}\n",
243 (((td.
trackFlags & TrackDesc.TRK_IMAGE) != 0) && (sectors[snum].dataOffset < fd.
tracks[track, side].
byteCount)) ?
" in Track Image" :
""));
248 ushort[] timing = null;
252 ushort timingFlags = readUInt16(buffer, ref bpos);
253 ushort timingSize = readUInt16(buffer, ref bpos);
254 int entries = (timingSize - 4) / 2;
255 timing =
new ushort[entries];
256 for (
int i = 0; i < entries; i++) {
258 timing[i] = (ushort)(readByte(buffer, ref bpos) << 8);
259 timing[i] = readByte(buffer, ref bpos);
261 maxBufPos = Math.Max(maxBufPos, bpos);
262 _infoBox.AppendText(String.Format(
" Reading Timing {0} bytes Flag={1} ({2}-{3})\n", timingSize, timingFlags, startPos, bpos - 1));
268 for (
int snum = 0; snum < td.
sectorCount; snum++) {
271 int fsize = 128 << sectors[snum].id.size;
273 for (
int i = 0; i < fsize; i++)
276 _infoBox.AppendText(String.Format(
" Transferring {0} Fuzzy bytes to sect {1}\n", fsize, fd.
tracks[track, side].
sectors[snum].
id.
number));
279 if ((sectors[snum].fdcFlags & SectorDesc.BIT_WIDTH) != 0) {
280 int tsize = (128 << sectors[snum].id.size) / 16;
283 for (
int i = 0; i < tsize; i++)
285 startTiming += tsize;
286 _infoBox.AppendText(String.Format(
" Transferring {0} Timing values to sect {1}\n", tsize, fd.
tracks[track, side].
sectors[snum].
id.
number));
289 for (
int i = 0; i < tsize; i++) {
299 Debug.Assert(timing.Length == startTiming,
"invalid timing size");
300 if (fuzzyMask != null)
301 Debug.Assert(fuzzyMask.Length == startFuzzy,
"invalid fuzzy size");
306 for (
int snum = 0; snum < td.
sectorCount; snum++) {
310 for (
int i = 0; i < 512; i++)
322 _infoBox.AppendText(String.Format(
" Standard Sector {0} {1} bytes ({2}-{3})\n", snum, 512, startPos, bpos));
323 maxBufPos = Math.Max(maxBufPos, bpos);
328 maxBufPos += maxBufPos % 2;
330 Debug.Assert(maxBufPos == track_record_start + td.
recordSize,
"Invalid Track Size",
331 String.Format(
"Track {0} Current pointer position = {1} next track = {2}", td.
trackNumber, bpos, track_record_start + td.
recordSize));
340 private static uint readUInt32(byte[] buf, ref uint pos) {
341 uint val = (uint)buf[pos] + (uint)(buf[pos + 1] << 8) + (uint)(buf[pos + 2] << 16) + (uint)(buf[pos + 3] << 24);
347 private static ushort readUInt16(byte[] buf, ref uint pos) {
348 ushort val = (ushort)buf[pos];
349 val += (ushort)(buf[pos + 1] << 8);
355 private static byte readByte(byte[] buf, ref uint pos) {
360 private static char readChar(byte[] buf, ref uint pos) {
361 return (
char)buf[pos++];
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...
byte reserved
Reserved (should be 0x00)
Could not open file for reading or file not found
ushort crc
CRC Value from address field
override string ToString()
Override ToString() to display File header information
byte trackType
track image type (not used)
byte track
Track number from address field
uint sectorCount
Number of sectors for this track
Contains information about one sector
ushort sectorCount
number of sectors in the track
uint fuzzyCount
number of bytes in the fuzzy mask
ushort readTime
This field contains either zero or the read time for the sector data block.
ushort bitPosition
position in the track of the sector address field in bits
const byte TRK_SECT_DESC
The track record contains sectorCount SectDesc
ushort bitPosition
This field store the position in number of bits of this sector address block from the index...
byte size
Size value from address field
PastiStatus readPasti(string fileName, Floppy fd)
Read a Pasti file and fills the Floppy structure
PastiReader(TextBox tb)
The Pasti reader constructor
byte[] trackData
buffer for the track data if necessary
const byte SECT_RNF
RNF or Seek error
bool standardTrack
The track follow the Atari standard
Contains information about one Track
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
Pasti File Sector Descriptor
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
The header in the file is not RSY
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
IDField id
Address field of sector (refer to the Address structure)
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
byte fdcFlags
This field contains a mixture of the FDC status, as it would have been read by the WD1772...
string pastiFileId
Identify a Pasti file and should be equal to the null terminated string “RSY”
uint dataOffset
Offset of sector data inside the track record
byte side
Head number from address field
byte[] fuzzyData
buffer for fuzzy mask bytes if necessary
ushort reserved_1
Reserved
const byte BIT_WIDTH
Sector has bit width variation
byte fdcFlags
Status returned by the FDC
PastiStatus
Status returned when reading Pasti file