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

Method encode

arch/c64/encoder.cc:158–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156
157public:
158 std::unique_ptr<Fluxmap> encode(const LogicalTrackLayout& ltl,
159 const std::vector<std::shared_ptr<const Sector>>& sectors,
160 const Image& image) override
161 {
162 /* The format ID Character # 1 and # 2 are in the .d64 image only
163 * present in track 18 sector zero which contains the BAM info in byte
164 * 162 and 163. it is written in every header of every sector and track.
165 * headers are not stored in a d64 disk image so we have to get it from
166 * track 18 which contains the BAM.
167 */
168
169 const auto& sectorData = image.get(
170 C64_BAM_TRACK, 0, 0); // Read de BAM to get the DISK ID bytes
171 if (sectorData)
172 {
173 ByteReader br(sectorData->data);
174 br.seek(162); // goto position of the first Disk ID Byte
175 _formatByte1 = br.read_8();
176 _formatByte2 = br.read_8();
177 }
178 else
179 _formatByte1 = _formatByte2 = 0;
180
181 double clockRateUs = clockPeriodForC64Track(ltl.logicalCylinder);
182 int bitsPerRevolution = 200000.0 / clockRateUs;
183
184 std::vector<bool> bits(bitsPerRevolution);
185 unsigned cursor = 0;
186
187 fillBitmapTo(bits,
188 cursor,
189 _config.post_index_gap_us() / clockRateUs,
190 {true, false});
191 lastBit = false;
192
193 for (const auto& sector : sectors)
194 writeSector(bits, cursor, sector);
195
196 if (cursor >= bits.size())
197 error("track data overrun by {} bits", cursor - bits.size());
198 fillBitmapTo(bits, cursor, bits.size(), {true, false});
199
200 std::unique_ptr<Fluxmap> fluxmap(new Fluxmap);
201 fluxmap->appendBits(
202 bits, calculatePhysicalClockPeriod(clockRateUs * 1e3, 200e6));
203 return fluxmap;
204 }
205
206private:
207 void writeSector(std::vector<bool>& bits,

Callers

nothing calls this directly

Calls 7

clockPeriodForC64TrackFunction · 0.85
fillBitmapToFunction · 0.85
errorFunction · 0.85
read_8Method · 0.80
getMethod · 0.45
seekMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected