mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Revamp how extra zeros are handled
It's not OK to call seek() here. Instead, add a function which can read an apple 8-bit flux value in terms of readRaw8 and readRawBits. Apply this function to all the data bytes, rather than just the first one.
This commit is contained in:
@@ -114,14 +114,28 @@ public:
|
||||
// as it was a '1' reaching the top bit of a shift register
|
||||
// that triggered a byte to be available, but it affects the
|
||||
// way the data is read here.
|
||||
auto p = tell();
|
||||
auto b = readRawBits(1);
|
||||
if(b[0]) seek(p);
|
||||
//
|
||||
// While the floppies tested only seemed to need this applied
|
||||
// to the first byte of the data record, applying it
|
||||
// consistently to all of them doesn't seem to hurt, and
|
||||
// simplifies the code.
|
||||
|
||||
/* Read and decode data. */
|
||||
|
||||
unsigned recordLength = APPLE2_ENCODED_SECTOR_LENGTH + 2;
|
||||
Bytes bytes = toBytes(readRawBits(recordLength*8)).slice(0, recordLength);
|
||||
auto readApple8 = [&]() {
|
||||
auto result = readRaw8();
|
||||
while(result & 0x80 == 0) {
|
||||
auto b = readRawBits(1);
|
||||
result = (result << 1) | b[0];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
constexpr unsigned recordLength = APPLE2_ENCODED_SECTOR_LENGTH + 2;
|
||||
uint8_t bytes[recordLength];
|
||||
for(auto &byte : bytes) {
|
||||
byte = readApple8();
|
||||
}
|
||||
|
||||
// Upgrade the sector from MISSING to BAD_CHECKSUM.
|
||||
// If decode_crazy_data succeeds, it upgrades the sector to
|
||||
|
||||
Reference in New Issue
Block a user