mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
bus/a2bus/a2mockingboard.cpp: Reduced gross copy/pasta in PSG control code and unnecessarily virtual member functions.
This commit is contained in:
parent
16a8ce5cb2
commit
28fafc0e47
@ -22,51 +22,47 @@
|
||||
|
||||
namespace {
|
||||
|
||||
/***************************************************************************
|
||||
PARAMETERS
|
||||
***************************************************************************/
|
||||
|
||||
#define VIA1_TAG "mockbd_via1"
|
||||
#define VIA2_TAG "mockbd_via2"
|
||||
#define AY1_TAG "mockbd_ay1"
|
||||
#define AY2_TAG "mockbd_ay2"
|
||||
#define AY3_TAG "mockbd_ay3"
|
||||
#define AY4_TAG "mockbd_ay4"
|
||||
#define E2P_TMS_TAG "tms5220"
|
||||
|
||||
//**************************************************************************
|
||||
// TYPE DEFINITIONS
|
||||
//**************************************************************************
|
||||
|
||||
class a2bus_ayboard_device:
|
||||
public device_t,
|
||||
public device_a2bus_card_interface
|
||||
public device_t,
|
||||
public device_a2bus_card_interface
|
||||
{
|
||||
public:
|
||||
void via1_irq_w(int state);
|
||||
void via2_irq_w(int state);
|
||||
u8 via1_in_a() { return m_porta1; }
|
||||
u8 via2_in_a() { return m_porta2; }
|
||||
void via1_out_a(u8 data);
|
||||
virtual void via1_out_b(u8 data);
|
||||
void via2_out_a(u8 data);
|
||||
virtual void via2_out_b(u8 data);
|
||||
|
||||
protected:
|
||||
// construction/destruction
|
||||
a2bus_ayboard_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
|
||||
a2bus_ayboard_device(
|
||||
const machine_config &mconfig,
|
||||
device_type type,
|
||||
const char *tag,
|
||||
device_t *owner,
|
||||
uint32_t clock) ATTR_COLD;
|
||||
|
||||
virtual void device_start() override;
|
||||
virtual void device_reset() override;
|
||||
virtual void device_add_mconfig(machine_config &config) override;
|
||||
// device_t implementation
|
||||
virtual void device_start() override ATTR_COLD;
|
||||
virtual void device_reset() override ATTR_COLD;
|
||||
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
|
||||
|
||||
// overrides of standard a2bus slot functions
|
||||
// device_a2bus_card_interface implementation
|
||||
virtual u8 read_c0nx(u8 offset) override { return 0xff; }
|
||||
virtual void write_c0nx(u8 offset, u8 data) override { }
|
||||
virtual u8 read_cnxx(u8 offset) override;
|
||||
virtual void write_cnxx(u8 offset, u8 data) override;
|
||||
|
||||
void add_common_devices(machine_config &config);
|
||||
static void via_psg_ctrl(ay8913_device &psg, u8 &latch, u8 data);
|
||||
|
||||
void via1_irq_w(int state);
|
||||
void via2_irq_w(int state);
|
||||
u8 via1_in_a() { return m_porta1; }
|
||||
u8 via2_in_a() { return m_porta2; }
|
||||
void via1_out_a(u8 data);
|
||||
void via1_out_b(u8 data);
|
||||
void via2_out_a(u8 data);
|
||||
void via2_out_b(u8 data);
|
||||
|
||||
// machine configuration fragments
|
||||
void single_via_devices(machine_config &config) ATTR_COLD;
|
||||
|
||||
required_device<via6522_device> m_via1;
|
||||
optional_device<via6522_device> m_via2;
|
||||
@ -80,12 +76,14 @@ protected:
|
||||
class a2bus_mockingboard_device : public a2bus_ayboard_device
|
||||
{
|
||||
public:
|
||||
a2bus_mockingboard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
a2bus_mockingboard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) ATTR_COLD;
|
||||
|
||||
virtual void via1_out_b(u8 data) override;
|
||||
protected:
|
||||
virtual void device_add_mconfig(machine_config &config) override;
|
||||
virtual void device_reset() override;
|
||||
// device_t implementation
|
||||
virtual void device_reset() override ATTR_COLD;
|
||||
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
|
||||
|
||||
void via1_out_b(u8 data);
|
||||
|
||||
required_device<votrax_sc01_device> m_sc01;
|
||||
|
||||
@ -99,19 +97,21 @@ private:
|
||||
class a2bus_phasor_device : public a2bus_ayboard_device
|
||||
{
|
||||
public:
|
||||
a2bus_phasor_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
|
||||
void via1_out_b(u8 data) override;
|
||||
void via2_out_b(u8 data) override;
|
||||
a2bus_phasor_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) ATTR_COLD;
|
||||
|
||||
protected:
|
||||
virtual void device_add_mconfig(machine_config &config) override;
|
||||
// device_t implementation
|
||||
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
|
||||
|
||||
// device_a2bus_card_interface implementation
|
||||
virtual u8 read_c0nx(u8 offset) override;
|
||||
virtual void write_c0nx(u8 offset, u8 data) override;
|
||||
virtual u8 read_cnxx(u8 offset) override;
|
||||
virtual void write_cnxx(u8 offset, u8 data) override;
|
||||
|
||||
void via1_out_b(u8 data);
|
||||
void via2_out_b(u8 data);
|
||||
|
||||
required_device<ay8913_device> m_ay3;
|
||||
required_device<ay8913_device> m_ay4;
|
||||
|
||||
@ -124,26 +124,29 @@ private:
|
||||
class a2bus_echoplus_device : public a2bus_ayboard_device
|
||||
{
|
||||
public:
|
||||
a2bus_echoplus_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
a2bus_echoplus_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) ATTR_COLD;
|
||||
|
||||
protected:
|
||||
virtual void device_add_mconfig(machine_config &config) override;
|
||||
|
||||
virtual void via1_out_b(u8 data) override;
|
||||
// device_t implementation
|
||||
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
|
||||
|
||||
// device_a2bus_card_interface implementation
|
||||
virtual u8 read_c0nx(u8 offset) override;
|
||||
virtual void write_c0nx(u8 offset, u8 data) override;
|
||||
virtual u8 read_cnxx(u8 offset) override;
|
||||
virtual void write_cnxx(u8 offset, u8 data) override;
|
||||
|
||||
void via1_out_b(u8 data);
|
||||
|
||||
required_device<tms5220_device> m_tms;
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_add_mconfig - add device configuration
|
||||
//-------------------------------------------------
|
||||
|
||||
void a2bus_ayboard_device::add_common_devices(machine_config &config)
|
||||
void a2bus_ayboard_device::single_via_devices(machine_config &config)
|
||||
{
|
||||
MOS6522(config, m_via1, 1022727);
|
||||
m_via1->readpa_handler().set(FUNC(a2bus_ayboard_device::via1_in_a));
|
||||
@ -151,36 +154,34 @@ void a2bus_ayboard_device::add_common_devices(machine_config &config)
|
||||
m_via1->writepb_handler().set(FUNC(a2bus_ayboard_device::via1_out_b));
|
||||
m_via1->irq_handler().set(FUNC(a2bus_ayboard_device::via1_irq_w));
|
||||
|
||||
SPEAKER(config, "lspeaker").front_left();
|
||||
SPEAKER(config, "rspeaker").front_right();
|
||||
|
||||
AY8913(config, m_ay1, 1022727);
|
||||
m_ay1->add_route(ALL_OUTPUTS, "lspeaker", 0.5);
|
||||
|
||||
AY8913(config, m_ay2, 1022727);
|
||||
m_ay2->add_route(ALL_OUTPUTS, "rspeaker", 0.5);
|
||||
}
|
||||
|
||||
void a2bus_ayboard_device::device_add_mconfig(machine_config &config)
|
||||
{
|
||||
single_via_devices(config);
|
||||
|
||||
MOS6522(config, m_via2, 1022727);
|
||||
m_via2->readpa_handler().set(FUNC(a2bus_ayboard_device::via2_in_a));
|
||||
m_via2->writepa_handler().set(FUNC(a2bus_ayboard_device::via2_out_a));
|
||||
m_via2->writepb_handler().set(FUNC(a2bus_ayboard_device::via2_out_b));
|
||||
m_via2->irq_handler().set(FUNC(a2bus_ayboard_device::via2_irq_w));
|
||||
|
||||
SPEAKER(config, "lspeaker").front_left();
|
||||
SPEAKER(config, "rspeaker").front_right();
|
||||
AY8913(config, m_ay1, 1022727);
|
||||
m_ay1->add_route(ALL_OUTPUTS, "lspeaker", 0.5);
|
||||
}
|
||||
|
||||
void a2bus_ayboard_device::device_add_mconfig(machine_config &config)
|
||||
{
|
||||
add_common_devices(config);
|
||||
|
||||
AY8913(config, m_ay2, 1022727);
|
||||
m_ay2->add_route(ALL_OUTPUTS, "rspeaker", 0.5);
|
||||
}
|
||||
|
||||
void a2bus_mockingboard_device::device_add_mconfig(machine_config &config)
|
||||
{
|
||||
add_common_devices(config);
|
||||
a2bus_ayboard_device::device_add_mconfig(config);
|
||||
|
||||
m_via1->writepb_handler().set(FUNC(a2bus_mockingboard_device::via1_out_b));
|
||||
m_via1->cb2_handler().set(FUNC(a2bus_mockingboard_device::write_via1_cb2));
|
||||
|
||||
AY8913(config, m_ay2, 1022727);
|
||||
m_ay2->add_route(ALL_OUTPUTS, "rspeaker", 0.5);
|
||||
|
||||
VOTRAX_SC01A(config, m_sc01, 1022727);
|
||||
m_sc01->ar_callback().set(m_via1, FUNC(via6522_device::write_cb1));
|
||||
m_sc01->add_route(ALL_OUTPUTS, "lspeaker", 1.0);
|
||||
@ -189,30 +190,28 @@ void a2bus_mockingboard_device::device_add_mconfig(machine_config &config)
|
||||
|
||||
void a2bus_phasor_device::device_add_mconfig(machine_config &config)
|
||||
{
|
||||
add_common_devices(config);
|
||||
a2bus_ayboard_device::device_add_mconfig(config);
|
||||
|
||||
m_via1->writepb_handler().set(FUNC(a2bus_phasor_device::via1_out_b));
|
||||
m_via2->writepb_handler().set(FUNC(a2bus_phasor_device::via2_out_b));
|
||||
|
||||
SPEAKER(config, "lspeaker2").front_left();
|
||||
SPEAKER(config, "rspeaker2").front_right();
|
||||
AY8913(config, m_ay2, 1022727);
|
||||
|
||||
m_ay2->reset_routes().add_route(ALL_OUTPUTS, "lspeaker2", 0.5);
|
||||
|
||||
AY8913(config, m_ay3, 1022727);
|
||||
AY8913(config, m_ay4, 1022727);
|
||||
m_ay2->add_route(ALL_OUTPUTS, "lspeaker2", 0.5);
|
||||
m_ay3->add_route(ALL_OUTPUTS, "rspeaker", 0.5);
|
||||
|
||||
AY8913(config, m_ay4, 1022727);
|
||||
m_ay4->add_route(ALL_OUTPUTS, "rspeaker2", 0.5);
|
||||
}
|
||||
|
||||
void a2bus_echoplus_device::device_add_mconfig(machine_config &config)
|
||||
{
|
||||
add_common_devices(config);
|
||||
single_via_devices(config);
|
||||
|
||||
config.device_remove(VIA2_TAG);
|
||||
m_via1->writepb_handler().set(FUNC(a2bus_ayboard_device::via1_out_b));
|
||||
|
||||
AY8913(config, m_ay2, 1022727);
|
||||
m_ay2->add_route(ALL_OUTPUTS, "rspeaker", 0.5);
|
||||
m_via1->writepb_handler().set(FUNC(a2bus_echoplus_device::via1_out_b));
|
||||
|
||||
SPEAKER(config, "echosp").front_center();
|
||||
TMS5220C(config, m_tms, 640000);
|
||||
@ -227,10 +226,10 @@ void a2bus_echoplus_device::device_add_mconfig(machine_config &config)
|
||||
a2bus_ayboard_device::a2bus_ayboard_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
|
||||
device_t(mconfig, type, tag, owner, clock),
|
||||
device_a2bus_card_interface(mconfig, *this),
|
||||
m_via1(*this, VIA1_TAG),
|
||||
m_via2(*this, VIA2_TAG),
|
||||
m_ay1(*this, AY1_TAG),
|
||||
m_ay2(*this, AY2_TAG),
|
||||
m_via1(*this, "via1"),
|
||||
m_via2(*this, "via2"),
|
||||
m_ay1(*this, "ay1"),
|
||||
m_ay2(*this, "ay2"),
|
||||
m_porta1(0),
|
||||
m_porta2(0)
|
||||
{
|
||||
@ -244,15 +243,15 @@ a2bus_mockingboard_device::a2bus_mockingboard_device(const machine_config &mconf
|
||||
|
||||
a2bus_phasor_device::a2bus_phasor_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
|
||||
a2bus_ayboard_device(mconfig, A2BUS_PHASOR, tag, owner, clock),
|
||||
m_ay3(*this, AY3_TAG),
|
||||
m_ay4(*this, AY4_TAG),
|
||||
m_ay3(*this, "ay3"),
|
||||
m_ay4(*this, "ay4"),
|
||||
m_native(false)
|
||||
{
|
||||
}
|
||||
|
||||
a2bus_echoplus_device::a2bus_echoplus_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
|
||||
a2bus_ayboard_device(mconfig, A2BUS_ECHOPLUS, tag, owner, clock),
|
||||
m_tms(*this, E2P_TMS_TAG)
|
||||
m_tms(*this, "tms5220")
|
||||
{
|
||||
}
|
||||
|
||||
@ -373,6 +372,27 @@ void a2bus_phasor_device::write_cnxx(u8 offset, u8 data)
|
||||
}
|
||||
}
|
||||
|
||||
inline void a2bus_ayboard_device::via_psg_ctrl(ay8913_device &psg, u8 &latch, u8 data)
|
||||
{
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
latch = psg.data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
psg.data_w(latch);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
psg.address_w(latch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void a2bus_ayboard_device::via1_irq_w(int state)
|
||||
{
|
||||
if (state)
|
||||
@ -410,23 +430,7 @@ void a2bus_ayboard_device::via1_out_b(u8 data)
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
m_porta1 = m_ay1->data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
m_ay1->data_w(m_porta1);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
m_ay1->address_w(m_porta1);
|
||||
break;
|
||||
}
|
||||
via_psg_ctrl(*m_ay1, m_porta1, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,45 +443,14 @@ void a2bus_echoplus_device::via1_out_b(u8 data)
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: reading with both PSGs selected should fight for the latch
|
||||
if (BIT(data, 3)) // BC2_1=1 (PSG1 active)
|
||||
{
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
m_porta1 = m_ay1->data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
m_ay1->data_w(m_porta1);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
m_ay1->address_w(m_porta1);
|
||||
break;
|
||||
}
|
||||
via_psg_ctrl(*m_ay1, m_porta1, data);
|
||||
}
|
||||
if (BIT(data, 4)) // BC2_2_=1 (PSG2 active)
|
||||
{
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
m_porta1 = m_ay2->data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
m_ay2->data_w(m_porta1);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
m_ay2->address_w(m_porta1);
|
||||
break;
|
||||
}
|
||||
via_psg_ctrl(*m_ay2, m_porta1, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,32 +475,11 @@ void a2bus_phasor_device::via1_out_b(u8 data)
|
||||
chip_sel = 1;
|
||||
|
||||
// logerror("Phasor: %02x to AY1/2 CS %02x (BDIR/BC1 %02x, data %02x)\n", m_porta1, chipSel, data & 3, data);
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
if (BIT(chip_sel, 0))
|
||||
m_porta1 = m_ay1->data_r();
|
||||
if (BIT(chip_sel, 1))
|
||||
m_porta1 = m_ay2->data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
if (BIT(chip_sel, 0))
|
||||
m_ay1->data_w(m_porta1);
|
||||
if (BIT(chip_sel, 1))
|
||||
m_ay2->data_w(m_porta1);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
if (BIT(chip_sel, 0))
|
||||
m_ay1->address_w(m_porta1);
|
||||
if (BIT(chip_sel, 1))
|
||||
m_ay2->address_w(m_porta1);
|
||||
break;
|
||||
}
|
||||
// TODO: reading with both PSGs selected should fight for the latch
|
||||
if (BIT(chip_sel, 0))
|
||||
via_psg_ctrl(*m_ay1, m_porta1, data);
|
||||
if (BIT(chip_sel, 1))
|
||||
via_psg_ctrl(*m_ay2, m_porta1, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,23 +496,7 @@ void a2bus_ayboard_device::via2_out_b(u8 data)
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
m_porta2 = m_ay2->data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
m_ay2->data_w(m_porta2);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
m_ay2->address_w(m_porta2);
|
||||
break;
|
||||
}
|
||||
via_psg_ctrl(*m_ay2, m_porta2, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -588,32 +524,11 @@ void a2bus_phasor_device::via2_out_b(u8 data)
|
||||
chip_sel = 1;
|
||||
|
||||
// logerror("Phasor: %02x to AY3/4 CS %02x (BDIR/BC1 %02x, data %02x)\n", m_porta2, chipSel, data & 3, data);
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
if (BIT(chip_sel, 0))
|
||||
m_porta2 = m_ay3->data_r();
|
||||
if (BIT(chip_sel, 1))
|
||||
m_porta2 = m_ay4->data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
if (BIT(chip_sel, 0))
|
||||
m_ay3->data_w(m_porta2);
|
||||
if (BIT(chip_sel, 1))
|
||||
m_ay4->data_w(m_porta2);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
if (BIT(chip_sel, 0))
|
||||
m_ay3->address_w(m_porta2);
|
||||
if (BIT(chip_sel, 1))
|
||||
m_ay4->address_w(m_porta2);
|
||||
break;
|
||||
}
|
||||
// TODO: reading with both PSGs selected should fight for the latch
|
||||
if (BIT(chip_sel, 0))
|
||||
via_psg_ctrl(*m_ay3, m_porta2, data);
|
||||
if (BIT(chip_sel, 1))
|
||||
via_psg_ctrl(*m_ay4, m_porta2, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -695,23 +610,7 @@ void a2bus_mockingboard_device::via1_out_b(u8 data)
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (data & 3)
|
||||
{
|
||||
case 0: // BDIR=0, BC1=0 (inactive)
|
||||
break;
|
||||
|
||||
case 1: // BDIR=0, BC1=1 (read PSG)
|
||||
m_porta1 = m_ay1->data_r();
|
||||
break;
|
||||
|
||||
case 2: // BDIR=1, BC1=0 (write PSG)
|
||||
m_ay1->data_w(m_porta1);
|
||||
break;
|
||||
|
||||
case 3: // BDIR=1, BC1=1 (latch)
|
||||
m_ay1->address_w(m_porta1);
|
||||
break;
|
||||
}
|
||||
via_psg_ctrl(*m_ay1, m_porta1, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user