I find the problem in the following routine. See memory.c.
Code:
void address_space::prepare_map()
{
const region_info *devregion = (m_spacenum == ADDRESS_SPACE_0) ? m_machine.region(m_device.tag()) : NULL;
UINT32 devregionsize = (devregion != NULL) ? devregion->bytes() : 0;
// allocate the address map
m_map = global_alloc(address_map(m_device.baseconfig(), m_spacenum));
// extract global parameters specified by the map
m_unmap = (m_map->m_unmapval == 0) ? 0 : ~0;
if (m_map->m_globalmask != 0)
{
m_addrmask = m_map->m_globalmask;
m_bytemask = address_to_byte_end(m_addrmask);
}
// make a pass over the address map, adjusting for the device and getting memory pointers
for (address_map_entry *entry = m_map->m_entrylist.first(); entry != NULL; entry = entry->next())
{
// computed adjusted addresses first
entry->m_bytestart = entry->m_addrstart;
entry->m_byteend = entry->m_addrend;
entry->m_bytemirror = entry->m_addrmirror;
entry->m_bytemask = entry->m_addrmask;
adjust_addresses(entry->m_bytestart, entry->m_byteend, entry->m_bytemask, entry->m_bytemirror);
"entry->m_addrmask" will be "0" in this time so that "entry->m_bytemask" also "0".
In this case, adjust_address() with mirror != 0 causes wrong mask adjustment.
Code:
inline void address_space::adjust_addresses(offs_t &start, offs_t &end, offs_t &mask, offs_t &mirror)
{
// adjust start/end/mask values
if (mask == 0)
mask = m_addrmask & ~mirror;
else
mask &= m_addrmask;
start &= ~mirror & m_addrmask;
end &= ~mirror & m_addrmask;
In 20pacgal.c, "0xA000 - 0xFFFF" is defined as "AM_RANGE(0x0a000, 0x0ffff) AM_MIRROR(0x40000) AM_ROM".
So... adjusted mask is "(0xFFFFF & 0xBFFFF (= ~0x40000)) = 0xBFFFF" (Not 0xFFFFF!).
This value is used in find_backing_memory() to add requested memory entry into each handlers.
The problem happens when compare "0xA000 - 0xFFFF" (ROM) vs "0x4FF00 - 0x4FFFF" (sprite_color_lookup).
Start_address is "0x4FF00 & 0xBFFFF = 0xFF00" and end_address is "0x4FFFF & 0xBFFFF = 0xFFFF".
So write_handler regists "ROM" entry as "sprite_color_lookup" and it breaks the contents of ROM at boot sequence.
Quick fix is...
Code:
// computed adjusted addresses first
entry->m_bytestart = entry->m_addrstart;
entry->m_byteend = entry->m_addrend;
entry->m_bytemirror = entry->m_addrmirror;
entry->m_bytemask = m_bytemask;
adjust_addresses(entry->m_bytestart, entry->m_byteend, entry->m_bytemask, entry->m_bytemirror);
Main point is that set tha value for (global) address_space's "m_bytemask" instead of address_map_entry's.
"Any company has no power to stop people emulating"
MAME is the emulator of no giving in the pressure from any company even if they don't allow