diff options
| author | 2019-01-22 11:35:46 -0500 | |
|---|---|---|
| committer | 2019-01-22 11:39:32 -0500 | |
| commit | a6f64287a3acbcb6ee629774918407be30807237 (patch) | |
| tree | aad4116170e4761c3f76eb2cec7396c0a86ec7dc /src/emu/devfind.cpp | |
| parent | 8bca61dcd6f0184fce5b82f9c0ed3c5fb2a80d5a (diff) | |
Add object finder for address spaces
(nw) The constructor and set_tag methods for required_address_space and optional_address_space work slightly differently from other finders in that they take the address space number as an extra argument. There is also an option to request a space having a specific data width, and validation checks this as well as the space number. There is also no (required|optional)_address_space_array, but that shouldn't really be necessary since devices shouldn't need large numbers of these finders.
Diffstat (limited to 'src/emu/devfind.cpp')
| -rw-r--r-- | src/emu/devfind.cpp | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/src/emu/devfind.cpp b/src/emu/devfind.cpp index d3cfaf8c0a1..c7d6520875b 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,6 +235,79 @@ 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 //------------------------------------------------- @@ -240,7 +318,7 @@ bool finder_base::report_missing(bool found, const char *objname, bool required) { osd_printf_error("Tag not defined for required %s\n", objname); return false; - } + } // just pass through in the found case if (found) |
