fixed ROM_COPY to use a relative region name, so it can be used in a device. [smf]

This commit is contained in:
smf- 2024-11-22 01:02:31 +00:00
parent 3e388b7da7
commit f789663244
3 changed files with 60 additions and 1 deletions

View File

@ -1077,6 +1077,64 @@ memory_region::memory_region(running_machine &machine, std::string name, u32 len
assert(width == 1 || width == 2 || width == 4 || width == 8);
}
std::string memory_region::sibling(std::string_view tag) const
{
std::string result;
if (!tag.empty() && (tag[0] == ':'))
{
// if the tag begins with a colon, ignore our path and start from the root
tag.remove_prefix(1);
result.assign(":");
}
else
{
// otherwise, start relative to current path
std::string::size_type lastcolon = m_name.find_last_of(':');
if (lastcolon != std::string::npos)
result.assign(m_name, 0, lastcolon + 1);
}
// iterate over the tag, look for special path characters to resolve
std::string_view::size_type delimiter;
while ((delimiter = tag.find_first_of("^:")) != std::string_view::npos)
{
// copy everything up to there
bool const parent = tag[delimiter] == '^';
result.append(tag, 0, delimiter);
tag.remove_prefix(delimiter + 1);
if (parent)
{
// strip trailing colons
std::string::size_type len = result.length();
while ((len > 1) && (result[--len] == ':'))
result.resize(len);
// remove the last path part, leaving the last colon
if (result != ":")
{
std::string::size_type lastcolon = result.find_last_of(':');
if (lastcolon != std::string::npos)
result.resize(lastcolon + 1);
}
}
else
{
// collapse successive colons
if (result.back() != ':')
result.append(1, ':');
delimiter = tag.find_first_not_of(':');
if (delimiter != std::string_view::npos)
tag.remove_prefix(delimiter);
}
}
// copy everything else
result.append(tag);
return result;
}
std::string memory_share::compare(u8 width, size_t bytes, endianness_t endianness) const
{
if (width != m_bitwidth)

View File

@ -2589,6 +2589,7 @@ public:
u8 *end() { return base() + m_buffer.size(); }
u32 bytes() const { return m_buffer.size(); }
const std::string &name() const { return m_name; }
std::string sibling(std::string_view tag) const;
// flag expansion
endianness_t endianness() const { return m_endianness; }

View File

@ -963,7 +963,7 @@ void rom_load_manager::fill_rom_data(memory_region &region, const rom_entry *rom
void rom_load_manager::copy_rom_data(memory_region &region, const rom_entry *romp)
{
u8 *base = region.base() + ROM_GETOFFSET(romp);
const std::string &srcrgntag = romp->name();
const std::string srcrgntag = region.sibling(romp->name());
u32 numbytes = ROM_GETLENGTH(romp);
u32 srcoffs = u32(strtol(romp->hashdata().c_str(), nullptr, 0)); /* srcoffset in place of hashdata */