From f4db841a2e70e0f4bf440b912de717c72d445a5f Mon Sep 17 00:00:00 2001 From: Olivier Galibert Date: Wed, 24 Aug 2016 23:07:14 +0200 Subject: [PATCH] dirom,okim6295: Add/fix banking support. Better okim fix post-release [O. Galibert] --- src/devices/sound/okim6295.cpp | 16 +-------------- src/emu/dirom.cpp | 36 +++++++++++++++++++++++++++------- src/emu/dirom.h | 6 ++++++ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/devices/sound/okim6295.cpp b/src/devices/sound/okim6295.cpp index f5b2490fb52..7926687b879 100644 --- a/src/devices/sound/okim6295.cpp +++ b/src/devices/sound/okim6295.cpp @@ -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); } diff --git a/src/emu/dirom.cpp b/src/emu/dirom.cpp index 45a4dd2dc56..a055ce00539 100644 --- a/src/emu/dirom.cpp +++ b/src/emu/dirom.cpp @@ -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(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(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); diff --git a/src/emu/dirom.h b/src/emu/dirom.h index 900b5a09517..b09d32c502a 100644 --- a/src/emu/dirom.h +++ b/src/emu/dirom.h @@ -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