Skip to content

Commit 0c55bcb

Browse files
committed
switch to uint32_t
1 parent 56ddaba commit 0c55bcb

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

Diff for: ArduinoFloppyReader/lib/ADFWriter.cpp

+33-33
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ typedef struct alignas(8) {
8989
unsigned char sectorNumber; // The sector we just read (0 to 11)
9090
unsigned char sectorsRemaining; // How many more sectors remain until the gap (0 to 10)
9191

92-
unsigned long sectorLabel[4]; // OS Recovery Data, we ignore this
92+
uint32_t sectorLabel[4]; // OS Recovery Data, we ignore this
9393

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
9696

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
9999

100100
RawDecodedSector data; // decoded sector data
101101

@@ -116,15 +116,15 @@ struct DecodedTrack {
116116
// *input; MFM coded data buffer (size == 2*data_size)
117117
// *output; decoded data buffer (size == data_size)
118118
// 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;
122122
unsigned int count;
123123

124124
// the decoding is made here long by long : with data_size/4 iterations
125125
for (count = 0; count < data_size / 4; count++) {
126126
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
128128

129129
chksum ^= odd_bits; // XOR Checksum
130130
chksum ^= even_bits;
@@ -140,12 +140,12 @@ unsigned long decodeMFMdata(const unsigned long* input, unsigned long* output, c
140140
// *input; RAW data buffer (size == data_size)
141141
// *output; MFM encoded buffer (size == data_size*2)
142142
// 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;
145145
unsigned int count;
146146

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);
149149

150150
// 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
151151
for (count = 0; count < data_size / 4; count++) {
@@ -301,11 +301,11 @@ bool decodeSector(const RawEncodedSector& rawSector, const unsigned int trackNum
301301
unsigned char* sectorData = (unsigned char*)rawSector;
302302

303303
// Read the first 4 bytes (8). This is the track header data
304-
sector.headerChecksumCalculated = decodeMFMdata((unsigned long*)(sectorData + 8), (unsigned long*)&sector, 4);
304+
sector.headerChecksumCalculated = decodeMFMdata((uint32_t*)(sectorData + 8), (uint32_t*)&sector, 4);
305305
// Decode the label data and update the checksum
306-
sector.headerChecksumCalculated ^= decodeMFMdata((unsigned long*)(sectorData + 16), (unsigned long*)&sector.sectorLabel[0], 16);
306+
sector.headerChecksumCalculated ^= decodeMFMdata((uint32_t*)(sectorData + 16), (uint32_t*)&sector.sectorLabel[0], 16);
307307
// Get the checksum for the header
308-
decodeMFMdata((unsigned long*)(sectorData + 48), (unsigned long*)&sector.headerChecksum, 4); // (computed on mfm longs, longs between offsets 8 and 44 == 2 * (1 + 4) longs)
308+
decodeMFMdata((uint32_t*)(sectorData + 48), (uint32_t*)&sector.headerChecksum, 4); // (computed on mfm longs, longs between offsets 8 and 44 == 2 * (1 + 4) longs)
309309
// If the header checksum fails we just cant trust anything we received, so we just drop it
310310
if ((sector.headerChecksum != sector.headerChecksumCalculated) && (!ignoreHeaderChecksum)) {
311311
return false;
@@ -329,7 +329,7 @@ bool decodeSector(const RawEncodedSector& rawSector, const unsigned int trackNum
329329
if (sector.trackNumber != targetTrackNumber) return false; // this'd be weird
330330

331331
// Get the checksum for the data
332-
decodeMFMdata((unsigned long*)(sectorData + 56), (unsigned long*)&sector.dataChecksum, 4);
332+
decodeMFMdata((uint32_t*)(sectorData + 56), (uint32_t*)&sector.dataChecksum, 4);
333333

334334

335335
// Lets see if we already have this one
@@ -342,7 +342,7 @@ bool decodeSector(const RawEncodedSector& rawSector, const unsigned int trackNum
342342
if (index != decodedTrack.validSectors.end()) return true;
343343

344344
// Decode the data and receive it's checksum
345-
sector.dataChecksumCalculated = decodeMFMdata((unsigned long*)(sectorData + 64), (unsigned long*)&sector.data[0], SECTOR_BYTES); // (from 64 to 1088 == 2*512 bytes)
345+
sector.dataChecksumCalculated = decodeMFMdata((uint32_t*)(sectorData + 64), (uint32_t*)&sector.data[0], SECTOR_BYTES); // (from 64 to 1088 == 2*512 bytes)
346346

347347
// Is the data valid?
348348
if (sector.dataChecksum != sector.dataChecksumCalculated) {
@@ -384,15 +384,15 @@ void encodeSector(const unsigned int trackNumber, const DiskSurface surface, con
384384
header.sectorsRemaining = NUM_SECTORS_PER_TRACK - sectorNumber; //1..11
385385

386386

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);
388388
// 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);
390390
// 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);
392392
// 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);
394394
// 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);
396396

397397
// Now fill in the MFM clock bits
398398
bool lastBit = encodedSector[7] & (1 << 0);
@@ -418,14 +418,14 @@ void encodeSector(const unsigned int trackNumber, const DiskSurface surface, con
418418
// Find sectors within raw data read from the drive by searching bit-by-bit for the SYNC bytes
419419
void findSectors(const RawTrackData& track, unsigned int trackNumber, DiskSurface side, unsigned short trackSync, DecodedTrack& decodedTrack, bool ignoreHeaderChecksum) {
420420
// 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);
422422
// For speed and to ignore some data errors, we now just search for syncsync and ignore the 2AAAAAAA part
423423

424424
// 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));
426426

427427
// Prepare our test buffer
428-
unsigned long decoded = 0;
428+
uint32_t decoded = 0;
429429

430430
// Keep runnign until we run out of data
431431
unsigned int byteIndex = 0;
@@ -1243,7 +1243,7 @@ struct SCPFileHeader {
12431243
unsigned char bitcellEncoding;
12441244
unsigned char numHeads;
12451245
unsigned char timeBase;
1246-
unsigned long checksum;
1246+
uint32_t checksum;
12471247
};
12481248

12491249
struct SCPTrackHeader {
@@ -1252,9 +1252,9 @@ struct SCPTrackHeader {
12521252
};
12531253

12541254
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
12581258
};
12591259

12601260
// 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
13241324
}
13251325

13261326
// Pad out the records. Theres 4 bytes for each track
1327-
unsigned long notPresent = 0;
1327+
uint32_t notPresent = 0;
13281328
for (unsigned int a = 0; a <168; a++) {
13291329
try {
13301330
hADFFile.write((const char*)&notPresent, sizeof(notPresent));
@@ -1433,7 +1433,7 @@ ADFResult ADFWriter::DiskToSCP(const std::wstring& outputFile, const unsigned in
14331433
}
14341434

14351435
// Get the current position
1436-
unsigned long currentPosition = (unsigned long)hADFFile.tellp();
1436+
uint32_t currentPosition = (uint32_t)hADFFile.tellp();
14371437

14381438
// Move to the beginning of the file, and write the offset for where this starts
14391439
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
14871487
while (hADFFile.good()) {
14881488
try {
14891489
hADFFile.read((char*)buffer, sizeof(buffer));
1490-
const unsigned long read = sizeof(buffer) / 4;
1490+
const uint32_t read = sizeof(buffer) / 4;
14911491
for (size_t pos = 0; pos < read; pos++)
14921492
header.checksum += buffer[pos];
14931493
}

Diff for: ArduinoFloppyReader/lib/ArduinoInterface.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ DiagnosticResponse ArduinoInterface::testTransferSpeed() {
265265

266266
unsigned char buffer[256];
267267
for (int a = 0; a <= 10; a++) {
268-
unsigned long read;
268+
uint32_t read;
269269

270270
read = m_comPort.read(buffer, sizeof(buffer));
271271

@@ -340,7 +340,7 @@ DiagnosticResponse ArduinoInterface::attemptToSync(std::string& versionString, S
340340
buffer[0] = SPECIAL_ABORT_CHAR;
341341
buffer[1] = COMMAND_VERSION;
342342

343-
unsigned long size = port.write(&buffer[0], 2);
343+
uint32_t size = port.write(&buffer[0], 2);
344344
if (size != 2) {
345345
// Couldn't write to device
346346
port.closePort();
@@ -462,7 +462,7 @@ DiagnosticResponse ArduinoInterface::openPort(const std::wstring& portName, bool
462462
char buffer[2];
463463
int counter = 0;
464464
for (;;) {
465-
unsigned long size = m_comPort.read(buffer, 1);
465+
uint32_t size = m_comPort.read(buffer, 1);
466466
if (size < 1)
467467
if (counter++>=10) break;
468468
}
@@ -931,10 +931,10 @@ DiagnosticResponse ArduinoInterface::readRotation(RotationExtractor& extractor,
931931
for (;;) {
932932

933933
// More efficient to read several bytes in one go
934-
unsigned long bytesAvailable = m_comPort.getBytesWaiting();
934+
uint32_t bytesAvailable = m_comPort.getBytesWaiting();
935935
if (bytesAvailable < 1) bytesAvailable = 1;
936936
if (bytesAvailable > sizeof(tempReadBuffer)) bytesAvailable = sizeof(tempReadBuffer);
937-
unsigned long bytesRead = m_comPort.read(tempReadBuffer, m_abortSignalled ? 1 : bytesAvailable);
937+
uint32_t bytesRead = m_comPort.read(tempReadBuffer, m_abortSignalled ? 1 : bytesAvailable);
938938

939939

940940
for (size_t a = 0; a < bytesRead; a++) {
@@ -1327,7 +1327,7 @@ DiagnosticResponse ArduinoInterface::runCommand(const char command, const char p
13271327
bool ArduinoInterface::deviceRead(void* target, const unsigned int numBytes, const bool failIfNotAllRead) {
13281328
if (!m_comPort.isPortOpen()) return false;
13291329

1330-
unsigned long read = m_comPort.read(target, numBytes);
1330+
uint32_t read = m_comPort.read(target, numBytes);
13311331

13321332
if (read < numBytes) {
13331333
if (failIfNotAllRead) return false;

0 commit comments

Comments
 (0)