@@ -89,13 +89,13 @@ typedef struct alignas(8) {
89
89
unsigned char sectorNumber; // The sector we just read (0 to 11)
90
90
unsigned char sectorsRemaining; // How many more sectors remain until the gap (0 to 10)
91
91
92
- unsigned long sectorLabel[4 ]; // OS Recovery Data, we ignore this
92
+ uint32_t sectorLabel[4 ]; // OS Recovery Data, we ignore this
93
93
94
- unsigned long headerChecksum; // Read from the header, header checksum
95
- unsigned long dataChecksum; // Read from the header, data checksum
94
+ uint32_t headerChecksum; // Read from the header, header checksum
95
+ uint32_t dataChecksum; // Read from the header, data checksum
96
96
97
- unsigned long headerChecksumCalculated; // The header checksum we calculate
98
- unsigned long dataChecksumCalculated; // The data checksum we calculate
97
+ uint32_t headerChecksumCalculated; // The header checksum we calculate
98
+ uint32_t dataChecksumCalculated; // The data checksum we calculate
99
99
100
100
RawDecodedSector data; // decoded sector data
101
101
@@ -116,15 +116,15 @@ struct DecodedTrack {
116
116
// *input; MFM coded data buffer (size == 2*data_size)
117
117
// *output; decoded data buffer (size == data_size)
118
118
// Returns the checksum calculated over the data
119
- unsigned long decodeMFMdata (const unsigned long * input, unsigned long * output, const unsigned int data_size) {
120
- unsigned long odd_bits, even_bits;
121
- unsigned long chksum = 0L ;
119
+ uint32_t decodeMFMdata (const uint32_t * input, uint32_t * output, const unsigned int data_size) {
120
+ uint32_t odd_bits, even_bits;
121
+ uint32_t chksum = 0L ;
122
122
unsigned int count;
123
123
124
124
// the decoding is made here long by long : with data_size/4 iterations
125
125
for (count = 0 ; count < data_size / 4 ; count++) {
126
126
odd_bits = *input; // longs with odd bits
127
- even_bits = *(unsigned long *)(((unsigned char *)input) + data_size); // longs with even bits - located 'data_size' bytes after the odd bits
127
+ even_bits = *(uint32_t *)(((unsigned char *)input) + data_size); // longs with even bits - located 'data_size' bytes after the odd bits
128
128
129
129
chksum ^= odd_bits; // XOR Checksum
130
130
chksum ^= even_bits;
@@ -140,12 +140,12 @@ unsigned long decodeMFMdata(const unsigned long* input, unsigned long* output, c
140
140
// *input; RAW data buffer (size == data_size)
141
141
// *output; MFM encoded buffer (size == data_size*2)
142
142
// Returns the checksum calculated over the data
143
- unsigned long encodeMFMdataPart1 (const unsigned long * input, unsigned long * output, const unsigned int data_size) {
144
- unsigned long chksum = 0L ;
143
+ uint32_t encodeMFMdataPart1 (const uint32_t * input, uint32_t * output, const unsigned int data_size) {
144
+ uint32_t chksum = 0L ;
145
145
unsigned int count;
146
146
147
- unsigned long * outputOdd = output;
148
- unsigned long * outputEven = (unsigned long *)(((unsigned char *)output) + data_size);
147
+ uint32_t * outputOdd = output;
148
+ uint32_t * outputEven = (uint32_t *)(((unsigned char *)output) + data_size);
149
149
150
150
// Encode over two passes. First split out the odd and even data, then encode the MFM values, the /4 is because we're working in longs, not bytes
151
151
for (count = 0 ; count < data_size / 4 ; count++) {
@@ -301,11 +301,11 @@ bool decodeSector(const RawEncodedSector& rawSector, const unsigned int trackNum
301
301
unsigned char * sectorData = (unsigned char *)rawSector;
302
302
303
303
// Read the first 4 bytes (8). This is the track header data
304
- sector.headerChecksumCalculated = decodeMFMdata ((unsigned long *)(sectorData + 8 ), (unsigned long *)§or, 4 );
304
+ sector.headerChecksumCalculated = decodeMFMdata ((uint32_t *)(sectorData + 8 ), (uint32_t *)§or, 4 );
305
305
// Decode the label data and update the checksum
306
- sector.headerChecksumCalculated ^= decodeMFMdata ((unsigned long *)(sectorData + 16 ), (unsigned long *)§or.sectorLabel [0 ], 16 );
306
+ sector.headerChecksumCalculated ^= decodeMFMdata ((uint32_t *)(sectorData + 16 ), (uint32_t *)§or.sectorLabel [0 ], 16 );
307
307
// Get the checksum for the header
308
- decodeMFMdata ((unsigned long *)(sectorData + 48 ), (unsigned long *)§or.headerChecksum , 4 ); // (computed on mfm longs, longs between offsets 8 and 44 == 2 * (1 + 4) longs)
308
+ decodeMFMdata ((uint32_t *)(sectorData + 48 ), (uint32_t *)§or.headerChecksum , 4 ); // (computed on mfm longs, longs between offsets 8 and 44 == 2 * (1 + 4) longs)
309
309
// If the header checksum fails we just cant trust anything we received, so we just drop it
310
310
if ((sector.headerChecksum != sector.headerChecksumCalculated ) && (!ignoreHeaderChecksum)) {
311
311
return false ;
@@ -329,7 +329,7 @@ bool decodeSector(const RawEncodedSector& rawSector, const unsigned int trackNum
329
329
if (sector.trackNumber != targetTrackNumber) return false ; // this'd be weird
330
330
331
331
// Get the checksum for the data
332
- decodeMFMdata ((unsigned long *)(sectorData + 56 ), (unsigned long *)§or.dataChecksum , 4 );
332
+ decodeMFMdata ((uint32_t *)(sectorData + 56 ), (uint32_t *)§or.dataChecksum , 4 );
333
333
334
334
335
335
// Lets see if we already have this one
@@ -342,7 +342,7 @@ bool decodeSector(const RawEncodedSector& rawSector, const unsigned int trackNum
342
342
if (index != decodedTrack.validSectors .end ()) return true ;
343
343
344
344
// Decode the data and receive it's checksum
345
- sector.dataChecksumCalculated = decodeMFMdata ((unsigned long *)(sectorData + 64 ), (unsigned long *)§or.data [0 ], SECTOR_BYTES); // (from 64 to 1088 == 2*512 bytes)
345
+ sector.dataChecksumCalculated = decodeMFMdata ((uint32_t *)(sectorData + 64 ), (uint32_t *)§or.data [0 ], SECTOR_BYTES); // (from 64 to 1088 == 2*512 bytes)
346
346
347
347
// Is the data valid?
348
348
if (sector.dataChecksum != sector.dataChecksumCalculated ) {
@@ -384,15 +384,15 @@ void encodeSector(const unsigned int trackNumber, const DiskSurface surface, con
384
384
header.sectorsRemaining = NUM_SECTORS_PER_TRACK - sectorNumber; // 1..11
385
385
386
386
387
- header.headerChecksumCalculated = encodeMFMdataPart1 ((const unsigned long *)&header, (unsigned long *)&encodedSector[8 ], 4 );
387
+ header.headerChecksumCalculated = encodeMFMdataPart1 ((const uint32_t *)&header, (uint32_t *)&encodedSector[8 ], 4 );
388
388
// Then theres the 16 bytes of the volume label that isnt used anyway
389
- header.headerChecksumCalculated ^= encodeMFMdataPart1 ((const unsigned long *)&header.sectorLabel , (unsigned long *)&encodedSector[16 ], 16 );
389
+ header.headerChecksumCalculated ^= encodeMFMdataPart1 ((const uint32_t *)&header.sectorLabel , (uint32_t *)&encodedSector[16 ], 16 );
390
390
// Thats 40 bytes written as everything doubles (8+4+4+16+16). - Encode the header checksum
391
- encodeMFMdataPart1 ((const unsigned long *)&header.headerChecksumCalculated , (unsigned long *)&encodedSector[48 ], 4 );
391
+ encodeMFMdataPart1 ((const uint32_t *)&header.headerChecksumCalculated , (uint32_t *)&encodedSector[48 ], 4 );
392
392
// And move on to the data section. Next should be the checksum, but we cant encode that until we actually know its value!
393
- header.dataChecksumCalculated = encodeMFMdataPart1 ((const unsigned long *)&input, (unsigned long *)&encodedSector[64 ], SECTOR_BYTES);
393
+ header.dataChecksumCalculated = encodeMFMdataPart1 ((const uint32_t *)&input, (uint32_t *)&encodedSector[64 ], SECTOR_BYTES);
394
394
// And add the checksum
395
- encodeMFMdataPart1 ( (const unsigned long *)&header.dataChecksumCalculated , (unsigned long *)&encodedSector[56 ], 4 );
395
+ encodeMFMdataPart1 ( (const uint32_t *)&header.dataChecksumCalculated , (uint32_t *)&encodedSector[56 ], 4 );
396
396
397
397
// Now fill in the MFM clock bits
398
398
bool lastBit = encodedSector[7 ] & (1 << 0 );
@@ -418,14 +418,14 @@ void encodeSector(const unsigned int trackNumber, const DiskSurface surface, con
418
418
// Find sectors within raw data read from the drive by searching bit-by-bit for the SYNC bytes
419
419
void findSectors (const RawTrackData& track, unsigned int trackNumber, DiskSurface side, unsigned short trackSync, DecodedTrack& decodedTrack, bool ignoreHeaderChecksum) {
420
420
// Work out what we need to search for which is 2AAAAAAAsyncsync
421
- // const unsigned long long search = (trackSync | (((DWORD)trackSync) << 16)) | (((long long)0x2AAAAAAA) << 32);
421
+ // const uint32_t long search = (trackSync | (((DWORD)trackSync) << 16)) | (((long long)0x2AAAAAAA) << 32);
422
422
// For speed and to ignore some data errors, we now just search for syncsync and ignore the 2AAAAAAA part
423
423
424
424
// Work out what we need to search for which is syncsync
425
- const unsigned long search = (trackSync | (((unsigned long )trackSync) << 16 ));
425
+ const uint32_t search = (trackSync | (((uint32_t )trackSync) << 16 ));
426
426
427
427
// Prepare our test buffer
428
- unsigned long decoded = 0 ;
428
+ uint32_t decoded = 0 ;
429
429
430
430
// Keep runnign until we run out of data
431
431
unsigned int byteIndex = 0 ;
@@ -1243,7 +1243,7 @@ struct SCPFileHeader {
1243
1243
unsigned char bitcellEncoding;
1244
1244
unsigned char numHeads;
1245
1245
unsigned char timeBase;
1246
- unsigned long checksum;
1246
+ uint32_t checksum;
1247
1247
};
1248
1248
1249
1249
struct SCPTrackHeader {
@@ -1252,9 +1252,9 @@ struct SCPTrackHeader {
1252
1252
};
1253
1253
1254
1254
struct SCPTrackRevolution {
1255
- unsigned long indexTime; // Time in NS/25 for this revolution
1256
- unsigned long trackLength; // Number of bit-cells in this revolution
1257
- unsigned long dataOffset; // From the start of SCPTrackHeader
1255
+ uint32_t indexTime; // Time in NS/25 for this revolution
1256
+ uint32_t trackLength; // Number of bit-cells in this revolution
1257
+ uint32_t dataOffset; // From the start of SCPTrackHeader
1258
1258
};
1259
1259
1260
1260
// Track data is 16-bit value in NS/25. If =0 means no flux transition for max time
@@ -1324,7 +1324,7 @@ ADFResult ADFWriter::DiskToSCP(const std::wstring& outputFile, const unsigned in
1324
1324
}
1325
1325
1326
1326
// Pad out the records. Theres 4 bytes for each track
1327
- unsigned long notPresent = 0 ;
1327
+ uint32_t notPresent = 0 ;
1328
1328
for (unsigned int a = 0 ; a <168 ; a++) {
1329
1329
try {
1330
1330
hADFFile.write ((const char *)¬Present, sizeof (notPresent));
@@ -1433,7 +1433,7 @@ ADFResult ADFWriter::DiskToSCP(const std::wstring& outputFile, const unsigned in
1433
1433
}
1434
1434
1435
1435
// Get the current position
1436
- unsigned long currentPosition = (unsigned long )hADFFile.tellp ();
1436
+ uint32_t currentPosition = (uint32_t )hADFFile.tellp ();
1437
1437
1438
1438
// Move to the beginning of the file, and write the offset for where this starts
1439
1439
hADFFile.seekp (sizeof (header) + (track.header .trackNumber * 4 ), std::fstream::beg);
@@ -1487,7 +1487,7 @@ ADFResult ADFWriter::DiskToSCP(const std::wstring& outputFile, const unsigned in
1487
1487
while (hADFFile.good ()) {
1488
1488
try {
1489
1489
hADFFile.read ((char *)buffer, sizeof (buffer));
1490
- const unsigned long read = sizeof (buffer) / 4 ;
1490
+ const uint32_t read = sizeof (buffer) / 4 ;
1491
1491
for (size_t pos = 0 ; pos < read ; pos++)
1492
1492
header.checksum += buffer[pos];
1493
1493
}
0 commit comments