From be2004af83f6caed3a518ce46e2d61b62648c653 Mon Sep 17 00:00:00 2001 From: Ivan Vangelista Date: Tue, 22 May 2018 19:40:01 +0200 Subject: [PATCH] exterm.cpp: device_finder and other cleanups (nw) --- src/mame/drivers/exterm.cpp | 101 +++++++++++++++--------------------- src/mame/includes/exterm.h | 31 +++++++---- src/mame/video/exterm.cpp | 7 +-- 3 files changed, 66 insertions(+), 73 deletions(-) diff --git a/src/mame/drivers/exterm.cpp b/src/mame/drivers/exterm.cpp index f98cea76542..c49aae5584c 100644 --- a/src/mame/drivers/exterm.cpp +++ b/src/mame/drivers/exterm.cpp @@ -70,7 +70,6 @@ #include "machine/watchdog.h" #include "sound/dac.h" #include "sound/volt_reg.h" -#include "sound/ym2151.h" #include "screen.h" #include "speaker.h" @@ -91,13 +90,13 @@ void exterm_state::machine_start() * *************************************/ -WRITE16_MEMBER(exterm_state::exterm_host_data_w) +WRITE16_MEMBER(exterm_state::host_data_w) { m_slave->host_w(space,offset / 0x0010000, data, 0xffff); } -READ16_MEMBER(exterm_state::exterm_host_data_r) +READ16_MEMBER(exterm_state::host_data_r) { return m_slave->host_r(space,offset / 0x0010000, 0xffff); } @@ -110,53 +109,41 @@ READ16_MEMBER(exterm_state::exterm_host_data_r) * *************************************/ -uint16_t exterm_state::exterm_trackball_port_r(int which, uint16_t mem_mask) +template +READ16_MEMBER(exterm_state::trackball_port_r) { uint16_t port; /* Read the fake input port */ - uint8_t trackball_pos = ioport(which ? "DIAL1" : "DIAL0")->read(); + uint8_t trackball_pos = m_dial[Which]->read(); /* Calculate the change from the last position. */ - uint8_t trackball_diff = m_trackball_old[which] - trackball_pos; + uint8_t trackball_diff = m_trackball_old[Which] - trackball_pos; - /* Store the new position for the next comparision. */ - m_trackball_old[which] = trackball_pos; + /* Store the new position for the next comparison. */ + m_trackball_old[Which] = trackball_pos; /* Move the sign bit to the high bit of the 6-bit trackball count. */ if (trackball_diff & 0x80) trackball_diff |= 0x20; /* Keep adding the changes. The counters will be reset later by a hardware write. */ - m_aimpos[which] = (m_aimpos[which] + trackball_diff) & 0x3f; + m_aimpos[Which] = (m_aimpos[Which] + trackball_diff) & 0x3f; /* Combine it with the standard input bits */ - port = ioport(which ? "P2" : "P1")->read(); + port = m_input[Which]->read(); - return (port & 0xc0ff) | (m_aimpos[which] << 8); + return (port & 0xc0ff) | (m_aimpos[Which] << 8); } -READ16_MEMBER(exterm_state::exterm_input_port_0_r) -{ - return exterm_trackball_port_r(0, mem_mask); -} - - -READ16_MEMBER(exterm_state::exterm_input_port_1_r) -{ - return exterm_trackball_port_r(1, mem_mask); -} - - - /************************************* * * Output port handlers * *************************************/ -WRITE16_MEMBER(exterm_state::exterm_output_port_0_w) +WRITE16_MEMBER(exterm_state::output_port_0_w) { /* All the outputs are activated on the rising edge */ @@ -209,9 +196,8 @@ TIMER_DEVICE_CALLBACK_MEMBER(exterm_state::master_sound_nmi_callback) WRITE8_MEMBER(exterm_state::ym2151_data_latch_w) { - ym2151_device *device = machine().device("ymsnd"); /* bit 7 of the sound control selects which port */ - device->write(space, m_sound_control >> 7, data); + m_ym2151->write(space, m_sound_control >> 7, data); } @@ -221,8 +207,7 @@ WRITE8_MEMBER(exterm_state::sound_nmi_rate_w) /* this value is latched into up-counters, which are clocked at the */ /* input clock / 256 */ attotime nmi_rate = attotime::from_hz(4000000) * (4096 * (256 - data)); - timer_device *nmi_timer = machine().device("snd_nmi_timer"); - nmi_timer->adjust(nmi_rate, 0, nmi_rate); + m_nmi_timer->adjust(nmi_rate, 0, nmi_rate); } @@ -258,16 +243,16 @@ void exterm_state::master_map(address_map &map) { map(0x00000000, 0x000fffff).mirror(0xfc700000).ram().share("master_videoram"); map(0x00800000, 0x00bfffff).mirror(0xfc400000).ram(); - map(0x01000000, 0x013fffff).mirror(0xfc000000).rw(this, FUNC(exterm_state::exterm_host_data_r), FUNC(exterm_state::exterm_host_data_w)); - map(0x01400000, 0x0143ffff).mirror(0xfc000000).r(this, FUNC(exterm_state::exterm_input_port_0_r)); - map(0x01440000, 0x0147ffff).mirror(0xfc000000).r(this, FUNC(exterm_state::exterm_input_port_1_r)); + map(0x01000000, 0x013fffff).mirror(0xfc000000).rw(this, FUNC(exterm_state::host_data_r), FUNC(exterm_state::host_data_w)); + map(0x01400000, 0x0143ffff).mirror(0xfc000000).r(this, FUNC(exterm_state::trackball_port_r<0>)); + map(0x01440000, 0x0147ffff).mirror(0xfc000000).r(this, FUNC(exterm_state::trackball_port_r<1>)); map(0x01480000, 0x014bffff).mirror(0xfc000000).portr("DSW"); - map(0x01500000, 0x0153ffff).mirror(0xfc000000).w(this, FUNC(exterm_state::exterm_output_port_0_w)); + map(0x01500000, 0x0153ffff).mirror(0xfc000000).w(this, FUNC(exterm_state::output_port_0_w)); map(0x01580000, 0x015bffff).mirror(0xfc000000).w(this, FUNC(exterm_state::sound_latch_w)).umask16(0x00ff); map(0x015c0000, 0x015fffff).mirror(0xfc000000).w("watchdog", FUNC(watchdog_timer_device::reset16_w)); map(0x01800000, 0x01807fff).mirror(0xfc7f8000).ram().w("palette", FUNC(palette_device::write16)).share("palette"); map(0x02800000, 0x02807fff).mirror(0xfc7f8000).ram().share("nvram"); - map(0x03000000, 0x03ffffff).mirror(0xfc000000).rom().region("user1", 0); + map(0x03000000, 0x03ffffff).mirror(0xfc000000).rom().region("maincpu", 0); map(0xc0000000, 0xc00001ff).rw(m_maincpu, FUNC(tms34010_device::io_register_r), FUNC(tms34010_device::io_register_w)); } @@ -292,7 +277,7 @@ void exterm_state::sound_master_map(address_map &map) map(0x0000, 0x07ff).mirror(0x1800).ram(); map(0x4000, 0x5fff).w(this, FUNC(exterm_state::ym2151_data_latch_w)); map(0x6000, 0x67ff).w(this, FUNC(exterm_state::sound_nmi_rate_w)); - map(0x6800, 0x6fff).r("soundlatch1", FUNC(generic_latch_8_device::read)); + map(0x6800, 0x6fff).r(m_soundlatch[0], FUNC(generic_latch_8_device::read)); map(0x7000, 0x77ff).r(this, FUNC(exterm_state::sound_nmi_to_slave_r)); /* AM_RANGE(0x7800, 0x7fff) unknown - to S4-13 */ map(0x8000, 0xffff).rom(); @@ -303,7 +288,7 @@ void exterm_state::sound_master_map(address_map &map) void exterm_state::sound_slave_map(address_map &map) { map(0x0000, 0x07ff).mirror(0x3800).ram(); - map(0x4000, 0x5fff).r("soundlatch2", FUNC(generic_latch_8_device::read)); + map(0x4000, 0x5fff).r(m_soundlatch[1], FUNC(generic_latch_8_device::read)); map(0x8000, 0xffff).rom(); map(0x8000, 0x8000).mirror(0x3ffe).w("dacvol", FUNC(dac_byte_interface::write)); map(0x8001, 0x8001).mirror(0x3ffe).w("dac", FUNC(dac_byte_interface::write)); @@ -389,40 +374,40 @@ INPUT_PORTS_END MACHINE_CONFIG_START(exterm_state::exterm) /* basic machine hardware */ - MCFG_DEVICE_ADD("maincpu", TMS34010, 40000000) + MCFG_DEVICE_ADD(m_maincpu, TMS34010, 40000000) MCFG_DEVICE_PROGRAM_MAP(master_map) - MCFG_TMS340X0_HALT_ON_RESET(false) /* halt on reset */ - MCFG_TMS340X0_PIXEL_CLOCK(40000000/8) /* pixel clock */ - MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */ - MCFG_TMS340X0_SCANLINE_IND16_CB(exterm_state, scanline_update) /* scanline updater (indexed16) */ - MCFG_TMS340X0_TO_SHIFTREG_CB(exterm_state, to_shiftreg_master) /* write to shiftreg function */ - MCFG_TMS340X0_FROM_SHIFTREG_CB(exterm_state, from_shiftreg_master) /* read from shiftreg function */ + MCFG_TMS340X0_HALT_ON_RESET(false) + MCFG_TMS340X0_PIXEL_CLOCK(40000000/8) + MCFG_TMS340X0_PIXELS_PER_CLOCK(1) + MCFG_TMS340X0_SCANLINE_IND16_CB(exterm_state, scanline_update) + MCFG_TMS340X0_TO_SHIFTREG_CB(exterm_state, to_shiftreg_master) + MCFG_TMS340X0_FROM_SHIFTREG_CB(exterm_state, from_shiftreg_master) - MCFG_DEVICE_ADD("slave", TMS34010, 40000000) + MCFG_DEVICE_ADD(m_slave, TMS34010, 40000000) MCFG_DEVICE_PROGRAM_MAP(slave_map) - MCFG_TMS340X0_HALT_ON_RESET(true) /* halt on reset */ - MCFG_TMS340X0_PIXEL_CLOCK(40000000/8) /* pixel clock */ - MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */ - MCFG_TMS340X0_TO_SHIFTREG_CB(exterm_state, to_shiftreg_slave) /* write to shiftreg function */ - MCFG_TMS340X0_FROM_SHIFTREG_CB(exterm_state, from_shiftreg_slave) /* read from shiftreg function */ + MCFG_TMS340X0_HALT_ON_RESET(true) + MCFG_TMS340X0_PIXEL_CLOCK(40000000/8) + MCFG_TMS340X0_PIXELS_PER_CLOCK(1) + MCFG_TMS340X0_TO_SHIFTREG_CB(exterm_state, to_shiftreg_slave) + MCFG_TMS340X0_FROM_SHIFTREG_CB(exterm_state, from_shiftreg_slave) - MCFG_DEVICE_ADD("audiocpu", M6502, 2000000) + MCFG_DEVICE_ADD(m_audiocpu, M6502, 2000000) MCFG_DEVICE_PROGRAM_MAP(sound_master_map) - MCFG_DEVICE_ADD("audioslave", M6502, 2000000) + MCFG_DEVICE_ADD(m_audioslave, M6502, 2000000) MCFG_DEVICE_PROGRAM_MAP(sound_slave_map) - MCFG_GENERIC_LATCH_8_ADD("soundlatch1") - MCFG_GENERIC_LATCH_DATA_PENDING_CB(INPUTLINE("audiocpu", M6502_IRQ_LINE)) + MCFG_GENERIC_LATCH_8_ADD(m_soundlatch[0]) + MCFG_GENERIC_LATCH_DATA_PENDING_CB(INPUTLINE(m_audiocpu, M6502_IRQ_LINE)) - MCFG_GENERIC_LATCH_8_ADD("soundlatch2") - MCFG_GENERIC_LATCH_DATA_PENDING_CB(INPUTLINE("audioslave", M6502_IRQ_LINE)) + MCFG_GENERIC_LATCH_8_ADD(m_soundlatch[1]) + MCFG_GENERIC_LATCH_DATA_PENDING_CB(INPUTLINE(m_audioslave, M6502_IRQ_LINE)) MCFG_QUANTUM_TIME(attotime::from_hz(6000)) MCFG_NVRAM_ADD_0FILL("nvram") - MCFG_TIMER_DRIVER_ADD("snd_nmi_timer", exterm_state, master_sound_nmi_callback) + MCFG_TIMER_DRIVER_ADD(m_nmi_timer, exterm_state, master_sound_nmi_callback) MCFG_WATCHDOG_ADD("watchdog") @@ -446,7 +431,7 @@ MACHINE_CONFIG_START(exterm_state::exterm) MCFG_DEVICE_ADD("vref", VOLTAGE_REGULATOR, 0) MCFG_VOLTAGE_REGULATOR_OUTPUT(5.0) MCFG_SOUND_ROUTE(0, "dacvol", 1.0, DAC_VREF_POS_INPUT) - MCFG_DEVICE_ADD("ymsnd", YM2151, 4000000) + MCFG_DEVICE_ADD(m_ym2151, YM2151, 4000000) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "speaker", 1.0) MACHINE_CONFIG_END @@ -465,7 +450,7 @@ ROM_START( exterm ) ROM_REGION( 0x10000, "audioslave", 0 ) /* 64k for DAC code */ ROM_LOAD( "v101d1", 0x8000, 0x8000, CRC(83268b7d) SHA1(a9139e80e2382122e9919c0555937e120d4414cf) ) - ROM_REGION16_LE( 0x200000, "user1", 0 ) /* 2MB for 34010 code */ + ROM_REGION16_LE( 0x200000, "maincpu", 0 ) /* 2MB for 34010 code */ ROM_LOAD16_BYTE( "v101bg0", 0x000000, 0x10000, CRC(8c8e72cf) SHA1(5e0fa805334f54f7e0293ea400bacb0e3e79ed56) ) ROM_LOAD16_BYTE( "v101bg1", 0x000001, 0x10000, CRC(cc2da0d8) SHA1(4ac23048d3ca771e315388603ad3b1b25030d6ff) ) ROM_LOAD16_BYTE( "v101bg2", 0x020000, 0x10000, CRC(2dcb3653) SHA1(2d74b58b02ae0587e3789d69feece268f582f226) ) diff --git a/src/mame/includes/exterm.h b/src/mame/includes/exterm.h index ad53dff6fae..22a29c32534 100644 --- a/src/mame/includes/exterm.h +++ b/src/mame/includes/exterm.h @@ -6,10 +6,10 @@ *************************************************************************/ -#include "cpu/tms32010/tms32010.h" #include "cpu/tms34010/tms34010.h" #include "machine/gen_latch.h" #include "machine/timer.h" +#include "sound/ym2151.h" class exterm_state : public driver_device { @@ -21,29 +21,42 @@ public: m_audioslave(*this, "audioslave"), m_soundlatch(*this, "soundlatch%u", 1), m_slave(*this, "slave"), + m_ym2151(*this, "ymsnd"), + m_nmi_timer(*this, "snd_nmi_timer"), m_master_videoram(*this, "master_videoram"), - m_slave_videoram(*this, "slave_videoram") { } + m_slave_videoram(*this, "slave_videoram"), + m_dial(*this, "DIAL%u", 0U), + m_input(*this, "P%u", 1U) { } + void exterm(machine_config &config); + +protected: + virtual void machine_start() override; + +private: required_device m_maincpu; required_device m_audiocpu; required_device m_audioslave; required_device_array m_soundlatch; required_device m_slave; + required_device m_ym2151; + required_device m_nmi_timer; required_shared_ptr m_master_videoram; required_shared_ptr m_slave_videoram; + required_ioport_array<2> m_dial; + required_ioport_array<2> m_input; + uint8_t m_aimpos[2]; uint8_t m_trackball_old[2]; uint8_t m_sound_control; uint16_t m_last; - virtual void machine_start() override; - DECLARE_WRITE16_MEMBER(exterm_host_data_w); - DECLARE_READ16_MEMBER(exterm_host_data_r); - DECLARE_READ16_MEMBER(exterm_input_port_0_r); - DECLARE_READ16_MEMBER(exterm_input_port_1_r); - DECLARE_WRITE16_MEMBER(exterm_output_port_0_w); + DECLARE_WRITE16_MEMBER(host_data_w); + DECLARE_READ16_MEMBER(host_data_r); + template DECLARE_READ16_MEMBER(trackball_port_r); + DECLARE_WRITE16_MEMBER(output_port_0_w); DECLARE_WRITE8_MEMBER(sound_latch_w); DECLARE_WRITE8_MEMBER(sound_nmi_rate_w); DECLARE_READ8_MEMBER(sound_nmi_to_slave_r); @@ -56,8 +69,6 @@ public: TMS340X0_FROM_SHIFTREG_CB_MEMBER(from_shiftreg_master); TMS340X0_TO_SHIFTREG_CB_MEMBER(to_shiftreg_slave); TMS340X0_FROM_SHIFTREG_CB_MEMBER(from_shiftreg_slave); - uint16_t exterm_trackball_port_r(int which, uint16_t mem_mask); - void exterm(machine_config &config); void master_map(address_map &map); void slave_map(address_map &map); void sound_master_map(address_map &map); diff --git a/src/mame/video/exterm.cpp b/src/mame/video/exterm.cpp index 331a62e627a..871cfcb4626 100644 --- a/src/mame/video/exterm.cpp +++ b/src/mame/video/exterm.cpp @@ -18,10 +18,8 @@ PALETTE_INIT_MEMBER(exterm_state, exterm) { - int i; - /* initialize 555 RGB lookup */ - for (i = 0; i < 32768; i++) + for (int i = 0; i < 32768; i++) palette.set_pen_color(i + 0x800, pal5bit(i >> 10), pal5bit(i >> 5), pal5bit(i >> 0)); } @@ -72,7 +70,6 @@ TMS340X0_SCANLINE_IND16_CB_MEMBER(exterm_state::scanline_update) tms340x0_device::display_params fgparams; int coladdr = params->coladdr; int fgcoladdr = 0; - int x; /* get parameters for the slave CPU */ m_slave->get_display_params(&fgparams); @@ -85,7 +82,7 @@ TMS340X0_SCANLINE_IND16_CB_MEMBER(exterm_state::scanline_update) } /* copy the non-blanked portions of this scanline */ - for (x = params->heblnk; x < params->hsblnk; x += 2) + for (int x = params->heblnk; x < params->hsblnk; x += 2) { uint16_t bgdata, fgdata = 0;