std::tuple<const char *, device_t *, device_t *> machine_config::prepare_replace(const char *tag) { // make sure we have the old device's actual owner std::pair<const char *, device_t *> const owner(resolve_owner(tag)); assert(owner.second); // remove references to the old device device_t *const old_device(owner.second->subdevice(owner.first)); if (old_device) remove_references(*old_device); else osd_printf_warning("Warning: attempting to replace non-existent device '%s'\n", tag); return std::make_tuple(owner.first, owner.second, old_device); }
device_t *machine_config::device_remove(device_t *owner, const char *tag) { // find the original device by relative tag (must exist) assert(owner != nullptr); device_t *device = owner->subdevice(tag); if (device == nullptr) { osd_printf_warning("Warning: attempting to remove non-existent device '%s'\n", tag); return nullptr; } // make sure we have the old device's actual owner owner = device->owner(); assert(owner != nullptr); // remove references to the old device remove_references(*device); // let the device's owner do the work owner->subdevices().m_list.remove(*device); return nullptr; }
device_t *machine_config::device_replace(device_t *owner, const char *tag, device_type type, UINT32 clock) { // find the original device by relative tag (must exist) assert(owner != nullptr); device_t *old_device = owner->subdevice(tag); if (old_device == nullptr) { osd_printf_warning("Warning: attempting to replace non-existent device '%s'\n", tag); return device_add(owner, tag, type, clock); } // make sure we have the old device's actual owner owner = old_device->owner(); assert(owner != nullptr); // remove references to the old device remove_references(*old_device); // allocate the new device device_t *new_device = (*type)(*this, tag, owner, clock); // substitute it for the old one in the owner's list return &config_new_device(owner->subdevices().m_list.replace_and_remove(*new_device, *old_device)); }