let's use Zaccaria as a demo for machine config in members

This commit is contained in:
Vas Crabb 2017-05-22 19:48:30 +10:00
parent ceb586419e
commit ed231988f1
6 changed files with 119 additions and 112 deletions

View File

@ -40,21 +40,21 @@ driver_device::~driver_device()
//-------------------------------------------------
// static_set_game - set the game in the device
// set_game_driver - set the game in the device
// configuration
//-------------------------------------------------
void driver_device::static_set_game(device_t &device, const game_driver &game)
void driver_device::set_game_driver(const game_driver &game)
{
driver_device &driver = downcast<driver_device &>(device);
assert(!m_system);
// set the system
driver.m_system = &game;
m_system = &game;
// and set the search path to include all parents
driver.m_searchpath = game.name;
m_searchpath = game.name;
for (int parent = driver_list::clone(game); parent != -1; parent = driver_list::clone(parent))
driver.m_searchpath.append(";").append(driver_list::driver(parent).name);
m_searchpath.append(";").append(driver_list::driver(parent).name);
}
@ -156,6 +156,7 @@ void driver_device::video_reset()
const tiny_rom_entry *driver_device::device_rom_region() const
{
assert(m_system);
return m_system->rom;
}
@ -166,6 +167,7 @@ const tiny_rom_entry *driver_device::device_rom_region() const
void driver_device::device_add_mconfig(machine_config &config)
{
assert(m_system);
m_system->machine_config(config, this, nullptr);
}

View File

@ -118,7 +118,7 @@ public:
};
// inline configuration helpers
static void static_set_game(device_t &device, const game_driver &game);
void set_game_driver(const game_driver &game);
static void static_set_callback(device_t &device, callback_type type, driver_callback_delegate callback);
// dummy driver_init callbacks

View File

@ -155,7 +155,7 @@ device_t *machine_config::device_add(device_t *owner, const char *tag, device_ty
m_root_device = type(*this, tag, nullptr, clock);
driver_device *driver = dynamic_cast<driver_device *>(m_root_device.get());
if (driver)
driver_device::static_set_game(*driver, m_gamedrv);
driver->set_game_driver(m_gamedrv);
m_root_device->add_machine_configuration(*this);
return m_root_device.get();
}

View File

@ -129,6 +129,23 @@ ATTR_COLD void MACHINE_CONFIG_NAME(_name)(machine_config &config, device_t *owne
assert(owner != nullptr); \
MACHINE_CONFIG_NAME(_base)(config, owner, device);
/**
@def MACHINE_CONFIG_MEMBER(_name)
Begins a device machine configuration member (usually overriding device_t::device_add_mconfig).
@param _name name of this config
@param _base name of the parent config
@hideinitializer
*/
#define MACHINE_CONFIG_MEMBER(_name) \
ATTR_COLD void _name(machine_config &config) \
{ \
device_t *const owner = this; \
device_t *device = nullptr; \
devcb_base *devcb = nullptr; \
(void)owner; \
(void)device; \
(void)devcb; \
/**
@def MACHINE_CONFIG_END
Ends a machine_config.

View File

@ -140,81 +140,6 @@ ADDRESS_MAP_END
//**************************************************************************
// MACHINE FRAGMENTS
//**************************************************************************
MACHINE_CONFIG_START(zac1b111xx_base_config)
MCFG_CPU_ADD("melodycpu", M6802, XTAL_3_579545MHz) // verified on pcb
MCFG_CPU_PROGRAM_MAP(zac1b111xx_melody_base_map)
MCFG_DEVICE_ADD("timebase", CLOCK, XTAL_3_579545MHz/4096/2) // CPU clock divided using 4040 and half of 74LS74
MCFG_CLOCK_SIGNAL_HANDLER(DEVWRITELINE("melodypia", pia6821_device, cb1_w))
MCFG_DEVICE_ADD("melodypia", PIA6821, 0)
MCFG_PIA_READPA_HANDLER(READ8(zac1b111xx_melody_base, melodypia_porta_r))
MCFG_PIA_WRITEPA_HANDLER(WRITE8(zac1b111xx_melody_base, melodypia_porta_w))
MCFG_PIA_WRITEPB_HANDLER(WRITE8(zac1b111xx_melody_base, melodypia_portb_w))
MCFG_PIA_IRQA_HANDLER(INPUTLINE("melodycpu", INPUT_LINE_NMI))
MCFG_PIA_IRQB_HANDLER(INPUTLINE("melodycpu", M6802_IRQ_LINE))
MCFG_SOUND_ADD("melodypsg1", AY8910, XTAL_3_579545MHz/2) // CPU clock divided using 4040
MCFG_AY8910_PORT_B_READ_CB(READ8(zac1b111xx_melody_base, melodypsg1_portb_r))
MCFG_SOUND_ADD("melodypsg2", AY8910, XTAL_3_579545MHz/2) // CPU clock divided using 4040
MACHINE_CONFIG_END
MACHINE_CONFIG_DERIVED(zac1b11107_config, zac1b111xx_base_config)
MCFG_CPU_MODIFY("melodycpu")
MCFG_CPU_PROGRAM_MAP(zac1b11107_melody_map)
MCFG_DEVICE_MODIFY("melodypsg1")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11107_audio_device, melodypsg1_porta_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.5, 0)
MCFG_DEVICE_MODIFY("melodypsg2")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11107_audio_device, melodypsg2_porta_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.5, 0)
MACHINE_CONFIG_END
MACHINE_CONFIG_DERIVED(zac1b11142_config, zac1b111xx_base_config)
MCFG_CPU_MODIFY("melodycpu")
MCFG_CPU_PROGRAM_MAP(zac1b11142_melody_map)
MCFG_DEVICE_MODIFY("melodypsg1")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11142_audio_device, ay_4g_porta_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.15, 0)
MCFG_DEVICE_MODIFY("melodypsg2")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11142_audio_device, ay_4h_porta_w))
MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(zac1b11142_audio_device, ay_4h_portb_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.15, 0)
MCFG_CPU_ADD("audiocpu", M6802, XTAL_3_579545MHz) // verified on pcb
MCFG_CPU_PROGRAM_MAP(zac1b11142_audio_map)
MCFG_CPU_PERIODIC_INT_DRIVER(zac1b11142_audio_device, input_poll, 60)
MCFG_DEVICE_ADD("pia_1i", PIA6821, 0)
MCFG_PIA_READPA_HANDLER(DEVREAD8("speech", tms5220_device, status_r))
MCFG_PIA_WRITEPA_HANDLER(DEVWRITE8("speech", tms5220_device, data_w))
MCFG_PIA_WRITEPB_HANDLER(WRITE8(zac1b11142_audio_device, pia_1i_portb_w))
MCFG_SOUND_ADD("dac", MC1408, 0) MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.40, 0) // mc1408.1f
MCFG_DEVICE_ADD("vref", VOLTAGE_REGULATOR, 0) MCFG_VOLTAGE_REGULATOR_OUTPUT(5.0)
MCFG_SOUND_ROUTE_EX(0, "dac", 1.0, DAC_VREF_POS_INPUT) MCFG_SOUND_ROUTE_EX(0, "dac", -1.0, DAC_VREF_NEG_INPUT)
// There is no xtal, the clock is obtained from a RC oscillator as shown in the TMS5220 datasheet (R=100kOhm C=22pF)
// 162kHz measured on pin 3 20 minutes after power on, clock would then be 162.3*4=649.2kHz
MCFG_SOUND_ADD("speech", TMS5200, 649200) // ROMCLK pin measured at 162.3Khz, OSC is exactly *4 of that)
MCFG_TMS52XX_IRQ_HANDLER(DEVWRITELINE("pia_1i", pia6821_device, cb1_w))
MCFG_TMS52XX_READYQ_HANDLER(DEVWRITELINE("pia_1i", pia6821_device, ca2_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.80, 0)
MACHINE_CONFIG_END
//**************************************************************************
// I/O PORT DEFINITIONS
//**************************************************************************
@ -228,7 +153,7 @@ INPUT_PORTS_START(zac1b11142_ioports)
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("P1") // test button? generates NMI on master CPU
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("P1") PORT_CHANGED_MEMBER(DEVICE_SELF, zac1b11142_audio_device, p1_changed, 0) // test button? generates NMI on master CPU
INPUT_PORTS_END
@ -292,6 +217,26 @@ READ8_MEMBER(zac1b111xx_melody_base::melodypsg1_portb_r)
return m_melody_command;
}
MACHINE_CONFIG_MEMBER(zac1b111xx_melody_base::device_add_mconfig)
MCFG_CPU_ADD("melodycpu", M6802, XTAL_3_579545MHz) // verified on pcb
MCFG_CPU_PROGRAM_MAP(zac1b111xx_melody_base_map)
MCFG_DEVICE_ADD("timebase", CLOCK, XTAL_3_579545MHz/4096/2) // CPU clock divided using 4040 and half of 74LS74
MCFG_CLOCK_SIGNAL_HANDLER(DEVWRITELINE("melodypia", pia6821_device, cb1_w))
MCFG_DEVICE_ADD("melodypia", PIA6821, 0)
MCFG_PIA_READPA_HANDLER(READ8(zac1b111xx_melody_base, melodypia_porta_r))
MCFG_PIA_WRITEPA_HANDLER(WRITE8(zac1b111xx_melody_base, melodypia_porta_w))
MCFG_PIA_WRITEPB_HANDLER(WRITE8(zac1b111xx_melody_base, melodypia_portb_w))
MCFG_PIA_IRQA_HANDLER(INPUTLINE("melodycpu", INPUT_LINE_NMI))
MCFG_PIA_IRQB_HANDLER(INPUTLINE("melodycpu", M6802_IRQ_LINE))
MCFG_SOUND_ADD("melodypsg1", AY8910, XTAL_3_579545MHz/2) // CPU clock divided using 4040
MCFG_AY8910_PORT_B_READ_CB(READ8(zac1b111xx_melody_base, melodypsg1_portb_r))
MCFG_SOUND_ADD("melodypsg2", AY8910, XTAL_3_579545MHz/2) // CPU clock divided using 4040
MACHINE_CONFIG_END
void zac1b111xx_melody_base::device_start()
{
save_item(NAME(m_melody_command));
@ -351,10 +296,20 @@ WRITE8_MEMBER(zac1b11107_audio_device::melodypsg2_porta_w)
// TODO: assume LEVELT is controlled here as is the case for 1B11142?
}
machine_config_constructor zac1b11107_audio_device::device_mconfig_additions() const
{
return MACHINE_CONFIG_NAME(zac1b11107_config);
}
MACHINE_CONFIG_MEMBER(zac1b11107_audio_device::device_add_mconfig)
zac1b111xx_melody_base::device_add_mconfig(config);
MCFG_CPU_MODIFY("melodycpu")
MCFG_CPU_PROGRAM_MAP(zac1b11107_melody_map)
MCFG_DEVICE_MODIFY("melodypsg1")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11107_audio_device, melodypsg1_porta_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.5, 0)
MCFG_DEVICE_MODIFY("melodypsg2")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11107_audio_device, melodypsg2_porta_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.5, 0)
MACHINE_CONFIG_END
@ -425,22 +380,52 @@ WRITE8_MEMBER(zac1b11142_audio_device::melody_command_w)
m_melody_command = data;
}
WRITE8_MEMBER(zac1b11142_audio_device::pia_1i_portb_w)
{
m_speech->rsq_w((data >> 0) & 0x01);
m_speech->wsq_w((data >> 1) & 0x01);
m_acs_cb((~data >> 3) & 0x01);
// TODO: a LED output().set_led_value(0, (data >> 4) & 0x01);
}
INTERRUPT_GEN_MEMBER(zac1b11142_audio_device::input_poll)
INPUT_CHANGED_MEMBER(zac1b11142_audio_device::p1_changed)
{
m_audiocpu->set_input_line(INPUT_LINE_NMI, (m_inputs->read() & 0x80) ? CLEAR_LINE : ASSERT_LINE);
}
machine_config_constructor zac1b11142_audio_device::device_mconfig_additions() const
WRITE8_MEMBER(zac1b11142_audio_device::pia_1i_portb_w)
{
return MACHINE_CONFIG_NAME(zac1b11142_config);
m_speech->rsq_w(BIT(data, 0));
m_speech->wsq_w(BIT(data, 1));
m_acs_cb(BIT(~data, 3));
// TODO: a LED output().set_led_value(0, BIT(data, 4));
}
MACHINE_CONFIG_MEMBER(zac1b11142_audio_device::device_add_mconfig)
zac1b111xx_melody_base::device_add_mconfig(config);
MCFG_CPU_MODIFY("melodycpu")
MCFG_CPU_PROGRAM_MAP(zac1b11142_melody_map)
MCFG_DEVICE_MODIFY("melodypsg1")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11142_audio_device, ay_4g_porta_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.15, 0)
MCFG_DEVICE_MODIFY("melodypsg2")
MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(zac1b11142_audio_device, ay_4h_porta_w))
MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(zac1b11142_audio_device, ay_4h_portb_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.15, 0)
MCFG_CPU_ADD("audiocpu", M6802, XTAL_3_579545MHz) // verified on pcb
MCFG_CPU_PROGRAM_MAP(zac1b11142_audio_map)
MCFG_DEVICE_ADD("pia_1i", PIA6821, 0)
MCFG_PIA_READPA_HANDLER(DEVREAD8("speech", tms5220_device, status_r))
MCFG_PIA_WRITEPA_HANDLER(DEVWRITE8("speech", tms5220_device, data_w))
MCFG_PIA_WRITEPB_HANDLER(WRITE8(zac1b11142_audio_device, pia_1i_portb_w))
MCFG_SOUND_ADD("dac", MC1408, 0) MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.40, 0) // mc1408.1f
MCFG_DEVICE_ADD("vref", VOLTAGE_REGULATOR, 0) MCFG_VOLTAGE_REGULATOR_OUTPUT(5.0)
MCFG_SOUND_ROUTE_EX(0, "dac", 1.0, DAC_VREF_POS_INPUT) MCFG_SOUND_ROUTE_EX(0, "dac", -1.0, DAC_VREF_NEG_INPUT)
// There is no xtal, the clock is obtained from a RC oscillator as shown in the TMS5220 datasheet (R=100kOhm C=22pF)
// 162kHz measured on pin 3 20 minutes after power on, clock would then be 162.3*4=649.2kHz
MCFG_SOUND_ADD("speech", TMS5200, 649200) // ROMCLK pin measured at 162.3Khz, OSC is exactly *4 of that)
MCFG_TMS52XX_IRQ_HANDLER(DEVWRITELINE("pia_1i", pia6821_device, cb1_w))
MCFG_TMS52XX_READYQ_HANDLER(DEVWRITELINE("pia_1i", pia6821_device, ca2_w))
MCFG_MIXER_ROUTE(ALL_OUTPUTS, DEVICE_SELF_OWNER, 0.80, 0)
}
ioport_constructor zac1b11142_audio_device::device_input_ports() const

View File

@ -35,12 +35,6 @@ DECLARE_DEVICE_TYPE(ZACCARIA_1B11142, zac1b11142_audio_device)
class zac1b111xx_melody_base : public device_t, public device_mixer_interface
{
public:
DECLARE_READ8_MEMBER(melodypia_porta_r);
DECLARE_WRITE8_MEMBER(melodypia_porta_w);
DECLARE_WRITE8_MEMBER(melodypia_portb_w);
DECLARE_READ8_MEMBER(melodypsg1_portb_r);
protected:
zac1b111xx_melody_base(
machine_config const &mconfig,
@ -49,6 +43,12 @@ protected:
device_t *owner,
u32 clock);
DECLARE_READ8_MEMBER(melodypia_porta_r);
DECLARE_WRITE8_MEMBER(melodypia_porta_w);
DECLARE_WRITE8_MEMBER(melodypia_portb_w);
DECLARE_READ8_MEMBER(melodypsg1_portb_r);
virtual void device_add_mconfig(machine_config &config) override;
virtual void device_start() override;
virtual void device_reset() override;
@ -70,12 +70,12 @@ public:
DECLARE_WRITE8_MEMBER(sound_w);
DECLARE_WRITE_LINE_MEMBER(reset_w);
protected:
// PSG output handlers
DECLARE_WRITE8_MEMBER(melodypsg1_porta_w);
DECLARE_WRITE8_MEMBER(melodypsg2_porta_w);
protected:
virtual machine_config_constructor device_mconfig_additions() const override;
virtual void device_add_mconfig(machine_config &config) override;
};
@ -92,21 +92,24 @@ public:
DECLARE_READ_LINE_MEMBER(acs_r);
DECLARE_WRITE_LINE_MEMBER(ressound_w);
// master audio section handlers
DECLARE_READ8_MEMBER(host_command_r);
DECLARE_WRITE8_MEMBER(melody_command_w);
DECLARE_INPUT_CHANGED_MEMBER(p1_changed);
protected:
// melody section handlers
DECLARE_WRITE8_MEMBER(ay_4g_porta_w);
DECLARE_WRITE8_MEMBER(ay_4h_porta_w);
DECLARE_WRITE8_MEMBER(ay_4h_portb_w);
// master audio section handlers
DECLARE_READ8_MEMBER(host_command_r);
DECLARE_WRITE8_MEMBER(melody_command_w);
DECLARE_WRITE8_MEMBER(pia_1i_portb_w);
// input ports don't push
INTERRUPT_GEN_MEMBER(input_poll);
protected:
virtual machine_config_constructor device_mconfig_additions() const override;
virtual void device_add_mconfig(machine_config &config) override;
virtual ioport_constructor device_input_ports() const override;
virtual void device_start() override;
virtual void device_reset() override;
@ -122,4 +125,4 @@ protected:
u8 m_host_command;
};
#endif // __AUDIO_ZACCARIA_H__
#endif // MAME_AUDIO_ZACCARIA_H