| 19 | D88ImageReader(const ImageReaderProto& config): ImageReader(config) {} |
| 20 | |
| 21 | std::unique_ptr<Image> readImage() override |
| 22 | { |
| 23 | std::ifstream inputFile( |
| 24 | _config.filename(), std::ios::in | std::ios::binary); |
| 25 | if (!inputFile.is_open()) |
| 26 | error("cannot open input file"); |
| 27 | |
| 28 | Bytes header(0x24); // read first entry of track table as well |
| 29 | inputFile.read((char*)header.begin(), header.size()); |
| 30 | |
| 31 | // the DIM header technically has a bit field for sectors present, |
| 32 | // however it is currently ignored by this reader |
| 33 | |
| 34 | std::string diskName = header.slice(0, 0x16); |
| 35 | |
| 36 | if (diskName[0]) |
| 37 | log("D88: disk name: {}", diskName); |
| 38 | |
| 39 | ByteReader headerReader(header); |
| 40 | |
| 41 | char mediaFlag = headerReader.seek(0x1b).read_8(); |
| 42 | |
| 43 | inputFile.seekg(0, std::ios::end); |
| 44 | int fileSize = inputFile.tellg(); |
| 45 | |
| 46 | int diskSize = headerReader.seek(0x1c).read_le32(); |
| 47 | |
| 48 | if (diskSize > fileSize) |
| 49 | log("D88: found multiple disk images. Only using first"); |
| 50 | |
| 51 | int trackTableEnd = headerReader.seek(0x20).read_le32(); |
| 52 | int trackTableSize = trackTableEnd - 0x20; |
| 53 | |
| 54 | Bytes trackTable(trackTableSize); |
| 55 | inputFile.seekg(0x20); |
| 56 | inputFile.read((char*)trackTable.begin(), trackTable.size()); |
| 57 | ByteReader trackTableReader(trackTable); |
| 58 | |
| 59 | auto ibm = _extraConfig.mutable_encoder()->mutable_ibm(); |
| 60 | int clockRate = 500; |
| 61 | if (mediaFlag == 0x20) |
| 62 | { |
| 63 | _extraConfig.mutable_drive()->set_high_density(true); |
| 64 | _extraConfig.mutable_layout()->set_format_type(FORMATTYPE_80TRACK); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | clockRate = 300; |
| 69 | _extraConfig.mutable_drive()->set_high_density(false); |
| 70 | _extraConfig.mutable_layout()->set_format_type(FORMATTYPE_40TRACK); |
| 71 | } |
| 72 | |
| 73 | auto layout = _extraConfig.mutable_layout(); |
| 74 | std::unique_ptr<Image> image(new Image); |
| 75 | for (int track = 0; track < trackTableSize / 4; track++) |
| 76 | { |
| 77 | int trackOffset = trackTableReader.seek(track * 4).read_le32(); |
| 78 | if (trackOffset == 0) |
nothing calls this directly
no test coverage detected