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

Function write_sector

arch/micropolis/encoder.cc:9–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include "lib/encoders/encoders.pb.h"
8
9static void write_sector(std::vector<bool>& bits,
10 unsigned& cursor,
11 const std::shared_ptr<const Sector>& sector,
12 MicropolisEncoderProto::EccType eccType)
13{
14 if ((sector->data.size() != 256) &&
15 (sector->data.size() != MICROPOLIS_ENCODED_SECTOR_SIZE))
16 error("unsupported sector size --- you must pick 256 or 275");
17
18 int fullSectorSize = 40 + MICROPOLIS_ENCODED_SECTOR_SIZE + 40 + 35;
19 auto fullSector = std::make_shared<std::vector<uint8_t>>();
20 fullSector->reserve(fullSectorSize);
21 /* sector preamble */
22 for (int i = 0; i < 40; i++)
23 fullSector->push_back(0);
24 Bytes sectorData;
25 if (sector->data.size() == MICROPOLIS_ENCODED_SECTOR_SIZE)
26 {
27 if (sector->data[0] != 0xFF)
28 error(
29 "275 byte sector doesn't start with sync byte 0xFF. "
30 "Corrupted sector");
31 uint8_t wantChecksum = sector->data[1 + 2 + 266];
32 uint8_t gotChecksum =
33 micropolisChecksum(sector->data.slice(1, 2 + 266));
34 if (wantChecksum != gotChecksum)
35 std::cerr << "Warning: checksum incorrect. Sector: "
36 << sector->logicalSector << std::endl;
37 sectorData = sector->data;
38 }
39 else
40 {
41 ByteWriter writer(sectorData);
42 writer.write_8(0xff); /* Sync */
43 writer.write_8(sector->logicalCylinder);
44 writer.write_8(sector->logicalSector);
45 for (int i = 0; i < 10; i++)
46 writer.write_8(0); /* Padding */
47 writer += sector->data;
48 writer.write_8(micropolisChecksum(sectorData.slice(1)));
49
50 uint8_t eccPresent = 0;
51 uint32_t ecc = 0;
52 if (eccType == MicropolisEncoderProto::VECTOR)
53 {
54 eccPresent = 0xaa;
55 ecc = vectorGraphicEcc(sectorData + Bytes(4));
56 }
57 writer.write_be32(ecc);
58 writer.write_8(eccPresent);
59 }
60 for (uint8_t b : sectorData)
61 fullSector->push_back(b);
62 /* sector postamble */
63 for (int i = 0; i < 40; i++)
64 fullSector->push_back(0);
65 /* filler */
66 for (int i = 0; i < 35; i++)

Callers 1

encodeMethod · 0.70

Calls 8

errorFunction · 0.85
micropolisChecksumFunction · 0.85
vectorGraphicEccFunction · 0.85
encodeMfmFunction · 0.85
sliceMethod · 0.80
BytesClass · 0.50
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected