| 19 | NFDImageReader(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 fileId(14); // read first entry of track table as well |
| 29 | inputFile.read((char*)fileId.begin(), fileId.size()); |
| 30 | |
| 31 | if (fileId == Bytes("T98FDDIMAGE.R1")) |
| 32 | { |
| 33 | error("NFD: r1 images are not currently supported"); |
| 34 | } |
| 35 | if (fileId != Bytes("T98FDDIMAGE.R0")) |
| 36 | { |
| 37 | error("NFD: could not find NFD header"); |
| 38 | } |
| 39 | |
| 40 | Bytes header(0x10a10); |
| 41 | inputFile.seekg(0, std::ios::beg); |
| 42 | inputFile.read((char*)header.begin(), header.size()); |
| 43 | |
| 44 | ByteReader headerReader(header); |
| 45 | |
| 46 | char heads = headerReader.seek(0x115).read_8(); |
| 47 | if (heads != 2) |
| 48 | { |
| 49 | error("NFD: unsupported number of heads"); |
| 50 | } |
| 51 | |
| 52 | if (_extraConfig.encoder().format_case() != |
| 53 | EncoderProto::FormatCase::FORMAT_NOT_SET) |
| 54 | log("NFD: overriding configured format"); |
| 55 | |
| 56 | auto ibm = _extraConfig.mutable_encoder()->mutable_ibm(); |
| 57 | auto layout = _extraConfig.mutable_layout(); |
| 58 | log("NFD: HD 1.2MB mode"); |
| 59 | log("NFD: forcing hign density mode"); |
| 60 | _extraConfig.mutable_drive()->set_high_density(true); |
| 61 | _extraConfig.mutable_layout()->set_format_type(FORMATTYPE_80TRACK); |
| 62 | |
| 63 | std::unique_ptr<Image> image(new Image); |
| 64 | for (int track = 0; track < 163; track++) |
| 65 | { |
| 66 | auto trackdata = ibm->add_trackdata(); |
| 67 | trackdata->set_target_clock_period_us(2); |
| 68 | trackdata->set_target_rotational_period_ms(167); |
| 69 | |
| 70 | auto layoutdata = layout->add_layoutdata(); |
| 71 | auto physical = layoutdata->mutable_physical(); |
| 72 | int currentTrackTrack = -1; |
| 73 | int currentTrackHead = -1; |
| 74 | int trackSectorSize = -1; |
| 75 | |
| 76 | for (int sectorInTrack = 0; sectorInTrack < 26; sectorInTrack++) |
| 77 | { |
| 78 | headerReader.seek(0x120 + track * 26 * 16 + sectorInTrack * 16); |