| 156 | ImdImageWriter(const ImageWriterProto& config): ImageWriter(config) {} |
| 157 | |
| 158 | void writeImage(const Image& image) override |
| 159 | { |
| 160 | const Geometry& geometry = image.getGeometry(); |
| 161 | unsigned numHeads; |
| 162 | unsigned numSectors; |
| 163 | unsigned numBytes; |
| 164 | std::ofstream outputFile( |
| 165 | _config.filename(), std::ios::out | std::ios::binary); |
| 166 | if (!outputFile.is_open()) |
| 167 | error("IMD: cannot open output file"); |
| 168 | unsigned numSectorsinTrack = 0; |
| 169 | |
| 170 | numHeads = geometry.numHeads; |
| 171 | numSectors = geometry.numSectors; |
| 172 | numBytes = geometry.sectorSize; |
| 173 | |
| 174 | Bytes imagenew; |
| 175 | ByteWriter bw(imagenew); |
| 176 | |
| 177 | ImdOutputProto::DataRate dataRate = _config.imd().data_rate(); |
| 178 | if (dataRate == ImdOutputProto::RATE_GUESS) |
| 179 | { |
| 180 | dataRate = (geometry.numSectors > 10) ? ImdOutputProto::RATE_HD |
| 181 | : ImdOutputProto::RATE_DD; |
| 182 | if (geometry.sectorSize <= 256) |
| 183 | dataRate = ImdOutputProto::RATE_SD; |
| 184 | log("IMD: guessing data rate as {}", |
| 185 | ImdOutputProto::DataRate_Name(dataRate)); |
| 186 | } |
| 187 | |
| 188 | ImdOutputProto::RecordingMode recordingMode = |
| 189 | _config.imd().recording_mode(); |
| 190 | if (recordingMode == ImdOutputProto::RECMODE_GUESS) |
| 191 | { |
| 192 | recordingMode = ImdOutputProto::RECMODE_MFM; |
| 193 | log("IMD: guessing recording mode as {}", |
| 194 | ImdOutputProto::RecordingMode_Name(recordingMode)); |
| 195 | } |
| 196 | |
| 197 | // Give the user a option to give a comment in the IMD file for archive |
| 198 | // purposes. |
| 199 | auto start = std::chrono::system_clock::now(); |
| 200 | std::time_t time = std::chrono::system_clock::to_time_t(start); |
| 201 | |
| 202 | std::string comment = _config.imd().comment(); |
| 203 | if (comment.size() == 0) |
| 204 | { |
| 205 | comment = LABEL; |
| 206 | comment.append(" date: "); |
| 207 | comment.append(std::ctime(&time)); |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | comment.insert(0, "IMD "); |
| 212 | } |
| 213 | bw.seek(0); |
| 214 | |
| 215 | bw.append(comment); |
nothing calls this directly
no test coverage detected