MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / decodeSectorRecord

Method decodeSectorRecord

arch/micropolis/decoder.cc:201–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199 }
200
201 void decodeSectorRecord() override
202 {
203 readRawBits(48);
204 auto rawbits = readRawBits(MICROPOLIS_ENCODED_SECTOR_SIZE * 16);
205 auto bytes =
206 decodeFmMfm(rawbits).slice(0, MICROPOLIS_ENCODED_SECTOR_SIZE);
207
208 bool eccPresent = bytes[274] == 0xaa;
209 uint32_t ecc = 0;
210 if (_config.ecc_type() == MicropolisDecoderProto::VECTOR && eccPresent)
211 {
212 ecc = vectorGraphicEcc(bytes.slice(0, 274));
213 if (ecc != 0)
214 {
215 vectorGraphicEccFix(bytes, ecc);
216 ecc = vectorGraphicEcc(bytes.slice(0, 274));
217 }
218 }
219
220 ByteReader br(bytes);
221
222 int syncByte = br.read_8(); /* sync */
223 if (syncByte != 0xFF)
224 return;
225
226 _sector->logicalCylinder = br.read_8();
227 _sector->logicalHead = _ltl->logicalHead;
228 _sector->logicalSector = br.read_8();
229 if (_sector->logicalSector > 15)
230 return;
231 if (_sector->logicalCylinder > 76)
232 return;
233 if (_sector->logicalCylinder != _ltl->logicalCylinder)
234 return;
235
236 br.read(10); /* OS data or padding */
237 auto data = br.read(MICROPOLIS_PAYLOAD_SIZE);
238 uint8_t wantChecksum = br.read_8();
239
240 /* If not specified, automatically determine the checksum type.
241 * Once the checksum type is determined, it will be used for the
242 * entire disk.
243 */
244 if (_checksumType == MicropolisDecoderProto::AUTO)
245 {
246 /* Calculate both standard Micropolis (MDOS, CP/M, OASIS) and MZOS
247 * checksums */
248 if (wantChecksum == micropolisChecksum(bytes.slice(1, 2 + 266)))
249 {
250 _checksumType = MicropolisDecoderProto::MICROPOLIS;
251 }
252 else if (wantChecksum ==
253 mzosChecksum(bytes.slice(
254 MICROPOLIS_HEADER_SIZE, MICROPOLIS_PAYLOAD_SIZE)))
255 {
256 _checksumType = MicropolisDecoderProto::MZOS;
257 std::cout << "Note: MZOS checksum detected." << std::endl;
258 }

Callers

nothing calls this directly

Calls 9

vectorGraphicEccFunction · 0.85
vectorGraphicEccFixFunction · 0.85
micropolisChecksumFunction · 0.85
mzosChecksumFunction · 0.85
errorFunction · 0.85
sliceMethod · 0.80
read_8Method · 0.80
decodeFmMfmFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected