Previous 199869 Revisions Next

r18417 Wednesday 10th October, 2012 at 15:33:36 UTC by O. Galibert
memory: Fix dynamic recursive device mapping [O. Galibert]

Situation:
- you have a device (pc-fdc) with a memory map on it
- you map it dynamically into a cpu (maincpu) address space with install_device (isa-fdc does that)
- the device pc-fdc has a subdevice (upd765)
- the subdevice upd765 has its own memory map
- the pc-fdc memory map includes the upd765 memory map through AM_DEVICE("upd765", ...)

Before the fix, the code would search for upd765 as a subdevice of
maincpu and not of pc-fdc.
[src/emu]addrmap.c addrmap.h memory.c memory.h

trunk/src/emu/memory.c
r18416r18417
17831783   m_map = global_alloc(address_map(m_device, m_spacenum));
17841784
17851785   // merge in the submaps
1786   m_map->uplift_submaps(machine(), m_device, endianness());
1786   m_map->uplift_submaps(machine(), m_device, machine().root_device(), endianness());
17871787
17881788   // extract global parameters specified by the map
17891789   m_unmap = (m_map->m_unmapval == 0) ? 0 : ~0;
r18416r18417
22512251void address_space::install_device_delegate(offs_t addrstart, offs_t addrend, device_t &device, address_map_delegate &delegate, int bits, UINT64 unitmask)
22522252{
22532253   address_map map(*this, addrstart, addrend, bits, unitmask, device, delegate);
2254   map.uplift_submaps(machine(), m_device, endianness());
2254   map.uplift_submaps(machine(), m_device, device, endianness());
22552255   populate_from_map(&map);
22562256}
22572257
trunk/src/emu/addrmap.c
r18416r18417
716716//  uplift_submaps - propagate in the device submaps
717717//-------------------------------------------------
718718
719void address_map::uplift_submaps(running_machine &machine, device_t &device, endianness_t endian)
719void address_map::uplift_submaps(running_machine &machine, device_t &device, device_t &owner, endianness_t endian)
720720{
721721   address_map_entry *prev = 0;
722722   address_map_entry *entry = m_entrylist.first();
r18416r18417
724724   {
725725      if (entry->m_read.m_type == AMH_DEVICE_SUBMAP)
726726      {
727         const char *tag = entry->m_read.m_tag;
727         astring tag;
728         owner.subtag(tag, entry->m_read.m_tag);
728729         device_t *mapdevice = machine.device(tag);
729         if (mapdevice == NULL)
730            throw emu_fatalerror("Attempted to submap a non-existent device '%s' in space %d of device '%s'\n", tag, m_spacenum, device.tag());
730         if (mapdevice == NULL) {
731            throw emu_fatalerror("Attempted to submap a non-existent device '%s' in space %d of device '%s'\n", tag.cstr(), m_spacenum, device.basetag());
732         }
731733         // Grab the submap
732734         address_map submap(*mapdevice, entry);
733735
734736         // Recursively uplift it if needed
735         submap.uplift_submaps(machine, *mapdevice, endian);
737         submap.uplift_submaps(machine, device, *mapdevice, endian);
736738
737739         // Compute the unit repartition characteristics
738740         int entry_bits = entry->m_submap_bits;
trunk/src/emu/memory.h
r18416r18417
437437   void *install_ram(offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, void *baseptr = NULL) { return install_ram_generic(addrstart, addrend, addrmask, addrmirror, ROW_READWRITE, baseptr); }
438438
439439   // install device memory maps
440   template <typename T> void install_device(offs_t addrstart, offs_t addrend, T &device, void (T::*map)(address_map &map, const device_t &device), int bits = 0, UINT64 unitmask = 0) {
440   template <typename T> void install_device(offs_t addrstart, offs_t addrend, T &device, void (T::*map)(address_map &map, device_t &device), int bits = 0, UINT64 unitmask = 0) {
441441      address_map_delegate delegate(map, "dynamic_device_install", &device);
442442      install_device_delegate(addrstart, addrend, device, delegate, bits, unitmask);
443443   }
trunk/src/emu/addrmap.h
r18416r18417
365365   offs_t               m_globalmask;      // global mask
366366   simple_list<address_map_entry> m_entrylist;   // list of entries
367367
368   void uplift_submaps(running_machine &machine, device_t &device, endianness_t endian);
368   void uplift_submaps(running_machine &machine, device_t &device, device_t &owner, endianness_t endian);
369369};
370370
371371

Previous 199869 Revisions Next


© 1997-2024 The MAME Team