From f18c7cd65ffdb0ac0b58907b79f9be86ee63f45e Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 16 Jul 2018 16:26:01 +1000 Subject: Allow per-device internal layouts and remove some more MCFG_ macros. Input and screen tags are now resolved relative to a layout's owner device. Easy way to demonstrate is with: mame64 intlc440 -tty ie15 Previously you'd only get the IE15 terminal's layout and you'd be unable to use the INTELLEC 4/40 front panel. Now you'll get the choice of layouts from both the system and the terminal device in video options. --- src/emu/render.cpp | 92 +++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'src/emu/render.cpp') diff --git a/src/emu/render.cpp b/src/emu/render.cpp index c5f4418f447..316fa05dd99 100644 --- a/src/emu/render.cpp +++ b/src/emu/render.cpp @@ -1589,7 +1589,7 @@ void render_target::load_layout_files(const internal_layout *layoutfile, bool si // if there's an explicit file, load that first const char *basename = m_manager.machine().basename(); if (layoutfile) - have_artwork |= load_layout_file(basename, layoutfile); + have_artwork |= load_layout_file(basename, *layoutfile); // if we're only loading this file, we know our final result if (!singlefile) @@ -1602,7 +1602,7 @@ void render_target::load_layout_files(util::xml::data_node const &rootnode, bool // if there's an explicit file, load that first const char *basename = m_manager.machine().basename(); - have_artwork |= load_layout_file(basename, rootnode); + have_artwork |= load_layout_file(m_manager.machine().root_device(), basename, rootnode); // if we're only loading this file, we know our final result if (!singlefile) @@ -1637,9 +1637,10 @@ void render_target::load_additional_layout_files(const char *basename, bool have // if a default view has been specified, use that as a fallback if (system.default_layout != nullptr) - have_default |= load_layout_file(nullptr, system.default_layout); - if (m_manager.machine().config().m_default_layout != nullptr) - have_default |= load_layout_file(nullptr, m_manager.machine().config().m_default_layout); + have_default |= load_layout_file(nullptr, *system.default_layout); + m_manager.machine().config().apply_default_layouts( + [this, &have_default] (device_t &dev, internal_layout const &layout) + { have_default |= load_layout_file(nullptr, layout, &dev); }); // try to load another file based on the parent driver name int cloneof = driver_list::clone(system); @@ -1682,9 +1683,9 @@ void render_target::load_additional_layout_files(const char *basename, bool have if (screens == 1) { if (system.flags & ORIENTATION_SWAP_XY) - load_layout_file(nullptr, &layout_vertical); + load_layout_file(nullptr, layout_vertical); else - load_layout_file(nullptr, &layout_horizont); + load_layout_file(nullptr, layout_horizont); if (m_filelist.empty()) throw emu_fatalerror("Couldn't parse default layout??"); } @@ -1693,7 +1694,7 @@ void render_target::load_additional_layout_files(const char *basename, bool have { if (screens == 2) { - load_layout_file(nullptr, &layout_dualhsxs); + load_layout_file(nullptr, layout_dualhsxs); if (m_filelist.empty()) throw emu_fatalerror("Couldn't parse default layout??"); } @@ -1703,7 +1704,7 @@ void render_target::load_additional_layout_files(const char *basename, bool have { if (!view_by_index(0)) { - load_layout_file(nullptr, &layout_noscreens); + load_layout_file(nullptr, layout_noscreens); if (m_filelist.empty()) throw emu_fatalerror("Couldn't parse default layout??"); } @@ -1854,7 +1855,7 @@ void render_target::load_additional_layout_files(const char *basename, bool have } // try to parse it - if (!load_layout_file(nullptr, *root)) + if (!load_layout_file(m_manager.machine().root_device(), nullptr, *root)) throw emu_fatalerror("Couldn't parse generated layout??"); } } @@ -1865,11 +1866,10 @@ void render_target::load_additional_layout_files(const char *basename, bool have // and append it to our list //------------------------------------------------- - -bool render_target::load_layout_file(const char *dirname, const internal_layout *layout_data) +bool render_target::load_layout_file(const char *dirname, const internal_layout &layout_data, device_t *device) { // +1 to ensure data is terminated for XML parser - auto tempout = make_unique_clear(layout_data->decompressed_size+1); + auto tempout = make_unique_clear(layout_data.decompressed_size + 1); z_stream stream; int zerr; @@ -1877,7 +1877,7 @@ bool render_target::load_layout_file(const char *dirname, const internal_layout /* initialize the stream */ memset(&stream, 0, sizeof(stream)); stream.next_out = tempout.get(); - stream.avail_out = layout_data->decompressed_size; + stream.avail_out = layout_data.decompressed_size; zerr = inflateInit(&stream); @@ -1888,8 +1888,8 @@ bool render_target::load_layout_file(const char *dirname, const internal_layout } /* decompress this chunk */ - stream.next_in = (unsigned char*)layout_data->data; - stream.avail_in = layout_data->compressed_size; + stream.next_in = (unsigned char *)layout_data.data; + stream.avail_in = layout_data.compressed_size; zerr = inflate(&stream, Z_NO_FLUSH); /* stop at the end of the stream */ @@ -1911,55 +1911,55 @@ bool render_target::load_layout_file(const char *dirname, const internal_layout return false; } - return load_layout_file(dirname, (const char*)tempout.get()); -} + util::xml::file::ptr rootnode(util::xml::file::string_read(reinterpret_cast(tempout.get()), nullptr)); + tempout.reset(); -bool render_target::load_layout_file(const char *dirname, const char *filename) -{ - util::xml::file::ptr rootnode; - if (filename[0] == '<') + // if we didn't get a properly-formatted XML file, record a warning and exit + if (!load_layout_file(device ? *device : m_manager.machine().root_device(), dirname, *rootnode)) { - // if the first character of the "file" is an open brace, assume it is an XML string - rootnode = util::xml::file::string_read(filename, nullptr); + osd_printf_warning("Improperly formatted XML string, ignoring\n"); + return false; } else { - // otherwise, assume it is a file + return true; + } +} - // build the path and optionally prepend the directory - std::string fname = std::string(filename).append(".lay"); - if (dirname != nullptr) - fname.insert(0, PATH_SEPARATOR).insert(0, dirname); +bool render_target::load_layout_file(const char *dirname, const char *filename) +{ + // build the path and optionally prepend the directory + std::string fname = std::string(filename).append(".lay"); + if (dirname) + fname.insert(0, PATH_SEPARATOR).insert(0, dirname); - // attempt to open the file; bail if we can't - emu_file layoutfile(m_manager.machine().options().art_path(), OPEN_FLAG_READ); - osd_file::error filerr = layoutfile.open(fname.c_str()); - if (filerr != osd_file::error::NONE) - return false; + // attempt to open the file; bail if we can't + emu_file layoutfile(m_manager.machine().options().art_path(), OPEN_FLAG_READ); + osd_file::error const filerr(layoutfile.open(fname.c_str())); + if (filerr != osd_file::error::NONE) + return false; - // read the file - rootnode = util::xml::file::read(layoutfile, nullptr); - } + // read the file + util::xml::file::ptr rootnode(util::xml::file::read(layoutfile, nullptr)); // if we didn't get a properly-formatted XML file, record a warning and exit - if (!load_layout_file(dirname, *rootnode)) + if (!load_layout_file(m_manager.machine().root_device(), dirname, *rootnode)) { - if (filename[0] != '<') - osd_printf_warning("Improperly formatted XML file '%s', ignoring\n", filename); - else - osd_printf_warning("Improperly formatted XML string, ignoring\n"); + osd_printf_warning("Improperly formatted XML file '%s', ignoring\n", filename); return false; } - - return true; + else + { + return true; + } } -bool render_target::load_layout_file(const char *dirname, util::xml::data_node const &rootnode) +bool render_target::load_layout_file(device_t &device, const char *dirname, util::xml::data_node const &rootnode) { // parse and catch any errors try { - m_filelist.emplace_back(m_manager.machine(), rootnode, dirname); + m_filelist.emplace_back(device, rootnode, dirname); } catch (emu_fatalerror &) { -- cgit v1.2.3-70-g09d2