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

Method readImage

lib/imagereader/d64imagereader.cc:17–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 D64ImageReader(const ImageReaderProto& config): ImageReader(config) {}
16
17 std::unique_ptr<Image> readImage() override
18 {
19 std::ifstream inputFile(
20 _config.filename(), std::ios::in | std::ios::binary);
21 if (!inputFile.is_open())
22 error("cannot open input file");
23
24 inputFile.seekg(0, inputFile.beg);
25 uint32_t begin = inputFile.tellg();
26 inputFile.seekg(0, inputFile.end);
27 uint32_t end = inputFile.tellg();
28 uint32_t inputFileSize = (end - begin);
29 inputFile.seekg(0, inputFile.beg);
30 Bytes data;
31 data.writer() += inputFile;
32 ByteReader br(data);
33
34 unsigned numCylinders = 39;
35 unsigned numHeads = 1;
36 unsigned numSectors = 0;
37
38 log("D64: reading image with {} tracks, {} heads",
39 numCylinders,
40 numHeads);
41
42 uint32_t offset = 0;
43
44 auto sectorsPerTrack = [&](int track) -> int
45 {
46 if (track < 17)
47 return 21;
48 if (track < 24)
49 return 19;
50 if (track < 30)
51 return 18;
52 return 17;
53 };
54
55 std::unique_ptr<Image> image(new Image);
56 for (int track = 0; track < 40; track++)
57 {
58 int numSectors = sectorsPerTrack(track);
59 for (int head = 0; head < numHeads; head++)
60 {
61 for (int sectorId = 0; sectorId < numSectors; sectorId++)
62 {
63 const auto& sector = image->put(track, head, sectorId);
64 if ((offset < inputFileSize))
65 { // still data available sector OK
66 br.seek(offset);
67 Bytes payload = br.read(256);
68 offset += 256;
69
70 sector->status = Sector::OK;
71 sector->data.writer().append(payload);
72 }
73 else
74 { // no more data in input file. Write sectors with status:

Callers

nothing calls this directly

Calls 7

errorFunction · 0.85
writerMethod · 0.80
calculateSizeMethod · 0.80
logFunction · 0.50
putMethod · 0.45
seekMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected