From 31b187b51e3d72d2d382911d1012f12250f0ee46 Mon Sep 17 00:00:00 2001 From: cam900 Date: Fri, 28 Feb 2025 23:04:01 +0900 Subject: yachiyo/mole.cpp: Cleaned up code: (#13427) Use a memory share creator for tile RAM, improved member names and tags. --- src/mame/yachiyo/mole.cpp | 72 ++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/src/mame/yachiyo/mole.cpp b/src/mame/yachiyo/mole.cpp index c265466387b..b332a5f2ab4 100644 --- a/src/mame/yachiyo/mole.cpp +++ b/src/mame/yachiyo/mole.cpp @@ -59,6 +59,8 @@ #include "speaker.h" #include "tilemap.h" +#include + namespace { @@ -68,10 +70,11 @@ public: mole_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag), m_maincpu(*this, "maincpu"), - m_gfxdecode(*this, "gfxdecode") + m_gfxdecode(*this, "gfxdecode"), + m_tileram(*this, "tileram", 0x400*2, ENDIANNESS_LITTLE) { } - void mole(machine_config &config); + void mole(machine_config &config) ATTR_COLD; protected: virtual void video_start() override ATTR_COLD; @@ -80,21 +83,21 @@ private: required_device m_maincpu; required_device m_gfxdecode; + memory_share_creator m_tileram; + /* video-related */ tilemap_t *m_bg_tilemap = nullptr; uint8_t m_tile_bank = 0; - /* memory */ - uint16_t m_tileram[0x400]; - - void mole_tileram_w(offs_t offset, uint8_t data); - void mole_tilebank_w(uint8_t data); - void mole_irqack_w(uint8_t data); - void mole_flipscreen_w(uint8_t data); - uint8_t mole_protection_r(offs_t offset); + void tileram_w(offs_t offset, uint8_t data); + void tilebank_w(uint8_t data); + void irqack_w(uint8_t data); + void flipscreen_w(uint8_t data); + uint8_t protection_r(offs_t offset); TILE_GET_INFO_MEMBER(get_bg_tile_info); - uint32_t screen_update_mole(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - void mole_map(address_map &map) ATTR_COLD; + uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + + void main_map(address_map &map) ATTR_COLD; }; @@ -106,42 +109,41 @@ private: TILE_GET_INFO_MEMBER(mole_state::get_bg_tile_info) { - uint16_t code = m_tileram[tile_index]; + uint16_t const code = m_tileram[tile_index]; - tileinfo.set((code & 0x200) ? 1 : 0, code & 0x1ff, 0, 0); + tileinfo.set(BIT(code, 9), code & 0x1ff, 0, 0); } void mole_state::video_start() { - memset(m_tileram, 0, sizeof(m_tileram)); + std::fill_n(&m_tileram[0], m_tileram.length(), 0); m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(mole_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 40, 25); - save_item(NAME(m_tileram)); save_item(NAME(m_tile_bank)); } -void mole_state::mole_tileram_w(offs_t offset, uint8_t data) +void mole_state::tileram_w(offs_t offset, uint8_t data) { m_tileram[offset] = data | (m_tile_bank << 8); m_bg_tilemap->mark_tile_dirty(offset); } -void mole_state::mole_tilebank_w(uint8_t data) +void mole_state::tilebank_w(uint8_t data) { m_tile_bank = data; } -void mole_state::mole_irqack_w(uint8_t data) +void mole_state::irqack_w(uint8_t data) { m_maincpu->set_input_line(0, CLEAR_LINE); } -void mole_state::mole_flipscreen_w(uint8_t data) +void mole_state::flipscreen_w(uint8_t data) { - flip_screen_set(data & 0x01); + flip_screen_set(BIT(data, 0)); } -uint32_t mole_state::screen_update_mole(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +uint32_t mole_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0); return 0; @@ -154,7 +156,7 @@ uint32_t mole_state::screen_update_mole(screen_device &screen, bitmap_ind16 &bit * *************************************/ -uint8_t mole_state::mole_protection_r(offs_t offset) +uint8_t mole_state::protection_r(offs_t offset) { /* Following are all known examples of Mole Attack ** code reading from the protection circuitry: @@ -209,23 +211,23 @@ uint8_t mole_state::mole_protection_r(offs_t offset) * *************************************/ -void mole_state::mole_map(address_map &map) +void mole_state::main_map(address_map &map) { map(0x0000, 0x03ff).ram(); - map(0x0800, 0x08ff).r(FUNC(mole_state::mole_protection_r)); + map(0x0800, 0x08ff).r(FUNC(mole_state::protection_r)); map(0x0800, 0x0800).nopw(); // ??? map(0x0820, 0x0820).nopw(); // ??? map(0x5000, 0x7fff).mirror(0x8000).rom(); - map(0x8000, 0x83ff).w(FUNC(mole_state::mole_tileram_w)).nopr(); - map(0x8400, 0x8400).w(FUNC(mole_state::mole_tilebank_w)); + map(0x8000, 0x83ff).w(FUNC(mole_state::tileram_w)).nopr(); + map(0x8400, 0x8400).w(FUNC(mole_state::tilebank_w)); map(0x8c00, 0x8c01).w("aysnd", FUNC(ay8910_device::data_address_w)); map(0x8c40, 0x8c40).nopw(); // ??? map(0x8c80, 0x8c80).nopw(); // ??? map(0x8c81, 0x8c81).nopw(); // ??? - map(0x8d00, 0x8d00).portr("DSW").w(FUNC(mole_state::mole_irqack_w)); + map(0x8d00, 0x8d00).portr("DSW").w(FUNC(mole_state::irqack_w)); map(0x8d40, 0x8d40).portr("IN0"); map(0x8d80, 0x8d80).portr("IN1"); - map(0x8dc0, 0x8dc0).portr("IN2").w(FUNC(mole_state::mole_flipscreen_w)); + map(0x8dc0, 0x8dc0).portr("IN2").w(FUNC(mole_state::flipscreen_w)); } @@ -307,8 +309,8 @@ static const gfx_layout tile_layout = static GFXDECODE_START( gfx_mole ) - GFXDECODE_ENTRY( "gfx1", 0x0000, tile_layout, 0x00, 1 ) - GFXDECODE_ENTRY( "gfx1", 0x3000, tile_layout, 0x00, 1 ) + GFXDECODE_ENTRY( "gfx", 0x0000, tile_layout, 0x00, 1 ) + GFXDECODE_ENTRY( "gfx", 0x3000, tile_layout, 0x00, 1 ) GFXDECODE_END @@ -321,8 +323,8 @@ GFXDECODE_END void mole_state::mole(machine_config &config) { /* basic machine hardware */ - M6502(config, m_maincpu, 2000000); // ??? - m_maincpu->set_addrmap(AS_PROGRAM, &mole_state::mole_map); + M6502(config, m_maincpu, 2'000'000); // ??? + m_maincpu->set_addrmap(AS_PROGRAM, &mole_state::main_map); m_maincpu->set_vblank_int("screen", FUNC(mole_state::irq0_line_assert)); /* video hardware */ @@ -331,7 +333,7 @@ void mole_state::mole(machine_config &config) screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); screen.set_size(40*8, 25*8); screen.set_visarea(0*8, 40*8-1, 0*8, 25*8-1); - screen.set_screen_update(FUNC(mole_state::screen_update_mole)); + screen.set_screen_update(FUNC(mole_state::screen_update)); screen.set_palette("palette"); GFXDECODE(config, m_gfxdecode, "palette", gfx_mole); @@ -356,7 +358,7 @@ ROM_START( mole ) // ALL ROMS ARE 2732 ROM_LOAD( "m2a.7h", 0x6000, 0x1000, CRC(f2a90642) SHA1(da6887725d70924fc4b9cca83172276976f5020c) ) ROM_LOAD( "m1a.8h", 0x7000, 0x1000, CRC(cff0119a) SHA1(48fc81b8c68e977680e7b8baf1193f0e7e0cd013) ) - ROM_REGION( 0x6000, "gfx1", 0 ) + ROM_REGION( 0x6000, "gfx", 0 ) ROM_LOAD( "mea.4a", 0x0000, 0x1000, CRC(49d89116) SHA1(aa4cde07e10624072e50ba5bd209acf93092cf78) ) ROM_LOAD( "mca.6a", 0x1000, 0x1000, CRC(04e90300) SHA1(c908a3a651e50428eedc2974160cdbf2ed946abc) ) ROM_LOAD( "maa.9a", 0x2000, 0x1000, CRC(6ce9442b) SHA1(c08bf0911f1dfd4a3f9452efcbb3fd3688c4bf8c) ) -- cgit v1.2.3-70-g09d2