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

Function write_sector

arch/macintosh/encoder.cc:172–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172static void write_sector(std::vector<bool>& bits,
173 unsigned& cursor,
174 const std::shared_ptr<const Sector>& sector)
175{
176 if ((sector->data.size() != 512) && (sector->data.size() != 524))
177 error("unsupported sector size --- you must pick 512 or 524");
178
179 write_bits(bits, cursor, 0xff, 1 * 8); /* pad byte */
180 for (int i = 0; i < 7; i++)
181 write_bits(bits, cursor, 0xff3fcff3fcffLL, 6 * 8); /* sync */
182 write_bits(bits, cursor, MAC_SECTOR_RECORD, 3 * 8);
183
184 uint8_t encodedTrack = sector->logicalCylinder & 0x3f;
185 uint8_t encodedSector = sector->logicalSector;
186 uint8_t encodedSide =
187 encode_side(sector->logicalCylinder, sector->logicalHead);
188 uint8_t formatByte = MAC_FORMAT_BYTE;
189 uint8_t headerChecksum =
190 (encodedTrack ^ encodedSector ^ encodedSide ^ formatByte) & 0x3f;
191
192 write_bits(bits, cursor, encode_data_gcr(encodedTrack), 1 * 8);
193 write_bits(bits, cursor, encode_data_gcr(encodedSector), 1 * 8);
194 write_bits(bits, cursor, encode_data_gcr(encodedSide), 1 * 8);
195 write_bits(bits, cursor, encode_data_gcr(formatByte), 1 * 8);
196 write_bits(bits, cursor, encode_data_gcr(headerChecksum), 1 * 8);
197
198 write_bits(bits, cursor, 0xdeaaff, 3 * 8);
199 write_bits(bits, cursor, 0xff3fcff3fcffLL, 6 * 8); /* sync */
200 write_bits(bits, cursor, MAC_DATA_RECORD, 3 * 8);
201 write_bits(bits, cursor, encode_data_gcr(sector->logicalSector), 1 * 8);
202
203 Bytes wireData;
204 wireData.writer()
205 .append(sector->data.slice(512, 12))
206 .append(sector->data.slice(0, 512));
207 for (uint8_t b : encode_crazy_data(wireData))
208 write_bits(bits, cursor, encode_data_gcr(b), 1 * 8);
209
210 write_bits(bits, cursor, 0xdeaaff, 3 * 8);
211}
212
213class MacintoshEncoder : public Encoder
214{

Callers 1

encodeMethod · 0.70

Calls 8

errorFunction · 0.85
encode_sideFunction · 0.85
encode_crazy_dataFunction · 0.85
writerMethod · 0.80
sliceMethod · 0.80
write_bitsFunction · 0.70
encode_data_gcrFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected