Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/src/emu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ files {
MAME_DIR .. "src/devices/sound/flt_rc.h",
MAME_DIR .. "src/emu/sound/wavwrite.c",
MAME_DIR .. "src/emu/sound/wavwrite.h",
MAME_DIR .. "src/emu/sound/vgmwrite.c",
MAME_DIR .. "src/emu/sound/vgmwrite.h",
MAME_DIR .. "src/devices/sound/samples.c",
MAME_DIR .. "src/devices/sound/samples.h",
MAME_DIR .. "src/emu/drivers/empty.c",
Expand Down
2 changes: 1 addition & 1 deletion src/devices/sound/2203intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void ym2203_device::device_start()
m_stream = machine().sound().stream_alloc(*this,0,1,rate, stream_update_delegate(FUNC(ym2203_device::stream_generate),this));

/* Initialize FM emurator */
m_chip = ym2203_init(this,this,clock(),rate,timer_handler,IRQHandler,&psgintf);
m_chip = ym2203_init(this,this,clock(),rate,timer_handler,IRQHandler,&psgintf,ay8910_device::m_flags);
assert_always(m_chip != NULL, "Error creating YM2203 chip");
}

Expand Down
2 changes: 1 addition & 1 deletion src/devices/sound/2608intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void ym2608_device::device_start()
/* initialize YM2608 */
m_chip = ym2608_init(this,this,clock(),rate,
pcmbufa,pcmsizea,
timer_handler,IRQHandler,&psgintf);
timer_handler,IRQHandler,&psgintf,ay8910_device::m_flags);
assert_always(m_chip != NULL, "Error creating YM2608 chip");
}

Expand Down
41 changes: 39 additions & 2 deletions src/devices/sound/ay8910.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ has twice the steps, happening twice as fast.

#include "emu.h"
#include "ay8910.h"
#include "sound/vgmwrite.h"

extern const device_type YM2203;
extern const device_type YM2608;
extern const device_type YM2610;
extern const device_type YM2610B;

/*************************************
*
Expand Down Expand Up @@ -583,6 +589,8 @@ UINT16 ay8910_device::mix_3D()

void ay8910_device::ay8910_write_reg(int r, int v)
{
vgm_write(vgm_idx, 0x00, r, v);

//if (r >= 11 && r <= 13 ) printf("%d %x %02x\n", PSG->index, r, v);
m_regs[r] = v;

Expand Down Expand Up @@ -878,6 +886,7 @@ void ay8910_device::ay8910_statesave()
void ay8910_device::device_start()
{
int master_clock = clock();
UINT8 chp_tp_vgm;

if (m_ioports < 1 && !(m_port_a_read_cb.isnull() && m_port_a_write_cb.isnull()))
fatalerror("Device '%s' is a %s and has no port A!", tag(), name());
Expand Down Expand Up @@ -910,6 +919,34 @@ void ay8910_device::device_start()

ay_set_clock(master_clock);
ay8910_statesave();

if (type() == AY8910) chp_tp_vgm = 0x00;
else if (type() == AY8912) chp_tp_vgm = 0x01;
else if (type() == AY8913) chp_tp_vgm = 0x02;
else if (type() == AY8930) chp_tp_vgm = 0x03;
else if (type() == AY8914) chp_tp_vgm = 0x04;
else if (type() == YM2149) chp_tp_vgm = 0x10;
else if (type() == YM3439) chp_tp_vgm = 0x11;
else if (type() == YMZ284) chp_tp_vgm = 0x12;
else if (type() == YMZ294) chp_tp_vgm = 0x13;
else if (type() == YM2203) chp_tp_vgm = 0x20;
else if (type() == YM2608) chp_tp_vgm = 0x21;
else if (type() == YM2610 || type() == YM2610B) chp_tp_vgm = 0x22;
else chp_tp_vgm = 0xFF;

if (! (chp_tp_vgm & 0x20))
{
vgm_idx = vgm_open(VGMC_AY8910, clock());
vgm_header_set(vgm_idx, 0x00, chp_tp_vgm);
vgm_header_set(vgm_idx, 0x01, m_flags);
vgm_header_set(vgm_idx, 0x10, m_res_load[0]);
vgm_header_set(vgm_idx, 0x11, m_res_load[1]);
vgm_header_set(vgm_idx, 0x12, m_res_load[2]);
}
else
{
vgm_idx = 0xFFFF;
}
}


Expand Down Expand Up @@ -1126,6 +1163,7 @@ const device_type AY8910 = &device_creator<ay8910_device>;
ay8910_device::ay8910_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, AY8910, "AY-3-8910A", tag, owner, clock, "ay8910", __FILE__),
device_sound_interface(mconfig, *this),
m_flags(AY8910_LEGACY_OUTPUT),
m_type(PSG_TYPE_AY),
m_streams(3),
m_ioports(2),
Expand All @@ -1148,7 +1186,6 @@ ay8910_device::ay8910_device(const machine_config &mconfig, const char *tag, dev
m_zero_is_off(1),
m_par(&ay8910_param),
m_par_env(&ay8910_param),
m_flags(AY8910_LEGACY_OUTPUT),
m_port_a_read_cb(*this),
m_port_b_read_cb(*this),
m_port_a_write_cb(*this),
Expand All @@ -1168,6 +1205,7 @@ ay8910_device::ay8910_device(const machine_config &mconfig, device_type type, co
psg_type_t psg_type, int streams, int ioports, const char *shortname, const char *source)
: device_t(mconfig, type, name, tag, owner, clock, shortname, source),
device_sound_interface(mconfig, *this),
m_flags(AY8910_LEGACY_OUTPUT),
m_type(psg_type),
m_streams(streams),
m_ioports(ioports),
Expand All @@ -1190,7 +1228,6 @@ ay8910_device::ay8910_device(const machine_config &mconfig, device_type type, co
m_zero_is_off( psg_type == PSG_TYPE_AY ? 1 : 0),
m_par( psg_type == PSG_TYPE_AY ? &ay8910_param : &ym2149_param),
m_par_env( psg_type == PSG_TYPE_AY ? &ay8910_param : &ym2149_param_env),
m_flags(AY8910_LEGACY_OUTPUT),
m_port_a_read_cb(*this),
m_port_b_read_cb(*this),
m_port_a_write_cb(*this),
Expand Down
3 changes: 2 additions & 1 deletion src/devices/sound/ay8910.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class ay8910_device : public device_t,
// device-level overrides
virtual void device_start();
virtual void device_reset();
int m_flags; /* Flags */

// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
Expand Down Expand Up @@ -191,12 +192,12 @@ class ay8910_device : public device_t,
INT32 m_vol_table[AY8910_NUM_CHANNELS][16];
INT32 m_env_table[AY8910_NUM_CHANNELS][32];
INT32 m_vol3d_table[8*32*32*32];
int m_flags; /* Flags */
int m_res_load[3]; /* Load on channel in ohms */
devcb_read8 m_port_a_read_cb;
devcb_read8 m_port_b_read_cb;
devcb_write8 m_port_a_write_cb;
devcb_write8 m_port_b_write_cb;
UINT16 vgm_idx; /* VGM index */
};

extern const device_type AY8910;
Expand Down
18 changes: 18 additions & 0 deletions src/devices/sound/c140.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Unmapped registers:


#include "emu.h"
#include "sound/vgmwrite.h"
#include "c140.h"

struct voice_registers
Expand Down Expand Up @@ -135,6 +136,18 @@ void c140_device::device_start()
m_mixer_buffer_left = auto_alloc_array(machine(), INT16, 2 * m_sample_rate);
m_mixer_buffer_right = m_mixer_buffer_left + m_sample_rate;

if (m_pRom != NULL)
{
m_vgm_idx = vgm_open(VGMC_C140, m_baserate);
vgm_header_set(m_vgm_idx, 0x01, m_banking_type);
vgm_write_large_data(m_vgm_idx, 0x01, region()->bytes(), 0x00, 0x00, m_pRom);
}
else
{
logerror("VGM Warning: C140 wants to use dynamic memory (i.e. RAM) - disabled C140 logging!\n");
m_vgm_idx = 0xFFFF;
}

save_item(NAME(m_REG));

for (int i = 0; i < C140_MAX_VOICE; i++)
Expand Down Expand Up @@ -373,6 +386,8 @@ WRITE8_MEMBER( c140_device::c140_w )

offset&=0x1ff;

vgm_write(m_vgm_idx, 0x00, offset, data);

// mirror the bank registers on the 219, fixes bkrtmaq (and probably xday2 based on notes in the HLE)
if ((offset >= 0x1f8) && (m_banking_type == C140_TYPE_ASIC219))
{
Expand Down Expand Up @@ -432,6 +447,9 @@ WRITE8_MEMBER( c140_device::c140_w )
void c140_device::set_base(void *base)
{
m_pRom = (INT8 *)base;

//logerror("VGM Warning: C140 uses Dynamic Memory!\n");
//vgm_write_large_data(m_vgm_idx, 0x01, region()->bytes(), 0x00, 0x00, m_pRom);
}


Expand Down
2 changes: 2 additions & 0 deletions src/devices/sound/c140.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class c140_device : public device_t,
INT16 m_pcmtbl[8]; //2000.06.26 CAB

C140_VOICE m_voi[C140_MAX_VOICE];

UINT16 m_vgm_idx; // VGM index
};

extern const device_type C140;
Expand Down
4 changes: 4 additions & 0 deletions src/devices/sound/c6280.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/

#include "emu.h"
#include "sound/vgmwrite.h"
#include "c6280.h"

/* only needed for io_buffer */
Expand Down Expand Up @@ -149,6 +150,8 @@ WRITE8_MEMBER( c6280_device::c6280_w )
{
m_cpudevice->io_set_buffer(data);

vgm_write(m_vgm_idx, 0x00, offset, data);

channel *chan = &m_channel[m_select];

/* Update stream */
Expand Down Expand Up @@ -245,6 +248,7 @@ c6280_device::c6280_device(const machine_config &mconfig, const char *tag, devic
void c6280_device::device_start()
{
int rate = clock() / 16;
m_vgm_idx = vgm_open(VGMC_C6280, clock());

/* Create stereo stream */
m_stream = machine().sound().stream_alloc(*this, 0, 2, rate);
Expand Down
2 changes: 2 additions & 0 deletions src/devices/sound/c6280.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class c6280_device : public device_t,
INT16 m_volume_table[32];
UINT32 m_noise_freq_tab[32];
UINT32 m_wave_freq_tab[4096];

UINT16 m_vgm_idx;
};

extern const device_type C6280;
Expand Down
38 changes: 36 additions & 2 deletions src/devices/sound/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@
/************************************************************************/

#include "emu.h"
#include "sound/vgmwrite.h"
#include "fm.h"


extern const device_type YM2610B; // YM2610B mode detection

/* include external DELTA-T unit (when needed) */
#if (BUILD_YM2608||BUILD_YM2610||BUILD_YM2610B)
#include "ymdeltat.h"
Expand Down Expand Up @@ -2093,6 +2096,7 @@ struct YM2203
UINT8 REGS[256]; /* registers */
FM_OPN OPN; /* OPN state */
FM_CH CH[3]; /* channel state */
UINT16 vgm_idx; /* VGM index */
};

/* Generate samples for one of the YM2203s */
Expand Down Expand Up @@ -2258,7 +2262,8 @@ static void YM2203_save_state(YM2203 *F2203, device_t *device)
'rate' is sampling rate
*/
void * ym2203_init(void *param, device_t *device, int clock, int rate,
FM_TIMERHANDLER timer_handler,FM_IRQHANDLER IRQHandler, const ssg_callbacks *ssg)
FM_TIMERHANDLER timer_handler,FM_IRQHANDLER IRQHandler, const ssg_callbacks *ssg,
int psg_flags)
{
YM2203 *F2203;

Expand All @@ -2285,6 +2290,10 @@ void * ym2203_init(void *param, device_t *device, int clock, int rate,
#ifdef __SAVE_H__
YM2203_save_state(F2203, device);
#endif

F2203->vgm_idx = vgm_open(VGMC_YM2203, F2203->OPN.ST.clock);
vgm_header_set(F2203->vgm_idx, 0x01, psg_flags);

return F2203;
}

Expand Down Expand Up @@ -2312,11 +2321,15 @@ int ym2203_write(void *chip,int a,UINT8 v)

/* prescaler select : 2d,2e,2f */
if( v >= 0x2d && v <= 0x2f )
{
vgm_write(F2203->vgm_idx, 0x00, v, 1);
OPNPrescaler_w(OPN , v , 1);
}
}
else
{ /* data port */
int addr = OPN->ST.address;
vgm_write(F2203->vgm_idx, 0x00, addr, v);
F2203->REGS[addr] = v;
switch( addr & 0xf0 )
{
Expand Down Expand Up @@ -2422,6 +2435,8 @@ struct YM2610

UINT8 flagmask; /* YM2608 only */
UINT8 irqmask; /* YM2608 only */

UINT16 vgm_idx; /* VGM index */
};

/* here is the virtual YM2608 */
Expand Down Expand Up @@ -2934,7 +2949,8 @@ static void YM2608_deltat_status_reset(void *chip, UINT8 changebits)
/* YM2608(OPNA) */
void * ym2608_init(void *param, device_t *device, int clock, int rate,
void *pcmrom,int pcmsize,
FM_TIMERHANDLER timer_handler,FM_IRQHANDLER IRQHandler, const ssg_callbacks *ssg)
FM_TIMERHANDLER timer_handler,FM_IRQHANDLER IRQHandler, const ssg_callbacks *ssg,
int psg_flags)
{
YM2608 *F2608;

Expand Down Expand Up @@ -2982,6 +2998,11 @@ void * ym2608_init(void *param, device_t *device, int clock, int rate,
#ifdef __SAVE_H__
YM2608_save_state(F2608, device);
#endif

F2608->vgm_idx = vgm_open(VGMC_YM2608, F2608->OPN.ST.clock);
vgm_header_set(F2608->vgm_idx, 0x01, psg_flags);
vgm_write_large_data(F2608->vgm_idx, 0x01, F2608->deltaT.memory_size, 0x00, 0x00, F2608->deltaT.memory);

return F2608;
}

Expand Down Expand Up @@ -3097,6 +3118,7 @@ int ym2608_write(void *chip, int a,UINT8 v)
/* prescaler selecter : 2d,2e,2f */
if( v >= 0x2d && v <= 0x2f )
{
vgm_write(F2608->vgm_idx, 0x00, v, 2);
OPNPrescaler_w(OPN , v , 2);
F2608->deltaT.freqbase = OPN->ST.freqbase;
}
Expand All @@ -3107,6 +3129,7 @@ int ym2608_write(void *chip, int a,UINT8 v)
break; /* verified on real YM2608 */

addr = OPN->ST.address;
vgm_write(F2608->vgm_idx, 0x00, addr, v);
F2608->REGS[addr] = v;
switch(addr & 0xf0)
{
Expand Down Expand Up @@ -3145,6 +3168,7 @@ int ym2608_write(void *chip, int a,UINT8 v)
break; /* verified on real YM2608 */

addr = OPN->ST.address;
vgm_write(F2608->vgm_idx, 0x01, addr, v);
F2608->REGS[addr | 0x100] = v;
ym2608_update_req(OPN->ST.param);
switch( addr & 0xf0 )
Expand Down Expand Up @@ -3618,6 +3642,7 @@ void *ym2610_init(void *param, device_t *device, int clock, int rate,

{
YM2610 *F2610;
UINT8 mode_b;

/* allocate extend state space */
F2610 = auto_alloc_clear(device->machine(), YM2610);
Expand Down Expand Up @@ -3655,6 +3680,13 @@ void *ym2610_init(void *param, device_t *device, int clock, int rate,
#ifdef __SAVE_H__
YM2610_save_state(F2610, device);
#endif

F2610->vgm_idx = vgm_open(VGMC_YM2610, F2610->OPN.ST.clock);
mode_b = (device->type() == YM2610B);
vgm_header_set(F2610->vgm_idx, 0x00, mode_b); // set YM2610B mode
vgm_write_large_data(F2610->vgm_idx, 0x01, F2610->pcm_size, 0x00, 0x00, F2610->pcmbuf);
vgm_write_large_data(F2610->vgm_idx, 0x02, F2610->deltaT.memory_size, 0x00, 0x00, F2610->deltaT.memory);

return F2610;
}

Expand Down Expand Up @@ -3775,6 +3807,7 @@ int ym2610_write(void *chip, int a, UINT8 v)
break; /* verified on real YM2608 */

addr = OPN->ST.address;
vgm_write(F2610->vgm_idx, 0x00, addr, v);
F2610->REGS[addr] = v;
switch(addr & 0xf0)
{
Expand Down Expand Up @@ -3844,6 +3877,7 @@ int ym2610_write(void *chip, int a, UINT8 v)

ym2610_update_req(OPN->ST.param);
addr = OPN->ST.address;
vgm_write(F2610->vgm_idx, 0x01, addr, v);
F2610->REGS[addr | 0x100] = v;
if( addr < 0x30 )
/* 100-12f : ADPCM A section */
Expand Down
Loading