diff options
author | 2022-04-11 06:54:35 -0400 | |
---|---|---|
committer | 2022-04-11 06:54:35 -0400 | |
commit | b8758ed358e38adc40294ba39a410fe06f1b0c7c (patch) | |
tree | 329acfa0b3dc212383e243edd1aa621b823d86a0 | |
parent | 9ef4774f2ee83df5ea6def9342450fad5061db23 (diff) |
Consolidated floppy_image_device::m_create_fs and floppy_image_device::m_io_fs vectors (#9542)
* Consolidated floppy_image_device::m_create_fs and floppy_image_device::m_io_fs vectors
We had two separate members in floppy_image_device (m_create_fs and m_io_fs) that contained the same data. Whether the file systems can be formatted or read can be identified by querying fs::manager_t.
For this reason, it seems bad to have these separate members, the seemingly only reason to make the UI code slightly less complicated. For this reason I consolidated these two members and moved the burden of selecting which ones are creatable to the UI code.
-rw-r--r-- | src/devices/imagedev/floppy.cpp | 7 | ||||
-rw-r--r-- | src/devices/imagedev/floppy.h | 5 | ||||
-rw-r--r-- | src/frontend/mame/ui/filecreate.cpp | 6 | ||||
-rw-r--r-- | src/frontend/mame/ui/filecreate.h | 6 | ||||
-rw-r--r-- | src/frontend/mame/ui/floppycntrl.cpp | 35 | ||||
-rw-r--r-- | src/frontend/mame/ui/floppycntrl.h | 1 |
6 files changed, 41 insertions, 19 deletions
diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index 61ef7988543..ce871860ad8 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -320,15 +320,12 @@ void floppy_image_device::setup_led_cb(led_cb cb) void floppy_image_device::fs_enum::add(const floppy_image_format_t &type, u32 image_size, const char *name, const char *description) { - if(m_manager->can_format()) - m_fid->m_create_fs.emplace_back(fs_info(m_manager, &type, image_size, name, description)); - if(m_manager->can_read()) - m_fid->m_io_fs.emplace_back(fs_info(m_manager, &type, image_size, name, description)); + m_fid->m_fs.emplace_back(fs_info(m_manager, &type, image_size, name, description)); } void floppy_image_device::fs_enum::add_raw(const char *name, u32 key, const char *description) { - m_fid->m_create_fs.emplace_back(fs_info(name, key, description)); + m_fid->m_fs.emplace_back(fs_info(name, key, description)); } void floppy_image_device::register_formats() diff --git a/src/devices/imagedev/floppy.h b/src/devices/imagedev/floppy.h index 3f2030e839c..de755fba4ec 100644 --- a/src/devices/imagedev/floppy.h +++ b/src/devices/imagedev/floppy.h @@ -80,8 +80,7 @@ public: void set_formats(std::function<void (format_registration &fr)> formats); const std::vector<const floppy_image_format_t *> &get_formats() const; - const std::vector<fs_info> &get_create_fs() const { return m_create_fs; } - const std::vector<fs_info> &get_io_fs() const { return m_io_fs; } + const std::vector<fs_info> &get_fs() const { return m_fs; } const floppy_image_format_t *get_load_format() const; const floppy_image_format_t *identify(std::string filename); void set_rpm(float rpm); @@ -189,7 +188,7 @@ protected: std::unique_ptr<floppy_image> image; char extension_list[256]; std::vector<const floppy_image_format_t *> fif_list; - std::vector<fs_info> m_create_fs, m_io_fs; + std::vector<fs_info> m_fs; std::vector<const fs::manager_t *> m_fs_managers; emu_timer *index_timer; diff --git a/src/frontend/mame/ui/filecreate.cpp b/src/frontend/mame/ui/filecreate.cpp index 8e036f4ae3b..3ecb44f9b62 100644 --- a/src/frontend/mame/ui/filecreate.cpp +++ b/src/frontend/mame/ui/filecreate.cpp @@ -290,9 +290,9 @@ SELECT FORMAT MENU // ctor //------------------------------------------------- -menu_select_floppy_init::menu_select_floppy_init(mame_ui_manager &mui, render_container &container, const std::vector<floppy_image_device::fs_info> &fs, int *result) +menu_select_floppy_init::menu_select_floppy_init(mame_ui_manager &mui, render_container &container, std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> &&fs, int *result) : menu(mui, container), - m_fs(fs), + m_fs(std::move(fs)), m_result(result) { @@ -316,7 +316,7 @@ void menu_select_floppy_init::populate(float &customtop, float &custombottom) { item_append(_("Select initial contents"), FLAG_DISABLE, nullptr); int id = 0; - for (const auto &fmt : m_fs) + for (const floppy_image_device::fs_info &fmt : m_fs) item_append(fmt.m_description, fmt.m_name, 0, (void *)(uintptr_t)(id++)); } diff --git a/src/frontend/mame/ui/filecreate.h b/src/frontend/mame/ui/filecreate.h index bc08ef66974..bf8d7accbf6 100644 --- a/src/frontend/mame/ui/filecreate.h +++ b/src/frontend/mame/ui/filecreate.h @@ -86,7 +86,7 @@ class menu_select_floppy_init : public menu { public: menu_select_floppy_init(mame_ui_manager &mui, render_container &container, - const std::vector<floppy_image_device::fs_info> &fs, int *result); + std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> &&fs, int *result); virtual ~menu_select_floppy_init() override; private: @@ -94,8 +94,8 @@ private: virtual void handle(event const *ev) override; // internal state - const std::vector<floppy_image_device::fs_info> &m_fs; - int * m_result; + std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> m_fs; + int * m_result; }; diff --git a/src/frontend/mame/ui/floppycntrl.cpp b/src/frontend/mame/ui/floppycntrl.cpp index 0e658b52199..9b85992a923 100644 --- a/src/frontend/mame/ui/floppycntrl.cpp +++ b/src/frontend/mame/ui/floppycntrl.cpp @@ -94,6 +94,11 @@ void menu_control_floppy_image::hook_load(const std::string &filename) } } +bool menu_control_floppy_image::can_format(const floppy_image_device::fs_info &fs) +{ + return !fs.m_manager || fs.m_manager->can_format(); +} + void menu_control_floppy_image::menu_activated() { switch (m_state) { @@ -124,26 +129,46 @@ void menu_control_floppy_image::menu_activated() m_state = START_FILE; menu_activated(); } else { - const auto &fs = fd.get_create_fs(); + // get all formatable file systems + std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> fs; + for (const auto &this_fs : fd.get_fs()) { + if (can_format(this_fs)) + fs.emplace_back(std::ref(this_fs)); + } + output_filename = util::zippath_combine(m_current_directory, m_current_file); if(fs.size() == 1) { - create_fs = &fs[0]; + create_fs = &(fs[0].get()); do_load_create(); stack_pop(); } else { m_submenu_result.i = -1; - menu::stack_push<menu_select_floppy_init>(ui(), container(), fs, &m_submenu_result.i); + menu::stack_push<menu_select_floppy_init>(ui(), container(), std::move(fs), &m_submenu_result.i); m_state = SELECT_INIT; } } break; case SELECT_INIT: - if(m_submenu_result.i == -1) { + // figure out which (if any) create file system was selected + create_fs = nullptr; + if(m_submenu_result.i >= 0) { + int i = 0; + for (const auto &this_fs : fd.get_fs()) { + if (can_format(this_fs)) { + if (i == m_submenu_result.i) { + create_fs = &this_fs; + break; + } + i++; + } + } + } + + if(!create_fs) { m_state = START_FILE; menu_activated(); } else { - create_fs = &fd.get_create_fs()[m_submenu_result.i]; do_load_create(); stack_pop(); } diff --git a/src/frontend/mame/ui/floppycntrl.h b/src/frontend/mame/ui/floppycntrl.h index 5923a9f8914..fd7e17cf7ce 100644 --- a/src/frontend/mame/ui/floppycntrl.h +++ b/src/frontend/mame/ui/floppycntrl.h @@ -39,6 +39,7 @@ private: void do_load_create(); virtual void hook_load(const std::string &filename) override; + static bool can_format(const floppy_image_device::fs_info &fs); }; } // namespace ui |