diff options
Diffstat (limited to 'src/emu/devfind.cpp')
-rw-r--r-- | src/emu/devfind.cpp | 105 |
1 files changed, 93 insertions, 12 deletions
diff --git a/src/emu/devfind.cpp b/src/emu/devfind.cpp index d3cfaf8c0a1..4128123e0f2 100644 --- a/src/emu/devfind.cpp +++ b/src/emu/devfind.cpp @@ -22,6 +22,8 @@ template class object_finder_base<memory_bank, false>; template class object_finder_base<memory_bank, true>; template class object_finder_base<ioport_port, false>; template class object_finder_base<ioport_port, true>; +template class object_finder_base<address_space, false>; +template class object_finder_base<address_space, true>; template class object_finder_base<u8, false>; template class object_finder_base<u8, true>; @@ -50,6 +52,9 @@ template class memory_bank_finder<true>; template class ioport_finder<false>; template class ioport_finder<true>; +template class address_space_finder<false>; +template class address_space_finder<true>; + template class region_ptr_finder<u8, false>; template class region_ptr_finder<u8, true>; template class region_ptr_finder<u16, false>; @@ -230,29 +235,105 @@ void *finder_base::find_memshare(u8 width, size_t &bytes, bool required) const //------------------------------------------------- +// find_addrspace - find address space +//------------------------------------------------- + +address_space *finder_base::find_addrspace(int spacenum, u8 width, bool required) const +{ + // look up the device and return nullptr if not found + device_t *const device(m_base.get().subdevice(m_tag)); + if (device == nullptr) + return nullptr; + + // check for memory interface and the specified space number + const device_memory_interface *memory; + if (!device->interface(memory)) + { + if (required) + osd_printf_warning("Device '%s' found but lacks memory interface\n", m_tag); + return nullptr; + } + if (!memory->has_space(spacenum)) + { + if (required) + osd_printf_warning("Device '%s' found but lacks address space #%d\n", m_tag, spacenum); + return nullptr; + } + + // check data width + address_space &space(memory->space(spacenum)); + if (width != 0 && width != space.data_width()) + { + if (required) + osd_printf_warning("Device '%s' found but address space #%d has the wrong data width (expected %d, found %d)\n", m_tag, spacenum, width, space.data_width()); + return nullptr; + } + + // return result + return &space; +} + + +//------------------------------------------------- +// validate_addrspace - find address space +//------------------------------------------------- + +bool finder_base::validate_addrspace(int spacenum, u8 width, bool required) const +{ + // look up the device and return false if not found + device_t *const device(m_base.get().subdevice(m_tag)); + if (device == nullptr) + return report_missing(false, "address space", required); + + // check for memory interface and a configuration for the designated space + const device_memory_interface *memory = nullptr; + const address_space_config *config = nullptr; + if (device->interface(memory)) + { + config = memory->space_config(spacenum); + if (required) + { + if (config == nullptr) + osd_printf_warning("Device '%s' found but lacks address space #%d\n", m_tag, spacenum); + else if (width != 0 && width != config->data_width()) + osd_printf_warning("Device '%s' found but space #%d has the wrong data width (expected %d, found %d)\n", m_tag, spacenum, width, config->data_width()); + } + } + else if (required) + osd_printf_warning("Device '%s' found but lacks memory interface\n", m_tag); + + // report result + return report_missing(config != nullptr && (width == 0 || width == config->data_width()), "address space", required); +} + + +//------------------------------------------------- // report_missing - report missing objects and // return true if it's ok //------------------------------------------------- bool finder_base::report_missing(bool found, const char *objname, bool required) const { - if (required && (strcmp(m_tag, DUMMY_TAG) == 0)) + if (required && (DUMMY_TAG == m_tag)) { osd_printf_error("Tag not defined for required %s\n", objname); return false; } - - // just pass through in the found case - if (found) + else if (found) + { + // just pass through in the found case return true; - - // otherwise, report - std::string const region_fulltag(m_base.get().subtag(m_tag)); - if (required) - osd_printf_error("Required %s '%s' not found\n", objname, region_fulltag.c_str()); + } else - osd_printf_verbose("Optional %s '%s' not found\n", objname, region_fulltag.c_str()); - return !required; + { + // otherwise, report + std::string const region_fulltag(m_base.get().subtag(m_tag)); + if (required) + osd_printf_error("Required %s '%s' not found\n", objname, region_fulltag.c_str()); + else if (DUMMY_TAG != m_tag) + osd_printf_verbose("Optional %s '%s' not found\n", objname, region_fulltag.c_str()); + return !required; + } } @@ -261,7 +342,7 @@ void finder_base::printf_warning(const char *format, ...) va_list argptr; char buffer[1024]; - /* do the output */ + // do the output va_start(argptr, format); vsnprintf(buffer, 1024, format, argptr); osd_printf_warning("%s", buffer); |