summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author cam900 <dbtlrchl@naver.com>2018-02-05 00:39:14 +0900
committer Vas Crabb <cuavas@users.noreply.github.com>2018-02-05 02:39:14 +1100
commit053fd7699f379d56dc7bedc7d872e16426c03bea (patch)
tree74092312e69a997273826f932c9acc58682d93eb
parent11e18ca812c491617c568dc1f1acb080376755ef (diff)
vgmplay : Add K051649 support (#3131)
-rw-r--r--scripts/target/mame/virtual.lua1
-rw-r--r--src/devices/sound/k051649.cpp42
-rw-r--r--src/devices/sound/k051649.h6
-rw-r--r--src/mame/drivers/vgmplay.cpp58
4 files changed, 96 insertions, 11 deletions
diff --git a/scripts/target/mame/virtual.lua b/scripts/target/mame/virtual.lua
index 2c25d206279..df41d5c7d70 100644
--- a/scripts/target/mame/virtual.lua
+++ b/scripts/target/mame/virtual.lua
@@ -37,6 +37,7 @@ SOUNDS["YMF271"] = true
SOUNDS["YMZ280B"] = true
SOUNDS["C6280"] = true
SOUNDS["SN76496"] = true
+SOUNDS["K051649"] = true
SOUNDS["K053260"] = true
SOUNDS["K054539"] = true
SOUNDS["SEGAPCM"] = true
diff --git a/src/devices/sound/k051649.cpp b/src/devices/sound/k051649.cpp
index 1114fa47c6c..a675c4f2c11 100644
--- a/src/devices/sound/k051649.cpp
+++ b/src/devices/sound/k051649.cpp
@@ -26,6 +26,7 @@
#include "emu.h"
#include "k051649.h"
+#include <algorithm>
#define FREQ_BITS 16
#define DEF_GAIN 8
@@ -51,7 +52,6 @@ k051649_device::k051649_device(const machine_config &mconfig, const char *tag, d
m_rate(0),
m_mixer_table(nullptr),
m_mixer_lookup(nullptr),
- m_mixer_buffer(nullptr),
m_test(0)
{
}
@@ -69,7 +69,7 @@ void k051649_device::device_start()
m_mclock = clock();
// allocate a buffer to mix into - 1 second's worth should be more than enough
- m_mixer_buffer = std::make_unique<short[]>(2 * m_rate);
+ m_mixer_buffer.resize(2 * m_rate);
// build the mixer table
make_mixer_table(5);
@@ -97,13 +97,42 @@ void k051649_device::device_reset()
//-------------------------------------------------
+// device_post_load - device-specific post-load
+//-------------------------------------------------
+
+void k051649_device::device_post_load()
+{
+ device_clock_changed();
+}
+
+
+//-------------------------------------------------
+// device_clock_changed - called if the clock
+// changes
+//-------------------------------------------------
+
+void k051649_device::device_clock_changed()
+{
+ uint32_t old_rate = m_rate;
+ m_rate = clock()/16;
+ m_mclock = clock();
+
+ if (old_rate < m_rate)
+ {
+ m_mixer_buffer.resize(2 * m_rate, 0);
+ }
+ m_stream->set_sample_rate(m_rate);
+}
+
+
+//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
// zap the contents of the mixer buffer
- memset(m_mixer_buffer.get(), 0, samples * sizeof(short));
+ std::fill(m_mixer_buffer.begin(), m_mixer_buffer.end(), 0);
for (sound_channel &voice : m_channel_list)
{
@@ -115,8 +144,6 @@ void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t *
int c=voice.counter;
int step = ((int64_t(m_mclock) << FREQ_BITS) / float((voice.frequency + 1) * 16 * (m_rate / 32))) + 0.5f;
- short *mix = m_mixer_buffer.get();
-
// add our contribution
for (int i = 0; i < samples; i++)
{
@@ -124,7 +151,7 @@ void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t *
c += step;
offs = (c >> FREQ_BITS) & 0x1f;
- *mix++ += (w[offs] * v)>>3;
+ m_mixer_buffer[i] += (w[offs] * v)>>3;
}
// update the counter for this voice
@@ -134,9 +161,8 @@ void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t *
// mix it down
stream_sample_t *buffer = outputs[0];
- short *mix = m_mixer_buffer.get();
for (int i = 0; i < samples; i++)
- *buffer++ = m_mixer_lookup[*mix++];
+ *buffer++ = m_mixer_lookup[m_mixer_buffer[i]];
}
diff --git a/src/devices/sound/k051649.h b/src/devices/sound/k051649.h
index d405617bcbf..3971d5371e7 100644
--- a/src/devices/sound/k051649.h
+++ b/src/devices/sound/k051649.h
@@ -44,6 +44,8 @@ protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
+ virtual void device_post_load() override;
+ virtual void device_clock_changed() override;
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override;
@@ -58,7 +60,7 @@ private:
volume(0),
key(0)
{
- memset(waveram, 0, sizeof(signed char)*32);
+ std::fill(std::begin(waveram), std::end(waveram), 0);
}
unsigned long counter;
@@ -80,7 +82,7 @@ private:
/* mixer tables and internal buffers */
std::unique_ptr<int16_t[]> m_mixer_table;
int16_t *m_mixer_lookup;
- std::unique_ptr<short[]> m_mixer_buffer;
+ std::vector<short> m_mixer_buffer;
/* chip registers */
uint8_t m_test;
diff --git a/src/mame/drivers/vgmplay.cpp b/src/mame/drivers/vgmplay.cpp
index b99a06f8e7b..1c4c361c0ca 100644
--- a/src/mame/drivers/vgmplay.cpp
+++ b/src/mame/drivers/vgmplay.cpp
@@ -18,6 +18,7 @@
#include "sound/c352.h"
#include "sound/c6280.h"
#include "sound/gb.h"
+#include "sound/k051649.h"
#include "sound/k053260.h"
#include "sound/k054539.h"
#include "sound/multipcm.h"
@@ -83,7 +84,8 @@ public:
A_YM2608 = 0x00013060,
A_K054539A = 0x00014000,
A_K054539B = 0x00014400,
- A_QSOUND = 0x00013070
+ A_QSOUND = 0x00013070,
+ A_K051649 = 0x00013080
};
enum io16_t
@@ -180,6 +182,7 @@ public:
template<int Chip> DECLARE_WRITE8_MEMBER(okim6295_clock_w);
template<int Chip> DECLARE_WRITE8_MEMBER(okim6295_pin7_w);
+ DECLARE_WRITE8_MEMBER(scc_w);
void vgmplay(machine_config &config);
private:
@@ -209,9 +212,11 @@ private:
required_device<ymz280b_device> m_ymz280b;
required_device<ym2608_device> m_ym2608;
required_device<qsound_device> m_qsound;
+ required_device<k051649_device> m_k051649;
uint32_t m_okim6295_clock[2];
uint32_t m_okim6295_pin7[2];
+ uint8_t m_scc_reg;
uint32_t r32(int offset) const;
uint8_t r8(int offset) const;
@@ -566,6 +571,15 @@ void vgmplay_device::execute_run()
break;
}
+ case 0xd2:
+ {
+ uint32_t offset = m_file->read_byte(m_pc+1) << 1;
+ m_io->write_byte(A_K051649 + (offset | 0), m_file->read_byte(m_pc+2));
+ m_io->write_byte(A_K051649 + (offset | 1), m_file->read_byte(m_pc+3));
+ m_pc += 4;
+ break;
+ }
+
case 0xd3:
{
uint16_t offset = m_file->read_byte(m_pc+1) << 16 | m_file->read_byte(m_pc+2);
@@ -1064,6 +1078,7 @@ vgmplay_state::vgmplay_state(const machine_config &mconfig, device_type type, co
, m_ymz280b(*this, "ymz280b")
, m_ym2608(*this, "ym2608")
, m_qsound(*this, "qsound")
+ , m_k051649(*this, "k051649")
{
}
@@ -1282,6 +1297,9 @@ void vgmplay_state::machine_start()
m_okim6295[1]->set_unscaled_clock(m_okim6295_clock[1]);
}
}
+ if(version >= 0x161 && r32(0x9c)) {
+ m_k051649->set_unscaled_clock(r32(0x9c));
+ }
if(version >= 0x161 && r32(0xa0)) {
uint32_t clock = r32(0xa0);
m_k054539[0]->set_unscaled_clock(clock & ~0x40000000);
@@ -1400,6 +1418,39 @@ WRITE8_MEMBER(vgmplay_device::okim6295_nmk112_bank_w)
}
}
+WRITE8_MEMBER(vgmplay_state::scc_w)
+{
+ switch(offset & 1)
+ {
+ case 0x00:
+ m_scc_reg = data;
+ break;
+ case 0x01:
+ switch(offset >> 1)
+ {
+ case 0x00:
+ m_k051649->k051649_waveform_w(space, m_scc_reg, data);
+ break;
+ case 0x01:
+ m_k051649->k051649_frequency_w(space, m_scc_reg, data);
+ break;
+ case 0x02:
+ m_k051649->k051649_volume_w(space, m_scc_reg, data);
+ break;
+ case 0x03:
+ m_k051649->k051649_keyonoff_w(space, m_scc_reg, data);
+ break;
+ case 0x04:
+ m_k051649->k052539_waveform_w(space, m_scc_reg, data);
+ break;
+ case 0x05:
+ m_k051649->k051649_test_w(space, m_scc_reg, data);
+ break;
+ }
+ break;
+ }
+}
+
static INPUT_PORTS_START( vgmplay )
INPUT_PORTS_END
@@ -1459,6 +1510,7 @@ static ADDRESS_MAP_START( soundchips_map, AS_IO, 8, vgmplay_state )
AM_RANGE(vgmplay_device::A_K054539A, vgmplay_device::A_K054539A+0x22f) AM_DEVWRITE ("k054539a", k054539_device, write)
AM_RANGE(vgmplay_device::A_K054539B, vgmplay_device::A_K054539B+0x22f) AM_DEVWRITE ("k054539b", k054539_device, write)
AM_RANGE(vgmplay_device::A_QSOUND, vgmplay_device::A_QSOUND+0x2) AM_DEVWRITE ("qsound", qsound_device, qsound_w)
+ AM_RANGE(vgmplay_device::A_K051649, vgmplay_device::A_K051649+0xf) AM_WRITE (scc_w)
ADDRESS_MAP_END
static ADDRESS_MAP_START( segapcm_map, 0, 8, vgmplay_state )
@@ -1661,6 +1713,10 @@ MACHINE_CONFIG_START(vgmplay_state::vgmplay)
MCFG_DEVICE_ADDRESS_MAP(0, qsound_map)
MCFG_SOUND_ROUTE(0, "lspeaker", 1)
MCFG_SOUND_ROUTE(1, "rspeaker", 1)
+
+ MCFG_K051649_ADD("k051649", 3579545)
+ MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.33)
+ MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.33)
MACHINE_CONFIG_END
ROM_START( vgmplay )