dirom,okim6295: Add/fix banking support. Better okim fix post-release [O. Galibert]

This commit is contained in:
Olivier Galibert 2016-08-24 23:07:14 +02:00
parent 4d440e949a
commit f4db841a2e
3 changed files with 36 additions and 22 deletions

View File

@ -196,21 +196,7 @@ void okim6295_device::set_bank_base(offs_t base, bool bDontUpdateStream)
{
m_stream->update();
}
// if we are setting a non-zero base, and we have no bank, allocate one
if (!m_bank_installed && base != 0)
{
// override our memory map with a bank
space().install_read_bank(0x00000, 0x3ffff, tag());
m_bank_installed = true;
}
// if we have a bank number, set the base pointer
if (m_bank_installed)
{
m_bank_offs = base;
membank(tag())->set_base(m_region->base() + base);
}
set_rom_bank(base / 0x40000);
}

View File

@ -16,17 +16,35 @@ const address_space_config *device_rom_interface::memory_space_config(address_sp
return spacenum ? nullptr : &m_rom_config;
}
void device_rom_interface::set_rom_bank(int bank)
{
if(!m_bank)
emu_fatalerror("%s: device_rom_interface::set_rom_bank called without banking setup", device().tag());
m_cur_bank = bank;
m_bank->set_entry(bank);
}
void device_rom_interface::reset_bank()
{
if(m_bank)
m_bank->set_entry(m_cur_bank);
}
void device_rom_interface::set_rom(const void *base, UINT32 size)
{
UINT32 mend = m_rom_config.addr_width() == 32 ? 0xffffffff : (1 << m_rom_config.addr_width()) - 1;
UINT32 rend = size-1;
if(rend > mend) {
device().logerror("Warning: The rom for device %s is %x bytes, while the chip addressing space is only %x bytes.\n", device().tag(), rend+1, mend+1);
rend = mend;
}
if(rend == mend)
space().install_rom(0, mend, const_cast<void *>(base));
else {
UINT32 banks = (rend+1) / (mend+1);
if(banks < 1)
banks = 1;
if(rend >= mend) {
space().install_read_bank(0, mend, device().tag());
m_bank = device().machine().memory().banks().find(device().tag())->second.get();
m_bank->configure_entries(0, banks, const_cast<void *>(base), mend+1);
} else {
// Round up to the nearest power-of-two-minus-one
UINT32 rmask = rend;
rmask |= rmask >> 1;
@ -45,6 +63,10 @@ void device_rom_interface::set_rom(const void *base, UINT32 size)
void device_rom_interface::interface_pre_start()
{
m_rom_direct = &space().direct();
m_bank = nullptr;
m_cur_bank = -1;
device().save_item(NAME(m_cur_bank));
device().machine().save().register_postload(save_prepost_delegate(FUNC(device_rom_interface::reset_bank), this));
if(!has_configured_map(0)) {
memory_region *reg = device().memregion(DEVICE_SELF);

View File

@ -29,11 +29,15 @@ public:
inline UINT64 read_qword(offs_t byteaddress) { return m_rom_direct->read_qword(byteaddress); }
void set_rom(const void *base, UINT32 size);
void set_rom_bank(int bank);
private:
const address_space_config m_rom_config;
direct_read_data *m_rom_direct;
memory_bank *m_bank;
int m_cur_bank;
virtual const address_space_config *memory_space_config(address_spacenum spacenum) const override;
virtual void interface_pre_start() override;
@ -41,6 +45,8 @@ private:
DECLARE_READ16_MEMBER(z16_r);
DECLARE_READ32_MEMBER(z32_r);
DECLARE_READ64_MEMBER(z64_r);
void reset_bank();
};
#endif