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

Function write_sector

arch/northstar/encoder.cc:20–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#define TOTAL_SECTOR_BYTES ()
19
20static void write_sector(std::vector<bool>& bits,
21 unsigned& cursor,
22 const std::shared_ptr<const Sector>& sector)
23{
24 int preambleSize = 0;
25 int encodedSectorSize = 0;
26 int gapFillSize = 0;
27 int preHeaderGapFillSize = 0;
28
29 bool doubleDensity;
30
31 switch (sector->data.size())
32 {
33 case NORTHSTAR_PAYLOAD_SIZE_SD:
34 preambleSize = NORTHSTAR_PREAMBLE_SIZE_SD;
35 encodedSectorSize = PRE_HEADER_GAP_FILL_SIZE_SD +
36 NORTHSTAR_ENCODED_SECTOR_SIZE_SD +
37 GAP_FILL_SIZE_SD;
38 gapFillSize = GAP_FILL_SIZE_SD;
39 preHeaderGapFillSize = PRE_HEADER_GAP_FILL_SIZE_SD;
40 doubleDensity = false;
41 break;
42 case NORTHSTAR_PAYLOAD_SIZE_DD:
43 preambleSize = NORTHSTAR_PREAMBLE_SIZE_DD;
44 encodedSectorSize = PRE_HEADER_GAP_FILL_SIZE_DD +
45 NORTHSTAR_ENCODED_SECTOR_SIZE_DD +
46 GAP_FILL_SIZE_DD;
47 gapFillSize = GAP_FILL_SIZE_DD;
48 preHeaderGapFillSize = PRE_HEADER_GAP_FILL_SIZE_DD;
49 doubleDensity = true;
50 break;
51 default:
52 error("unsupported sector size --- you must pick 256 or 512");
53 break;
54 }
55
56 int fullSectorSize = preambleSize + encodedSectorSize;
57 auto fullSector = std::make_shared<std::vector<uint8_t>>();
58 fullSector->reserve(fullSectorSize);
59
60 /* sector gap after index pulse */
61 for (int i = 0; i < preHeaderGapFillSize; i++)
62 fullSector->push_back(GAP1_FILL_BYTE);
63
64 /* sector preamble */
65 for (int i = 0; i < preambleSize; i++)
66 fullSector->push_back(0);
67
68 Bytes sectorData;
69 if (sector->data.size() == encodedSectorSize)
70 sectorData = sector->data;
71 else
72 {
73 ByteWriter writer(sectorData);
74 writer.write_8(0xFB); /* sync character */
75 if (doubleDensity == true)
76 {
77 writer.write_8(0xFB); /* Double-density has two sync characters */

Callers 1

encodeMethod · 0.70

Calls 7

errorFunction · 0.85
northstarChecksumFunction · 0.85
encodeMfmFunction · 0.85
encodeFmFunction · 0.85
sliceMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected