diff --git a/doc/using.md b/doc/using.md index fd8e0851..85fd4001 100644 --- a/doc/using.md +++ b/doc/using.md @@ -267,7 +267,8 @@ FluxEngine also supports a number of file system image formats. When using the - `` Read from a [FDI image file](https://www.pc98.org/project/doc/hdi.html), - commonly used by PC-98 emulators. **Read Only.** + commonly used by PC-98 emulators. Supports automatically configuring + the encoder. **Read Only.** - `` diff --git a/lib/imagereader/fdiimagereader.cc b/lib/imagereader/fdiimagereader.cc index bd439902..ab17c358 100644 --- a/lib/imagereader/fdiimagereader.cc +++ b/lib/imagereader/fdiimagereader.cc @@ -3,6 +3,7 @@ #include "sector.h" #include "imagereader/imagereader.h" #include "image.h" +#include "proto.h" #include "lib/config.pb.h" #include "fmt/format.h" #include @@ -75,6 +76,34 @@ public: trackCount++; } + if (config.encoder().format_case() == EncoderProto::FormatCase::FORMAT_NOT_SET) + { + auto ibm = config.mutable_encoder()->mutable_ibm(); + auto trackdata = ibm->add_trackdata(); + trackdata->set_clock_rate_khz(500); + auto sectors = trackdata->mutable_sectors(); + switch (fddType) { + case 0x90: + std::cout << "FDI: automatically setting format to 1.2MB (1024 byte sectors)\n"; + config.mutable_cylinders()->set_end(76); + trackdata->set_track_length_ms(167); + trackdata->set_sector_size(1024); + for (int i = 0; i < 9; i++) + sectors->add_sector(i); + break; + case 0x30: + std::cout << "FDI: automatically setting format to 1.44MB\n"; + trackdata->set_track_length_ms(200); + trackdata->set_sector_size(512); + for (int i = 0; i < 18; i++) + sectors->add_sector(i); + break; + default: + Error() << fmt::format("FDI: unknown fdd type 0x%02x, could not determine write profile automatically", fddType); + break; + } + } + image->calculateSize(); const Geometry& geometry = image->getGeometry(); std::cout << fmt::format("FDI: read {} tracks, {} sides, {} kB total\n",