MSM6258 emulator de-MAMEfication

This commit is contained in:
tildearrow 2022-05-22 17:49:41 -05:00
parent 393d1c018d
commit 98e9a4b28d
3 changed files with 24 additions and 64 deletions

View file

@ -323,6 +323,8 @@ src/engine/platform/sound/ymz280b.cpp
src/engine/platform/sound/rf5c68.cpp src/engine/platform/sound/rf5c68.cpp
src/engine/platform/sound/oki/okim6258.cpp
src/engine/platform/oplAInterface.cpp src/engine/platform/oplAInterface.cpp
src/engine/platform/ym2608Interface.cpp src/engine/platform/ym2608Interface.cpp
src/engine/platform/ym2610Interface.cpp src/engine/platform/ym2610Interface.cpp

View file

@ -11,8 +11,9 @@
**********************************************************************************************/ **********************************************************************************************/
#include "emu.h"
#include "okim6258.h" #include "okim6258.h"
#include <string.h>
#include <math.h>
#define COMMAND_STOP (1 << 0) #define COMMAND_STOP (1 << 0)
#define COMMAND_PLAY (1 << 1) #define COMMAND_PLAY (1 << 1)
@ -34,9 +35,6 @@ static int tables_computed = 0;
// device type definition
DEFINE_DEVICE_TYPE(OKIM6258, okim6258_device, "okim6258", "OKI MSM6258 ADPCM")
//************************************************************************** //**************************************************************************
// LIVE DEVICE // LIVE DEVICE
@ -46,19 +44,18 @@ DEFINE_DEVICE_TYPE(OKIM6258, okim6258_device, "okim6258", "OKI MSM6258 ADPCM")
// okim6258_device - constructor // okim6258_device - constructor
//------------------------------------------------- //-------------------------------------------------
okim6258_device::okim6258_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) okim6258_device::okim6258_device(uint32_t clock)
: device_t(mconfig, OKIM6258, tag, owner, clock), :
device_sound_interface(mconfig, *this),
m_status(0), m_status(0),
m_start_divider(0), m_start_divider(0),
m_divider(512), m_divider(512),
m_adpcm_type(0), m_adpcm_type(0),
m_data_in(0), m_data_in(0),
m_nibble_shift(0), m_nibble_shift(0),
m_stream(nullptr),
m_output_bits(0), m_output_bits(0),
m_signal(0), m_signal(0),
m_step(0) m_step(0),
m_clock(clock)
{ {
} }
@ -114,12 +111,8 @@ void okim6258_device::device_start()
m_divider = dividers[m_start_divider]; m_divider = dividers[m_start_divider];
m_stream = stream_alloc(0, 1, clock()/m_divider);
m_signal = -2; m_signal = -2;
m_step = 0; m_step = 0;
state_save_register();
} }
@ -129,8 +122,6 @@ void okim6258_device::device_start()
void okim6258_device::device_reset() void okim6258_device::device_reset()
{ {
m_stream->update();
m_signal = -2; m_signal = -2;
m_step = 0; m_step = 0;
m_status = 0; m_status = 0;
@ -141,7 +132,7 @@ void okim6258_device::device_reset()
// sound_stream_update - handle a stream update // sound_stream_update - handle a stream update
//------------------------------------------------- //-------------------------------------------------
void okim6258_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) void okim6258_device::sound_stream_update(short** outputs, int len)
{ {
auto &buffer = outputs[0]; auto &buffer = outputs[0];
@ -149,7 +140,7 @@ void okim6258_device::sound_stream_update(sound_stream &stream, std::vector<read
{ {
int nibble_shift = m_nibble_shift; int nibble_shift = m_nibble_shift;
for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) for (int sampindex = 0; sampindex < len; sampindex++)
{ {
/* Compute the new amplitude and update the current step */ /* Compute the new amplitude and update the current step */
int nibble = (m_data_in >> nibble_shift) & 0xf; int nibble = (m_data_in >> nibble_shift) & 0xf;
@ -159,7 +150,7 @@ void okim6258_device::sound_stream_update(sound_stream &stream, std::vector<read
nibble_shift ^= 4; nibble_shift ^= 4;
buffer.put_int(sampindex, sample, 32768); buffer[sampindex]=sample;
} }
/* Update the parameters */ /* Update the parameters */
@ -167,29 +158,12 @@ void okim6258_device::sound_stream_update(sound_stream &stream, std::vector<read
} }
else else
{ {
buffer.fill(0); memset(buffer,0,len*sizeof(short));
} }
} }
/**********************************************************************************************
state save support for MAME
***********************************************************************************************/
void okim6258_device::state_save_register()
{
save_item(NAME(m_status));
save_item(NAME(m_divider));
save_item(NAME(m_data_in));
save_item(NAME(m_nibble_shift));
save_item(NAME(m_signal));
save_item(NAME(m_step));
}
int16_t okim6258_device::clock_adpcm(uint8_t nibble) int16_t okim6258_device::clock_adpcm(uint8_t nibble)
{ {
int32_t max = (1 << (m_output_bits - 1)) - 1; int32_t max = (1 << (m_output_bits - 1)) - 1;
@ -224,7 +198,6 @@ int16_t okim6258_device::clock_adpcm(uint8_t nibble)
void okim6258_device::set_divider(int val) void okim6258_device::set_divider(int val)
{ {
m_divider = dividers[val]; m_divider = dividers[val];
notify_clock_changed();
} }
@ -236,7 +209,6 @@ void okim6258_device::set_divider(int val)
void okim6258_device::device_clock_changed() void okim6258_device::device_clock_changed()
{ {
m_stream->set_sample_rate(clock() / m_divider);
} }
@ -248,7 +220,7 @@ void okim6258_device::device_clock_changed()
int okim6258_device::get_vclk() int okim6258_device::get_vclk()
{ {
return (clock() / m_divider); return (m_clock / m_divider);
} }
@ -260,8 +232,6 @@ int okim6258_device::get_vclk()
uint8_t okim6258_device::status_r() uint8_t okim6258_device::status_r()
{ {
m_stream->update();
return (m_status & STATUS_PLAYING) ? 0x00 : 0x80; return (m_status & STATUS_PLAYING) ? 0x00 : 0x80;
} }
@ -273,9 +243,6 @@ uint8_t okim6258_device::status_r()
***********************************************************************************************/ ***********************************************************************************************/
void okim6258_device::data_w(uint8_t data) void okim6258_device::data_w(uint8_t data)
{ {
/* update the stream */
m_stream->update();
m_data_in = data; m_data_in = data;
m_nibble_shift = 0; m_nibble_shift = 0;
} }
@ -289,8 +256,6 @@ void okim6258_device::data_w(uint8_t data)
void okim6258_device::ctrl_w(uint8_t data) void okim6258_device::ctrl_w(uint8_t data)
{ {
m_stream->update();
if (data & COMMAND_STOP) if (data & COMMAND_STOP)
{ {
m_status &= ~(STATUS_PLAYING | STATUS_RECORDING); m_status &= ~(STATUS_PLAYING | STATUS_RECORDING);
@ -316,7 +281,7 @@ void okim6258_device::ctrl_w(uint8_t data)
if (data & COMMAND_RECORD) if (data & COMMAND_RECORD)
{ {
logerror("M6258: Record enabled\n"); //logerror("M6258: Record enabled\n");
m_status |= STATUS_RECORDING; m_status |= STATUS_RECORDING;
} }
else else

View file

@ -3,8 +3,7 @@
#ifndef MAME_SOUND_OKIM6258_H #ifndef MAME_SOUND_OKIM6258_H
#define MAME_SOUND_OKIM6258_H #define MAME_SOUND_OKIM6258_H
#pragma once #include <stdint.h>
//************************************************************************** //**************************************************************************
// TYPE DEFINITIONS // TYPE DEFINITIONS
@ -12,9 +11,7 @@
// ======================> okim6258_device // ======================> okim6258_device
class okim6258_device : public device_t, class okim6258_device {
public device_sound_interface
{
public: public:
static constexpr int FOSC_DIV_BY_1024 = 0; static constexpr int FOSC_DIV_BY_1024 = 0;
static constexpr int FOSC_DIV_BY_768 = 1; static constexpr int FOSC_DIV_BY_768 = 1;
@ -26,7 +23,7 @@ public:
static constexpr int OUTPUT_10BITS = 10; static constexpr int OUTPUT_10BITS = 10;
static constexpr int OUTPUT_12BITS = 12; static constexpr int OUTPUT_12BITS = 12;
okim6258_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); okim6258_device(uint32_t clock);
// configuration // configuration
void set_start_div(int div) { m_start_divider = div; } void set_start_div(int div) { m_start_divider = div; }
@ -40,17 +37,15 @@ public:
void set_divider(int val); void set_divider(int val);
int get_vclk(); int get_vclk();
protected: // device-levels
// device-level overrides virtual void device_start();
virtual void device_start() override; virtual void device_reset();
virtual void device_reset() override; virtual void device_clock_changed();
virtual void device_clock_changed() override;
// sound stream update overrides // sound stream updates
virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; virtual void sound_stream_update(short** outputs, int len);
private: private:
void state_save_register();
int16_t clock_adpcm(uint8_t nibble); int16_t clock_adpcm(uint8_t nibble);
uint8_t m_status; uint8_t m_status;
@ -60,15 +55,13 @@ private:
uint8_t m_adpcm_type; /* 3/4 bit ADPCM select */ uint8_t m_adpcm_type; /* 3/4 bit ADPCM select */
uint8_t m_data_in; /* ADPCM data-in register */ uint8_t m_data_in; /* ADPCM data-in register */
uint8_t m_nibble_shift; /* nibble select */ uint8_t m_nibble_shift; /* nibble select */
sound_stream *m_stream; /* which stream are we playing on? */
uint8_t m_output_bits; /* D/A precision is 10-bits but 12-bit data can be uint8_t m_output_bits; /* D/A precision is 10-bits but 12-bit data can be
output serially to an external DAC */ output serially to an external DAC */
int32_t m_signal; int32_t m_signal;
int32_t m_step; int32_t m_step;
unsigned int m_clock;
}; };
DECLARE_DEVICE_TYPE(OKIM6258, okim6258_device)
#endif // MAME_SOUND_OKIM6258_H #endif // MAME_SOUND_OKIM6258_H