mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
floppy: Change the formats from an intrusive list to a vector
This commit is contained in:
parent
3ade0ad948
commit
ef0d18e0bb
@ -247,7 +247,6 @@ floppy_image_device::floppy_image_device(const machine_config &mconfig, device_t
|
||||
input_format(nullptr),
|
||||
output_format(nullptr),
|
||||
image(),
|
||||
fif_list(nullptr),
|
||||
index_timer(nullptr),
|
||||
tracks(0),
|
||||
sides(0),
|
||||
@ -280,12 +279,8 @@ floppy_image_device::floppy_image_device(const machine_config &mconfig, device_t
|
||||
|
||||
floppy_image_device::~floppy_image_device()
|
||||
{
|
||||
for(floppy_image_format_t *format = fif_list; format; ) {
|
||||
floppy_image_format_t* tmp_format = format;
|
||||
format = format->next;
|
||||
delete tmp_format;
|
||||
}
|
||||
fif_list = nullptr;
|
||||
for(floppy_image_format_t *format : fif_list)
|
||||
delete format;
|
||||
}
|
||||
|
||||
void floppy_image_device::setup_load_cb(load_cb cb)
|
||||
@ -338,16 +333,12 @@ void floppy_image_device::register_formats()
|
||||
format_registration_cb(fr);
|
||||
|
||||
extension_list[0] = '\0';
|
||||
fif_list = nullptr;
|
||||
fif_list.clear();
|
||||
for(floppy_format_type fft : fr.m_formats)
|
||||
{
|
||||
// allocate a new format
|
||||
floppy_image_format_t *fif = fft();
|
||||
if(!fif_list)
|
||||
fif_list = fif;
|
||||
else
|
||||
fif_list->append(fif);
|
||||
|
||||
fif_list.push_back(fif);
|
||||
add_format(fif->name(), fif->description(), fif->extensions(), "");
|
||||
|
||||
image_specify_extension( extension_list, 256, fif->extensions() );
|
||||
@ -367,7 +358,7 @@ void floppy_image_device::set_formats(std::function<void (format_registration &f
|
||||
format_registration_cb = formats;
|
||||
}
|
||||
|
||||
floppy_image_format_t *floppy_image_device::get_formats() const
|
||||
const std::vector<floppy_image_format_t *> &floppy_image_device::get_formats() const
|
||||
{
|
||||
return fif_list;
|
||||
}
|
||||
@ -551,7 +542,7 @@ floppy_image_format_t *floppy_image_device::identify(std::string filename)
|
||||
io.filler = 0xff;
|
||||
int best = 0;
|
||||
floppy_image_format_t *best_format = nullptr;
|
||||
for (floppy_image_format_t *format = fif_list; format; format = format->next)
|
||||
for (floppy_image_format_t *format : fif_list)
|
||||
{
|
||||
int score = format->identify(&io, form_factor, variants);
|
||||
if(score > best) {
|
||||
@ -599,7 +590,7 @@ image_init_result floppy_image_device::call_load()
|
||||
io.filler = 0xff;
|
||||
int best = 0;
|
||||
floppy_image_format_t *best_format = nullptr;
|
||||
for (floppy_image_format_t *format = fif_list; format; format = format->next) {
|
||||
for (floppy_image_format_t *format : fif_list) {
|
||||
int score = format->identify(&io, form_factor, variants);
|
||||
if(score > best) {
|
||||
best = score;
|
||||
@ -804,7 +795,7 @@ image_init_result floppy_image_device::call_create(int format_type, util::option
|
||||
output_format = nullptr;
|
||||
|
||||
// search for a suitable format based on the extension
|
||||
for(floppy_image_format_t *i = fif_list; i; i = i->next)
|
||||
for(floppy_image_format_t *i : fif_list)
|
||||
{
|
||||
// only consider formats that actually support saving
|
||||
if(!i->supports_save())
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
virtual ~floppy_image_device();
|
||||
|
||||
void set_formats(std::function<void (format_registration &fr)> formats);
|
||||
floppy_image_format_t *get_formats() const;
|
||||
const std::vector<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; }
|
||||
floppy_image_format_t *get_load_format() const;
|
||||
@ -188,7 +188,7 @@ protected:
|
||||
std::vector<uint32_t> variants;
|
||||
std::unique_ptr<floppy_image> image;
|
||||
char extension_list[256];
|
||||
floppy_image_format_t *fif_list;
|
||||
std::vector<floppy_image_format_t *> fif_list;
|
||||
std::vector<fs_info> m_create_fs, m_io_fs;
|
||||
std::vector<const filesystem_manager_t *> m_fs_managers;
|
||||
emu_timer *index_timer;
|
||||
|
@ -238,12 +238,11 @@ SELECT FORMAT MENU
|
||||
// ctor
|
||||
//-------------------------------------------------
|
||||
|
||||
menu_select_format::menu_select_format(mame_ui_manager &mui, render_container &container, floppy_image_format_t **formats, int ext_match, int total_usable, int *result)
|
||||
menu_select_format::menu_select_format(mame_ui_manager &mui, render_container &container, const std::vector<floppy_image_format_t *> &formats, int ext_match, floppy_image_format_t **result)
|
||||
: menu(mui, container)
|
||||
{
|
||||
m_formats = formats;
|
||||
m_ext_match = ext_match;
|
||||
m_total_usable = total_usable;
|
||||
m_result = result;
|
||||
}
|
||||
|
||||
@ -264,13 +263,13 @@ menu_select_format::~menu_select_format()
|
||||
void menu_select_format::populate(float &customtop, float &custombottom)
|
||||
{
|
||||
item_append(_("Select image format"), FLAG_DISABLE, nullptr);
|
||||
for (int i = 0; i < m_total_usable; i++)
|
||||
for (unsigned int i = 0; i != m_formats.size(); i++)
|
||||
{
|
||||
const floppy_image_format_t *fmt = m_formats[i];
|
||||
floppy_image_format_t *fmt = m_formats[i];
|
||||
|
||||
if (i && i == m_ext_match)
|
||||
item_append(menu_item_type::SEPARATOR);
|
||||
item_append(fmt->description(), fmt->name(), 0, (void *)(uintptr_t)i);
|
||||
item_append(fmt->description(), fmt->name(), 0, fmt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,7 +284,7 @@ void menu_select_format::handle()
|
||||
const event *event = process(0);
|
||||
if (event != nullptr && event->iptkey == IPT_UI_SELECT)
|
||||
{
|
||||
*m_result = int(uintptr_t(event->itemref));
|
||||
*m_result = (floppy_image_format_t *)event->itemref;
|
||||
stack_pop();
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ class menu_select_format : public menu
|
||||
{
|
||||
public:
|
||||
menu_select_format(mame_ui_manager &mui, render_container &container,
|
||||
floppy_image_format_t **formats, int ext_match, int total_usable, int *result);
|
||||
const std::vector<floppy_image_format_t *> &formats, int ext_match, floppy_image_format_t **result);
|
||||
virtual ~menu_select_format() override;
|
||||
|
||||
private:
|
||||
@ -72,10 +72,9 @@ private:
|
||||
virtual void handle() override;
|
||||
|
||||
// internal state
|
||||
floppy_image_format_t ** m_formats;
|
||||
int m_ext_match;
|
||||
int m_total_usable;
|
||||
int * m_result;
|
||||
std::vector<floppy_image_format_t *> m_formats;
|
||||
int m_ext_match;
|
||||
floppy_image_format_t * *m_result;
|
||||
};
|
||||
|
||||
// ======================> menu_select_floppy_init
|
||||
|
@ -30,11 +30,6 @@ menu_control_floppy_image::menu_control_floppy_image(mame_ui_manager &mui, rende
|
||||
input_filename(),
|
||||
output_filename()
|
||||
{
|
||||
int fcnt = 0;
|
||||
for(const floppy_image_format_t *i = fd.get_formats(); i; i = i->next)
|
||||
fcnt++;
|
||||
|
||||
format_array = std::make_unique<floppy_image_format_t * []>(fcnt);
|
||||
}
|
||||
|
||||
menu_control_floppy_image::~menu_control_floppy_image()
|
||||
@ -103,37 +98,34 @@ void menu_control_floppy_image::handle()
|
||||
{
|
||||
switch (m_state) {
|
||||
case DO_CREATE: {
|
||||
floppy_image_format_t *fif_list = fd.get_formats();
|
||||
int ext_match;
|
||||
int total_usable = 0;
|
||||
for(floppy_image_format_t *i = fif_list; i; i = i->next) {
|
||||
std::vector<floppy_image_format_t *> format_array;
|
||||
for(floppy_image_format_t *i : fd.get_formats()) {
|
||||
if(!i->supports_save())
|
||||
continue;
|
||||
if (i->extension_matches(m_current_file.c_str()))
|
||||
format_array[total_usable++] = i;
|
||||
format_array.push_back(i);
|
||||
}
|
||||
ext_match = total_usable;
|
||||
for(floppy_image_format_t *i = fif_list; i; i = i->next) {
|
||||
int ext_match = format_array.size();
|
||||
for(floppy_image_format_t *i : fd.get_formats()) {
|
||||
if(!i->supports_save())
|
||||
continue;
|
||||
if (!i->extension_matches(m_current_file.c_str()))
|
||||
format_array[total_usable++] = i;
|
||||
format_array.push_back(i);
|
||||
}
|
||||
m_submenu_result.i = -1;
|
||||
menu::stack_push<menu_select_format>(ui(), container(), format_array.get(), ext_match, total_usable, &m_submenu_result.i);
|
||||
output_format = nullptr;
|
||||
menu::stack_push<menu_select_format>(ui(), container(), format_array, ext_match, &output_format);
|
||||
|
||||
m_state = SELECT_FORMAT;
|
||||
break;
|
||||
}
|
||||
|
||||
case SELECT_FORMAT:
|
||||
if(m_submenu_result.i == -1) {
|
||||
if(!output_format) {
|
||||
m_state = START_FILE;
|
||||
handle();
|
||||
} else {
|
||||
const auto &fs = fd.get_create_fs();
|
||||
output_filename = util::zippath_combine(m_current_directory, m_current_file);
|
||||
output_format = format_array[m_submenu_result.i];
|
||||
if(fs.size() == 1) {
|
||||
create_fs = &fs[0];
|
||||
do_load_create();
|
||||
|
@ -30,7 +30,6 @@ private:
|
||||
enum { SELECT_FORMAT = LAST_ID, SELECT_MEDIA, SELECT_INIT, SELECT_RW };
|
||||
|
||||
floppy_image_device &fd;
|
||||
std::unique_ptr<floppy_image_format_t * []> format_array;
|
||||
floppy_image_format_t *input_format, *output_format;
|
||||
const floppy_image_device::fs_info *create_fs;
|
||||
std::string input_filename, output_filename;
|
||||
|
@ -995,23 +995,6 @@ bool floppy_image_format_t::has_variant(const std::vector<uint32_t> &variants, u
|
||||
return false;
|
||||
}
|
||||
|
||||
floppy_image_format_t::floppy_image_format_t()
|
||||
{
|
||||
next = nullptr;
|
||||
}
|
||||
|
||||
floppy_image_format_t::~floppy_image_format_t()
|
||||
{
|
||||
}
|
||||
|
||||
void floppy_image_format_t::append(floppy_image_format_t *_next)
|
||||
{
|
||||
if(next)
|
||||
next->append(_next);
|
||||
else
|
||||
next = _next;
|
||||
}
|
||||
|
||||
bool floppy_image_format_t::save(io_generic *, const std::vector<uint32_t> &, floppy_image *)
|
||||
{
|
||||
return false;
|
||||
|
@ -224,8 +224,7 @@ class floppy_image;
|
||||
class floppy_image_format_t
|
||||
{
|
||||
public:
|
||||
floppy_image_format_t();
|
||||
virtual ~floppy_image_format_t();
|
||||
virtual ~floppy_image_format_t() = default;
|
||||
|
||||
/*! @brief Identify an image.
|
||||
The identify function tests if the image is valid
|
||||
@ -270,10 +269,6 @@ public:
|
||||
//! @returns true if format supports saving.
|
||||
virtual bool supports_save() const = 0;
|
||||
|
||||
//! Used if a linked list of formats is needed
|
||||
floppy_image_format_t *next;
|
||||
//! This appends a format to the linked list of formats, needed for floppy_image_device().
|
||||
void append(floppy_image_format_t *_next);
|
||||
//! This checks if the file has the proper extension for this format.
|
||||
//! @param file_name
|
||||
//! @returns true if file matches the extension.
|
||||
|
@ -1039,8 +1039,7 @@ void debug_imgui::refresh_typelist()
|
||||
if(fd == nullptr)
|
||||
return;
|
||||
|
||||
floppy_image_format_t* format_list = fd->get_formats();
|
||||
for(floppy_image_format_t* flist = format_list; flist; flist = flist->next)
|
||||
for(floppy_image_format_t* flist : fd->get_formats())
|
||||
{
|
||||
if(flist->supports_save())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user