Modernized vc4000 device. [Andrew Gardner]

This commit is contained in:
Andrew Gardner 2013-03-06 04:36:55 +00:00
parent c64c35d64a
commit 17c063bcb2
3 changed files with 57 additions and 98 deletions

View File

@ -8,97 +8,19 @@
#include "includes/vc4000.h"
struct vc4000_sound
{
sound_stream *channel;
UINT8 reg[1];
int size, pos;
unsigned level;
};
static vc4000_sound *get_token(device_t *device)
{
assert(device != NULL);
assert(device->type() == VC4000);
return (vc4000_sound *) downcast<vc4000_sound_device *>(device)->token();
}
void vc4000_soundport_w (device_t *device, int offset, int data)
{
vc4000_sound *token = get_token(device);
token->channel->update();
token->reg[offset] = data;
switch (offset)
{
case 0:
token->pos = 0;
token->level = TRUE;
// frequency 7874/(data+1)
token->size = device->machine().sample_rate() * (data + 1) /7874;
break;
}
}
/************************************/
/* Sound handler update */
/************************************/
static STREAM_UPDATE( vc4000_update )
{
int i;
vc4000_sound *token = get_token(device);
stream_sample_t *buffer = outputs[0];
for (i = 0; i < samples; i++, buffer++)
{
*buffer = 0;
if (token->reg[0] && token->pos <= token->size / 2)
{
*buffer = 0x7fff;
}
if (token->pos <= token->size)
token->pos++;
if (token->pos > token->size)
token->pos = 0;
}
}
/************************************/
/* Sound handler start */
/************************************/
static DEVICE_START(vc4000_sound)
{
vc4000_sound *token = get_token(device);
memset(token, 0, sizeof(*token));
token->channel = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), 0, vc4000_update);
}
const device_type VC4000 = &device_creator<vc4000_sound_device>;
vc4000_sound_device::vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, VC4000, "VC 4000 Custom", tag, owner, clock),
device_sound_interface(mconfig, *this)
device_sound_interface(mconfig, *this),
m_channel(NULL),
m_size(0),
m_pos(0),
m_level(0)
{
m_token = global_alloc_clear(vc4000_sound);
memset(m_reg, 0, sizeof(UINT8)*1);
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void vc4000_sound_device::device_config_complete()
{
}
//-------------------------------------------------
// device_start - device-specific startup
@ -106,15 +28,45 @@ void vc4000_sound_device::device_config_complete()
void vc4000_sound_device::device_start()
{
DEVICE_START_NAME( vc4000_sound )(this);
m_channel = stream_alloc(0, 1, machine().sample_rate());
}
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void vc4000_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
// should never get here
fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
int i;
stream_sample_t *buffer = outputs[0];
for (i = 0; i < samples; i++, buffer++)
{
*buffer = 0;
if (m_reg[0] && m_pos <= m_size / 2)
{
*buffer = 0x7fff;
}
if (m_pos <= m_size)
m_pos++;
if (m_pos > m_size)
m_pos = 0;
}
}
void vc4000_sound_device::soundport_w(int offset, int data)
{
m_channel->update();
m_reg[offset] = data;
switch (offset)
{
case 0:
m_pos = 0;
m_level = TRUE;
// frequency 7874/(data+1)
m_size = machine().sample_rate() * (data + 1) /7874;
break;
}
}

View File

@ -139,30 +139,37 @@ protected:
/*----------- defined in audio/vc4000.c -----------*/
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// ======================> vc4000_sound_device
class vc4000_sound_device : public device_t,
public device_sound_interface
public device_sound_interface
{
public:
vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
~vc4000_sound_device() { global_free(m_token); }
~vc4000_sound_device() { }
// access to legacy token
void *token() const { assert(m_token != NULL); return m_token; }
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
public:
void soundport_w(int mode, int data);
private:
// internal state
void *m_token;
sound_stream *m_channel;
UINT8 m_reg[1];
int m_size;
int m_pos;
unsigned m_level;
};
extern const device_type VC4000;
void vc4000_soundport_w (device_t *device, int mode, int data);
#endif /* VC4000_H_ */

View File

@ -320,7 +320,7 @@ WRITE8_MEMBER( vc4000_state::vc4000_video_w )
case 0xc7: // Soundregister
m_video.reg.data[offset] = data;
vc4000_soundport_w(machine().device("custom"), 0, data);
machine().device<vc4000_sound_device>("custom")->soundport_w(0, data);
break;
case 0xc8: // Digits 1 and 2