diff options
author | 2024-02-15 15:18:27 -0500 | |
---|---|---|
committer | 2024-02-15 15:24:35 -0500 | |
commit | 25976be0ac640e4b4b3ad2d79846fcdd06933c1d (patch) | |
tree | 6cb762c0c273122de9505d794bebb245bb0ccbb5 /src/tools/image_handler.cpp | |
parent | 01a2d4ed004ae6710d2ea5109fe1ec240d66ffcb (diff) |
image_handler.cpp: Floppy fixes
- Refilter list of specific floppy formats using the known form factor and variant before trying to mount a filesystem on an image
- Sort identify results by decreasing score (code already expects the best format to be first)
* formats/ap_dsk35.cpp: Remove temporary hack
Diffstat (limited to 'src/tools/image_handler.cpp')
-rw-r--r-- | src/tools/image_handler.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/tools/image_handler.cpp b/src/tools/image_handler.cpp index 60ab72e61f8..14976516e1c 100644 --- a/src/tools/image_handler.cpp +++ b/src/tools/image_handler.cpp @@ -15,6 +15,8 @@ #include "multibyte.h" #include "strformat.h" +#include <algorithm> + // Format enumeration @@ -43,7 +45,7 @@ namespace { struct fs_enum : public fs::manager_t::floppy_enumerator { filesystem_format *m_format; - fs_enum(filesystem_format *format, const std::vector<u32> &variants) : fs::manager_t::floppy_enumerator(floppy_image::FF_UNKNOWN, variants), m_format(format) {} + fs_enum(filesystem_format *format, u32 form_factor, const std::vector<u32> &variants) : fs::manager_t::floppy_enumerator(form_factor, variants), m_format(format) {} virtual void add_format(const floppy_image_format_t &type, u32 image_size, const char *name, const char *description) override { m_format->m_floppy = true; @@ -65,7 +67,7 @@ void formats_table::init() mame_formats_full_list(en); for(auto &f : filesystem_formats) { - fs_enum fen(f.get(), variants); + fs_enum fen(f.get(), floppy_image::FF_UNKNOWN, variants); f->m_manager->enumerate_f(fen); } @@ -244,6 +246,9 @@ std::vector<std::pair<u8, const floppy_format_info *>> image_handler::identify(c res.emplace_back(std::make_pair(score, e.second)); } + // Sort results by decreasing score + std::stable_sort(res.begin(), res.end(), [](const auto &a, const auto &b) { return a.first > b.first; }); + return res; } @@ -295,8 +300,14 @@ void image_handler::floppy_create(const floppy_create_info &format, fs::meta_dat bool image_handler::floppy_mount_fs(const filesystem_format &format) { + // Create a restricted copy of the format list based on the known form factor and variant + filesystem_format fmtcopy(format.m_manager, format.m_category); + std::vector<u32> const var(1, m_floppy_image.get_variant()); + fs_enum fen(&fmtcopy, m_floppy_image.get_form_factor(), var); + format.m_manager->enumerate_f(fen); + m_floppy_fs_converter = nullptr; - for(const auto &ci : format.m_floppy_create) { + for(const auto &ci : fmtcopy.m_floppy_create) { if(ci->m_type != m_floppy_fs_converter) { std::vector<uint32_t> variants; m_floppy_fs_converter = ci->m_type; |