Merge pull request #590 from ajrhacker/atarisnd

Modernize sound volume setting code in various Atari drivers [AJR]
This commit is contained in:
Miodrag Milanović 2016-01-29 17:45:14 +01:00
commit d23a4183d9
15 changed files with 97 additions and 125 deletions

View File

@ -131,7 +131,7 @@ WRITE16_MEMBER(arcadecl_state::latch_w)
if (ACCESSING_BITS_0_7)
{
m_oki->set_bank_base((data & 0x80) ? 0x40000 : 0x00000);
set_oki6295_volume((data & 0x001f) * 100 / 0x1f);
m_oki->set_output_gain(ALL_OUTPUTS, (data & 0x001f) / 31.0f);
}
}

View File

@ -127,9 +127,6 @@
#include "emu.h"
#include "includes/atarisy2.h"
#include "sound/tms5220.h"
#include "sound/2151intf.h"
#include "sound/pokey.h"
#define MASTER_CLOCK XTAL_20MHz
@ -328,7 +325,7 @@ READ8_MEMBER(atarisy2_state::switch_6502_r)
{
int result = ioport("1840")->read();
if ((m_has_tms5220) && (machine().device<tms5220_device>("tms")->readyq_r() == 0))
if (m_tms5220.found() && (m_tms5220->readyq_r() == 0))
result &= ~0x04;
if (!(ioport("1801")->read() & 0x80)) result |= 0x10;
@ -340,10 +337,10 @@ WRITE8_MEMBER(atarisy2_state::switch_6502_w)
{
output().set_led_value(0, data & 0x04);
output().set_led_value(1, data & 0x08);
if (m_has_tms5220)
if (m_tms5220.found())
{
data = 12 | ((data >> 5) & 1);
machine().device<tms5220_device>("tms")->set_frequency(MASTER_CLOCK/4 / (16 - data) / 2);
m_tms5220->set_frequency(MASTER_CLOCK/4 / (16 - data) / 2);
}
}
@ -629,7 +626,7 @@ WRITE8_MEMBER(atarisy2_state::mixer_w)
if (!(data & 0x02)) rbott += 1.0/47;
if (!(data & 0x04)) rbott += 1.0/22;
gain = (rbott == 0) ? 1.0 : ((1.0/rbott) / (rtop + (1.0/rbott)));
set_ym2151_volume(gain * 100);
m_ym2151->set_output_gain(ALL_OUTPUTS, gain);
/* bits 3-4 control the volume of the POKEYs, using 47k and 100k resistors */
rtop = 1.0/(1.0/100 + 1.0/100);
@ -637,16 +634,20 @@ WRITE8_MEMBER(atarisy2_state::mixer_w)
if (!(data & 0x08)) rbott += 1.0/47;
if (!(data & 0x10)) rbott += 1.0/22;
gain = (rbott == 0) ? 1.0 : ((1.0/rbott) / (rtop + (1.0/rbott)));
set_pokey_volume(gain * 100);
m_pokey1->set_output_gain(ALL_OUTPUTS, gain);
m_pokey2->set_output_gain(ALL_OUTPUTS, gain);
/* bits 5-7 control the volume of the TMS5220, using 22k, 47k, and 100k resistors */
rtop = 1.0/(1.0/100 + 1.0/100);
rbott = 0;
if (!(data & 0x20)) rbott += 1.0/100;
if (!(data & 0x40)) rbott += 1.0/47;
if (!(data & 0x80)) rbott += 1.0/22;
gain = (rbott == 0) ? 1.0 : ((1.0/rbott) / (rtop + (1.0/rbott)));
set_tms5220_volume(gain * 100);
if (m_tms5220.found())
{
rtop = 1.0/(1.0/100 + 1.0/100);
rbott = 0;
if (!(data & 0x20)) rbott += 1.0/100;
if (!(data & 0x40)) rbott += 1.0/47;
if (!(data & 0x80)) rbott += 1.0/22;
gain = (rbott == 0) ? 1.0 : ((1.0/rbott) / (rtop + (1.0/rbott)));
m_tms5220->set_output_gain(ALL_OUTPUTS, gain);
}
}
@ -664,9 +665,9 @@ WRITE8_MEMBER(atarisy2_state::sound_reset_w)
/* a large number of signals are reset when this happens */
m_soundcomm->reset();
machine().device("ymsnd")->reset();
if (m_has_tms5220)
if (m_tms5220.found())
{
machine().device("tms")->reset(); // technically what happens is the tms5220 gets a long stream of 0xFF written to it when sound_reset_state is 0 which halts the chip after a few frames, but this works just as well, even if it isn't exactly true to hardware... The hardware may not have worked either, the resistors to pull input to 0xFF are fighting against the ls263 gate holding the latched value to be sent to the chip.
m_tms5220->reset(); // technically what happens is the tms5220 gets a long stream of 0xFF written to it when sound_reset_state is 0 which halts the chip after a few frames, but this works just as well, even if it isn't exactly true to hardware... The hardware may not have worked either, the resistors to pull input to 0xFF are fighting against the ls263 gate holding the latched value to be sent to the chip.
}
mixer_w(space, 0, 0);
}
@ -714,17 +715,17 @@ READ8_MEMBER(atarisy2_state::sound_6502_r)
WRITE8_MEMBER(atarisy2_state::tms5220_w)
{
if (m_has_tms5220)
if (m_tms5220.found())
{
machine().device<tms5220_device>("tms")->data_w(space, 0, data);
m_tms5220->data_w(space, 0, data);
}
}
WRITE8_MEMBER(atarisy2_state::tms5220_strobe_w)
{
if (m_has_tms5220)
if (m_tms5220.found())
{
machine().device<tms5220_device>("tms")->wsq_w(1-(offset & 1));
m_tms5220->wsq_w(1-(offset & 1));
}
}
@ -3142,8 +3143,7 @@ DRIVER_INIT_MEMBER(atarisy2_state,paperboy)
}
m_pedal_count = 0;
m_has_tms5220 = 1;
machine().device<tms5220_device>("tms")->rsq_w(1); // /RS is tied high on sys2 hw
m_tms5220->rsq_w(1); // /RS is tied high on sys2 hw
}
@ -3155,8 +3155,7 @@ DRIVER_INIT_MEMBER(atarisy2_state,720)
m_slapstic->slapstic_init(machine(), 107);
m_pedal_count = -1;
m_has_tms5220 = 1;
machine().device<tms5220_device>("tms")->rsq_w(1); // /RS is tied high on sys2 hw
m_tms5220->rsq_w(1); // /RS is tied high on sys2 hw
}
@ -3172,7 +3171,6 @@ DRIVER_INIT_MEMBER(atarisy2_state,ssprint)
memcpy(&cpu1[i + 0x10000], &cpu1[i], 0x10000);
m_pedal_count = 3;
m_has_tms5220 = 0;
}
@ -3188,7 +3186,6 @@ DRIVER_INIT_MEMBER(atarisy2_state,csprint)
memcpy(&cpu1[i + 0x10000], &cpu1[i], 0x10000);
m_pedal_count = 2;
m_has_tms5220 = 0;
}
@ -3197,8 +3194,7 @@ DRIVER_INIT_MEMBER(atarisy2_state,apb)
m_slapstic->slapstic_init(machine(), 110);
m_pedal_count = 2;
m_has_tms5220 = 1;
machine().device<tms5220_device>("tms")->rsq_w(1); // /RS is tied high on sys2 hw
m_tms5220->rsq_w(1); // /RS is tied high on sys2 hw
}

View File

@ -191,13 +191,12 @@ WRITE16_MEMBER(gauntlet_state::sound_reset_w)
m_soundcomm->sound_cpu_reset();
if (m_sound_reset_val & 1)
{
machine().device("ymsnd")->reset();
tms5220_device *tms5220 = machine().device<tms5220_device>("tms");
tms5220->reset();
tms5220->set_frequency(ATARI_CLOCK_14MHz/2 / 11);
set_ym2151_volume(0);
set_pokey_volume(0);
set_tms5220_volume(0);
m_ym2151->reset();
m_tms5220->reset();
m_tms5220->set_frequency(ATARI_CLOCK_14MHz/2 / 11);
m_ym2151->set_output_gain(ALL_OUTPUTS, 0.0f);
m_pokey->set_output_gain(ALL_OUTPUTS, 0.0f);
m_tms5220->set_output_gain(ALL_OUTPUTS, 0.0f);
}
}
}
@ -213,12 +212,11 @@ WRITE16_MEMBER(gauntlet_state::sound_reset_w)
READ8_MEMBER(gauntlet_state::switch_6502_r)
{
tms5220_device *tms5220 = machine().device<tms5220_device>("tms");
int temp = 0x30;
if (m_soundcomm->main_to_sound_ready()) temp ^= 0x80;
if (m_soundcomm->sound_to_main_ready()) temp ^= 0x40;
if (!tms5220->readyq_r()) temp ^= 0x20;
if (!m_tms5220->readyq_r()) temp ^= 0x20;
if (!(ioport("803008")->read() & 0x0008)) temp ^= 0x10;
return temp;
@ -233,24 +231,23 @@ READ8_MEMBER(gauntlet_state::switch_6502_r)
WRITE8_MEMBER(gauntlet_state::sound_ctl_w)
{
tms5220_device *tms5220 = machine().device<tms5220_device>("tms");
switch (offset & 7)
{
case 0: /* music reset, bit D7, low reset */
if (((data>>7)&1) == 0) machine().device("ymsnd")->reset();
if (((data>>7)&1) == 0) m_ym2151->reset();
break;
case 1: /* speech write, bit D7, active low */
tms5220->wsq_w(data >> 7);
m_tms5220->wsq_w(data >> 7);
break;
case 2: /* speech reset, bit D7, active low */
tms5220->rsq_w(data >> 7);
m_tms5220->rsq_w(data >> 7);
break;
case 3: /* speech squeak, bit D7 */
data = 5 | ((data >> 6) & 2);
tms5220->set_frequency(ATARI_CLOCK_14MHz/2 / (16 - data));
m_tms5220->set_frequency(ATARI_CLOCK_14MHz/2 / (16 - data));
break;
}
}
@ -265,9 +262,9 @@ WRITE8_MEMBER(gauntlet_state::sound_ctl_w)
WRITE8_MEMBER(gauntlet_state::mixer_w)
{
set_ym2151_volume((data & 7) * 100 / 7);
set_pokey_volume(((data >> 3) & 3) * 100 / 3);
set_tms5220_volume(((data >> 5) & 7) * 100 / 7);
m_ym2151->set_output_gain(ALL_OUTPUTS, (data & 7) / 7.0f);
m_pokey->set_output_gain(ALL_OUTPUTS, ((data >> 3) & 3) / 3.0f);
m_tms5220->set_output_gain(ALL_OUTPUTS, ((data >> 5) & 7) / 7.0f);
}

View File

@ -105,12 +105,12 @@ WRITE16_MEMBER(rampart_state::latch_w)
/* lower byte being modified? */
if (ACCESSING_BITS_0_7)
{
set_oki6295_volume((data & 0x0020) ? 100 : 0);
m_oki->set_output_gain(ALL_OUTPUTS, (data & 0x0020) ? 1.0f : 0.0f);
if (!(data & 0x0010))
m_oki->reset();
set_ym2413_volume(((data >> 1) & 7) * 100 / 7);
m_ym2413->set_output_gain(ALL_OUTPUTS, ((data >> 1) & 7) / 7.0f);
if (!(data & 0x0001))
machine().device("ymsnd")->reset();
m_ym2413->reset();
}
}

View File

@ -84,7 +84,7 @@ WRITE16_MEMBER(relief_state::audio_control_w)
if (ACCESSING_BITS_0_7)
{
m_ym2413_volume = (data >> 1) & 15;
set_ym2413_volume((m_ym2413_volume * m_overall_volume * 100) / (127 * 15));
m_ym2413->set_output_gain(ALL_OUTPUTS, (m_ym2413_volume * m_overall_volume) / (127.0f * 15.0f));
m_adpcm_bank = ((data >> 6) & 3) | (m_adpcm_bank & 4);
}
if (ACCESSING_BITS_8_15)
@ -99,8 +99,8 @@ WRITE16_MEMBER(relief_state::audio_volume_w)
if (ACCESSING_BITS_0_7)
{
m_overall_volume = data & 127;
set_ym2413_volume((m_ym2413_volume * m_overall_volume * 100) / (127 * 15));
set_oki6295_volume(m_overall_volume * 100 / 127);
m_ym2413->set_output_gain(ALL_OUTPUTS, (m_ym2413_volume * m_overall_volume) / (127.0f * 15.0f));
m_oki->set_output_gain(ALL_OUTPUTS, m_overall_volume / 127.0f);
}
}

View File

@ -8,15 +8,18 @@
#include "machine/atarigen.h"
#include "video/atarimo.h"
#include "sound/okim6295.h"
class arcadecl_state : public atarigen_state
{
public:
arcadecl_state(const machine_config &mconfig, device_type type, const char *tag)
: atarigen_state(mconfig, type, tag),
m_oki(*this, "oki"),
m_mob(*this, "mob"),
m_bitmap(*this, "bitmap") { }
required_device<okim6295_device> m_oki;
optional_device<atari_motion_objects_device> m_mob;
required_shared_ptr<UINT16> m_bitmap;

View File

@ -15,6 +15,8 @@ class atarisy1_state : public atarigen_state
public:
atarisy1_state(const machine_config &mconfig, device_type type, const char *tag)
: atarigen_state(mconfig, type, tag),
m_audiocpu(*this, "audiocpu"),
m_soundcomm(*this, "soundcomm"),
m_bankselect(*this, "bankselect"),
m_mob(*this, "mob"),
m_joystick_timer(*this, "joystick_timer"),
@ -25,6 +27,9 @@ public:
m_int3off_timer(*this, "int3off_timer"),
m_tms(*this, "tms") { }
required_device<cpu_device> m_audiocpu;
required_device<atari_sound_comm_device> m_soundcomm;
required_shared_ptr<UINT16> m_bankselect;
required_device<atari_motion_objects_device> m_mob;

View File

@ -10,6 +10,9 @@
#include "video/atarimo.h"
#include "cpu/m6502/m6502.h"
#include "cpu/t11/t11.h"
#include "sound/2151intf.h"
#include "sound/pokey.h"
#include "sound/tms5220.h"
#include "slapstic.h"
class atarisy2_state : public atarigen_state
@ -23,6 +26,11 @@ public:
m_slapstic_base(*this, "slapstic_base"),
m_playfield_tilemap(*this, "playfield"),
m_alpha_tilemap(*this, "alpha"),
m_soundcomm(*this, "soundcomm"),
m_ym2151(*this, "ymsnd"),
m_pokey1(*this, "pokey1"),
m_pokey2(*this, "pokey2"),
m_tms5220(*this, "tms"),
m_rombank1(*this, "rombank1"),
m_rombank2(*this, "rombank2"),
m_slapstic(*this, "slapstic")
@ -40,7 +48,11 @@ public:
INT8 m_pedal_count;
UINT8 m_has_tms5220;
required_device<atari_sound_comm_device> m_soundcomm;
required_device<ym2151_device> m_ym2151;
required_device<pokey_device> m_pokey1;
required_device<pokey_device> m_pokey2;
optional_device<tms5220_device> m_tms5220;
UINT8 m_which_adc;

View File

@ -14,9 +14,14 @@ class badlands_state : public atarigen_state
public:
badlands_state(const machine_config &mconfig, device_type type, const char *tag)
: atarigen_state(mconfig, type, tag),
m_audiocpu(*this, "audiocpu"),
m_soundcomm(*this, "soundcomm"),
m_playfield_tilemap(*this, "playfield"),
m_mob(*this, "mob") { }
optional_device<cpu_device> m_audiocpu;
optional_device<atari_sound_comm_device> m_soundcomm;
required_device<tilemap_device> m_playfield_tilemap;
required_device<atari_motion_objects_device> m_mob;

View File

@ -24,6 +24,7 @@ public:
m_daccpu(*this, "dac"),
m_dac1(*this, "dac1"),
m_dac2(*this, "dac2"),
m_soundcomm(*this, "soundcomm"),
m_jsa(*this, "jsa"),
m_playfield_tilemap(*this, "playfield"),
m_alpha_tilemap(*this, "alpha"),
@ -40,6 +41,7 @@ public:
optional_device<cpu_device> m_daccpu;
optional_device<dac_device> m_dac1;
optional_device<dac_device> m_dac2;
optional_device<atari_sound_comm_device> m_soundcomm;
optional_device<atari_jsa_ii_device> m_jsa;
required_device<tilemap_device> m_playfield_tilemap;
required_device<tilemap_device> m_alpha_tilemap;

View File

@ -8,16 +8,30 @@
#include "machine/atarigen.h"
#include "video/atarimo.h"
#include "sound/2151intf.h"
#include "sound/pokey.h"
#include "sound/tms5220.h"
class gauntlet_state : public atarigen_state
{
public:
gauntlet_state(const machine_config &mconfig, device_type type, const char *tag)
: atarigen_state(mconfig, type, tag),
m_audiocpu(*this, "audiocpu"),
m_soundcomm(*this, "soundcomm"),
m_ym2151(*this, "ymsnd"),
m_pokey(*this, "pokey"),
m_tms5220(*this, "tms"),
m_playfield_tilemap(*this, "playfield"),
m_alpha_tilemap(*this, "alpha"),
m_mob(*this, "mob") { }
required_device<cpu_device> m_audiocpu;
required_device<atari_sound_comm_device> m_soundcomm;
required_device<ym2151_device> m_ym2151;
required_device<pokey_device> m_pokey;
required_device<tms5220_device> m_tms5220;
required_device<tilemap_device> m_playfield_tilemap;
required_device<tilemap_device> m_alpha_tilemap;
required_device<atari_motion_objects_device> m_mob;

View File

@ -8,6 +8,7 @@
#include "machine/atarigen.h"
#include "sound/okim6295.h"
#include "sound/2413intf.h"
#include "video/atarimo.h"
class rampart_state : public atarigen_state
@ -17,10 +18,12 @@ public:
: atarigen_state(mconfig, type, tag),
m_mob(*this, "mob"),
m_oki(*this, "oki"),
m_ym2413(*this, "ymsnd"),
m_bitmap(*this, "bitmap") { }
required_device<atari_motion_objects_device> m_mob;
required_device<okim6295_device> m_oki;
required_device<ym2413_device> m_ym2413;
required_shared_ptr<UINT16> m_bitmap;

View File

@ -8,6 +8,8 @@
#include "machine/atarigen.h"
#include "video/atarimo.h"
#include "sound/okim6295.h"
#include "sound/2413intf.h"
class relief_state : public atarigen_state
{
@ -15,10 +17,14 @@ public:
relief_state(const machine_config &mconfig, device_type type, const char *tag)
: atarigen_state(mconfig, type, tag),
m_vad(*this, "vad"),
m_oki(*this, "oki"),
m_ym2413(*this, "ymsnd"),
m_okibank(*this, "okibank")
{ }
required_device<atari_vad_device> m_vad;
required_device<okim6295_device> m_oki;
required_device<ym2413_device> m_ym2413;
required_memory_bank m_okibank;
UINT8 m_ym2413_volume;

View File

@ -10,11 +10,6 @@
#include "emu.h"
#include "cpu/m6502/m6502.h"
#include "sound/2151intf.h"
#include "sound/2413intf.h"
#include "sound/tms5220.h"
#include "sound/okim6295.h"
#include "sound/pokey.h"
#include "video/atarimo.h"
#include "atarigen.h"
@ -965,9 +960,6 @@ atarigen_state::atarigen_state(const machine_config &mconfig, device_type type,
m_slapstic_mirror(0),
m_scanlines_per_callback(0),
m_maincpu(*this, "maincpu"),
m_audiocpu(*this, "audiocpu"),
m_oki(*this, "oki"),
m_soundcomm(*this, "soundcomm"),
m_gfxdecode(*this, "gfxdecode"),
m_screen(*this, "screen"),
m_palette(*this, "palette"),
@ -1291,57 +1283,6 @@ READ16_MEMBER(atarigen_state::slapstic_r)
/***************************************************************************
SOUND HELPERS
***************************************************************************/
//-------------------------------------------------
// set_volume_by_type: Scans for a particular
// sound chip and changes the volume on all
// channels associated with it.
//-------------------------------------------------
void atarigen_state::set_volume_by_type(int volume, device_type type)
{
sound_interface_iterator iter(*this);
for (device_sound_interface *sound = iter.first(); sound != nullptr; sound = iter.next())
if (sound->device().type() == type)
sound->set_output_gain(ALL_OUTPUTS, volume / 100.0);
}
//-------------------------------------------------
// set_XXXXX_volume: Sets the volume for a given
// type of chip.
//-------------------------------------------------
void atarigen_state::set_ym2151_volume(int volume)
{
set_volume_by_type(volume, YM2151);
}
void atarigen_state::set_ym2413_volume(int volume)
{
set_volume_by_type(volume, YM2413);
}
void atarigen_state::set_pokey_volume(int volume)
{
set_volume_by_type(volume, POKEY);
}
void atarigen_state::set_tms5220_volume(int volume)
{
set_volume_by_type(volume, TMS5220);
}
void atarigen_state::set_oki6295_volume(int volume)
{
set_volume_by_type(volume, OKIM6295);
}
/***************************************************************************
SCANLINE TIMING
***************************************************************************/

View File

@ -14,7 +14,6 @@
#include "machine/eeprompar.h"
#include "video/atarimo.h"
#include "cpu/m6502/m6502.h"
#include "sound/okim6295.h"
#include "includes/slapstic.h"
@ -362,14 +361,6 @@ public:
DECLARE_WRITE16_MEMBER(slapstic_w);
DECLARE_READ16_MEMBER(slapstic_r);
// sound helpers
void set_volume_by_type(int volume, device_type type);
void set_ym2151_volume(int volume);
void set_ym2413_volume(int volume);
void set_pokey_volume(int volume);
void set_tms5220_volume(int volume);
void set_oki6295_volume(int volume);
// scanline timing
void scanline_timer_reset(screen_device &screen, int frequency);
void scanline_timer(emu_timer &timer, screen_device &screen, int scanline);
@ -412,10 +403,7 @@ public:
atarigen_screen_timer m_screen_timer[2];
required_device<cpu_device> m_maincpu;
optional_device<cpu_device> m_audiocpu;
optional_device<okim6295_device> m_oki;
optional_device<atari_sound_comm_device> m_soundcomm;
optional_device<gfxdecode_device> m_gfxdecode;
optional_device<screen_device> m_screen;
optional_device<palette_device> m_palette;