From 6e8646ac297a7b5d56f9dda30fcb1d87c9f8aefc Mon Sep 17 00:00:00 2001 From: Andrew Gardner Date: Fri, 1 Mar 2013 15:56:10 +0000 Subject: [PATCH] Modernized gomoku, astrocade, saa1099, st0016, and c140 sound devices. [Andrew Gardner] --- src/emu/sound/astrocde.c | 295 ++++++++------------- src/emu/sound/astrocde.h | 54 +++- src/emu/sound/c140.c | 450 ++++++++++++++------------------ src/emu/sound/c140.h | 100 ++++++- src/emu/sound/saa1099.c | 367 +++++++++++--------------- src/emu/sound/saa1099.h | 96 ++++++- src/emu/sound/st0016.c | 173 ++++++------ src/emu/sound/st0016.h | 39 ++- src/mame/audio/gomoku.c | 270 ++++++++----------- src/mame/drivers/astrocde.c | 14 +- src/mame/drivers/bingor.c | 6 +- src/mame/drivers/blitz68k.c | 2 +- src/mame/drivers/g627.c | 2 +- src/mame/drivers/gal3.c | 8 +- src/mame/drivers/gomoku.c | 4 +- src/mame/drivers/jclub2.c | 4 +- src/mame/drivers/jpmsys5.c | 7 +- src/mame/drivers/macs.c | 4 +- src/mame/drivers/manohman.c | 6 +- src/mame/drivers/mastboy.c | 6 +- src/mame/drivers/mpu4vid.c | 18 +- src/mame/drivers/namcona1.c | 14 +- src/mame/drivers/namcos2.c | 18 +- src/mame/drivers/namcos21.c | 8 +- src/mame/drivers/speglsht.c | 4 +- src/mame/drivers/srmp5.c | 4 +- src/mame/drivers/st0016.c | 4 +- src/mame/drivers/xorworld.c | 6 +- src/mame/includes/gomoku.h | 63 ++++- src/mame/includes/jpmsys5.h | 1 - src/mame/video/astrocde.c | 2 +- src/mess/drivers/samcoupe.c | 6 +- src/mess/machine/isa_gblaster.c | 8 +- src/mess/machine/isa_sblaster.c | 8 +- 34 files changed, 1032 insertions(+), 1039 deletions(-) diff --git a/src/emu/sound/astrocde.c b/src/emu/sound/astrocde.c index f0f66f9c3fc..52ab586f69c 100644 --- a/src/emu/sound/astrocde.c +++ b/src/emu/sound/astrocde.c @@ -43,58 +43,74 @@ #include "astrocde.h" -struct astrocade_state +// device type definition +const device_type ASTROCADE = &device_creator; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// astrocade_device - constructor +//------------------------------------------------- + +astrocade_device::astrocade_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, ASTROCADE, "Astrocade", tag, owner, clock), + device_sound_interface(mconfig, *this), + m_stream(NULL), + m_master_count(0), + m_vibrato_clock(0), + m_noise_clock(0), + m_noise_state(0), + m_a_count(0), + m_a_state(0), + m_b_count(0), + m_b_state(0), + m_c_count(0), + m_c_state(0) { - sound_stream *stream; /* sound stream */ - - UINT8 reg[8]; /* 8 control registers */ - - UINT8 master_count; /* current master oscillator count */ - UINT16 vibrato_clock; /* current vibrato clock */ - - UINT8 noise_clock; /* current noise generator clock */ - UINT16 noise_state; /* current noise LFSR state */ - - UINT8 a_count; /* current tone generator A count */ - UINT8 a_state; /* current tone generator A state */ - - UINT8 b_count; /* current tone generator B count */ - UINT8 b_state; /* current tone generator B state */ - - UINT8 c_count; /* current tone generator C count */ - UINT8 c_state; /* current tone generator C state */ - - UINT8 bitswap[256]; /* bitswap table */ -}; - - -INLINE astrocade_state *get_safe_token(device_t *device) -{ - assert(device != NULL); - assert(device->type() == ASTROCADE); - return (astrocade_state *)downcast(device)->token(); + memset(m_reg, 0, sizeof(UINT8)*8); + memset(m_bitswap, 0, sizeof(UINT8)*256); } +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- -/************************************* - * - * Core sound update - * - *************************************/ - -static STREAM_UPDATE( astrocade_update ) +void astrocade_device::device_start() +{ + int i; + + /* generate a bitswap table for the noise */ + for (i = 0; i < 256; i++) + m_bitswap[i] = BITSWAP8(i, 0,1,2,3,4,5,6,7); + + /* allocate a stream for output */ + m_stream = stream_alloc(0, 1, clock()); + + /* reset state */ + device_reset(); + state_save_register(); +} + + +//------------------------------------------------- +// sound_stream_update - handle a stream update +//------------------------------------------------- + +void astrocade_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) { - astrocade_state *chip = (astrocade_state *)param; stream_sample_t *dest = outputs[0]; UINT16 noise_state; UINT8 master_count; UINT8 noise_clock; /* load some locals */ - master_count = chip->master_count; - noise_clock = chip->noise_clock; - noise_state = chip->noise_state; + master_count = m_master_count; + noise_clock = m_noise_clock; + noise_state = m_noise_state; /* loop over samples */ while (samples > 0) @@ -110,16 +126,16 @@ static STREAM_UPDATE( astrocade_update ) samples -= samples_this_time; /* sum the output of the tone generators */ - if (chip->a_state) - cursample += chip->reg[6] & 0x0f; - if (chip->b_state) - cursample += chip->reg[6] >> 4; - if (chip->c_state) - cursample += chip->reg[5] & 0x0f; + if (m_a_state) + cursample += m_reg[6] & 0x0f; + if (m_b_state) + cursample += m_reg[6] >> 4; + if (m_c_state) + cursample += m_reg[5] & 0x0f; /* add in the noise if it is enabled, based on the top bit of the LFSR */ - if ((chip->reg[5] & 0x20) && (noise_state & 0x4000)) - cursample += chip->reg[7] >> 4; + if ((m_reg[5] & 0x20) && (noise_state & 0x4000)) + cursample += m_reg[7] >> 4; /* scale to max and output */ cursample = cursample * 32767 / 60; @@ -136,7 +152,7 @@ static STREAM_UPDATE( astrocade_update ) noise_clock -= 64; /* the same clock also controls the vibrato clock, which is a 13-bit counter */ - chip->vibrato_clock++; + m_vibrato_clock++; } /* clock the master oscillator; this is an 8-bit up counter */ @@ -144,17 +160,17 @@ static STREAM_UPDATE( astrocade_update ) if (master_count == 0) { /* reload based on mux value -- the value from the register is negative logic */ - master_count = ~chip->reg[0]; + master_count = ~m_reg[0]; /* mux value 0 means reload based on the vibrato control */ - if ((chip->reg[5] & 0x10) == 0) + if ((m_reg[5] & 0x10) == 0) { /* vibrato speed (register 4 bits 6-7) selects one of the top 4 bits */ /* of the 13-bit vibrato clock to use (0=highest freq, 3=lowest) */ - if (!((chip->vibrato_clock >> (chip->reg[4] >> 6)) & 0x0200)) + if (!((m_vibrato_clock >> (m_reg[4] >> 6)) & 0x0200)) { /* if the bit is clear, we add the vibrato volume to the counter */ - master_count += chip->reg[4] & 0x3f; + master_count += m_reg[4] & 0x3f; } } @@ -163,187 +179,106 @@ static STREAM_UPDATE( astrocade_update ) { /* the top 8 bits of the noise LFSR are ANDed with the noise volume */ /* register and added to the count */ - master_count += chip->bitswap[(noise_state >> 7) & 0xff] & chip->reg[7]; + master_count += m_bitswap[(noise_state >> 7) & 0xff] & m_reg[7]; } /* clock tone A */ - if (++chip->a_count == 0) + if (++m_a_count == 0) { - chip->a_state ^= 1; - chip->a_count = ~chip->reg[1]; + m_a_state ^= 1; + m_a_count = ~m_reg[1]; } /* clock tone B */ - if (++chip->b_count == 0) + if (++m_b_count == 0) { - chip->b_state ^= 1; - chip->b_count = ~chip->reg[2]; + m_b_state ^= 1; + m_b_count = ~m_reg[2]; } /* clock tone C */ - if (++chip->c_count == 0) + if (++m_c_count == 0) { - chip->c_state ^= 1; - chip->c_count = ~chip->reg[3]; + m_c_state ^= 1; + m_c_count = ~m_reg[3]; } } } /* put back the locals */ - chip->master_count = master_count; - chip->noise_clock = noise_clock; - chip->noise_state = noise_state; + m_master_count = master_count; + m_noise_clock = noise_clock; + m_noise_state = noise_state; } +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- -/************************************* - * - * Chip reset - * - *************************************/ - -static DEVICE_RESET( astrocade ) +void astrocade_device::device_reset() { - astrocade_state *chip = get_safe_token(device); + memset(m_reg, 0, sizeof(m_reg)); - memset(chip->reg, 0, sizeof(chip->reg)); + m_master_count = 0; + m_vibrato_clock = 0; - chip->master_count = 0; - chip->vibrato_clock = 0; + m_noise_clock = 0; + m_noise_state = 0; - chip->noise_clock = 0; - chip->noise_state = 0; + m_a_count = 0; + m_a_state = 0; - chip->a_count = 0; - chip->a_state = 0; + m_b_count = 0; + m_b_state = 0; - chip->b_count = 0; - chip->b_state = 0; - - chip->c_count = 0; - chip->c_state = 0; + m_c_count = 0; + m_c_state = 0; } -/************************************* - * - * Save state registration - * - *************************************/ +//------------------------------------------------- +// Save state registration +//------------------------------------------------- -static void astrocade_state_save_register(astrocade_state *chip, device_t *device) +void astrocade_device::state_save_register() { - device->save_item(NAME(chip->reg)); + save_item(NAME(m_reg)); - device->save_item(NAME(chip->master_count)); - device->save_item(NAME(chip->vibrato_clock)); + save_item(NAME(m_master_count)); + save_item(NAME(m_vibrato_clock)); - device->save_item(NAME(chip->noise_clock)); - device->save_item(NAME(chip->noise_state)); + save_item(NAME(m_noise_clock)); + save_item(NAME(m_noise_state)); - device->save_item(NAME(chip->a_count)); - device->save_item(NAME(chip->a_state)); + save_item(NAME(m_a_count)); + save_item(NAME(m_a_state)); - device->save_item(NAME(chip->b_count)); - device->save_item(NAME(chip->b_state)); + save_item(NAME(m_b_count)); + save_item(NAME(m_b_state)); - device->save_item(NAME(chip->c_count)); - device->save_item(NAME(chip->c_state)); + save_item(NAME(m_c_count)); + save_item(NAME(m_c_state)); } - -/************************************* - * - * Chip initialization - * - *************************************/ - -static DEVICE_START( astrocade ) -{ - astrocade_state *chip = get_safe_token(device); - int i; - - /* generate a bitswap table for the noise */ - for (i = 0; i < 256; i++) - chip->bitswap[i] = BITSWAP8(i, 0,1,2,3,4,5,6,7); - - /* allocate a stream for output */ - chip->stream = device->machine().sound().stream_alloc(*device, 0, 1, device->clock(), chip, astrocade_update); - - /* reset state */ - DEVICE_RESET_CALL(astrocade); - astrocade_state_save_register(chip, device); -} - - - /************************************* * * Sound write accessors * *************************************/ -WRITE8_DEVICE_HANDLER( astrocade_sound_w ) +WRITE8_MEMBER( astrocade_device::astrocade_sound_w ) { - astrocade_state *chip = get_safe_token(device); - if ((offset & 8) != 0) offset = (offset >> 8) & 7; else offset &= 7; /* update */ - chip->stream->update(); + m_stream->update(); /* stash the new register value */ - chip->reg[offset & 7] = data; + m_reg[offset & 7] = data; } -const device_type ASTROCADE = &device_creator; - -astrocade_device::astrocade_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, ASTROCADE, "Astrocade", tag, owner, clock), - device_sound_interface(mconfig, *this) -{ - m_token = global_alloc_clear(astrocade_state); -} - -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void astrocade_device::device_config_complete() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void astrocade_device::device_start() -{ - DEVICE_START_NAME( astrocade )(this); -} - -//------------------------------------------------- -// device_reset - device-specific reset -//------------------------------------------------- - -void astrocade_device::device_reset() -{ - DEVICE_RESET_NAME( astrocade )(this); -} - -//------------------------------------------------- -// sound_stream_update - handle a stream update -//------------------------------------------------- - -void astrocade_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"); -} diff --git a/src/emu/sound/astrocde.h b/src/emu/sound/astrocde.h index 92e9685174d..36516a6d735 100644 --- a/src/emu/sound/astrocde.h +++ b/src/emu/sound/astrocde.h @@ -3,30 +3,66 @@ #ifndef __ASTROCDE_H__ #define __ASTROCDE_H__ -#include "devlegcy.h" -DECLARE_WRITE8_DEVICE_HANDLER( astrocade_sound_w ); +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_ASTROCADE_ADD(_tag, _clock) \ + MCFG_DEVICE_ADD(_tag, ASTROCADE, _clock) +#define MCFG_ASTROCADE_REPLACE(_tag, _clock) \ + MCFG_DEVICE_REPLACE(_tag, ASTROCADE, _clock) + + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> astrocade_device class astrocade_device : public device_t, - public device_sound_interface + public device_sound_interface { public: astrocade_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~astrocade_device() { global_free(m_token); } + ~astrocade_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(); virtual void device_reset(); // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + +public: + DECLARE_WRITE8_MEMBER( astrocade_sound_w ); + private: - // internal state - void *m_token; + void state_save_register(); + +private: + sound_stream *m_stream; /* sound stream */ + + UINT8 m_reg[8]; /* 8 control registers */ + + UINT8 m_master_count; /* current master oscillator count */ + UINT16 m_vibrato_clock; /* current vibrato clock */ + + UINT8 m_noise_clock; /* current noise generator clock */ + UINT16 m_noise_state; /* current noise LFSR state */ + + UINT8 m_a_count; /* current tone generator A count */ + UINT8 m_a_state; /* current tone generator A state */ + + UINT8 m_b_count; /* current tone generator B count */ + UINT8 m_b_state; /* current tone generator B state */ + + UINT8 m_c_count; /* current tone generator C count */ + UINT8 m_c_state; /* current tone generator C state */ + + UINT8 m_bitswap[256]; /* bitswap table */ }; extern const device_type ASTROCADE; diff --git a/src/emu/sound/c140.c b/src/emu/sound/c140.c index 90391f65dbe..faae14e0f15 100644 --- a/src/emu/sound/c140.c +++ b/src/emu/sound/c140.c @@ -46,8 +46,6 @@ Unmapped registers: #include "emu.h" #include "c140.h" -#define MAX_VOICE 24 - struct voice_registers { UINT8 volume_right; @@ -65,177 +63,14 @@ struct voice_registers UINT8 reserved[4]; }; -struct VOICE -{ - long ptoffset; - long pos; - long key; - //--work - long lastdt; - long prevdt; - long dltdt; - //--reg - long rvol; - long lvol; - long frequency; - long bank; - long mode; - long sample_start; - long sample_end; - long sample_loop; -}; - -struct c140_state -{ - int sample_rate; - sound_stream *stream; - int banking_type; - /* internal buffers */ - INT16 *mixer_buffer_left; - INT16 *mixer_buffer_right; - - int baserate; - void *pRom; - UINT8 REG[0x200]; - - INT16 pcmtbl[8]; //2000.06.26 CAB - - VOICE voi[MAX_VOICE]; -}; - -INLINE c140_state *get_safe_token(device_t *device) -{ - assert(device != NULL); - assert(device->type() == C140); - return (c140_state *)downcast(device)->token(); -} +// device type definition +const device_type C140 = &device_creator; -static void init_voice( VOICE *v ) -{ - v->key=0; - v->ptoffset=0; - v->rvol=0; - v->lvol=0; - v->frequency=0; - v->bank=0; - v->mode=0; - v->sample_start=0; - v->sample_end=0; - v->sample_loop=0; -} -READ8_DEVICE_HANDLER( c140_r ) -{ - c140_state *info = get_safe_token(device); - offset&=0x1ff; - return info->REG[offset]; -} - -/* - find_sample: compute the actual address of a sample given it's - address and banking registers, as well as the board type. - - I suspect in "real life" this works like the Sega MultiPCM where the banking - is done by a small PAL or GAL external to the sound chip, which can be switched - per-game or at least per-PCB revision as addressing range needs grow. - */ -static long find_sample(c140_state *info, long adrs, long bank, int voice) -{ - long newadr = 0; - - static const INT16 asic219banks[4] = { 0x1f7, 0x1f1, 0x1f3, 0x1f5 }; - - adrs=(bank<<16)+adrs; - - switch (info->banking_type) - { - case C140_TYPE_SYSTEM2: - // System 2 banking - newadr = ((adrs&0x200000)>>2)|(adrs&0x7ffff); - break; - - case C140_TYPE_SYSTEM21: - // System 21 banking. - // similar to System 2's. - newadr = ((adrs&0x300000)>>1)+(adrs&0x7ffff); - break; - - case C140_TYPE_ASIC219: - // ASIC219's banking is fairly simple - newadr = ((info->REG[asic219banks[voice/4]]&0x3) * 0x20000) + adrs; - break; - } - - return (newadr); -} -WRITE8_DEVICE_HANDLER( c140_w ) -{ - c140_state *info = get_safe_token(device); - info->stream->update(); - - offset&=0x1ff; - - // mirror the bank registers on the 219, fixes bkrtmaq (and probably xday2 based on notes in the HLE) - if ((offset >= 0x1f8) && (info->banking_type == C140_TYPE_ASIC219)) - { - offset -= 8; - } - - info->REG[offset]=data; - if( offset<0x180 ) - { - VOICE *v = &info->voi[offset>>4]; - - if( (offset&0xf)==0x5 ) - { - if( data&0x80 ) - { - const struct voice_registers *vreg = (struct voice_registers *) &info->REG[offset&0x1f0]; - v->key=1; - v->ptoffset=0; - v->pos=0; - v->lastdt=0; - v->prevdt=0; - v->dltdt=0; - v->bank = vreg->bank; - v->mode = data; - - // on the 219 asic, addresses are in words - if (info->banking_type == C140_TYPE_ASIC219) - { - v->sample_loop = (vreg->loop_msb*256 + vreg->loop_lsb)*2; - v->sample_start = (vreg->start_msb*256 + vreg->start_lsb)*2; - v->sample_end = (vreg->end_msb*256 + vreg->end_lsb)*2; - - #if 0 - logerror("219: play v %d mode %02x start %x loop %x end %x\n", - offset>>4, v->mode, - find_sample(info, v->sample_start, v->bank, offset>>4), - find_sample(info, v->sample_loop, v->bank, offset>>4), - find_sample(info, v->sample_end, v->bank, offset>>4)); - #endif - } - else - { - v->sample_loop = vreg->loop_msb*256 + vreg->loop_lsb; - v->sample_start = vreg->start_msb*256 + vreg->start_lsb; - v->sample_end = vreg->end_msb*256 + vreg->end_lsb; - } - } - else - { - v->key=0; - } - } - } -} - -void c140_set_base(device_t *device, void *base) -{ - c140_state *info = get_safe_token(device); - info->pRom = base; -} +//************************************************************************** +// LIVE DEVICE +//************************************************************************** INLINE int limit(INT32 in) { @@ -244,9 +79,72 @@ INLINE int limit(INT32 in) return in; } -static STREAM_UPDATE( update_stereo ) + +//------------------------------------------------- +// c140_device - constructor +//------------------------------------------------- + +c140_device::c140_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, C140, "C140", tag, owner, clock), + device_sound_interface(mconfig, *this), + m_sample_rate(0), + m_stream(NULL), + m_banking_type(0), + m_mixer_buffer_left(NULL), + m_mixer_buffer_right(NULL), + m_baserate(0), + m_pRom(NULL) +{ + memset(m_REG, 0, sizeof(UINT8)*0x200); + memset(m_pcmtbl, 0, sizeof(INT16)*8); +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void c140_device::device_start() +{ + const c140_interface *intf = (const c140_interface *)static_config(); + + m_sample_rate=m_baserate=clock(); + + m_banking_type = intf->banking_type; + + m_stream = stream_alloc(0, 2, m_sample_rate); + + m_pRom=*region(); + + /* make decompress pcm table */ //2000.06.26 CAB + { + int i; + INT32 segbase=0; + for(i=0;i<8;i++) + { + m_pcmtbl[i]=segbase; //segment base value + segbase += 16<baserate*2.0 / (float)info->sample_rate; + float pbase=(float)m_baserate*2.0 / (float)m_sample_rate; INT16 *lmix, *rmix; - if(samples>info->sample_rate) samples=info->sample_rate; + if(samples>m_sample_rate) samples=m_sample_rate; /* zap the contents of the mixer buffer */ - memset(info->mixer_buffer_left, 0, samples * sizeof(INT16)); - memset(info->mixer_buffer_right, 0, samples * sizeof(INT16)); + memset(m_mixer_buffer_left, 0, samples * sizeof(INT16)); + memset(m_mixer_buffer_right, 0, samples * sizeof(INT16)); /* get the number of voices to update */ - voicecnt = (info->banking_type == C140_TYPE_ASIC219) ? 16 : 24; + voicecnt = (m_banking_type == C140_TYPE_ASIC219) ? 16 : 24; //--- audio update for( i=0;ivoi[i]; - const struct voice_registers *vreg = (struct voice_registers *)&info->REG[i*16]; + C140_VOICE *v = &m_voi[i]; + const struct voice_registers *vreg = (struct voice_registers *)&m_REG[i*16]; if( v->key ) { @@ -288,12 +186,12 @@ static STREAM_UPDATE( update_stereo ) delta=(long)((float)frequency * pbase); /* Calculate left/right channel volumes */ - lvol=(vreg->volume_left*32)/MAX_VOICE; //32ch -> 24ch - rvol=(vreg->volume_right*32)/MAX_VOICE; + lvol=(vreg->volume_left*32)/C140_MAX_VOICE; //32ch -> 24ch + rvol=(vreg->volume_right*32)/C140_MAX_VOICE; /* Set mixer outputs base pointers */ - lmix = info->mixer_buffer_left; - rmix = info->mixer_buffer_right; + lmix = m_mixer_buffer_left; + rmix = m_mixer_buffer_right; /* Retrieve sample start/end and calculate size */ st=v->sample_start; @@ -301,7 +199,7 @@ static STREAM_UPDATE( update_stereo ) sz=ed-st; /* Retrieve base pointer to the sample data */ - pSampleData=(signed char*)((FPTR)info->pRom + find_sample(info, st, v->bank, i)); + pSampleData=(signed char*)((FPTR)m_pRom + find_sample(st, v->bank, i)); /* Fetch back previous data pointers */ offset=v->ptoffset; @@ -311,7 +209,7 @@ static STREAM_UPDATE( update_stereo ) dltdt=v->dltdt; /* Switch on data type - compressed PCM is only for C140 */ - if ((v->mode&8) && (info->banking_type != C140_TYPE_ASIC219)) + if ((v->mode&8) && (m_banking_type != C140_TYPE_ASIC219)) { //compressed PCM (maybe correct...) /* Loop for enough to fill sample buffer as requested */ @@ -343,8 +241,8 @@ static STREAM_UPDATE( update_stereo ) /* decompress to 13bit range */ //2000.06.26 CAB sdt=dt>>3; //signed - if(sdt<0) sdt = (sdt<<(dt&7)) - info->pcmtbl[dt&7]; - else sdt = (sdt<<(dt&7)) + info->pcmtbl[dt&7]; + if(sdt<0) sdt = (sdt<<(dt&7)) - m_pcmtbl[dt&7]; + else sdt = (sdt<<(dt&7)) + m_pcmtbl[dt&7]; prevdt=lastdt; lastdt=sdt; @@ -387,7 +285,7 @@ static STREAM_UPDATE( update_stereo ) { prevdt=lastdt; - if (info->banking_type == C140_TYPE_ASIC219) + if (m_banking_type == C140_TYPE_ASIC219) { lastdt = pSampleData[BYTE_XOR_BE(pos)]; @@ -426,8 +324,8 @@ static STREAM_UPDATE( update_stereo ) } /* render to MAME's stream buffer */ - lmix = info->mixer_buffer_left; - rmix = info->mixer_buffer_right; + lmix = m_mixer_buffer_left; + rmix = m_mixer_buffer_right; { stream_sample_t *dest1 = outputs[0]; stream_sample_t *dest2 = outputs[1]; @@ -439,75 +337,131 @@ static STREAM_UPDATE( update_stereo ) } } -static DEVICE_START( c140 ) + +READ8_MEMBER( c140_device::c140_r ) { - const c140_interface *intf = (const c140_interface *)device->static_config(); - c140_state *info = get_safe_token(device); + offset&=0x1ff; + return m_REG[offset]; +} - info->sample_rate=info->baserate=device->clock(); - info->banking_type = intf->banking_type; +WRITE8_MEMBER( c140_device::c140_w ) +{ + m_stream->update(); - info->stream = device->machine().sound().stream_alloc(*device,0,2,info->sample_rate,info,update_stereo); + offset&=0x1ff; - info->pRom=*device->region(); - - /* make decompress pcm table */ //2000.06.26 CAB + // 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)) { - int i; - INT32 segbase=0; - for(i=0;i<8;i++) + offset -= 8; + } + + m_REG[offset]=data; + if( offset<0x180 ) + { + C140_VOICE *v = &m_voi[offset>>4]; + + if( (offset&0xf)==0x5 ) { - info->pcmtbl[i]=segbase; //segment base value - segbase += 16<key=1; + v->ptoffset=0; + v->pos=0; + v->lastdt=0; + v->prevdt=0; + v->dltdt=0; + v->bank = vreg->bank; + v->mode = data; + + // on the 219 asic, addresses are in words + if (m_banking_type == C140_TYPE_ASIC219) + { + v->sample_loop = (vreg->loop_msb*256 + vreg->loop_lsb)*2; + v->sample_start = (vreg->start_msb*256 + vreg->start_lsb)*2; + v->sample_end = (vreg->end_msb*256 + vreg->end_lsb)*2; + + #if 0 + logerror("219: play v %d mode %02x start %x loop %x end %x\n", + offset>>4, v->mode, + find_sample(v->sample_start, v->bank, offset>>4), + find_sample(v->sample_loop, v->bank, offset>>4), + find_sample(v->sample_end, v->bank, offset>>4)); + #endif + } + else + { + v->sample_loop = vreg->loop_msb*256 + vreg->loop_lsb; + v->sample_start = vreg->start_msb*256 + vreg->start_lsb; + v->sample_end = vreg->end_msb*256 + vreg->end_lsb; + } + } + else + { + v->key=0; + } } } +} - memset(info->REG,0,sizeof(info->REG)); + +void c140_device::set_base(void *base) +{ + m_pRom = base; +} + + +void c140_device::init_voice( C140_VOICE *v ) +{ + v->key=0; + v->ptoffset=0; + v->rvol=0; + v->lvol=0; + v->frequency=0; + v->bank=0; + v->mode=0; + v->sample_start=0; + v->sample_end=0; + v->sample_loop=0; +} + + +/* + find_sample: compute the actual address of a sample given it's + address and banking registers, as well as the board type. + + I suspect in "real life" this works like the Sega MultiPCM where the banking + is done by a small PAL or GAL external to the sound chip, which can be switched + per-game or at least per-PCB revision as addressing range needs grow. + */ +long c140_device::find_sample(long adrs, long bank, int voice) +{ + long newadr = 0; + + static const INT16 asic219banks[4] = { 0x1f7, 0x1f1, 0x1f3, 0x1f5 }; + + adrs=(bank<<16)+adrs; + + switch (m_banking_type) { - int i; - for(i=0;ivoi[i] ); + case C140_TYPE_SYSTEM2: + // System 2 banking + newadr = ((adrs&0x200000)>>2)|(adrs&0x7ffff); + break; + + case C140_TYPE_SYSTEM21: + // System 21 banking. + // similar to System 2's. + newadr = ((adrs&0x300000)>>1)+(adrs&0x7ffff); + break; + + case C140_TYPE_ASIC219: + // ASIC219's banking is fairly simple + newadr = ((m_REG[asic219banks[voice/4]]&0x3) * 0x20000) + adrs; + break; } - /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ - info->mixer_buffer_left = auto_alloc_array(device->machine(), INT16, 2 * info->sample_rate); - info->mixer_buffer_right = info->mixer_buffer_left + info->sample_rate; -} - -const device_type C140 = &device_creator; - -c140_device::c140_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, C140, "C140", tag, owner, clock), - device_sound_interface(mconfig, *this) -{ - m_token = global_alloc_clear(c140_state); -} - -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void c140_device::device_config_complete() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void c140_device::device_start() -{ - DEVICE_START_NAME( c140 )(this); -} - -//------------------------------------------------- -// sound_stream_update - handle a stream update -//------------------------------------------------- - -void c140_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"); + return (newadr); } diff --git a/src/emu/sound/c140.h b/src/emu/sound/c140.h index c7f270fa645..175127906f0 100644 --- a/src/emu/sound/c140.h +++ b/src/emu/sound/c140.h @@ -5,12 +5,7 @@ #ifndef __C140_H__ #define __C140_H__ -#include "devlegcy.h" - -DECLARE_READ8_DEVICE_HANDLER( c140_r ); -DECLARE_WRITE8_DEVICE_HANDLER( c140_w ); - -void c140_set_base(device_t *device, void *base); +#define C140_MAX_VOICE 24 enum { @@ -19,29 +14,106 @@ enum C140_TYPE_ASIC219 }; -struct c140_interface { +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_C140_ADD(_tag, _clock) \ + MCFG_DEVICE_ADD(_tag, C140, _clock) +#define MCFG_C140_REPLACE(_tag, _clock) \ + MCFG_DEVICE_REPLACE(_tag, C140, _clock) + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +struct c140_interface +{ int banking_type; }; + +struct C140_VOICE +{ + C140_VOICE() : + ptoffset(0), + pos(0), + key(0), + lastdt(0), + prevdt(0), + dltdt(0), + rvol(0), + lvol(0), + frequency(0), + bank(0), + mode(0), + sample_start(0), + sample_end(0), + sample_loop(0) {} + + long ptoffset; + long pos; + long key; + //--work + long lastdt; + long prevdt; + long dltdt; + //--reg + long rvol; + long lvol; + long frequency; + long bank; + long mode; + + long sample_start; + long sample_end; + long sample_loop; +}; + + +// ======================> c140_device + class c140_device : public device_t, - public device_sound_interface + public device_sound_interface { public: c140_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~c140_device() { global_free(m_token); } + ~c140_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: + DECLARE_READ8_MEMBER( c140_r ); + DECLARE_WRITE8_MEMBER( c140_w ); + +public: + void set_base(void *base); + private: - // internal state - void *m_token; + void init_voice( C140_VOICE *v ); + long find_sample(long adrs, long bank, int voice); + +private: + int m_sample_rate; + sound_stream *m_stream; + int m_banking_type; + /* internal buffers */ + INT16 *m_mixer_buffer_left; + INT16 *m_mixer_buffer_right; + + int m_baserate; + void *m_pRom; + UINT8 m_REG[0x200]; + + INT16 m_pcmtbl[8]; //2000.06.26 CAB + + C140_VOICE m_voi[C140_MAX_VOICE]; }; extern const device_type C140; diff --git a/src/emu/sound/saa1099.c b/src/emu/sound/saa1099.c index 9297a537739..03f221fc87d 100644 --- a/src/emu/sound/saa1099.c +++ b/src/emu/sound/saa1099.c @@ -66,55 +66,9 @@ #include "emu.h" #include "saa1099.h" - #define LEFT 0x00 #define RIGHT 0x01 -/* this structure defines a channel */ -struct saa1099_channel -{ - int frequency; /* frequency (0x00..0xff) */ - int freq_enable; /* frequency enable */ - int noise_enable; /* noise enable */ - int octave; /* octave (0x00..0x07) */ - int amplitude[2]; /* amplitude (0x00..0x0f) */ - int envelope[2]; /* envelope (0x00..0x0f or 0x10 == off) */ - - /* vars to simulate the square wave */ - double counter; - double freq; - int level; -}; - -/* this structure defines a noise channel */ -struct saa1099_noise -{ - /* vars to simulate the noise generator output */ - double counter; - double freq; - int level; /* noise polynomal shifter */ -}; - -/* this structure defines a SAA1099 chip */ -struct saa1099_state -{ - device_t *device; - sound_stream * stream; /* our stream */ - int noise_params[2]; /* noise generators parameters */ - int env_enable[2]; /* envelope generators enable */ - int env_reverse_right[2]; /* envelope reversed for right channel */ - int env_mode[2]; /* envelope generators mode */ - int env_bits[2]; /* non zero = 3 bits resolution */ - int env_clock[2]; /* envelope clock mode (non-zero external) */ - int env_step[2]; /* current envelope step */ - int all_ch_enable; /* all channels enable */ - int sync_state; /* sync all channels */ - int selected_reg; /* selected register */ - struct saa1099_channel channels[6]; /* channels */ - struct saa1099_noise noise[2]; /* noise generators */ - double sample_rate; -}; - static const int amplitude_lookup[16] = { 0*32767/16, 1*32767/16, 2*32767/16, 3*32767/16, 4*32767/16, 5*32767/16, 6*32767/16, 7*32767/16, @@ -166,64 +120,60 @@ static const UINT8 envelope[8][64] = { }; -INLINE saa1099_state *get_safe_token(device_t *device) +// device type definition +const device_type SAA1099 = &device_creator; + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// saa1099_device - constructor +//------------------------------------------------- + +saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, SAA1099, "SAA1099", tag, owner, clock), + device_sound_interface(mconfig, *this), + m_stream(NULL), + m_all_ch_enable(0), + m_sync_state(0), + m_selected_reg(0), + m_sample_rate(0.0) { - assert(device != NULL); - assert(device->type() == SAA1099); - return (saa1099_state *)downcast(device)->token(); + memset(m_noise_params, 0, sizeof(int)*2); + memset(m_env_enable, 0, sizeof(int)*2); + memset(m_env_reverse_right, 0, sizeof(int)*2); + memset(m_env_mode, 0, sizeof(int)*2); + memset(m_env_bits, 0, sizeof(int)*2); + memset(m_env_clock, 0, sizeof(int)*2); + memset(m_env_step, 0, sizeof(int)*2); } -static void saa1099_envelope(saa1099_state *saa, int ch) +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void saa1099_device::device_start() { - if (saa->env_enable[ch]) - { - int step, mode, mask; - mode = saa->env_mode[ch]; - /* step from 0..63 and then loop in steps 32..63 */ - step = saa->env_step[ch] = - ((saa->env_step[ch] + 1) & 0x3f) | (saa->env_step[ch] & 0x20); + /* copy global parameters */ + m_sample_rate = clock() / 256; - mask = 15; - if (saa->env_bits[ch]) - mask &= ~1; /* 3 bit resolution, mask LSB */ - - saa->channels[ch*3+0].envelope[ LEFT] = - saa->channels[ch*3+1].envelope[ LEFT] = - saa->channels[ch*3+2].envelope[ LEFT] = envelope[mode][step] & mask; - if (saa->env_reverse_right[ch] & 0x01) - { - saa->channels[ch*3+0].envelope[RIGHT] = - saa->channels[ch*3+1].envelope[RIGHT] = - saa->channels[ch*3+2].envelope[RIGHT] = (15 - envelope[mode][step]) & mask; - } - else - { - saa->channels[ch*3+0].envelope[RIGHT] = - saa->channels[ch*3+1].envelope[RIGHT] = - saa->channels[ch*3+2].envelope[RIGHT] = envelope[mode][step] & mask; - } - } - else - { - /* envelope mode off, set all envelope factors to 16 */ - saa->channels[ch*3+0].envelope[ LEFT] = - saa->channels[ch*3+1].envelope[ LEFT] = - saa->channels[ch*3+2].envelope[ LEFT] = - saa->channels[ch*3+0].envelope[RIGHT] = - saa->channels[ch*3+1].envelope[RIGHT] = - saa->channels[ch*3+2].envelope[RIGHT] = 16; - } + /* for each chip allocate one stream */ + m_stream = stream_alloc(0, 2, m_sample_rate); } -static STREAM_UPDATE( saa1099_update ) +//------------------------------------------------- +// sound_stream_update - handle a stream update +//------------------------------------------------- + +void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) { - saa1099_state *saa = (saa1099_state *)param; int j, ch; /* if the channels are disabled we're done */ - if (!saa->all_ch_enable) + if (!m_all_ch_enable) { /* init output data */ memset(outputs[LEFT],0,samples*sizeof(*outputs[LEFT])); @@ -233,12 +183,12 @@ static STREAM_UPDATE( saa1099_update ) for (ch = 0; ch < 2; ch++) { - switch (saa->noise_params[ch]) + switch (m_noise_params[ch]) { - case 0: saa->noise[ch].freq = 31250.0 * 2; break; - case 1: saa->noise[ch].freq = 15625.0 * 2; break; - case 2: saa->noise[ch].freq = 7812.5 * 2; break; - case 3: saa->noise[ch].freq = saa->channels[ch * 3].freq; break; + case 0: m_noise[ch].freq = 31250.0 * 2; break; + case 1: m_noise[ch].freq = 15625.0 * 2; break; + case 2: m_noise[ch].freq = 7812.5 * 2; break; + case 3: m_noise[ch].freq = m_channels[ch * 3].freq; break; } } @@ -250,48 +200,48 @@ static STREAM_UPDATE( saa1099_update ) /* for each channel */ for (ch = 0; ch < 6; ch++) { - if (saa->channels[ch].freq == 0.0) - saa->channels[ch].freq = (double)((2 * 15625) << saa->channels[ch].octave) / - (511.0 - (double)saa->channels[ch].frequency); + if (m_channels[ch].freq == 0.0) + m_channels[ch].freq = (double)((2 * 15625) << m_channels[ch].octave) / + (511.0 - (double)m_channels[ch].frequency); /* check the actual position in the square wave */ - saa->channels[ch].counter -= saa->channels[ch].freq; - while (saa->channels[ch].counter < 0) + m_channels[ch].counter -= m_channels[ch].freq; + while (m_channels[ch].counter < 0) { /* calculate new frequency now after the half wave is updated */ - saa->channels[ch].freq = (double)((2 * 15625) << saa->channels[ch].octave) / - (511.0 - (double)saa->channels[ch].frequency); + m_channels[ch].freq = (double)((2 * 15625) << m_channels[ch].octave) / + (511.0 - (double)m_channels[ch].frequency); - saa->channels[ch].counter += saa->sample_rate; - saa->channels[ch].level ^= 1; + m_channels[ch].counter += m_sample_rate; + m_channels[ch].level ^= 1; /* eventually clock the envelope counters */ - if (ch == 1 && saa->env_clock[0] == 0) - saa1099_envelope(saa, 0); - if (ch == 4 && saa->env_clock[1] == 0) - saa1099_envelope(saa, 1); + if (ch == 1 && m_env_clock[0] == 0) + saa1099_envelope(0); + if (ch == 4 && m_env_clock[1] == 0) + saa1099_envelope(1); } /* if the noise is enabled */ - if (saa->channels[ch].noise_enable) + if (m_channels[ch].noise_enable) { /* if the noise level is high (noise 0: chan 0-2, noise 1: chan 3-5) */ - if (saa->noise[ch/3].level & 1) + if (m_noise[ch/3].level & 1) { /* subtract to avoid overflows, also use only half amplitude */ - output_l -= saa->channels[ch].amplitude[ LEFT] * saa->channels[ch].envelope[ LEFT] / 16 / 2; - output_r -= saa->channels[ch].amplitude[RIGHT] * saa->channels[ch].envelope[RIGHT] / 16 / 2; + output_l -= m_channels[ch].amplitude[ LEFT] * m_channels[ch].envelope[ LEFT] / 16 / 2; + output_r -= m_channels[ch].amplitude[RIGHT] * m_channels[ch].envelope[RIGHT] / 16 / 2; } } /* if the square wave is enabled */ - if (saa->channels[ch].freq_enable) + if (m_channels[ch].freq_enable) { /* if the channel level is high */ - if (saa->channels[ch].level & 1) + if (m_channels[ch].level & 1) { - output_l += saa->channels[ch].amplitude[ LEFT] * saa->channels[ch].envelope[ LEFT] / 16; - output_r += saa->channels[ch].amplitude[RIGHT] * saa->channels[ch].envelope[RIGHT] / 16; + output_l += m_channels[ch].amplitude[ LEFT] * m_channels[ch].envelope[ LEFT] / 16; + output_r += m_channels[ch].amplitude[RIGHT] * m_channels[ch].envelope[RIGHT] / 16; } } } @@ -299,14 +249,14 @@ static STREAM_UPDATE( saa1099_update ) for (ch = 0; ch < 2; ch++) { /* check the actual position in noise generator */ - saa->noise[ch].counter -= saa->noise[ch].freq; - while (saa->noise[ch].counter < 0) + m_noise[ch].counter -= m_noise[ch].freq; + while (m_noise[ch].counter < 0) { - saa->noise[ch].counter += saa->sample_rate; - if( ((saa->noise[ch].level & 0x4000) == 0) == ((saa->noise[ch].level & 0x0040) == 0) ) - saa->noise[ch].level = (saa->noise[ch].level << 1) | 1; + m_noise[ch].counter += m_sample_rate; + if( ((m_noise[ch].level & 0x4000) == 0) == ((m_noise[ch].level & 0x0040) == 0) ) + m_noise[ch].level = (m_noise[ch].level << 1) | 1; else - saa->noise[ch].level <<= 1; + m_noise[ch].level <<= 1; } } /* write sound data to the buffer */ @@ -316,159 +266,148 @@ static STREAM_UPDATE( saa1099_update ) } - -static DEVICE_START( saa1099 ) +void saa1099_device::saa1099_envelope(int ch) { - saa1099_state *saa = get_safe_token(device); + if (m_env_enable[ch]) + { + int step, mode, mask; + mode = m_env_mode[ch]; + /* step from 0..63 and then loop in steps 32..63 */ + step = m_env_step[ch] = + ((m_env_step[ch] + 1) & 0x3f) | (m_env_step[ch] & 0x20); - /* copy global parameters */ - saa->device = device; - saa->sample_rate = device->clock() / 256; + mask = 15; + if (m_env_bits[ch]) + mask &= ~1; /* 3 bit resolution, mask LSB */ - /* for each chip allocate one stream */ - saa->stream = device->machine().sound().stream_alloc(*device, 0, 2, saa->sample_rate, saa, saa1099_update); + m_channels[ch*3+0].envelope[ LEFT] = + m_channels[ch*3+1].envelope[ LEFT] = + m_channels[ch*3+2].envelope[ LEFT] = envelope[mode][step] & mask; + if (m_env_reverse_right[ch] & 0x01) + { + m_channels[ch*3+0].envelope[RIGHT] = + m_channels[ch*3+1].envelope[RIGHT] = + m_channels[ch*3+2].envelope[RIGHT] = (15 - envelope[mode][step]) & mask; + } + else + { + m_channels[ch*3+0].envelope[RIGHT] = + m_channels[ch*3+1].envelope[RIGHT] = + m_channels[ch*3+2].envelope[RIGHT] = envelope[mode][step] & mask; + } + } + else + { + /* envelope mode off, set all envelope factors to 16 */ + m_channels[ch*3+0].envelope[ LEFT] = + m_channels[ch*3+1].envelope[ LEFT] = + m_channels[ch*3+2].envelope[ LEFT] = + m_channels[ch*3+0].envelope[RIGHT] = + m_channels[ch*3+1].envelope[RIGHT] = + m_channels[ch*3+2].envelope[RIGHT] = 16; + } } -WRITE8_DEVICE_HANDLER( saa1099_control_w ) -{ - saa1099_state *saa = get_safe_token(device); +WRITE8_MEMBER( saa1099_device::saa1099_control_w ) +{ if ((data & 0xff) > 0x1c) { /* Error! */ - logerror("%s: (SAA1099 '%s') Unknown register selected\n",device->machine().describe_context(), device->tag()); + logerror("%s: (SAA1099 '%s') Unknown register selected\n", machine().describe_context(), tag()); } - saa->selected_reg = data & 0x1f; - if (saa->selected_reg == 0x18 || saa->selected_reg == 0x19) + m_selected_reg = data & 0x1f; + if (m_selected_reg == 0x18 || m_selected_reg == 0x19) { /* clock the envelope channels */ - if (saa->env_clock[0]) - saa1099_envelope(saa,0); - if (saa->env_clock[1]) - saa1099_envelope(saa,1); + if (m_env_clock[0]) + saa1099_envelope(0); + if (m_env_clock[1]) + saa1099_envelope(1); } } -WRITE8_DEVICE_HANDLER( saa1099_data_w ) +WRITE8_MEMBER( saa1099_device::saa1099_data_w ) { - saa1099_state *saa = get_safe_token(device); - int reg = saa->selected_reg; + int reg = m_selected_reg; int ch; /* first update the stream to this point in time */ - saa->stream->update(); + m_stream->update(); switch (reg) { /* channel i amplitude */ case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: ch = reg & 7; - saa->channels[ch].amplitude[LEFT] = amplitude_lookup[data & 0x0f]; - saa->channels[ch].amplitude[RIGHT] = amplitude_lookup[(data >> 4) & 0x0f]; + m_channels[ch].amplitude[LEFT] = amplitude_lookup[data & 0x0f]; + m_channels[ch].amplitude[RIGHT] = amplitude_lookup[(data >> 4) & 0x0f]; break; /* channel i frequency */ case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: ch = reg & 7; - saa->channels[ch].frequency = data & 0xff; + m_channels[ch].frequency = data & 0xff; break; /* channel i octave */ case 0x10: case 0x11: case 0x12: ch = (reg - 0x10) << 1; - saa->channels[ch + 0].octave = data & 0x07; - saa->channels[ch + 1].octave = (data >> 4) & 0x07; + m_channels[ch + 0].octave = data & 0x07; + m_channels[ch + 1].octave = (data >> 4) & 0x07; break; /* channel i frequency enable */ case 0x14: - saa->channels[0].freq_enable = data & 0x01; - saa->channels[1].freq_enable = data & 0x02; - saa->channels[2].freq_enable = data & 0x04; - saa->channels[3].freq_enable = data & 0x08; - saa->channels[4].freq_enable = data & 0x10; - saa->channels[5].freq_enable = data & 0x20; + m_channels[0].freq_enable = data & 0x01; + m_channels[1].freq_enable = data & 0x02; + m_channels[2].freq_enable = data & 0x04; + m_channels[3].freq_enable = data & 0x08; + m_channels[4].freq_enable = data & 0x10; + m_channels[5].freq_enable = data & 0x20; break; /* channel i noise enable */ case 0x15: - saa->channels[0].noise_enable = data & 0x01; - saa->channels[1].noise_enable = data & 0x02; - saa->channels[2].noise_enable = data & 0x04; - saa->channels[3].noise_enable = data & 0x08; - saa->channels[4].noise_enable = data & 0x10; - saa->channels[5].noise_enable = data & 0x20; + m_channels[0].noise_enable = data & 0x01; + m_channels[1].noise_enable = data & 0x02; + m_channels[2].noise_enable = data & 0x04; + m_channels[3].noise_enable = data & 0x08; + m_channels[4].noise_enable = data & 0x10; + m_channels[5].noise_enable = data & 0x20; break; /* noise generators parameters */ case 0x16: - saa->noise_params[0] = data & 0x03; - saa->noise_params[1] = (data >> 4) & 0x03; + m_noise_params[0] = data & 0x03; + m_noise_params[1] = (data >> 4) & 0x03; break; /* envelope generators parameters */ case 0x18: case 0x19: ch = reg - 0x18; - saa->env_reverse_right[ch] = data & 0x01; - saa->env_mode[ch] = (data >> 1) & 0x07; - saa->env_bits[ch] = data & 0x10; - saa->env_clock[ch] = data & 0x20; - saa->env_enable[ch] = data & 0x80; + m_env_reverse_right[ch] = data & 0x01; + m_env_mode[ch] = (data >> 1) & 0x07; + m_env_bits[ch] = data & 0x10; + m_env_clock[ch] = data & 0x20; + m_env_enable[ch] = data & 0x80; /* reset the envelope */ - saa->env_step[ch] = 0; + m_env_step[ch] = 0; break; /* channels enable & reset generators */ case 0x1c: - saa->all_ch_enable = data & 0x01; - saa->sync_state = data & 0x02; + m_all_ch_enable = data & 0x01; + m_sync_state = data & 0x02; if (data & 0x02) { int i; /* Synch & Reset generators */ - logerror("%s: (SAA1099 '%s') -reg 0x1c- Chip reset\n",device->machine().describe_context(), device->tag()); + logerror("%s: (SAA1099 '%s') -reg 0x1c- Chip reset\n", machine().describe_context(), tag()); for (i = 0; i < 6; i++) { - saa->channels[i].level = 0; - saa->channels[i].counter = 0.0; + m_channels[i].level = 0; + m_channels[i].counter = 0.0; } } break; default: /* Error! */ - logerror("%s: (SAA1099 '%s') Unknown operation (reg:%02x, data:%02x)\n",device->machine().describe_context(), device->tag(), reg, data); + logerror("%s: (SAA1099 '%s') Unknown operation (reg:%02x, data:%02x)\n", machine().describe_context(), tag(), reg, data); } } - -const device_type SAA1099 = &device_creator; - -saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, SAA1099, "SAA1099", tag, owner, clock), - device_sound_interface(mconfig, *this) -{ - m_token = global_alloc_clear(saa1099_state); -} - -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void saa1099_device::device_config_complete() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void saa1099_device::device_start() -{ - DEVICE_START_NAME( saa1099 )(this); -} - -//------------------------------------------------- -// sound_stream_update - handle a stream update -//------------------------------------------------- - -void saa1099_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"); -} diff --git a/src/emu/sound/saa1099.h b/src/emu/sound/saa1099.h index 7e2f6ed6a1d..f7350286070 100644 --- a/src/emu/sound/saa1099.h +++ b/src/emu/sound/saa1099.h @@ -1,36 +1,106 @@ +/********************************************** + Philips SAA1099 Sound driver +**********************************************/ + #pragma once #ifndef __SAA1099_H__ #define __SAA1099_H__ -#include "devlegcy.h" +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** -/********************************************** - Philips SAA1099 Sound driver -**********************************************/ +#define MCFG_SAA1099_ADD(_tag, _clock) \ + MCFG_DEVICE_ADD(_tag, SAA1099, _clock) +#define MCFG_SAA1099_REPLACE(_tag, _clock) \ + MCFG_DEVICE_REPLACE(_tag, SAA1099, _clock) -DECLARE_WRITE8_DEVICE_HANDLER( saa1099_control_w ); -DECLARE_WRITE8_DEVICE_HANDLER( saa1099_data_w ); + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +struct saa1099_channel +{ + saa1099_channel() : + frequency(0), + freq_enable(0), + noise_enable(0), + octave(0), + counter(0.0), + freq(0.0), + level(0) + { + memset(amplitude, 0, sizeof(int)*2); + memset(envelope, 0, sizeof(int)*2); + } + + int frequency; /* frequency (0x00..0xff) */ + int freq_enable; /* frequency enable */ + int noise_enable; /* noise enable */ + int octave; /* octave (0x00..0x07) */ + int amplitude[2]; /* amplitude (0x00..0x0f) */ + int envelope[2]; /* envelope (0x00..0x0f or 0x10 == off) */ + + /* vars to simulate the square wave */ + double counter; + double freq; + int level; +}; + +struct saa1099_noise +{ + saa1099_noise() : + counter(0.0), + freq(0.0), + level(0) {} + + /* vars to simulate the noise generator output */ + double counter; + double freq; + int level; /* noise polynomal shifter */ +}; + + +// ======================> saa1099_device class saa1099_device : public device_t, - public device_sound_interface + public device_sound_interface { public: saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~saa1099_device() { global_free(m_token); } + ~saa1099_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: + DECLARE_WRITE8_MEMBER( saa1099_control_w ); + DECLARE_WRITE8_MEMBER( saa1099_data_w ); + private: - // internal state - void *m_token; + void saa1099_envelope(int ch); + +private: + sound_stream *m_stream; /* our stream */ + int m_noise_params[2]; /* noise generators parameters */ + int m_env_enable[2]; /* envelope generators enable */ + int m_env_reverse_right[2]; /* envelope reversed for right channel */ + int m_env_mode[2]; /* envelope generators mode */ + int m_env_bits[2]; /* non zero = 3 bits resolution */ + int m_env_clock[2]; /* envelope clock mode (non-zero external) */ + int m_env_step[2]; /* current envelope step */ + int m_all_ch_enable; /* all channels enable */ + int m_sync_state; /* sync all channels */ + int m_selected_reg; /* selected register */ + saa1099_channel m_channels[6]; /* channels */ + saa1099_noise m_noise[2]; /* noise generators */ + double m_sample_rate; }; extern const device_type SAA1099; diff --git a/src/emu/sound/st0016.c b/src/emu/sound/st0016.c index 986654aa7e0..68e212363a2 100644 --- a/src/emu/sound/st0016.c +++ b/src/emu/sound/st0016.c @@ -9,59 +9,53 @@ #define VERBOSE (0) #define LOG(x) do { if (VERBOSE) logerror x; } while (0) -struct st0016_device_state -{ - sound_stream * stream; - UINT8 **sound_ram; - int vpos[8], frac[8], lponce[8]; - UINT8 regs[0x100]; -}; -INLINE st0016_device_state *get_safe_token(device_t *device) +// device type definition +const device_type ST0016 = &device_creator; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// st0016_device - constructor +//------------------------------------------------- + +st0016_device::st0016_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, ST0016, "ST0016", tag, owner, clock), + device_sound_interface(mconfig, *this), + m_stream(NULL), + m_sound_ram(NULL) { - assert(device != NULL); - assert(device->type() == ST0016); - return (st0016_device_state *)downcast(device)->token(); + memset(m_vpos, 0, sizeof(int)*8); + memset(m_frac, 0, sizeof(int)*8); + memset(m_lponce, 0, sizeof(int)*8); + memset(m_regs, 0, sizeof(UINT8)*0x100); } -READ8_DEVICE_HANDLER( st0016_snd_r ) +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void st0016_device::device_start() { - st0016_device_state *info = get_safe_token(device); - return info->regs[offset]; + const st0016_interface *intf = (const st0016_interface *)static_config(); + + m_sound_ram = intf->p_soundram; + + m_stream = stream_alloc(0, 2, 44100); } -WRITE8_DEVICE_HANDLER( st0016_snd_w ) + +//------------------------------------------------- +// sound_stream_update - handle a stream update +//------------------------------------------------- + +void st0016_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) { - st0016_device_state *info = get_safe_token(device); - int voice = offset/32; - int reg = offset & 0x1f; - int oldreg = info->regs[offset]; - int vbase = offset & ~0x1f; - - info->regs[offset] = data; - - if ((voice < 8) && (data != oldreg)) - { - if ((reg == 0x16) && (data != 0)) - { - info->vpos[voice] = info->frac[voice] = info->lponce[voice] = 0; - - LOG(("Key on V%02d: st %06x-%06x lp %06x-%06x frq %x flg %x\n", voice, - info->regs[vbase+2]<<16 | info->regs[vbase+1]<<8 | info->regs[vbase+2], - info->regs[vbase+0xe]<<16 | info->regs[vbase+0xd]<<8 | info->regs[vbase+0xc], - info->regs[vbase+6]<<16 | info->regs[vbase+5]<<8 | info->regs[vbase+4], - info->regs[vbase+0xa]<<16 | info->regs[vbase+0x9]<<8 | info->regs[vbase+0x8], - info->regs[vbase+0x11]<<8 | info->regs[vbase+0x10], - info->regs[vbase+0x16])); - } - } -} - -static STREAM_UPDATE( st0016_update ) -{ - st0016_device_state *info = (st0016_device_state *)param; - UINT8 *sound_ram = *info->sound_ram; + UINT8 *sound_ram = *m_sound_ram; int v, i, snum; unsigned char *slot; INT32 mix[48000*2]; @@ -73,7 +67,7 @@ static STREAM_UPDATE( st0016_update ) for (v = 0; v < 8; v++) { - slot = (unsigned char *)&info->regs[v * 32]; + slot = (unsigned char *)&m_regs[v * 32]; if (slot[0x16] & 0x06) { @@ -87,38 +81,38 @@ static STREAM_UPDATE( st0016_update ) for (snum = 0; snum < samples; snum++) { - sample = sound_ram[(sptr + info->vpos[v])&0x1fffff]<<8; + sample = sound_ram[(sptr + m_vpos[v])&0x1fffff]<<8; *mixp++ += (sample * (char)slot[0x14]) >> 8; *mixp++ += (sample * (char)slot[0x15]) >> 8; - info->frac[v] += freq; - info->vpos[v] += (info->frac[v]>>16); - info->frac[v] &= 0xffff; + m_frac[v] += freq; + m_vpos[v] += (m_frac[v]>>16); + m_frac[v] &= 0xffff; // stop if we're at the end - if (info->lponce[v]) + if (m_lponce[v]) { // we've looped once, check loop end rather than sample end - if ((info->vpos[v] + sptr) >= leptr) + if ((m_vpos[v] + sptr) >= leptr) { - info->vpos[v] = (lsptr - sptr); + m_vpos[v] = (lsptr - sptr); } } else { // not looped yet, check sample end - if ((info->vpos[v] + sptr) >= eptr) + if ((m_vpos[v] + sptr) >= eptr) { if (slot[0x16] & 0x01) // loop? { - info->vpos[v] = (lsptr - sptr); - info->lponce[v] = 1; + m_vpos[v] = (lsptr - sptr); + m_lponce[v] = 1; } else { slot[0x16] = 0; - info->vpos[v] = info->frac[v] = 0; + m_vpos[v] = m_frac[v] = 0; } } } @@ -134,50 +128,35 @@ static STREAM_UPDATE( st0016_update ) } } -static DEVICE_START( st0016 ) + +READ8_MEMBER( st0016_device::st0016_snd_r ) { - const st0016_interface *intf = (const st0016_interface *)device->static_config(); - st0016_device_state *info = get_safe_token(device); - - info->sound_ram = intf->p_soundram; - - info->stream = device->machine().sound().stream_alloc(*device, 0, 2, 44100, info, st0016_update); + return m_regs[offset]; } -const device_type ST0016 = &device_creator; - -st0016_device::st0016_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, ST0016, "ST0016", tag, owner, clock), - device_sound_interface(mconfig, *this) +WRITE8_MEMBER( st0016_device::st0016_snd_w ) { - m_token = global_alloc_clear(st0016_device_state); + int voice = offset/32; + int reg = offset & 0x1f; + int oldreg = m_regs[offset]; + int vbase = offset & ~0x1f; + + m_regs[offset] = data; + + if ((voice < 8) && (data != oldreg)) + { + if ((reg == 0x16) && (data != 0)) + { + m_vpos[voice] = m_frac[voice] = m_lponce[voice] = 0; + + LOG(("Key on V%02d: st %06x-%06x lp %06x-%06x frq %x flg %x\n", voice, + m_regs[vbase+2]<<16 | m_regs[vbase+1]<<8 | m_regs[vbase+2], + m_regs[vbase+0xe]<<16 | m_regs[vbase+0xd]<<8 | m_regs[vbase+0xc], + m_regs[vbase+6]<<16 | m_regs[vbase+5]<<8 | m_regs[vbase+4], + m_regs[vbase+0xa]<<16 | m_regs[vbase+0x9]<<8 | m_regs[vbase+0x8], + m_regs[vbase+0x11]<<8 | m_regs[vbase+0x10], + m_regs[vbase+0x16])); + } + } } -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void st0016_device::device_config_complete() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void st0016_device::device_start() -{ - DEVICE_START_NAME( st0016 )(this); -} - -//------------------------------------------------- -// sound_stream_update - handle a stream update -//------------------------------------------------- - -void st0016_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"); -} diff --git a/src/emu/sound/st0016.h b/src/emu/sound/st0016.h index f3ec01b1829..322afca9ee6 100644 --- a/src/emu/sound/st0016.h +++ b/src/emu/sound/st0016.h @@ -3,35 +3,54 @@ #ifndef __ST0016_H__ #define __ST0016_H__ -#include "devlegcy.h" + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_ST0016_ADD(_tag, _clock) \ + MCFG_DEVICE_ADD(_tag, ST0016, _clock) +#define MCFG_ST0016_REPLACE(_tag, _clock) \ + MCFG_DEVICE_REPLACE(_tag, ST0016, _clock) + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** struct st0016_interface { UINT8 **p_soundram; }; -DECLARE_READ8_DEVICE_HANDLER( st0016_snd_r ); -DECLARE_WRITE8_DEVICE_HANDLER( st0016_snd_w ); + +// ======================> st0016_device class st0016_device : public device_t, - public device_sound_interface + public device_sound_interface { public: st0016_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~st0016_device() { global_free(m_token); } + ~st0016_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: + DECLARE_READ8_MEMBER( st0016_snd_r ); + DECLARE_WRITE8_MEMBER( st0016_snd_w ); + private: - // internal state - void *m_token; + sound_stream *m_stream; + UINT8 **m_sound_ram; + int m_vpos[8]; + int m_frac[8]; + int m_lponce[8]; + UINT8 m_regs[0x100]; }; extern const device_type ST0016; diff --git a/src/mame/audio/gomoku.c b/src/mame/audio/gomoku.c index fae7483f4e2..077fa78e470 100644 --- a/src/mame/audio/gomoku.c +++ b/src/mame/audio/gomoku.c @@ -9,102 +9,104 @@ #include "emu.h" #include "includes/gomoku.h" - -/* 4 voices max */ -#define MAX_VOICES 4 - - static const int samplerate = 48000; static const int defgain = 48; -/* this structure defines the parameters for a channel */ -struct sound_channel +// device type definition +const device_type GOMOKU = &device_creator; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// gomoku_sound_device - constructor +//------------------------------------------------- + +gomoku_sound_device::gomoku_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, GOMOKU, "Gomoku Custom", tag, owner, clock), + device_sound_interface(mconfig, *this), + m_last_channel(NULL), + m_sound_rom(NULL), + m_num_voices(0), + m_sound_enable(0), + m_stream(NULL), + m_mixer_table(NULL), + m_mixer_lookup(NULL), + m_mixer_buffer(NULL), + m_mixer_buffer_2(NULL) { - int channel; - int frequency; - int counter; - int volume; - int oneshotplaying; -}; - - -struct gomoku_sound_state -{ - /* data about the sound system */ - sound_channel m_channel_list[MAX_VOICES]; - sound_channel *m_last_channel; - - /* global sound parameters */ - const UINT8 *m_sound_rom; - int m_num_voices; - int m_sound_enable; - sound_stream *m_stream; - - /* mixer tables and internal buffers */ - INT16 *m_mixer_table; - INT16 *m_mixer_lookup; - short *m_mixer_buffer; - short *m_mixer_buffer_2; - - UINT8 m_soundregs1[0x20]; - UINT8 m_soundregs2[0x20]; -}; - -INLINE gomoku_sound_state *get_safe_token( device_t *device ) -{ - assert(device != NULL); - assert(device->type() == GOMOKU); - - return (gomoku_sound_state *)downcast(device)->token(); + memset(m_channel_list, 0, sizeof(gomoku_sound_channel)*GOMOKU_MAX_VOICES); + memset(m_soundregs1, 0, sizeof(UINT8)*0x20); + memset(m_soundregs2, 0, sizeof(UINT8)*0x20); } -/* build a table to divide by the number of voices; gain is specified as gain*16 */ -static void make_mixer_table(device_t *device, int voices, int gain) +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void gomoku_sound_device::device_start() { - gomoku_sound_state *state = get_safe_token(device); - int count = voices * 128; - int i; + gomoku_sound_channel *voice; + int ch; - /* allocate memory */ - state->m_mixer_table = auto_alloc_array(device->machine(), INT16, 256 * voices); + /* get stream channels */ + m_stream = stream_alloc(0, 1, samplerate); - /* find the middle of the table */ - state->m_mixer_lookup = state->m_mixer_table + (128 * voices); + /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ + m_mixer_buffer = auto_alloc_array(machine(), short, 2 * samplerate); + m_mixer_buffer_2 = m_mixer_buffer + samplerate; - /* fill in the table - 16 bit case */ - for (i = 0; i < count; i++) + /* build the mixer table */ + make_mixer_table(8, defgain); + + /* extract globals from the interface */ + m_num_voices = GOMOKU_MAX_VOICES; + m_last_channel = m_channel_list + m_num_voices; + + m_sound_rom = memregion("gomoku")->base(); + + /* start with sound enabled, many games don't have a sound enable register */ + m_sound_enable = 1; + + /* reset all the voices */ + for (ch = 0, voice = m_channel_list; voice < m_last_channel; ch++, voice++) { - int val = i * gain * 16 / voices; - if (val > 32767) val = 32767; - state->m_mixer_lookup[ i] = val; - state->m_mixer_lookup[-i] = -val; + voice->channel = ch; + voice->frequency = 0; + voice->counter = 0; + voice->volume = 0; + voice->oneshotplaying = 0; } } -/* generate sound to the mix buffer in mono */ -static STREAM_UPDATE( gomoku_update_mono ) +//------------------------------------------------- +// sound_stream_update - handle a stream update in mono +//------------------------------------------------- + +void gomoku_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) { - gomoku_sound_state *state = get_safe_token(device); stream_sample_t *buffer = outputs[0]; - sound_channel *voice; + gomoku_sound_channel *voice; short *mix; int i, ch; /* if no sound, we're done */ - if (state->m_sound_enable == 0) + if (m_sound_enable == 0) { memset(buffer, 0, samples * sizeof(*buffer)); return; } /* zap the contents of the mixer buffer */ - memset(state->m_mixer_buffer, 0, samples * sizeof(short)); + memset(m_mixer_buffer, 0, samples * sizeof(short)); /* loop over each voice and add its contribution */ - for (ch = 0, voice = state->m_channel_list; voice < state->m_last_channel; ch++, voice++) + for (ch = 0, voice = m_channel_list; voice < m_last_channel; ch++, voice++) { int f = 16 * voice->frequency; int v = voice->volume; @@ -116,11 +118,11 @@ static STREAM_UPDATE( gomoku_update_mono ) int c = voice->counter; if (ch < 3) - w_base = 0x20 * (state->m_soundregs1[0x06 + (ch * 8)] & 0x0f); + w_base = 0x20 * (m_soundregs1[0x06 + (ch * 8)] & 0x0f); else - w_base = 0x100 * (state->m_soundregs2[0x1d] & 0x0f); + w_base = 0x100 * (m_soundregs2[0x1d] & 0x0f); - mix = state->m_mixer_buffer; + mix = m_mixer_buffer; /* add our contribution */ for (i = 0; i < samples; i++) @@ -133,15 +135,15 @@ static STREAM_UPDATE( gomoku_update_mono ) /* use full byte, first the high 4 bits, then the low 4 bits */ if (c & 0x8000) - *mix++ += ((state->m_sound_rom[offs] & 0x0f) - 8) * v; + *mix++ += ((m_sound_rom[offs] & 0x0f) - 8) * v; else - *mix++ += (((state->m_sound_rom[offs]>>4) & 0x0f) - 8) * v; + *mix++ += (((m_sound_rom[offs]>>4) & 0x0f) - 8) * v; } else { int offs = (w_base + (c >> 16)) & 0x0fff; - if (state->m_sound_rom[offs] == 0xff) + if (m_sound_rom[offs] == 0xff) { voice->oneshotplaying = 0; } @@ -150,9 +152,9 @@ static STREAM_UPDATE( gomoku_update_mono ) { /* use full byte, first the high 4 bits, then the low 4 bits */ if (c & 0x8000) - *mix++ += ((state->m_sound_rom[offs] & 0x0f) - 8) * v; + *mix++ += ((m_sound_rom[offs] & 0x0f) - 8) * v; else - *mix++ += (((state->m_sound_rom[offs]>>4) & 0x0f) - 8) * v; + *mix++ += (((m_sound_rom[offs]>>4) & 0x0f) - 8) * v; } } @@ -163,104 +165,86 @@ static STREAM_UPDATE( gomoku_update_mono ) } /* mix it down */ - mix = state->m_mixer_buffer; + mix = m_mixer_buffer; for (i = 0; i < samples; i++) - *buffer++ = state->m_mixer_lookup[*mix++]; + *buffer++ = m_mixer_lookup[*mix++]; } - -static DEVICE_START( gomoku_sound ) +/* build a table to divide by the number of voices; gain is specified as gain*16 */ +void gomoku_sound_device::make_mixer_table(int voices, int gain) { - gomoku_sound_state *state = get_safe_token(device); - running_machine &machine = device->machine(); - sound_channel *voice; - int ch; + int count = voices * 128; + int i; - /* get stream channels */ - state->m_stream = device->machine().sound().stream_alloc(*device, 0, 1, samplerate, NULL, gomoku_update_mono); + /* allocate memory */ + m_mixer_table = auto_alloc_array(machine(), INT16, 256 * voices); - /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ - state->m_mixer_buffer = auto_alloc_array(machine, short, 2 * samplerate); - state->m_mixer_buffer_2 = state->m_mixer_buffer + samplerate; + /* find the middle of the table */ + m_mixer_lookup = m_mixer_table + (128 * voices); - /* build the mixer table */ - make_mixer_table(device, 8, defgain); - - /* extract globals from the interface */ - state->m_num_voices = MAX_VOICES; - state->m_last_channel = state->m_channel_list + state->m_num_voices; - - state->m_sound_rom = machine.root_device().memregion("gomoku")->base(); - - /* start with sound enabled, many games don't have a sound enable register */ - state->m_sound_enable = 1; - - /* reset all the voices */ - for (ch = 0, voice = state->m_channel_list; voice < state->m_last_channel; ch++, voice++) + /* fill in the table - 16 bit case */ + for (i = 0; i < count; i++) { - voice->channel = ch; - voice->frequency = 0; - voice->counter = 0; - voice->volume = 0; - voice->oneshotplaying = 0; + int val = i * gain * 16 / voices; + if (val > 32767) val = 32767; + m_mixer_lookup[ i] = val; + m_mixer_lookup[-i] = -val; } } /********************************************************************************/ -WRITE8_DEVICE_HANDLER( gomoku_sound1_w ) +WRITE8_MEMBER( gomoku_sound_device::sound1_w ) { - gomoku_sound_state *state = get_safe_token(device); - sound_channel *voice; + gomoku_sound_channel *voice; int base; int ch; /* update the streams */ - state->m_stream->update(); + m_stream->update(); /* set the register */ - state->m_soundregs1[offset] = data; + m_soundregs1[offset] = data; /* recompute all the voice parameters */ - for (ch = 0, base = 0, voice = state->m_channel_list; voice < state->m_channel_list + 3; ch++, voice++, base += 8) + for (ch = 0, base = 0, voice = m_channel_list; voice < m_channel_list + 3; ch++, voice++, base += 8) { voice->channel = ch; - voice->frequency = state->m_soundregs1[0x02 + base] & 0x0f; - voice->frequency = voice->frequency * 16 + ((state->m_soundregs1[0x01 + base]) & 0x0f); - voice->frequency = voice->frequency * 16 + ((state->m_soundregs1[0x00 + base]) & 0x0f); + voice->frequency = m_soundregs1[0x02 + base] & 0x0f; + voice->frequency = voice->frequency * 16 + ((m_soundregs1[0x01 + base]) & 0x0f); + voice->frequency = voice->frequency * 16 + ((m_soundregs1[0x00 + base]) & 0x0f); } } -WRITE8_DEVICE_HANDLER( gomoku_sound2_w ) +WRITE8_MEMBER( gomoku_sound_device::sound2_w ) { - gomoku_sound_state *state = get_safe_token(device); - sound_channel *voice; + gomoku_sound_channel *voice; int base; int ch; /* update the streams */ - state->m_stream->update(); + m_stream->update(); /* set the register */ - state->m_soundregs2[offset] = data; + m_soundregs2[offset] = data; /* recompute all the voice parameters */ - for (ch = 0, base = 0, voice = state->m_channel_list; voice < state->m_channel_list + 3; ch++, voice++, base += 8) + for (ch = 0, base = 0, voice = m_channel_list; voice < m_channel_list + 3; ch++, voice++, base += 8) { voice->channel = ch; - voice->volume = state->m_soundregs2[0x06 + base] & 0x0f; + voice->volume = m_soundregs2[0x06 + base] & 0x0f; voice->oneshotplaying = 0; } if (offset == 0x1d) { - voice = &state->m_channel_list[3]; + voice = &m_channel_list[3]; voice->channel = 3; // oneshot frequency is hand tune... - if ((state->m_soundregs2[0x1d] & 0x0f) < 0x0c) + if ((m_soundregs2[0x1d] & 0x0f) < 0x0c) voice->frequency = 3000 / 16; // ichi, ni, san, yon, go else voice->frequency = 8000 / 16; // shoot @@ -268,48 +252,10 @@ WRITE8_DEVICE_HANDLER( gomoku_sound2_w ) voice->volume = 8; voice->counter = 0; - if (state->m_soundregs2[0x1d] & 0x0f) + if (m_soundregs2[0x1d] & 0x0f) voice->oneshotplaying = 1; else voice->oneshotplaying = 0; } } - -const device_type GOMOKU = &device_creator; - -gomoku_sound_device::gomoku_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, GOMOKU, "Gomoku Custom", tag, owner, clock), - device_sound_interface(mconfig, *this) -{ - m_token = global_alloc_clear(gomoku_sound_state); -} - -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void gomoku_sound_device::device_config_complete() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void gomoku_sound_device::device_start() -{ - DEVICE_START_NAME( gomoku_sound )(this); -} - -//------------------------------------------------- -// sound_stream_update - handle a stream update -//------------------------------------------------- - -void gomoku_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"); -} diff --git a/src/mame/drivers/astrocde.c b/src/mame/drivers/astrocde.c index 09f16629770..06d9f546979 100644 --- a/src/mame/drivers/astrocde.c +++ b/src/mame/drivers/astrocde.c @@ -676,7 +676,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( port_map_stereo_pattern, AS_IO, 8, astrocde_state ) AM_RANGE(0x0000, 0x0019) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(astrocade_data_chip_register_r, astrocade_data_chip_register_w) - AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("astrocade2", astrocade_sound_w) + AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE("astrocade2", astrocade_device, astrocade_sound_w) AM_RANGE(0x0078, 0x007e) AM_MIRROR(0xff00) AM_WRITE(astrocade_pattern_board_w) AM_RANGE(0xa55b, 0xa55b) AM_WRITE(protected_ram_enable_w) ADDRESS_MAP_END @@ -684,7 +684,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( port_map_16col_pattern, AS_IO, 8, astrocde_state ) AM_RANGE(0x0000, 0x0019) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(astrocade_data_chip_register_r, astrocade_data_chip_register_w) - AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("astrocade2", astrocade_sound_w) + AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE("astrocade2", astrocade_device, astrocade_sound_w) AM_RANGE(0x0078, 0x007e) AM_MIRROR(0xff00) AM_WRITE(astrocade_pattern_board_w) AM_RANGE(0x00bf, 0x00bf) AM_MIRROR(0xff00) AM_WRITE(profpac_page_select_w) AM_RANGE(0x00c3, 0x00c3) AM_MIRROR(0xff00) AM_READ(profpac_intercept_r) @@ -1325,7 +1325,7 @@ static MACHINE_CONFIG_FRAGMENT( astrocade_mono_sound ) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("astrocade1", ASTROCADE, ASTROCADE_CLOCK/4) + MCFG_ASTROCADE_ADD("astrocade1", ASTROCADE_CLOCK/4) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END @@ -1335,10 +1335,10 @@ static MACHINE_CONFIG_FRAGMENT( astrocade_stereo_sound ) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("astrocade1", ASTROCADE, ASTROCADE_CLOCK/4) + MCFG_ASTROCADE_ADD("astrocade1", ASTROCADE_CLOCK/4) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.0) - MCFG_SOUND_ADD("astrocade2", ASTROCADE, ASTROCADE_CLOCK/4) + MCFG_ASTROCADE_ADD("astrocade2", ASTROCADE_CLOCK/4) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0) MACHINE_CONFIG_END @@ -1441,10 +1441,10 @@ static MACHINE_CONFIG_DERIVED( gorf, astrocade_base ) MCFG_SPEAKER_ADD("upper", 0.0, 0.0, 1.0) MCFG_SPEAKER_ADD("lower", 0.0, -0.5, 1.0) - MCFG_SOUND_ADD("astrocade1", ASTROCADE, ASTROCADE_CLOCK/4) + MCFG_ASTROCADE_ADD("astrocade1", ASTROCADE_CLOCK/4) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "upper", 1.0) - MCFG_SOUND_ADD("astrocade2", ASTROCADE, ASTROCADE_CLOCK/4) + MCFG_ASTROCADE_ADD("astrocade2", ASTROCADE_CLOCK/4) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lower", 1.0) #if USE_FAKE_VOTRAX diff --git a/src/mame/drivers/bingor.c b/src/mame/drivers/bingor.c index b484a7e09f3..27ea589e1fc 100644 --- a/src/mame/drivers/bingor.c +++ b/src/mame/drivers/bingor.c @@ -522,8 +522,8 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( bingor_io, AS_IO, 16, bingor_state ) // AM_RANGE(0x0000, 0x00ff) AM_READ(test_r ) - AM_RANGE(0x0100, 0x0101) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x0102, 0x0103) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x0100, 0x0101) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x0102, 0x0103) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) // AM_RANGE(0x0200, 0x0201) AM_READ(test_r ) ADDRESS_MAP_END @@ -644,7 +644,7 @@ static MACHINE_CONFIG_START( bingor, bingor_state ) MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("saa", SAA1099, 6000000 ) + MCFG_SAA1099_ADD("saa", 6000000 ) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) MACHINE_CONFIG_END diff --git a/src/mame/drivers/blitz68k.c b/src/mame/drivers/blitz68k.c index 78f5232f080..eedab3f516d 100644 --- a/src/mame/drivers/blitz68k.c +++ b/src/mame/drivers/blitz68k.c @@ -1994,7 +1994,7 @@ static MACHINE_CONFIG_START( maxidbl, blitz68k_state ) MCFG_RAMDAC_ADD("ramdac", ramdac_intf, ramdac_map) MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("saa", SAA1099, XTAL_8MHz/2) + MCFG_SAA1099_ADD("saa", XTAL_8MHz/2) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END diff --git a/src/mame/drivers/g627.c b/src/mame/drivers/g627.c index 86486e0f922..075c27b8efb 100644 --- a/src/mame/drivers/g627.c +++ b/src/mame/drivers/g627.c @@ -80,7 +80,7 @@ static ADDRESS_MAP_START( g627_io, AS_IO, 8, g627_state ) ADDRESS_MAP_GLOBAL_MASK(0xff) AM_RANGE(0x00, 0x02) AM_WRITE(disp_w) AM_RANGE(0x03, 0x07) AM_WRITE(lamp_w) - AM_RANGE(0x10, 0x17) AM_DEVWRITE_LEGACY("astrocade", astrocade_sound_w) + AM_RANGE(0x10, 0x17) AM_DEVWRITE("astrocade", astrocade_device, astrocade_sound_w) AM_RANGE(0x20, 0x27) AM_DEVREADWRITE("i8156", i8155_device, io_r, io_w) ADDRESS_MAP_END diff --git a/src/mame/drivers/gal3.c b/src/mame/drivers/gal3.c index 8327623b055..9b682181d9f 100644 --- a/src/mame/drivers/gal3.c +++ b/src/mame/drivers/gal3.c @@ -438,11 +438,11 @@ static ADDRESS_MAP_START( sound_cpu_map, AS_PROGRAM, 16, gal3_state ) AM_RANGE(0x110000, 0x113fff) AM_RAM /// AM_RANGE(0x120000, 0x120003) AM_RAM //2ieme byte /// AM_RANGE(0x200000, 0x20017f) AM_RAM //C140 - AM_RANGE(0x200000, 0x2037ff) AM_DEVREADWRITE8_LEGACY("c140_16a", c140_r, c140_w, 0x00ff) //C140/////////// + AM_RANGE(0x200000, 0x2037ff) AM_DEVREADWRITE8("c140_16a", c140_device, c140_r, c140_w, 0x00ff) //C140/////////// /// AM_RANGE(0x201000, 0x20117f) AM_RAM //C140 /// AM_RANGE(0x202000, 0x20217f) AM_RAM //C140 /// AM_RANGE(0x203000, 0x20317f) AM_RAM //C140 - AM_RANGE(0x204000, 0x2047ff) AM_DEVREADWRITE8_LEGACY("c140_16g", c140_r, c140_w, 0x00ff) //C140 + AM_RANGE(0x204000, 0x2047ff) AM_DEVREADWRITE8("c140_16g", c140_device, c140_r, c140_w, 0x00ff) //C140 /// AM_RANGE(0x090000, 0xffffff) AM_RAM ADDRESS_MAP_END @@ -637,12 +637,12 @@ static MACHINE_CONFIG_START( gal3, gal3_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140_16g", C140, 8000000/374) + MCFG_C140_ADD("c140_16g", 8000000/374) MCFG_SOUND_CONFIG(C140_interface) //to be verified MCFG_SOUND_ROUTE(0, "lspeaker", 0.50) MCFG_SOUND_ROUTE(1, "rspeaker", 0.50) - MCFG_SOUND_ADD("c140_16a", C140, 8000000/374) + MCFG_C140_ADD("c140_16a", 8000000/374) MCFG_SOUND_CONFIG(C140_interface) MCFG_SOUND_ROUTE(0, "lspeaker", 0.50) MCFG_SOUND_ROUTE(1, "rspeaker", 0.50) diff --git a/src/mame/drivers/gomoku.c b/src/mame/drivers/gomoku.c index 042a3c09467..a43cb660744 100644 --- a/src/mame/drivers/gomoku.c +++ b/src/mame/drivers/gomoku.c @@ -44,8 +44,8 @@ static ADDRESS_MAP_START( gomoku_map, AS_PROGRAM, 8, gomoku_state ) AM_RANGE(0x5000, 0x53ff) AM_RAM_WRITE(gomoku_videoram_w) AM_SHARE("videoram") AM_RANGE(0x5400, 0x57ff) AM_RAM_WRITE(gomoku_colorram_w) AM_SHARE("colorram") AM_RANGE(0x5800, 0x58ff) AM_RAM_WRITE(gomoku_bgram_w) AM_SHARE("bgram") - AM_RANGE(0x6000, 0x601f) AM_DEVWRITE_LEGACY("gomoku", gomoku_sound1_w) - AM_RANGE(0x6800, 0x681f) AM_DEVWRITE_LEGACY("gomoku", gomoku_sound2_w) + AM_RANGE(0x6000, 0x601f) AM_DEVWRITE("gomoku", gomoku_sound_device, sound1_w) + AM_RANGE(0x6800, 0x681f) AM_DEVWRITE("gomoku", gomoku_sound_device, sound2_w) AM_RANGE(0x7000, 0x7000) AM_WRITENOP AM_RANGE(0x7001, 0x7001) AM_WRITE(gomoku_flipscreen_w) AM_RANGE(0x7002, 0x7002) AM_WRITE(gomoku_bg_dispsw_w) diff --git a/src/mame/drivers/jclub2.c b/src/mame/drivers/jclub2.c index ac8ffc10b8e..30cf4dabf5a 100644 --- a/src/mame/drivers/jclub2.c +++ b/src/mame/drivers/jclub2.c @@ -758,7 +758,7 @@ MACHINE_CONFIG_END static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, darkhors_state ) AM_RANGE(0x0000, 0x7fff) AM_ROM AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1") - AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w) + AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w) AM_RANGE(0xf000, 0xffff) AM_RAM ADDRESS_MAP_END @@ -817,7 +817,7 @@ static MACHINE_CONFIG_START( jclub2o, darkhors_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("stsnd", ST0016, 0) + MCFG_ST0016_ADD("stsnd", 0) MCFG_SOUND_CONFIG(st0016_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) diff --git a/src/mame/drivers/jpmsys5.c b/src/mame/drivers/jpmsys5.c index 175bee055a1..42091a6c6ef 100644 --- a/src/mame/drivers/jpmsys5.c +++ b/src/mame/drivers/jpmsys5.c @@ -30,6 +30,7 @@ #include "emu.h" #include "includes/jpmsys5.h" +#include "sound/saa1099.h" #include "jpmsys5.lh" enum state { IDLE, START, DATA, STOP1, STOP2 }; @@ -325,8 +326,8 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( 68000_awp_map_saa, AS_PROGRAM, 16, jpmsys5_state ) JPM_SYS5_COMMON_MAP - AM_RANGE(0x0460a0, 0x0460a1) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x0460a2, 0x0460a3) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x0460a0, 0x0460a1) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x0460a2, 0x0460a3) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) AM_RANGE(0x04c100, 0x04c105) AM_READWRITE(jpm_upd7759_r, jpm_upd7759_w) // do the SAA boards have the UPD? ADDRESS_MAP_END @@ -890,7 +891,7 @@ MACHINE_CONFIG_START( jpmsys5, jpmsys5_state ) MCFG_SOUND_ADD("upd7759", UPD7759, UPD7759_STANDARD_CLOCK) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30) - MCFG_SOUND_ADD("saa", SAA1099, 4000000 /* guess */) + MCFG_SAA1099_ADD("saa", 4000000 /* guess */) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) /* 6840 PTM */ diff --git a/src/mame/drivers/macs.c b/src/mame/drivers/macs.c index 67c54312363..0280de695b2 100644 --- a/src/mame/drivers/macs.c +++ b/src/mame/drivers/macs.c @@ -94,7 +94,7 @@ static ADDRESS_MAP_START( macs_mem, AS_PROGRAM, 8, macs_state ) AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w) AM_RANGE(0xe000, 0xe7ff) AM_RAM /* work ram ? */ AM_RANGE(0xe800, 0xe87f) AM_RAM AM_SHARE("ram2") - AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w) + AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w) AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w) AM_RANGE(0xf000, 0xf7ff) AM_RAMBANK("bank3") /* common /backup ram ?*/ @@ -500,7 +500,7 @@ static MACHINE_CONFIG_START( macs, macs_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("stsnd", ST0016, 0) + MCFG_ST0016_ADD("stsnd", 0) MCFG_SOUND_CONFIG(st0016_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) diff --git a/src/mame/drivers/manohman.c b/src/mame/drivers/manohman.c index 646da6341c2..107d65b57d3 100644 --- a/src/mame/drivers/manohman.c +++ b/src/mame/drivers/manohman.c @@ -153,8 +153,8 @@ public: static ADDRESS_MAP_START( manohman_map, AS_PROGRAM, 16, _manohman_state ) AM_RANGE(0x000000, 0x01ffff) AM_ROM AM_RANGE(0x100000, 0x100001) AM_NOP // smell to MAX696 watchdog... - AM_RANGE(0x300000, 0x300001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x300002, 0x300003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x300000, 0x300001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x300002, 0x300003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) AM_RANGE(0x500000, 0x503fff) AM_RAM AM_RANGE(0x600006, 0x600007) AM_RAM // write bitpatterns to compare with the 500000-503ff8 RAM testing. // AM_RANGE(0xYYYYYY, 0xYYYYYY) AM_RAM @@ -211,7 +211,7 @@ static MACHINE_CONFIG_START( manohman, _manohman_state ) // sound hardware MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("saa", SAA1099, MASTER_CLOCK /* guess */) + MCFG_SAA1099_ADD("saa", MASTER_CLOCK /* guess */) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END diff --git a/src/mame/drivers/mastboy.c b/src/mame/drivers/mastboy.c index e5a6aa0165c..56193728eb3 100644 --- a/src/mame/drivers/mastboy.c +++ b/src/mame/drivers/mastboy.c @@ -722,8 +722,8 @@ static ADDRESS_MAP_START( mastboy_map, AS_PROGRAM, 8, mastboy_state ) AM_RANGE(0xff818, 0xff81f) AM_READ_PORT("DSW2") AM_RANGE(0xff820, 0xff827) AM_WRITE(mastboy_bank_w) - AM_RANGE(0xff828, 0xff828) AM_DEVWRITE_LEGACY("saa", saa1099_data_w) - AM_RANGE(0xff829, 0xff829) AM_DEVWRITE_LEGACY("saa", saa1099_control_w) + AM_RANGE(0xff828, 0xff828) AM_DEVWRITE("saa", saa1099_device, saa1099_data_w) + AM_RANGE(0xff829, 0xff829) AM_DEVWRITE("saa", saa1099_device, saa1099_control_w) AM_RANGE(0xff830, 0xff830) AM_WRITE(mastboy_msm5205_data_w) AM_RANGE(0xff838, 0xff838) AM_WRITE(mastboy_irq0_ack_w) AM_RANGE(0xff839, 0xff839) AM_WRITE(msm5205_mastboy_m5205_sambit0_w) @@ -907,7 +907,7 @@ static MACHINE_CONFIG_START( mastboy, mastboy_state ) // sound hardware MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("saa", SAA1099, 6000000 ) + MCFG_SAA1099_ADD("saa", 6000000 ) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) MCFG_SOUND_ADD("msm", MSM5205, 384000) diff --git a/src/mame/drivers/mpu4vid.c b/src/mame/drivers/mpu4vid.c index 370f5fbc5aa..0427051d86f 100644 --- a/src/mame/drivers/mpu4vid.c +++ b/src/mame/drivers/mpu4vid.c @@ -1410,8 +1410,8 @@ static ADDRESS_MAP_START( mpu4_68k_map, AS_PROGRAM, 16, mpu4vid_state ) AM_RANGE(0x000000, 0x7fffff) AM_ROM AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram") // AM_RANGE(0x810000, 0x81ffff) AM_RAM /* ? */ - AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w) /* AM_RANGE(0xa00004, 0xa0000f) AM_READWRITE_LEGACY(mpu4_vid_unmap_r, mpu4_vid_unmap_w) */ @@ -1430,8 +1430,8 @@ static ADDRESS_MAP_START( mpu4oki_68k_map, AS_PROGRAM, 16, mpu4vid_state ) AM_RANGE(0x600000, 0x63ffff) AM_RAM /* The Mating Game has an extra 256kB RAM on the program card */ // AM_RANGE(0x640000, 0x7fffff) AM_NOP /* Possible bug, reads and writes here */ AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram") - AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w) AM_RANGE(0xb00000, 0xb0000f) AM_DEVREADWRITE("scn2674_vid", scn2674_device, mpu4_vid_scn2674_r, mpu4_vid_scn2674_w) @@ -1452,8 +1452,8 @@ static ADDRESS_MAP_START( bwbvid_68k_map, AS_PROGRAM, 16, mpu4vid_state ) AM_RANGE(0x000000, 0x7fffff) AM_ROM AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram") AM_RANGE(0x810000, 0x81ffff) AM_RAM /* ? */ - AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w) // AM_RANGE(0xa00000, 0xa0000f) AM_READWRITE_LEGACY(bt471_r,bt471_w) //Some games use this /* AM_RANGE(0xa00004, 0xa0000f) AM_READWRITE_LEGACY(mpu4_vid_unmap_r, mpu4_vid_unmap_w) */ @@ -1470,8 +1470,8 @@ static ADDRESS_MAP_START( bwbvid5_68k_map, AS_PROGRAM, 16, mpu4vid_state ) AM_RANGE(0x000000, 0x7fffff) AM_ROM AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram") AM_RANGE(0x810000, 0x81ffff) AM_RAM /* ? */ - AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w) //AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(bt471_r,bt471_w) Some games use this /* AM_RANGE(0xa00004, 0xa0000f) AM_READWRITE_LEGACY(mpu4_vid_unmap_r, mpu4_vid_unmap_w) */ @@ -1549,7 +1549,7 @@ static MACHINE_CONFIG_START( mpu4_vid, mpu4vid_state ) MCFG_PTM6840_ADD("6840ptm_68k", ptm_vid_intf) /* Present on all video cards */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("saa", SAA1099, 8000000) + MCFG_SAA1099_ADD("saa", 8000000) MCFG_SOUND_ROUTE(0, "lspeaker", 0.5) MCFG_SOUND_ROUTE(1, "rspeaker", 0.5) diff --git a/src/mame/drivers/namcona1.c b/src/mame/drivers/namcona1.c index 38de2579bb0..96d55dd01a3 100644 --- a/src/mame/drivers/namcona1.c +++ b/src/mame/drivers/namcona1.c @@ -804,23 +804,23 @@ WRITE16_MEMBER(namcona1_state::na1mcu_shared_w) READ16_MEMBER(namcona1_state::snd_r) { - device_t *device = machine().device("c140"); + c140_device *device = machine().device("c140"); /* can't use DEVREADWRITE8 for this because it is opposite endianness to the CPU for some reason */ - return c140_r(device,space,offset*2+1) | c140_r(device,space,offset*2)<<8; + return device->c140_r(space,offset*2+1) | device->c140_r(space,offset*2)<<8; } WRITE16_MEMBER(namcona1_state::snd_w) { - device_t *device = machine().device("c140"); + c140_device *device = machine().device("c140"); /* can't use DEVREADWRITE8 for this because it is opposite endianness to the CPU for some reason */ if (ACCESSING_BITS_0_7) { - c140_w(device,space,(offset*2)+1, data); + device->c140_w(space,(offset*2)+1, data); } if (ACCESSING_BITS_8_15) { - c140_w(device,space,(offset*2), data>>8); + device->c140_w(space,(offset*2), data>>8); } } @@ -916,7 +916,7 @@ WRITE8_MEMBER(namcona1_state::port8_w) void namcona1_state::machine_start() { - c140_set_base(machine().device("c140"), m_workram); + machine().device("c140")->set_base(m_workram); } // for games with the MCU emulated, the MCU boots the 68000. don't allow it before that. @@ -1032,7 +1032,7 @@ static MACHINE_CONFIG_START( namcona1, namcona1_state ) /* sound hardware */ MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, 44100) + MCFG_C140_ADD("c140", 44100) MCFG_SOUND_CONFIG(C140_interface_typeA) MCFG_SOUND_ROUTE(0, "rspeaker", 1.00) MCFG_SOUND_ROUTE(1, "lspeaker", 1.00) diff --git a/src/mame/drivers/namcos2.c b/src/mame/drivers/namcos2.c index 94dd05baa18..a90795597df 100644 --- a/src/mame/drivers/namcos2.c +++ b/src/mame/drivers/namcos2.c @@ -737,7 +737,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( sound_default_am, AS_PROGRAM, 8, namcos2_state ) AM_RANGE(0x0000, 0x3fff) AM_ROMBANK("bank6") /* banked */ AM_RANGE(0x4000, 0x4001) AM_DEVREADWRITE("ymsnd", ym2151_device,read,write) - AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE_LEGACY("c140", c140_r,c140_w) + AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE("c140", c140_device, c140_r,c140_w) AM_RANGE(0x7000, 0x77ff) AM_READWRITE(dpram_byte_r,dpram_byte_w) AM_SHARE("dpram") AM_RANGE(0x7800, 0x7fff) AM_READWRITE(dpram_byte_r,dpram_byte_w) /* mirror */ AM_RANGE(0x8000, 0x9fff) AM_RAM @@ -1640,7 +1640,7 @@ static MACHINE_CONFIG_START( default, namcos2_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.75) MCFG_SOUND_ROUTE(1, "rspeaker", 0.75) @@ -1653,7 +1653,7 @@ MACHINE_CONFIG_END /* adjusted machine driver start */ static MACHINE_CONFIG_DERIVED( default2, default ) - MCFG_SOUND_REPLACE("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_REPLACE("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) @@ -1667,7 +1667,7 @@ MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( default3, default ) - MCFG_SOUND_REPLACE("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_REPLACE("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.45) MCFG_SOUND_ROUTE(1, "rspeaker", 0.45) @@ -1714,7 +1714,7 @@ static MACHINE_CONFIG_START( gollygho, namcos2_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.75) MCFG_SOUND_ROUTE(1, "rspeaker", 0.75) @@ -1765,7 +1765,7 @@ static MACHINE_CONFIG_START( finallap, namcos2_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.75) MCFG_SOUND_ROUTE(1, "rspeaker", 0.75) @@ -1814,7 +1814,7 @@ static MACHINE_CONFIG_START( sgunner, namcos2_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.75) MCFG_SOUND_ROUTE(1, "rspeaker", 0.75) @@ -1865,7 +1865,7 @@ static MACHINE_CONFIG_START( luckywld, namcos2_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 0.75) MCFG_SOUND_ROUTE(1, "rspeaker", 0.75) @@ -1914,7 +1914,7 @@ static MACHINE_CONFIG_START( metlhawk, namcos2_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */ + MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */ MCFG_SOUND_CONFIG(c140_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) diff --git a/src/mame/drivers/namcos21.c b/src/mame/drivers/namcos21.c index c01936bffe0..13ae752510d 100644 --- a/src/mame/drivers/namcos21.c +++ b/src/mame/drivers/namcos21.c @@ -1369,7 +1369,7 @@ static ADDRESS_MAP_START( am_sound_winrun, AS_PROGRAM, 8, namcos21_state ) AM_RANGE(0x0000, 0x3fff) AM_ROMBANK("bank6") /* banked */ AM_RANGE(0x3000, 0x3003) AM_WRITENOP /* ? */ AM_RANGE(0x4000, 0x4001) AM_DEVREADWRITE("ymsnd", ym2151_device,read,write) - AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE_LEGACY("c140", c140_r,c140_w) + AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE("c140", c140_device, c140_r,c140_w) AM_RANGE(0x7000, 0x77ff) AM_READWRITE(namcos2_dualportram_byte_r,namcos2_dualportram_byte_w) AM_SHARE("mpdualportram") AM_RANGE(0x7800, 0x7fff) AM_READWRITE(namcos2_dualportram_byte_r,namcos2_dualportram_byte_w) /* mirror */ AM_RANGE(0x8000, 0x9fff) AM_RAM @@ -1533,7 +1533,7 @@ static MACHINE_CONFIG_START( namcos21, namcos21_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, 8000000/374) + MCFG_C140_ADD("c140", 8000000/374) MCFG_SOUND_CONFIG(C140_interface) MCFG_SOUND_ROUTE(0, "lspeaker", 0.50) MCFG_SOUND_ROUTE(1, "rspeaker", 0.50) @@ -1588,7 +1588,7 @@ static MACHINE_CONFIG_START( driveyes, namcos21_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, 8000000/374) + MCFG_C140_ADD("c140", 8000000/374) MCFG_SOUND_CONFIG(C140_interface) MCFG_SOUND_ROUTE(0, "lspeaker", 0.50) MCFG_SOUND_ROUTE(1, "rspeaker", 0.50) @@ -1646,7 +1646,7 @@ static MACHINE_CONFIG_START( winrun, namcos21_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("c140", C140, 8000000/374) + MCFG_C140_ADD("c140", 8000000/374) MCFG_SOUND_CONFIG(C140_interface) MCFG_SOUND_ROUTE(0, "lspeaker", 0.50) MCFG_SOUND_ROUTE(1, "rspeaker", 0.50) diff --git a/src/mame/drivers/speglsht.c b/src/mame/drivers/speglsht.c index 65ca007c079..e1f3ceea36d 100644 --- a/src/mame/drivers/speglsht.c +++ b/src/mame/drivers/speglsht.c @@ -144,7 +144,7 @@ static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, speglsht_state ) AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w) AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_RANGE(0xe800, 0xe87f) AM_RAM - AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w) + AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w) AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w) AM_RANGE(0xf000, 0xffff) AM_RAM AM_SHARE("shared") @@ -409,7 +409,7 @@ static MACHINE_CONFIG_START( speglsht, speglsht_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("stsnd", ST0016, 0) + MCFG_ST0016_ADD("stsnd", 0) MCFG_SOUND_CONFIG(st0016_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) diff --git a/src/mame/drivers/srmp5.c b/src/mame/drivers/srmp5.c index 3ea157bd03d..aa08a915a4e 100644 --- a/src/mame/drivers/srmp5.c +++ b/src/mame/drivers/srmp5.c @@ -369,7 +369,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, srmp5_state ) AM_RANGE(0x0000, 0x7fff) AM_ROM AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1") - AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w) + AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w) AM_RANGE(0xf000, 0xffff) AM_RAM ADDRESS_MAP_END @@ -560,7 +560,7 @@ static MACHINE_CONFIG_START( srmp5, srmp5_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("stsnd", ST0016, 0) + MCFG_ST0016_ADD("stsnd", 0) MCFG_SOUND_CONFIG(st0016_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) diff --git a/src/mame/drivers/st0016.c b/src/mame/drivers/st0016.c index 41d30bf974c..1588ebc8cd1 100644 --- a/src/mame/drivers/st0016.c +++ b/src/mame/drivers/st0016.c @@ -32,7 +32,7 @@ static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, st0016_state ) AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w) AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_RANGE(0xe800, 0xe87f) AM_RAM /* common ram */ - AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w) /* sound regs 8 x $20 bytes, see notes */ + AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) /* sound regs 8 x $20 bytes, see notes */ AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w) AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w) AM_RANGE(0xf000, 0xffff) AM_RAM /* work ram */ @@ -461,7 +461,7 @@ static MACHINE_CONFIG_START( st0016, st0016_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("stsnd", ST0016, 0) + MCFG_ST0016_ADD("stsnd", 0) MCFG_SOUND_CONFIG(st0016_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) diff --git a/src/mame/drivers/xorworld.c b/src/mame/drivers/xorworld.c index 748c29b913e..d7a2d2358c4 100644 --- a/src/mame/drivers/xorworld.c +++ b/src/mame/drivers/xorworld.c @@ -83,8 +83,8 @@ static ADDRESS_MAP_START( xorworld_map, AS_PROGRAM, 16, xorworld_state ) AM_RANGE(0x200000, 0x200001) AM_READ_PORT("P1") AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P2") AM_RANGE(0x600000, 0x600001) AM_READ_PORT("DSW") - AM_RANGE(0x800000, 0x800001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff) - AM_RANGE(0x800002, 0x800003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff) + AM_RANGE(0x800000, 0x800001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff) + AM_RANGE(0x800002, 0x800003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff) AM_RANGE(0xa00008, 0xa00009) AM_WRITE(eeprom_chip_select_w) AM_RANGE(0xa0000a, 0xa0000b) AM_WRITE(eeprom_serial_clock_w) AM_RANGE(0xa0000c, 0xa0000d) AM_WRITE(eeprom_data_w) @@ -196,7 +196,7 @@ static MACHINE_CONFIG_START( xorworld, xorworld_state ) // sound hardware MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("saa", SAA1099, 8000000 /* guess */) + MCFG_SAA1099_ADD("saa", 8000000 /* guess */) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END diff --git a/src/mame/includes/gomoku.h b/src/mame/includes/gomoku.h index 93cc681078d..31d10d88622 100644 --- a/src/mame/includes/gomoku.h +++ b/src/mame/includes/gomoku.h @@ -1,4 +1,3 @@ -#include "devlegcy.h" class gomoku_state : public driver_device { @@ -31,28 +30,72 @@ public: /*----------- defined in audio/gomoku.c -----------*/ -DECLARE_WRITE8_DEVICE_HANDLER( gomoku_sound1_w ); -DECLARE_WRITE8_DEVICE_HANDLER( gomoku_sound2_w ); +/* 4 voices max */ +#define GOMOKU_MAX_VOICES 4 + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +struct gomoku_sound_channel +{ + gomoku_sound_channel(): + channel(0), + frequency(0), + counter(0), + volume(0), + oneshotplaying(0) {} + + int channel; + int frequency; + int counter; + int volume; + int oneshotplaying; +}; + + +// ======================> gomoku_sound_device class gomoku_sound_device : public device_t, - public device_sound_interface + public device_sound_interface { public: gomoku_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~gomoku_sound_device() { global_free(m_token); } + ~gomoku_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: + DECLARE_WRITE8_MEMBER( sound1_w ); + DECLARE_WRITE8_MEMBER( sound2_w ); + private: - // internal state - void *m_token; + void make_mixer_table(int voices, int gain); + +private: + /* data about the sound system */ + gomoku_sound_channel m_channel_list[GOMOKU_MAX_VOICES]; + gomoku_sound_channel *m_last_channel; + + /* global sound parameters */ + const UINT8 *m_sound_rom; + int m_num_voices; + int m_sound_enable; + sound_stream *m_stream; + + /* mixer tables and internal buffers */ + INT16 *m_mixer_table; + INT16 *m_mixer_lookup; + short *m_mixer_buffer; + short *m_mixer_buffer_2; + + UINT8 m_soundregs1[0x20]; + UINT8 m_soundregs2[0x20]; }; extern const device_type GOMOKU; diff --git a/src/mame/includes/jpmsys5.h b/src/mame/includes/jpmsys5.h index abe8c1de013..c16d1d4fbab 100644 --- a/src/mame/includes/jpmsys5.h +++ b/src/mame/includes/jpmsys5.h @@ -3,7 +3,6 @@ #include "machine/6840ptm.h" #include "machine/6850acia.h" #include "sound/2413intf.h" -#include "sound/saa1099.h" #include "sound/upd7759.h" #include "video/tms34061.h" #include "machine/nvram.h" diff --git a/src/mame/video/astrocde.c b/src/mame/video/astrocde.c index d07d35bd8b0..9027ea87f84 100644 --- a/src/mame/video/astrocde.c +++ b/src/mame/video/astrocde.c @@ -576,7 +576,7 @@ WRITE8_MEMBER(astrocde_state::astrocade_data_chip_register_w) case 0x17: /* noise volume register */ case 0x18: /* sound block transfer */ if (m_video_config & AC_SOUND_PRESENT) - astrocade_sound_w(machine().device("astrocade1"), space, offset, data); + machine().device("astrocade1")->astrocade_sound_w(space, offset, data); break; case 0x19: /* expand register */ diff --git a/src/mess/drivers/samcoupe.c b/src/mess/drivers/samcoupe.c index b744a66fde8..0fed5564354 100644 --- a/src/mess/drivers/samcoupe.c +++ b/src/mess/drivers/samcoupe.c @@ -314,8 +314,8 @@ static ADDRESS_MAP_START( samcoupe_io, AS_IO, 8, samcoupe_state ) AM_RANGE(0x00fd, 0x00fd) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(samcoupe_midi_r, samcoupe_midi_w) AM_RANGE(0x00fe, 0x00fe) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(samcoupe_keyboard_r, samcoupe_border_w) AM_RANGE(0x00ff, 0x00ff) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READ(samcoupe_attributes_r) - AM_RANGE(0x00ff, 0x00ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("saa1099", saa1099_data_w) - AM_RANGE(0x01ff, 0x01ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("saa1099", saa1099_control_w) + AM_RANGE(0x00ff, 0x00ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE("saa1099", saa1099_device, saa1099_data_w) + AM_RANGE(0x01ff, 0x01ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE("saa1099", saa1099_device, saa1099_control_w) ADDRESS_MAP_END @@ -551,7 +551,7 @@ static MACHINE_CONFIG_START( samcoupe, samcoupe_state ) MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_SOUND_ADD(SPEAKER_TAG, SPEAKER_SOUND, 0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) - MCFG_SOUND_ADD("saa1099", SAA1099, SAMCOUPE_XTAL_X1/3) /* 8 MHz */ + MCFG_SAA1099_ADD("saa1099", SAMCOUPE_XTAL_X1/3) /* 8 MHz */ MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) diff --git a/src/mess/machine/isa_gblaster.c b/src/mess/machine/isa_gblaster.c index 648f6d0488e..bdaccff910e 100644 --- a/src/mess/machine/isa_gblaster.c +++ b/src/mess/machine/isa_gblaster.c @@ -19,9 +19,9 @@ */ static MACHINE_CONFIG_FRAGMENT( game_blaster_config ) MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("saa1099.1", SAA1099, 4772720) + MCFG_SAA1099_ADD("saa1099.1", 4772720) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) - MCFG_SOUND_ADD("saa1099.2", SAA1099, 4772720) + MCFG_SAA1099_ADD("saa1099.2", 4772720) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) MACHINE_CONFIG_END @@ -34,8 +34,8 @@ static WRITE8_DEVICE_HANDLER( saa1099_16_w ) { switch(offset) { - case 0 : saa1099_control_w( device, space, offset, data ); break; - case 1 : saa1099_data_w( device, space, offset, data ); break; + case 0 : dynamic_cast(device)->saa1099_control_w( space, offset, data ); break; + case 1 : dynamic_cast(device)->saa1099_data_w( space, offset, data ); break; } } diff --git a/src/mess/machine/isa_sblaster.c b/src/mess/machine/isa_sblaster.c index 485721275ed..0f99b9c7242 100644 --- a/src/mess/machine/isa_sblaster.c +++ b/src/mess/machine/isa_sblaster.c @@ -95,10 +95,10 @@ static MACHINE_CONFIG_FRAGMENT( sblaster1_0_config ) MCFG_SOUND_CONFIG(pc_ym3812_interface) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 3.00) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 3.00) - MCFG_SOUND_ADD("saa1099.1", SAA1099, 4772720) + MCFG_SAA1099_ADD("saa1099.1", 4772720) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50) - MCFG_SOUND_ADD("saa1099.2", SAA1099, 4772720) + MCFG_SAA1099_ADD("saa1099.2", 4772720) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50) @@ -176,8 +176,8 @@ static WRITE8_DEVICE_HANDLER( saa1099_16_w ) { switch(offset) { - case 0 : saa1099_control_w( device, space, offset, data ); break; - case 1 : saa1099_data_w( device, space, offset, data ); break; + case 0 : dynamic_cast(device)->saa1099_control_w( space, offset, data ); break; + case 1 : dynamic_cast(device)->saa1099_data_w( space, offset, data ); break; } }