From 7f13cc2de1af6f5351fc281e5797be6381e8c10e Mon Sep 17 00:00:00 2001 From: Olivier Galibert Date: Thu, 10 Dec 2020 13:37:51 +0100 Subject: [PATCH] slapstic: make the modern interface even nicer, convert rampart and gauntlet --- src/mame/drivers/atetris.cpp | 4 ++-- src/mame/drivers/gauntlet.cpp | 19 ++++++------------- src/mame/drivers/rampart.cpp | 16 +++------------- src/mame/drivers/starwars.cpp | 4 ++-- src/mame/includes/gauntlet.h | 1 - src/mame/includes/rampart.h | 3 --- src/mame/machine/harddriv.cpp | 4 ++-- src/mame/machine/slapstic.cpp | 21 +++++++++++++++------ src/mame/machine/slapstic.h | 8 ++++++-- src/mame/video/atarisy2.cpp | 8 ++++---- 10 files changed, 40 insertions(+), 48 deletions(-) diff --git a/src/mame/drivers/atetris.cpp b/src/mame/drivers/atetris.cpp index 882f4977b6a..53a8c4392af 100644 --- a/src/mame/drivers/atetris.cpp +++ b/src/mame/drivers/atetris.cpp @@ -117,7 +117,7 @@ void atetris_state::machine_start() void atetris_state::machine_reset() { - m_current_bank = m_slapstic->slapstic_bank() & 1; + m_current_bank = m_slapstic->bank() & 1; reset_bank(); /* start interrupts going (32V clocked by 16V) */ @@ -135,7 +135,7 @@ void atetris_state::machine_reset() uint8_t atetris_state::slapstic_r(address_space &space, offs_t offset) { int result = m_slapstic_base[0x2000 + offset]; - int new_bank = m_slapstic->slapstic_tweak(space, offset) & 1; + int new_bank = m_slapstic->tweak(space, offset) & 1; /* update for the new bank */ if (new_bank != m_current_bank) diff --git a/src/mame/drivers/gauntlet.cpp b/src/mame/drivers/gauntlet.cpp index 608179bd511..f72195e3ddf 100644 --- a/src/mame/drivers/gauntlet.cpp +++ b/src/mame/drivers/gauntlet.cpp @@ -549,6 +549,7 @@ void gauntlet_state::gauntlet(machine_config & config) { gauntlet_base(config); SLAPSTIC(config, m_slapstic, 104, true); + m_slapstic->set_bank(m_slapstic_bank); } @@ -556,6 +557,7 @@ void gauntlet_state::gaunt2p(machine_config & config) { gauntlet_base(config); SLAPSTIC(config, m_slapstic, 107, true); + m_slapstic->set_bank(m_slapstic_bank); } @@ -563,6 +565,7 @@ void gauntlet_state::gauntlet2(machine_config & config) { gauntlet_base(config); SLAPSTIC(config, m_slapstic, 106, true); + m_slapstic->set_bank(m_slapstic_bank); } @@ -570,6 +573,7 @@ void gauntlet_state::vindctr2(machine_config & config) { gauntlet_base(config); SLAPSTIC(config, m_slapstic, 118, true); + m_slapstic->set_bank(m_slapstic_bank); } @@ -1651,24 +1655,13 @@ void gauntlet_state::swap_memory(void *ptr1, void *ptr2, int bytes) } } -void gauntlet_state::slapstic_tweak(offs_t offset, u16 &, u16) -{ - m_slapstic->slapstic_tweak(m_maincpu->space(AS_PROGRAM), (offset >> 1) & 0x3fff); - m_slapstic_bank->set_entry(m_slapstic->slapstic_bank()); -} - -void gauntlet_state::machine_reset() -{ - m_slapstic_bank->set_entry(m_slapstic->slapstic_bank()); -} - void gauntlet_state::common_init(int vindctr2) { u8 *rom = memregion("maincpu")->base(); m_slapstic_bank->configure_entries(0, 4, rom + 0x38000, 0x2000); m_maincpu->space(AS_PROGRAM).install_readwrite_tap(0x38000, 0x3ffff, 0x280000, "slapstic", - [this](offs_t offset, u16 &data, u16 mem_mask) { slapstic_tweak(offset, data, mem_mask); }, - [this](offs_t offset, u16 &data, u16 mem_mask) { slapstic_tweak(offset, data, mem_mask); }); + [this](offs_t offset, u16 &data, u16 mem_mask) { m_slapstic->tweak(m_maincpu->space(), offset >> 1); }, + [this](offs_t offset, u16 &data, u16 mem_mask) { m_slapstic->tweak(m_maincpu->space(), offset >> 1); }); // swap the top and bottom halves of the main CPU ROM images swap_memory(rom + 0x000000, rom + 0x008000, 0x8000); diff --git a/src/mame/drivers/rampart.cpp b/src/mame/drivers/rampart.cpp index a9e1769ca7d..06aaf9d8036 100644 --- a/src/mame/drivers/rampart.cpp +++ b/src/mame/drivers/rampart.cpp @@ -329,6 +329,7 @@ void rampart_state::rampart(machine_config &config) m_maincpu->set_addrmap(AS_PROGRAM, &rampart_state::main_map); SLAPSTIC(config, m_slapstic, 118, true); + m_slapstic->set_bank(m_slapstic_bank); TIMER(config, "scantimer").configure_scanline(FUNC(rampart_state::scanline_interrupt), m_screen, 0, 32); @@ -491,23 +492,12 @@ ROM_END * *************************************/ -void rampart_state::slapstic_tweak(offs_t offset, u16 &, u16) -{ - m_slapstic->slapstic_tweak(m_maincpu->space(AS_PROGRAM), (offset >> 1) & 0x3fff); - m_slapstic_bank->set_entry(m_slapstic->slapstic_bank()); -} - void rampart_state::machine_start() { m_slapstic_bank->configure_entries(0, 4, memregion("maincpu")->base() + 0x40000, 0x2000); m_maincpu->space(AS_PROGRAM).install_readwrite_tap(0x140000, 0x147fff, 0x438000, "slapstic", - [this](offs_t offset, u16 &data, u16 mem_mask) { slapstic_tweak(offset, data, mem_mask); }, - [this](offs_t offset, u16 &data, u16 mem_mask) { slapstic_tweak(offset, data, mem_mask); }); -} - -void rampart_state::machine_reset() -{ - m_slapstic_bank->set_entry(m_slapstic->slapstic_bank()); + [this](offs_t offset, u16 &data, u16 mem_mask) { m_slapstic->tweak(m_maincpu->space(), offset >> 1); }, + [this](offs_t offset, u16 &data, u16 mem_mask) { m_slapstic->tweak(m_maincpu->space(), offset >> 1); }); } diff --git a/src/mame/drivers/starwars.cpp b/src/mame/drivers/starwars.cpp index b540cb07ef3..d9331bc76a9 100644 --- a/src/mame/drivers/starwars.cpp +++ b/src/mame/drivers/starwars.cpp @@ -62,7 +62,7 @@ void starwars_state::machine_reset() if (m_slapstic_device.found()) { /* reset the slapstic */ - m_slapstic_current_bank = m_slapstic_device->slapstic_bank(); + m_slapstic_current_bank = m_slapstic_device->bank(); memcpy(m_slapstic_base, &m_slapstic_source[m_slapstic_current_bank * 0x2000], 0x2000); } @@ -93,7 +93,7 @@ void starwars_state::irq_ack_w(uint8_t data) void starwars_state::esb_slapstic_tweak(address_space &space, offs_t offset) { - int new_bank = m_slapstic_device->slapstic_tweak(space, offset); + int new_bank = m_slapstic_device->tweak(space, offset); /* update for the new bank */ if (new_bank != m_slapstic_current_bank) diff --git a/src/mame/includes/gauntlet.h b/src/mame/includes/gauntlet.h index 0ee7a83a51b..28dc5bc990e 100644 --- a/src/mame/includes/gauntlet.h +++ b/src/mame/includes/gauntlet.h @@ -54,7 +54,6 @@ public: protected: virtual void video_start() override; - virtual void machine_reset() override; private: void video_int_ack_w(uint16_t data = 0); diff --git a/src/mame/includes/rampart.h b/src/mame/includes/rampart.h index c1d59bc4152..13039d01099 100644 --- a/src/mame/includes/rampart.h +++ b/src/mame/includes/rampart.h @@ -38,7 +38,6 @@ public: protected: virtual void machine_start() override; - virtual void machine_reset() override; virtual void video_start() override; private: @@ -62,8 +61,6 @@ private: required_shared_ptr m_bitmap; static const atari_motion_objects_config s_mob_config; - - void slapstic_tweak(offs_t offset, u16 &, u16); }; #endif // MAME_INCLUDES_RAMPART_H diff --git a/src/mame/machine/harddriv.cpp b/src/mame/machine/harddriv.cpp index 36dba404b55..194a9e7f58f 100644 --- a/src/mame/machine/harddriv.cpp +++ b/src/mame/machine/harddriv.cpp @@ -1699,13 +1699,13 @@ void harddriv_state::hddspcom_control_w(offs_t offset, uint16_t data) void harddriv_state::rd68k_slapstic_w(address_space &space, offs_t offset, uint16_t data) { - m_slapstic_device->slapstic_tweak(space, offset & 0x3fff); + m_slapstic_device->tweak(space, offset & 0x3fff); } uint16_t harddriv_state::rd68k_slapstic_r(address_space &space, offs_t offset) { - int bank = m_slapstic_device->slapstic_tweak(space, offset & 0x3fff) * 0x4000; + int bank = m_slapstic_device->tweak(space, offset & 0x3fff) * 0x4000; return m_m68k_slapstic_base[bank + (offset & 0x3fff)]; } diff --git a/src/mame/machine/slapstic.cpp b/src/mame/machine/slapstic.cpp index 93a1b5aefa0..b916a2ae229 100644 --- a/src/mame/machine/slapstic.cpp +++ b/src/mame/machine/slapstic.cpp @@ -209,6 +209,7 @@ atari_slapstic_device::atari_slapstic_device(const machine_config &mconfig, cons bit_bank(0), add_bank(0), bit_xor(0), + m_bank(*this, finder_base::DUMMY_TAG), m_legacy_configured(false), m_legacy_space(nullptr), m_legacy_memptr(nullptr), @@ -252,7 +253,7 @@ atari_slapstic_device::atari_slapstic_device(const machine_config &mconfig, cons void atari_slapstic_device::device_post_load() { if (m_legacy_configured) - legacy_update_bank(slapstic_bank()); + legacy_update_bank(bank()); } /************************************* @@ -787,8 +788,11 @@ void atari_slapstic_device::device_reset(void) /* the 111 and later chips seem to reset to bank 0 */ current_bank = slapstic.bankstart; + if(m_bank) + m_bank->set_entry(current_bank); + if (m_legacy_configured) - legacy_update_bank(slapstic_bank()); + legacy_update_bank(bank()); } @@ -799,7 +803,7 @@ void atari_slapstic_device::device_reset(void) * *************************************/ -int atari_slapstic_device::slapstic_bank(void) +int atari_slapstic_device::bank(void) { return current_bank; } @@ -859,8 +863,10 @@ int atari_slapstic_device::alt2_kludge(address_space &space, offs_t offset) * *************************************/ -int atari_slapstic_device::slapstic_tweak(address_space &space, offs_t offset) +int atari_slapstic_device::tweak(address_space &space, offs_t offset) { + offset &= 0x3fff; + /* reset is universal */ if (offset == 0x0000) { @@ -1071,6 +1077,9 @@ int atari_slapstic_device::slapstic_tweak(address_space &space, offs_t offset) if (LOG_SLAPSTIC) slapstic_log(offset); + if(m_bank) + m_bank->set_entry(current_bank); + /* return the active bank */ return current_bank; } @@ -1161,7 +1170,7 @@ void atari_slapstic_device::slapstic_w(offs_t offset, u16 data, u16 mem_mask) { assert(m_legacy_configured); - // legacy_update_bank(slapstic_tweak(*m_legacy_space, offset)); + legacy_update_bank(tweak(*m_legacy_space, offset)); } @@ -1180,7 +1189,7 @@ u16 atari_slapstic_device::slapstic_r(offs_t offset, u16 mem_mask) if (!machine().side_effects_disabled()) { // then determine the new one - legacy_update_bank(slapstic_tweak(*m_legacy_space, offset)); + legacy_update_bank(tweak(*m_legacy_space, offset)); } return result; } diff --git a/src/mame/machine/slapstic.h b/src/mame/machine/slapstic.h index 3497958fca0..769580702df 100644 --- a/src/mame/machine/slapstic.h +++ b/src/mame/machine/slapstic.h @@ -118,8 +118,10 @@ public: atari_slapstic_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - int slapstic_bank(); - int slapstic_tweak(address_space &space, offs_t offset); + template void set_bank(T &&tag) { m_bank.set_tag(std::forward(tag)); } + + int bank(); + int tweak(address_space &space, offs_t offset); int alt2_kludge(address_space &space, offs_t offset); @@ -158,6 +160,8 @@ private: void slapstic_w(offs_t offset, u16 data, u16 mem_mask); uint16_t slapstic_r(offs_t offset, u16 mem_mask); + optional_memory_bank m_bank; + bool m_legacy_configured; address_space * m_legacy_space; u16 * m_legacy_memptr; diff --git a/src/mame/video/atarisy2.cpp b/src/mame/video/atarisy2.cpp index f9ef54e5176..1486919e0dc 100644 --- a/src/mame/video/atarisy2.cpp +++ b/src/mame/video/atarisy2.cpp @@ -190,20 +190,20 @@ rgb_t atarisy2_state::RRRRGGGGBBBBIIII(uint32_t raw) uint16_t atarisy2_state::slapstic_r(address_space &space, offs_t offset) { int result = m_slapstic_region[offset + 0100000/2]; - m_slapstic->slapstic_tweak(space, offset); + m_slapstic->tweak(space, offset); /* an extra tweak for the next opcode fetch */ - m_vrambank->set_bank(m_slapstic->slapstic_tweak(space, 0x1234)); + m_vrambank->set_bank(m_slapstic->tweak(space, 0x1234)); return result; } void atarisy2_state::slapstic_w(address_space &space, offs_t offset, uint16_t data) { - m_slapstic->slapstic_tweak(space, offset); + m_slapstic->tweak(space, offset); /* an extra tweak for the next opcode fetch */ - m_vrambank->set_bank(m_slapstic->slapstic_tweak(space, 0x1234)); + m_vrambank->set_bank(m_slapstic->tweak(space, 0x1234)); }