| 120 | } |
| 121 | |
| 122 | void decodeDataRecord() override |
| 123 | { |
| 124 | /* Check ID. */ |
| 125 | |
| 126 | if (readRaw24() != APPLE2_DATA_RECORD) |
| 127 | return; |
| 128 | |
| 129 | // Sometimes there's a 1-bit gap between APPLE2_DATA_RECORD and |
| 130 | // the data itself. This has been seen on real world disks |
| 131 | // such as the Apple II Operating System Kit from Apple2Online. |
| 132 | // However, I haven't seen it described in any of the various |
| 133 | // references. |
| 134 | // |
| 135 | // This extra '0' bit would not affect the real disk interface, |
| 136 | // as it was a '1' reaching the top bit of a shift register |
| 137 | // that triggered a byte to be available, but it affects the |
| 138 | // way the data is read here. |
| 139 | // |
| 140 | // While the floppies tested only seemed to need this applied |
| 141 | // to the first byte of the data record, applying it |
| 142 | // consistently to all of them doesn't seem to hurt, and |
| 143 | // simplifies the code. |
| 144 | |
| 145 | /* Read and decode data. */ |
| 146 | |
| 147 | auto readApple8 = [&]() |
| 148 | { |
| 149 | auto result = 0; |
| 150 | while ((result & 0x80) == 0) |
| 151 | { |
| 152 | auto b = readRawBits(1); |
| 153 | if (b.empty()) |
| 154 | break; |
| 155 | result = (result << 1) | b[0]; |
| 156 | } |
| 157 | return result; |
| 158 | }; |
| 159 | |
| 160 | constexpr unsigned recordLength = APPLE2_ENCODED_SECTOR_LENGTH + 2; |
| 161 | uint8_t bytes[recordLength]; |
| 162 | for (auto& byte : bytes) |
| 163 | { |
| 164 | byte = readApple8(); |
| 165 | } |
| 166 | |
| 167 | // Upgrade the sector from MISSING to BAD_CHECKSUM. |
| 168 | // If decode_crazy_data succeeds, it upgrades the sector to |
| 169 | // OK. |
| 170 | _sector->status = Sector::BAD_CHECKSUM; |
| 171 | _sector->data = decode_crazy_data(&bytes[0], _sector->status); |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | std::unique_ptr<Decoder> createApple2Decoder(const DecoderProto& config) |
nothing calls this directly
no test coverage detected