Previous 199869 Revisions Next

r26108 Monday 11th November, 2013 at 21:35:57 UTC by Osso
Modernized es5505/es5506 device. (nw)
[src/emu/sound]es5506.c es5506.h
[src/mame/audio]taito_en.c
[src/mame/drivers]itech32.c macrossp.c ssv.c
[src/mame/includes]ssv.h
[src/mess/drivers]esq5505.c esqkt.c

trunk/src/emu/sound/es5506.c
r26107r26108
8484
8585#include "emu.h"
8686#include "es5506.h"
87#include "devlegcy.h"
8887
8988
90
9189/**********************************************************************************************
9290
9391     CONSTANTS
r26107r26108
9694
9795#define LOG_COMMANDS            0
9896#define RAINE_CHECK             0
99#define MAKE_WAVS               0
10097
10198#if MAKE_WAVS
10299#include "wavwrite.h"
r26107r26108
130127#define CONTROL_STOPMASK        (CONTROL_STOP1 | CONTROL_STOP0)
131128
132129
130es550x_device::es550x_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source)
131   : device_t(mconfig, type, name, tag, owner, clock, shortname, source),
132      device_sound_interface(mconfig, *this),
133      m_stream(NULL),
134      m_sample_rate(0),
135      m_write_latch(0),
136      m_read_latch(0),
137      m_master_clock(0),
138      m_current_page(0),
139      m_active_voices(0),
140      m_mode(0),
141      m_wst(0),
142      m_wend(0),
143      m_lrend(0),
144      m_irqv(0),
145      m_scratch(NULL),
146      m_ulaw_lookup(NULL),
147      m_volume_lookup(NULL),
148      #if MAKE_WAVS
149      m_wavraw(NULL),
150      #endif
151      m_eslog(NULL)
152{
153   for (int i = 0; i < 4; i++)
154   {
155      m_region_base[i] = NULL;
156   }
157}
133158
134/**********************************************************************************************
159const device_type ES5506 = &device_creator<es5506_device>;
135160
136     INTERNAL DATA STRUCTURES
161es5506_device::es5506_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
162   : es550x_device(mconfig, ES5506, "ES5506", tag, owner, clock, "es5506", __FILE__)
163{
164}
137165
138***********************************************************************************************/
166//-------------------------------------------------
167//  device_config_complete - perform any
168//  operations now that the configuration is
169//  complete
170//-------------------------------------------------
139171
140/* struct describing a single playing voice */
141struct es5506_voice
172void es550x_device::device_config_complete()
142173{
143   /* external state */
144   UINT32      control;                /* control register */
145   UINT32      freqcount;              /* frequency count register */
146   UINT32      start;                  /* start register */
147   UINT32      lvol;                   /* left volume register */
148   UINT32      end;                    /* end register */
149   UINT32      lvramp;                 /* left volume ramp register */
150   UINT32      accum;                  /* accumulator register */
151   UINT32      rvol;                   /* right volume register */
152   UINT32      rvramp;                 /* right volume ramp register */
153   UINT32      ecount;                 /* envelope count register */
154   UINT32      k2;                     /* k2 register */
155   UINT32      k2ramp;                 /* k2 ramp register */
156   UINT32      k1;                     /* k1 register */
157   UINT32      k1ramp;                 /* k1 ramp register */
158   INT32       o4n1;                   /* filter storage O4(n-1) */
159   INT32       o3n1;                   /* filter storage O3(n-1) */
160   INT32       o3n2;                   /* filter storage O3(n-2) */
161   INT32       o2n1;                   /* filter storage O2(n-1) */
162   INT32       o2n2;                   /* filter storage O2(n-2) */
163   INT32       o1n1;                   /* filter storage O1(n-1) */
164   UINT32      exbank;                 /* external address bank */
174}
165175
166   /* internal state */
167   UINT8       index;                  /* index of this voice */
168   UINT8       filtcount;              /* filter count */
169   UINT32      accum_mask;
170};
176void es5506_device::device_config_complete()
177{
178   // inherit a copy of the static data
179   const es5506_interface *intf = reinterpret_cast<const es5506_interface *>(static_config());
180   if (intf != NULL)
181   *static_cast<es5506_interface *>(this) = *intf;
171182
172struct es5506_state
183   // or initialize to defaults if none provided
184   else
185   {
186      m_region0 = "";
187      m_region1 = "";
188      m_region2 = "";
189      m_region3 = "";
190      m_channels = 0;
191      memset(&m_irq_callback, 0, sizeof(m_irq_callback));
192      memset(&m_read_port, 0, sizeof(m_read_port));
193   }
194}
195
196//-------------------------------------------------
197//  device_start - device-specific startup
198//-------------------------------------------------
199void es550x_device::device_start()
173200{
174   sound_stream *stream;               /* which stream are we using */
175   int         sample_rate;            /* current sample rate */
176   UINT16 *    region_base[4];         /* pointer to the base of the region */
177   UINT32      write_latch;            /* currently accumulated data for write */
178   UINT32      read_latch;             /* currently accumulated data for read */
179   UINT32      master_clock;           /* master clock frequency */
180   devcb_resolved_write_line irq_callback;   /* IRQ callback */
181   devcb_resolved_read16     port_read;       /* input port read */
201}
182202
183   UINT8       current_page;           /* current register page */
184   UINT8       active_voices;          /* number of active voices */
185   UINT8       mode;                   /* MODE register */
186   UINT8       wst;                    /* W_ST register */
187   UINT8       wend;                   /* W_END register */
188   UINT8       lrend;                  /* LR_END register */
189   UINT8       irqv;                   /* IRQV register */
203void es5506_device::device_start()
204{
205   int j;
206   UINT32 accum_mask;
207   int channels = 1;  /* 1 channel by default, for backward compatibility */
190208
191   es5506_voice voice[32];             /* the 32 voices */
209   /* only override the number of channels if the value is in the valid range 1 .. 6 */
210   if (1 <= m_channels && m_channels <= 6)
211      channels = m_channels;
192212
193   INT32 *     scratch;
213   /* debugging */
214   if (LOG_COMMANDS && !m_eslog)
215      m_eslog = fopen("es.log", "w");
194216
195   INT16 *     ulaw_lookup;
196   UINT16 *    volume_lookup;
197   device_t *device;
217   /* create the stream */
218   m_stream = machine().sound().stream_alloc(*this, 0, 2 * channels, clock() / (16*32), this);
198219
199   int         channels;               /* the number of output stereo channels: 1..4 for 5505, 1..6 for 5506 */
220   /* initialize the regions */
221   m_region_base[0] = m_region0 ? (UINT16 *)machine().root_device().memregion(m_region0)->base() : NULL;
222   m_region_base[1] = m_region1 ? (UINT16 *)machine().root_device().memregion(m_region1)->base() : NULL;
223   m_region_base[2] = m_region2 ? (UINT16 *)machine().root_device().memregion(m_region2)->base() : NULL;
224   m_region_base[3] = m_region3 ? (UINT16 *)machine().root_device().memregion(m_region3)->base() : NULL;
200225
201#if MAKE_WAVS
202   void *      wavraw;                 /* raw waveform */
203#endif
204};
226   /* initialize the rest of the structure */
227   m_master_clock = clock();
228   m_irq_callback_func.resolve(m_irq_callback, *this);
229   m_port_read_func.resolve(m_read_port, *this);
230   m_irqv = 0x80;
231   m_channels = channels;
205232
233   /* compute the tables */
234   compute_tables();
206235
207INLINE es5506_state *get_safe_token(device_t *device)
236   /* init the voices */
237   accum_mask = 0xffffffff;
238   for (j = 0; j < 32; j++)
239   {
240      m_voice[j].index = j;
241      m_voice[j].control = CONTROL_STOPMASK;
242      m_voice[j].lvol = 0xffff;
243      m_voice[j].rvol = 0xffff;
244      m_voice[j].exbank = 0;
245      m_voice[j].accum_mask = accum_mask;
246   }
247
248   /* allocate memory */
249   m_scratch = auto_alloc_array_clear(machine(), INT32, 2 * MAX_SAMPLE_CHUNK);
250
251   /* register save */
252   save_item(NAME(m_sample_rate));
253   save_item(NAME(m_write_latch));
254   save_item(NAME(m_read_latch));
255
256   save_item(NAME(m_current_page));
257   save_item(NAME(m_active_voices));
258   save_item(NAME(m_mode));
259   save_item(NAME(m_wst));
260   save_item(NAME(m_wend));
261   save_item(NAME(m_lrend));
262   save_item(NAME(m_irqv));
263
264   save_pointer(NAME(m_scratch), 2 * MAX_SAMPLE_CHUNK);
265
266   for (j = 0; j < 32; j++)
267   {
268      save_item(NAME(m_voice[j].control), j);
269      save_item(NAME(m_voice[j].freqcount), j);
270      save_item(NAME(m_voice[j].start), j);
271      save_item(NAME(m_voice[j].lvol), j);
272      save_item(NAME(m_voice[j].end), j);
273      save_item(NAME(m_voice[j].lvramp), j);
274      save_item(NAME(m_voice[j].accum), j);
275      save_item(NAME(m_voice[j].rvol), j);
276      save_item(NAME(m_voice[j].rvramp), j);
277      save_item(NAME(m_voice[j].ecount), j);
278      save_item(NAME(m_voice[j].k2), j);
279      save_item(NAME(m_voice[j].k2ramp), j);
280      save_item(NAME(m_voice[j].k1), j);
281      save_item(NAME(m_voice[j].k1ramp), j);
282      save_item(NAME(m_voice[j].o4n1), j);
283      save_item(NAME(m_voice[j].o3n1), j);
284      save_item(NAME(m_voice[j].o3n2), j);
285      save_item(NAME(m_voice[j].o2n1), j);
286      save_item(NAME(m_voice[j].o2n2), j);
287      save_item(NAME(m_voice[j].o1n1), j);
288      save_item(NAME(m_voice[j].exbank), j);
289      save_item(NAME(m_voice[j].filtcount), j);
290   }
291
292   /* success */
293}
294
295//-------------------------------------------------
296//  device_reset - device-specific reset
297//-------------------------------------------------
298
299void es550x_device::device_reset()
208300{
209   assert(device != NULL);
210   assert(device->type() == ES5505 || device->type() == ES5506);
211   return (es5506_state *)downcast<es5506_device *>(device)->token();
212301}
213302
303//-------------------------------------------------
304//  device_stop - device-specific stop
305//-------------------------------------------------
214306
307void es550x_device::device_stop()
308{
309   /* debugging */
310   if (LOG_COMMANDS && m_eslog)
311   {
312      fclose(m_eslog);
313      m_eslog = NULL;
314   }
215315
216/**********************************************************************************************
316   #if MAKE_WAVS
317   {
318      int i;
217319
218     GLOBAL VARIABLES
320      for (i = 0; i < MAX_ES5506; i++)
321      {
322         if (es5506[i].m_wavraw)
323            wav_close(es5506[i].m_wavraw);
324      }
325   }
326   #endif
327}
219328
220***********************************************************************************************/
329const device_type ES5505 = &device_creator<es5505_device>;
221330
222static FILE *eslog;
331es5505_device::es5505_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
332   : es550x_device(mconfig, ES5505, "ES5505", tag, owner, clock, "es5505", __FILE__)
333{
334}
223335
336//-------------------------------------------------
337//  device_config_complete - perform any
338//  operations now that the configuration is
339//  complete
340//-------------------------------------------------
224341
342void es5505_device::device_config_complete()
343{
344   // inherit a copy of the static data
345   const es5505_interface *intf = reinterpret_cast<const es5505_interface *>(static_config());
346   if (intf != NULL)
347   *static_cast<es5505_interface *>(this) = *intf;
225348
349   // or initialize to defaults if none provided
350   else
351   {
352      m_es5505_region0 = "";
353      m_es5505_region1 = "";
354      m_es5505_channels = 0;
355      memset(&m_es5505_irq_callback, 0, sizeof(m_es5505_irq_callback));
356      memset(&m_es5505_read_port, 0, sizeof(m_es5505_read_port));
357   }
358}
359
360//-------------------------------------------------
361//  device_start - device-specific startup
362//-------------------------------------------------
363
364void es5505_device::device_start()
365{
366   int j;
367   UINT32 accum_mask;
368   int channels = 1;  /* 1 channel by default, for backward compatibility */
369
370   /* only override the number of channels if the value is in the valid range 1 .. 4 */
371   if (1 <= m_es5505_channels && m_es5505_channels <= 4)
372      channels = m_es5505_channels;
373
374   /* debugging */
375   if (LOG_COMMANDS && !m_eslog)
376      m_eslog = fopen("es.log", "w");
377
378   /* create the stream */
379   m_stream = machine().sound().stream_alloc(*this, 0, 2 * channels, clock() / (16*32), this);
380
381   /* initialize the regions */
382   m_region_base[0] = m_es5505_region0 ? (UINT16 *)machine().root_device().memregion(m_es5505_region0)->base() : NULL;
383   m_region_base[1] = m_es5505_region1 ? (UINT16 *)machine().root_device().memregion(m_es5505_region1)->base() : NULL;
384   
385   /* initialize the rest of the structure */
386   m_master_clock = clock();
387   m_irq_callback_func.resolve(m_es5505_irq_callback, *this);
388   m_port_read_func.resolve(m_es5505_read_port, *this);
389   m_irqv = 0x80;
390   m_es5505_channels = channels;
391
392   /* compute the tables */
393   compute_tables();
394
395   /* init the voices */
396   accum_mask = 0x7fffffff;
397   for (j = 0; j < 32; j++)
398   {
399      m_voice[j].index = j;
400      m_voice[j].control = CONTROL_STOPMASK;
401      m_voice[j].lvol = 0xffff;
402      m_voice[j].rvol = 0xffff;
403      m_voice[j].exbank = 0;
404      m_voice[j].accum_mask = accum_mask;
405   }
406
407   /* allocate memory */
408   m_scratch = auto_alloc_array_clear(machine(), INT32, 2 * MAX_SAMPLE_CHUNK);
409
410   /* register save */
411   save_item(NAME(m_sample_rate));
412   save_item(NAME(m_write_latch));
413   save_item(NAME(m_read_latch));
414
415   save_item(NAME(m_current_page));
416   save_item(NAME(m_active_voices));
417   save_item(NAME(m_mode));
418   save_item(NAME(m_wst));
419   save_item(NAME(m_wend));
420   save_item(NAME(m_lrend));
421   save_item(NAME(m_irqv));
422
423   save_pointer(NAME(m_scratch), 2 * MAX_SAMPLE_CHUNK);
424
425   for (j = 0; j < 32; j++)
426   {
427      save_item(NAME(m_voice[j].control), j);
428      save_item(NAME(m_voice[j].freqcount), j);
429      save_item(NAME(m_voice[j].start), j);
430      save_item(NAME(m_voice[j].lvol), j);
431      save_item(NAME(m_voice[j].end), j);
432      save_item(NAME(m_voice[j].lvramp), j);
433      save_item(NAME(m_voice[j].accum), j);
434      save_item(NAME(m_voice[j].rvol), j);
435      save_item(NAME(m_voice[j].rvramp), j);
436      save_item(NAME(m_voice[j].ecount), j);
437      save_item(NAME(m_voice[j].k2), j);
438      save_item(NAME(m_voice[j].k2ramp), j);
439      save_item(NAME(m_voice[j].k1), j);
440      save_item(NAME(m_voice[j].k1ramp), j);
441      save_item(NAME(m_voice[j].o4n1), j);
442      save_item(NAME(m_voice[j].o3n1), j);
443      save_item(NAME(m_voice[j].o3n2), j);
444      save_item(NAME(m_voice[j].o2n1), j);
445      save_item(NAME(m_voice[j].o2n2), j);
446      save_item(NAME(m_voice[j].o1n1), j);
447      save_item(NAME(m_voice[j].exbank), j);
448      save_item(NAME(m_voice[j].filtcount), j);
449   }
450
451   /* success */
452}
453
454
226455/**********************************************************************************************
227456
228457     update_irq_state -- update the IRQ state
229458
230459***********************************************************************************************/
231460
232static void update_irq_state(es5506_state *chip)
461
462void es550x_device::update_irq_state()
233463{
234464   /* ES5505/6 irq line has been set high - inform the host */
235   if (!chip->irq_callback.isnull())
236      chip->irq_callback(1); /* IRQB set high */
465   if (!m_irq_callback_func.isnull())
466      m_irq_callback_func(1); /* IRQB set high */
237467}
238468
239static void update_internal_irq_state(es5506_state *chip)
469void es550x_device::update_internal_irq_state()
240470{
241471   /*  Host (cpu) has just read the voice interrupt vector (voice IRQ ack).
242472
r26107r26108
247477       terms they get updated next time generate_samples() is called.
248478   */
249479
250   chip->irqv=0x80;
480   m_irqv=0x80;
251481
252   if (!chip->irq_callback.isnull())
253      chip->irq_callback(0); /* IRQB set low */
482   if (!m_irq_callback_func.isnull())
483      m_irq_callback_func(0); /* IRQB set low */
254484}
255485
256486/**********************************************************************************************
r26107r26108
259489
260490***********************************************************************************************/
261491
262static void compute_tables(es5506_state *chip)
492void es550x_device::compute_tables()
263493{
264494   int i;
265495
266496   /* allocate ulaw lookup table */
267   chip->ulaw_lookup = auto_alloc_array(chip->device->machine(), INT16, 1 << ULAW_MAXBITS);
497   m_ulaw_lookup = auto_alloc_array_clear(machine(), INT16, 1 << ULAW_MAXBITS);
268498
269499   /* generate ulaw lookup table */
270500   for (i = 0; i < (1 << ULAW_MAXBITS); i++)
r26107r26108
274504      UINT32 mantissa = (rawval << 3) & 0xffff;
275505
276506      if (exponent == 0)
277         chip->ulaw_lookup[i] = (INT16)mantissa >> 7;
507         m_ulaw_lookup[i] = (INT16)mantissa >> 7;
278508      else
279509      {
280510         mantissa = (mantissa >> 1) | (~mantissa & 0x8000);
281         chip->ulaw_lookup[i] = (INT16)mantissa >> (7 - exponent);
511         m_ulaw_lookup[i] = (INT16)mantissa >> (7 - exponent);
282512      }
283513   }
284514
285515   /* allocate volume lookup table */
286   chip->volume_lookup = auto_alloc_array(chip->device->machine(), UINT16, 4096);
516   m_volume_lookup = auto_alloc_array_clear(machine(), UINT16, 4096);
287517
288518   /* generate volume lookup table */
289519   for (i = 0; i < 4096; i++)
r26107r26108
291521      UINT8 exponent = i >> 8;
292522      UINT32 mantissa = (i & 0xff) | 0x100;
293523
294      chip->volume_lookup[i] = (mantissa << 11) >> (20 - exponent);
524      m_volume_lookup[i] = (mantissa << 11) >> (20 - exponent);
295525   }
296526}
297527
r26107r26108
523753
524754***********************************************************************************************/
525755
526static void generate_dummy(es5506_state *chip, es5506_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples)
756void es550x_device::generate_dummy(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples)
527757{
528758   UINT32 freqcount = voice->freqcount;
529759   UINT32 accum = voice->accum & voice->accum_mask;
r26107r26108
584814
585815***********************************************************************************************/
586816
587static void generate_ulaw(es5506_state *chip, es5506_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples)
817void es550x_device::generate_ulaw(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples)
588818{
589819   UINT32 freqcount = voice->freqcount;
590820   UINT32 accum = voice->accum & voice->accum_mask;
591   INT32 lvol = chip->volume_lookup[voice->lvol >> 4];
592   INT32 rvol = chip->volume_lookup[voice->rvol >> 4];
821   INT32 lvol = m_volume_lookup[voice->lvol >> 4];
822   INT32 rvol = m_volume_lookup[voice->rvol >> 4];
593823
594824   /* pre-add the bank offset */
595825   base += voice->exbank;
r26107r26108
609839            INT32 val2 = base[((accum + (1 << 11)) & voice->accum_mask) >> 11];
610840
611841            /* decompress u-law */
612            val1 = chip->ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)];
613            val2 = chip->ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)];
842            val1 = m_ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)];
843            val2 = m_ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)];
614844
615845            /* interpolate */
616846            val1 = interpolate(val1, val2, accum);
r26107r26108
623853            if (voice->ecount != 0)
624854            {
625855               update_envelopes(voice, 1);
626               lvol = chip->volume_lookup[voice->lvol >> 4];
627               rvol = chip->volume_lookup[voice->rvol >> 4];
856               lvol = m_volume_lookup[voice->lvol >> 4];
857               rvol = m_volume_lookup[voice->rvol >> 4];
628858            }
629859
630860            /* apply volumes and add */
r26107r26108
647877            INT32 val2 = base[((accum + (1 << 11)) & voice->accum_mask) >> 11];
648878
649879            /* decompress u-law */
650            val1 = chip->ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)];
651            val2 = chip->ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)];
880            val1 = m_ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)];
881            val2 = m_ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)];
652882
653883            /* interpolate */
654884            val1 = interpolate(val1, val2, accum);
r26107r26108
661891            if (voice->ecount != 0)
662892            {
663893               update_envelopes(voice, 1);
664               lvol = chip->volume_lookup[voice->lvol >> 4];
665               rvol = chip->volume_lookup[voice->rvol >> 4];
894               lvol = m_volume_lookup[voice->lvol >> 4];
895               rvol = m_volume_lookup[voice->rvol >> 4];
666896            }
667897
668898            /* apply volumes and add */
r26107r26108
690920
691921***********************************************************************************************/
692922
693static void generate_pcm(es5506_state *chip, es5506_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples)
923void es550x_device::generate_pcm(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples)
694924{
695925   UINT32 freqcount = voice->freqcount;
696926   UINT32 accum = voice->accum & voice->accum_mask;
697   INT32 lvol = chip->volume_lookup[voice->lvol >> 4];
698   INT32 rvol = chip->volume_lookup[voice->rvol >> 4];
927   INT32 lvol = m_volume_lookup[voice->lvol >> 4];
928   INT32 rvol = m_volume_lookup[voice->rvol >> 4];
699929
700930   /* pre-add the bank offset */
701931   base += voice->exbank;
r26107r26108
725955            if (voice->ecount != 0)
726956            {
727957               update_envelopes(voice, 1);
728               lvol = chip->volume_lookup[voice->lvol >> 4];
729               rvol = chip->volume_lookup[voice->rvol >> 4];
958               lvol = m_volume_lookup[voice->lvol >> 4];
959               rvol = m_volume_lookup[voice->rvol >> 4];
730960            }
731961
732962            /* apply volumes and add */
r26107r26108
759989            if (voice->ecount != 0)
760990            {
761991               update_envelopes(voice, 1);
762               lvol = chip->volume_lookup[voice->lvol >> 4];
763               rvol = chip->volume_lookup[voice->rvol >> 4];
992               lvol = m_volume_lookup[voice->lvol >> 4];
993               rvol = m_volume_lookup[voice->rvol >> 4];
764994            }
765995
766996            /* apply volumes and add */
r26107r26108
7881018
7891019***********************************************************************************************/
7901020
791static void generate_samples(es5506_state *chip, INT32 **outputs, int offset, int samples)
1021void es5506_device::generate_samples(INT32 **outputs, int offset, int samples)
7921022{
7931023   int v;
7941024
r26107r26108
7971027      return;
7981028
7991029   /* clear out the accumulators */
800   for (int i = 0; i < chip->channels << 1; i++)
1030   for (int i = 0; i < m_channels << 1; i++)
8011031   {
8021032      memset(outputs[i] + offset, 0, sizeof(INT32) * samples);
8031033   }
8041034
8051035   /* loop over voices */
806   for (v = 0; v <= chip->active_voices; v++)
1036   for (v = 0; v <= m_active_voices; v++)
8071037   {
808      es5506_voice *voice = &chip->voice[v];
809      UINT16 *base = chip->region_base[voice->control >> 14];
1038      es550x_voice *voice = &m_voice[v];
1039      UINT16 *base = m_region_base[voice->control >> 14];
8101040
8111041      /* special case: if end == start, stop the voice */
8121042      if (voice->start == voice->end)
8131043         voice->control |= CONTROL_STOP0;
8141044
8151045      int voice_channel = (voice->control & CONTROL_CAMASK) >> 10;
816      int channel = voice_channel % chip->channels;
1046      int channel = voice_channel % m_channels;
8171047      int l = channel << 1;
8181048      int r = l + 1;
8191049      INT32 *left = outputs[l] + offset;
r26107r26108
8231053      if (!base)
8241054      {
8251055         logerror("es5506: NULL region base %d\n",voice->control >> 14);
826         generate_dummy(chip, voice, base, left, right, samples);
1056         generate_dummy(voice, base, left, right, samples);
8271057      }
8281058      else if (voice->control & 0x2000)
829         generate_ulaw(chip, voice, base, left, right, samples);
1059         generate_ulaw(voice, base, left, right, samples);
8301060      else
831         generate_pcm(chip, voice, base, left, right, samples);
1061         generate_pcm(voice, base, left, right, samples);
8321062
8331063      /* does this voice have it's IRQ bit raised? */
8341064      if (voice->control&CONTROL_IRQ)
r26107r26108
8361066         logerror("es5506: IRQ raised on voice %d!!\n",v);
8371067
8381068         /* only update voice vector if existing IRQ is acked by host */
839         if (chip->irqv&0x80)
1069         if (m_irqv&0x80)
8401070         {
8411071            /* latch voice number into vector, and set high bit low */
842            chip->irqv=v&0x7f;
1072            m_irqv=v&0x7f;
8431073
8441074            /* take down IRQ bit on voice */
8451075            voice->control&=~CONTROL_IRQ;
8461076
8471077            /* inform host of irq */
848            update_irq_state(chip);
1078            update_irq_state();
8491079         }
8501080      }
8511081   }
8521082}
8531083
854
855
856/**********************************************************************************************
857
858     es5506_update -- update the sound chip so that it is in sync with CPU execution
859
860***********************************************************************************************/
861
862STREAM_UPDATE( es5506_update )
1084void es5505_device::generate_samples(INT32 **outputs, int offset, int samples)
8631085{
864   es5506_state *chip = (es5506_state *)param;
1086   int v;
8651087
866#if MAKE_WAVS
867   /* start the logging once we have a sample rate */
868   if (chip->sample_rate)
869   {
870      if (!chip->wavraw)
871         chip->wavraw = wav_open("raw.wav", chip->sample_rate, 2);
872   }
873#endif
1088   /* skip if nothing to do */
1089   if (!samples)
1090      return;
8741091
875   /* loop until all samples are output */
876   int offset = 0;
877   while (samples)
1092   /* clear out the accumulators */
1093   for (int i = 0; i < m_es5505_channels << 1; i++)
8781094   {
879      int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples;
880
881      generate_samples(chip, outputs, offset, length);
882
883#if MAKE_WAVS
884      /* log the raw data */
885      if (chip->wavraw) {
886         /* determine left/right source data */
887         INT32 *lsrc = chip->scratch, *rsrc = chip->scratch + length;
888         int channel;
889         memset(lsrc, 0, sizeof(INT32) * length * 2);
890         /* loop over the output channels */
891         for (channel = 0; channel < chip->channels; channel++) {
892            INT32 *l = outputs[(channel << 1)] + offset;
893            INT32 *r = outputs[(channel << 1) + 1] + offset;
894            /* add the current channel's samples to the WAV data */
895            for (samp = 0; samp < length; samp++) {
896               lsrc[samp] += l[samp];
897               rsrc[samp] += r[samp];
898            }
899         }
900         wav_add_data_32lr(chip->wavraw, lsrc, rsrc, length, 4);
901      }
902#endif
903
904      /* account for these samples */
905      offset += length;
906      samples -= length;
1095      memset(outputs[i] + offset, 0, sizeof(INT32) * samples);
9071096   }
908}
9091097
910
911/**********************************************************************************************
912
913     DEVICE_START( es5506 ) -- start emulation of the ES5506
914
915***********************************************************************************************/
916
917static void es5506_start_common(device_t *device, const void *config, device_type sndtype)
918{
919   const es5506_interface *intf = (const es5506_interface *)config;
920   es5506_state *chip = get_safe_token(device);
921   int j;
922   UINT32 accum_mask;
923   int channels = 1;  /* 1 channel by default, for backward compatibility */
924
925   /* only override the number of channels if the value is in the valid range 1 .. 6 */
926   if (1 <= intf->channels && intf->channels <= 6)
927      channels = intf->channels;
928
929   /* debugging */
930   if (LOG_COMMANDS && !eslog)
931      eslog = fopen("es.log", "w");
932
933   /* create the stream */
934   chip->stream = device->machine().sound().stream_alloc(*device, 0, 2 * channels, device->clock() / (16*32), chip, es5506_update);
935
936   /* initialize the regions */
937   chip->region_base[0] = intf->region0 ? (UINT16 *)device->machine().root_device().memregion(intf->region0)->base() : NULL;
938   chip->region_base[1] = intf->region1 ? (UINT16 *)device->machine().root_device().memregion(intf->region1)->base() : NULL;
939   chip->region_base[2] = intf->region2 ? (UINT16 *)device->machine().root_device().memregion(intf->region2)->base() : NULL;
940   chip->region_base[3] = intf->region3 ? (UINT16 *)device->machine().root_device().memregion(intf->region3)->base() : NULL;
941
942   /* initialize the rest of the structure */
943   chip->device = device;
944   chip->master_clock = device->clock();
945   chip->irq_callback.resolve(intf->irq_callback,*device);
946   chip->port_read.resolve(intf->read_port,*device);
947   chip->irqv = 0x80;
948   chip->channels = channels;
949
950   /* compute the tables */
951   compute_tables(chip);
952
953   /* init the voices */
954   accum_mask = (sndtype == ES5506) ? 0xffffffff : 0x7fffffff;
955   for (j = 0; j < 32; j++)
1098   /* loop over voices */
1099   for (v = 0; v <= m_active_voices; v++)
9561100   {
957      chip->voice[j].index = j;
958      chip->voice[j].control = CONTROL_STOPMASK;
959      chip->voice[j].lvol = 0xffff;
960      chip->voice[j].rvol = 0xffff;
961      chip->voice[j].exbank = 0;
962      chip->voice[j].accum_mask = accum_mask;
963   }
1101      es550x_voice *voice = &m_voice[v];
1102      UINT16 *base = m_region_base[voice->control >> 14];
9641103
965   /* allocate memory */
966   chip->scratch = auto_alloc_array(device->machine(), INT32, 2 * MAX_SAMPLE_CHUNK);
1104      /* special case: if end == start, stop the voice */
1105      if (voice->start == voice->end)
1106         voice->control |= CONTROL_STOP0;
9671107
968   /* register save */
969   device->save_item(NAME(chip->sample_rate));
970   device->save_item(NAME(chip->write_latch));
971   device->save_item(NAME(chip->read_latch));
1108      int voice_channel = (voice->control & CONTROL_CAMASK) >> 10;
1109      int channel = voice_channel % m_es5505_channels;
1110      int l = channel << 1;
1111      int r = l + 1;
1112      INT32 *left = outputs[l] + offset;
1113      INT32 *right = outputs[r] + offset;
9721114
973   device->save_item(NAME(chip->current_page));
974   device->save_item(NAME(chip->active_voices));
975   device->save_item(NAME(chip->mode));
976   device->save_item(NAME(chip->wst));
977   device->save_item(NAME(chip->wend));
978   device->save_item(NAME(chip->lrend));
979   device->save_item(NAME(chip->irqv));
1115      /* generate from the appropriate source */
1116      if (!base)
1117      {
1118         logerror("es5506: NULL region base %d\n",voice->control >> 14);
1119         generate_dummy(voice, base, left, right, samples);
1120      }
1121      else if (voice->control & 0x2000)
1122         generate_ulaw(voice, base, left, right, samples);
1123      else
1124         generate_pcm(voice, base, left, right, samples);
9801125
981   device->save_pointer(NAME(chip->scratch), 2 * MAX_SAMPLE_CHUNK);
1126      /* does this voice have it's IRQ bit raised? */
1127      if (voice->control&CONTROL_IRQ)
1128      {
1129         logerror("es5506: IRQ raised on voice %d!!\n",v);
9821130
983   for (j = 0; j < 32; j++)
984   {
985      device->save_item(NAME(chip->voice[j].control), j);
986      device->save_item(NAME(chip->voice[j].freqcount), j);
987      device->save_item(NAME(chip->voice[j].start), j);
988      device->save_item(NAME(chip->voice[j].lvol), j);
989      device->save_item(NAME(chip->voice[j].end), j);
990      device->save_item(NAME(chip->voice[j].lvramp), j);
991      device->save_item(NAME(chip->voice[j].accum), j);
992      device->save_item(NAME(chip->voice[j].rvol), j);
993      device->save_item(NAME(chip->voice[j].rvramp), j);
994      device->save_item(NAME(chip->voice[j].ecount), j);
995      device->save_item(NAME(chip->voice[j].k2), j);
996      device->save_item(NAME(chip->voice[j].k2ramp), j);
997      device->save_item(NAME(chip->voice[j].k1), j);
998      device->save_item(NAME(chip->voice[j].k1ramp), j);
999      device->save_item(NAME(chip->voice[j].o4n1), j);
1000      device->save_item(NAME(chip->voice[j].o3n1), j);
1001      device->save_item(NAME(chip->voice[j].o3n2), j);
1002      device->save_item(NAME(chip->voice[j].o2n1), j);
1003      device->save_item(NAME(chip->voice[j].o2n2), j);
1004      device->save_item(NAME(chip->voice[j].o1n1), j);
1005      device->save_item(NAME(chip->voice[j].exbank), j);
1006      device->save_item(NAME(chip->voice[j].filtcount), j);
1007   }
1131         /* only update voice vector if existing IRQ is acked by host */
1132         if (m_irqv&0x80)
1133         {
1134            /* latch voice number into vector, and set high bit low */
1135            m_irqv=v&0x7f;
10081136
1009   /* success */
1010}
1137            /* take down IRQ bit on voice */
1138            voice->control&=~CONTROL_IRQ;
10111139
1012
1013static DEVICE_START( es5506 )
1014{
1015   es5506_start_common(device, device->static_config(), ES5506);
1016}
1017
1018
1019
1020/**********************************************************************************************
1021
1022     DEVICE_STOP( es5506 ) -- stop emulation of the ES5506
1023
1024***********************************************************************************************/
1025
1026static DEVICE_STOP( es5506 )
1027{
1028   /* debugging */
1029   if (LOG_COMMANDS && eslog)
1030   {
1031      fclose(eslog);
1032      eslog = NULL;
1140            /* inform host of irq */
1141            update_irq_state();
1142         }
1143      }
10331144   }
1034
1035#if MAKE_WAVS
1036{
1037   int i;
1038
1039   for (i = 0; i < MAX_ES5506; i++)
1040   {
1041      if (es5506[i].wavraw)
1042         wav_close(es5506[i].wavraw);
1043   }
10441145}
1045#endif
1046}
10471146
10481147
10491148
10501149/**********************************************************************************************
10511150
1052     es5506_reg_write -- handle a write to the selected ES5506 register
1151     reg_write -- handle a write to the selected ES5506 register
10531152
10541153***********************************************************************************************/
10551154
1056INLINE void es5506_reg_write_low(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT32 data)
1155inline void es5506_device::reg_write_low(es550x_voice *voice, offs_t offset, UINT32 data)
10571156{
10581157   switch (offset)
10591158   {
10601159      case 0x00/8:    /* CR */
10611160         voice->control = data & 0xffff;
1062         if (LOG_COMMANDS && eslog)
1063            fprintf(eslog, "voice %d, control=%04x\n", chip->current_page & 0x1f, voice->control);
1161         if (LOG_COMMANDS && m_eslog)
1162            fprintf(m_eslog, "voice %d, control=%04x\n", m_current_page & 0x1f, voice->control);
10641163         break;
10651164
10661165      case 0x08/8:    /* FC */
10671166         voice->freqcount = data & 0x1ffff;
1068         if (LOG_COMMANDS && eslog)
1069            fprintf(eslog, "voice %d, freq count=%08x\n", chip->current_page & 0x1f, voice->freqcount);
1167         if (LOG_COMMANDS && m_eslog)
1168            fprintf(m_eslog, "voice %d, freq count=%08x\n", m_current_page & 0x1f, voice->freqcount);
10701169         break;
10711170
10721171      case 0x10/8:    /* LVOL */
10731172         voice->lvol = data & 0xffff;
1074         if (LOG_COMMANDS && eslog)
1075            fprintf(eslog, "voice %d, left vol=%04x\n", chip->current_page & 0x1f, voice->lvol);
1173         if (LOG_COMMANDS && m_eslog)
1174            fprintf(m_eslog, "voice %d, left vol=%04x\n", m_current_page & 0x1f, voice->lvol);
10761175         break;
10771176
10781177      case 0x18/8:    /* LVRAMP */
10791178         voice->lvramp = (data & 0xff00) >> 8;
1080         if (LOG_COMMANDS && eslog)
1081            fprintf(eslog, "voice %d, left vol ramp=%04x\n", chip->current_page & 0x1f, voice->lvramp);
1179         if (LOG_COMMANDS && m_eslog)
1180            fprintf(m_eslog, "voice %d, left vol ramp=%04x\n", m_current_page & 0x1f, voice->lvramp);
10821181         break;
10831182
10841183      case 0x20/8:    /* RVOL */
10851184         voice->rvol = data & 0xffff;
1086         if (LOG_COMMANDS && eslog)
1087            fprintf(eslog, "voice %d, right vol=%04x\n", chip->current_page & 0x1f, voice->rvol);
1185         if (LOG_COMMANDS && m_eslog)
1186            fprintf(m_eslog, "voice %d, right vol=%04x\n", m_current_page & 0x1f, voice->rvol);
10881187         break;
10891188
10901189      case 0x28/8:    /* RVRAMP */
10911190         voice->rvramp = (data & 0xff00) >> 8;
1092         if (LOG_COMMANDS && eslog)
1093            fprintf(eslog, "voice %d, right vol ramp=%04x\n", chip->current_page & 0x1f, voice->rvramp);
1191         if (LOG_COMMANDS && m_eslog)
1192            fprintf(m_eslog, "voice %d, right vol ramp=%04x\n", m_current_page & 0x1f, voice->rvramp);
10941193         break;
10951194
10961195      case 0x30/8:    /* ECOUNT */
10971196         voice->ecount = data & 0x1ff;
10981197         voice->filtcount = 0;
1099         if (LOG_COMMANDS && eslog)
1100            fprintf(eslog, "voice %d, envelope count=%04x\n", chip->current_page & 0x1f, voice->ecount);
1198         if (LOG_COMMANDS && m_eslog)
1199            fprintf(m_eslog, "voice %d, envelope count=%04x\n", m_current_page & 0x1f, voice->ecount);
11011200         break;
11021201
11031202      case 0x38/8:    /* K2 */
11041203         voice->k2 = data & 0xffff;
1105         if (LOG_COMMANDS && eslog)
1106            fprintf(eslog, "voice %d, K2=%04x\n", chip->current_page & 0x1f, voice->k2);
1204         if (LOG_COMMANDS && m_eslog)
1205            fprintf(m_eslog, "voice %d, K2=%04x\n", m_current_page & 0x1f, voice->k2);
11071206         break;
11081207
11091208      case 0x40/8:    /* K2RAMP */
11101209         voice->k2ramp = ((data & 0xff00) >> 8) | ((data & 0x0001) << 31);
1111         if (LOG_COMMANDS && eslog)
1112            fprintf(eslog, "voice %d, K2 ramp=%04x\n", chip->current_page & 0x1f, voice->k2ramp);
1210         if (LOG_COMMANDS && m_eslog)
1211            fprintf(m_eslog, "voice %d, K2 ramp=%04x\n", m_current_page & 0x1f, voice->k2ramp);
11131212         break;
11141213
11151214      case 0x48/8:    /* K1 */
11161215         voice->k1 = data & 0xffff;
1117         if (LOG_COMMANDS && eslog)
1118            fprintf(eslog, "voice %d, K1=%04x\n", chip->current_page & 0x1f, voice->k1);
1216         if (LOG_COMMANDS && m_eslog)
1217            fprintf(m_eslog, "voice %d, K1=%04x\n", m_current_page & 0x1f, voice->k1);
11191218         break;
11201219
11211220      case 0x50/8:    /* K1RAMP */
11221221         voice->k1ramp = ((data & 0xff00) >> 8) | ((data & 0x0001) << 31);
1123         if (LOG_COMMANDS && eslog)
1124            fprintf(eslog, "voice %d, K1 ramp=%04x\n", chip->current_page & 0x1f, voice->k1ramp);
1222         if (LOG_COMMANDS && m_eslog)
1223            fprintf(m_eslog, "voice %d, K1 ramp=%04x\n", m_current_page & 0x1f, voice->k1ramp);
11251224         break;
11261225
11271226      case 0x58/8:    /* ACTV */
11281227      {
1129         chip->active_voices = data & 0x1f;
1130         chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1));
1131         chip->stream->set_sample_rate(chip->sample_rate);
1228         m_active_voices = data & 0x1f;
1229         m_sample_rate = m_master_clock / (16 * (m_active_voices + 1));
1230         m_stream->set_sample_rate(m_sample_rate);
11321231
1133         if (LOG_COMMANDS && eslog)
1134            fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate);
1232         if (LOG_COMMANDS && m_eslog)
1233            fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate);
11351234         break;
11361235      }
11371236
11381237      case 0x60/8:    /* MODE */
1139         chip->mode = data & 0x1f;
1238         m_mode = data & 0x1f;
11401239         break;
11411240
11421241      case 0x68/8:    /* PAR - read only */
r26107r26108
11441243         break;
11451244
11461245      case 0x78/8:    /* PAGE */
1147         chip->current_page = data & 0x7f;
1246         m_current_page = data & 0x7f;
11481247         break;
11491248   }
11501249}
11511250
1152
1153INLINE void es5506_reg_write_high(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT32 data)
1251inline void es5506_device::reg_write_high(es550x_voice *voice, offs_t offset, UINT32 data)
11541252{
11551253   switch (offset)
11561254   {
11571255      case 0x00/8:    /* CR */
11581256         voice->control = data & 0xffff;
1159         if (LOG_COMMANDS && eslog)
1160            fprintf(eslog, "voice %d, control=%04x\n", chip->current_page & 0x1f, voice->control);
1257         if (LOG_COMMANDS && m_eslog)
1258            fprintf(m_eslog, "voice %d, control=%04x\n", m_current_page & 0x1f, voice->control);
11611259         break;
11621260
11631261      case 0x08/8:    /* START */
11641262         voice->start = data & 0xfffff800;
1165         if (LOG_COMMANDS && eslog)
1166            fprintf(eslog, "voice %d, loop start=%08x\n", chip->current_page & 0x1f, voice->start);
1263         if (LOG_COMMANDS && m_eslog)
1264            fprintf(m_eslog, "voice %d, loop start=%08x\n", m_current_page & 0x1f, voice->start);
11671265         break;
11681266
11691267      case 0x10/8:    /* END */
11701268         voice->end = data & 0xffffff80;
1171         if (LOG_COMMANDS && eslog)
1172            fprintf(eslog, "voice %d, loop end=%08x\n", chip->current_page & 0x1f, voice->end);
1269         if (LOG_COMMANDS && m_eslog)
1270            fprintf(m_eslog, "voice %d, loop end=%08x\n", m_current_page & 0x1f, voice->end);
11731271         break;
11741272
11751273      case 0x18/8:    /* ACCUM */
11761274         voice->accum = data;
1177         if (LOG_COMMANDS && eslog)
1178            fprintf(eslog, "voice %d, accum=%08x\n", chip->current_page & 0x1f, voice->accum);
1275         if (LOG_COMMANDS && m_eslog)
1276            fprintf(m_eslog, "voice %d, accum=%08x\n", m_current_page & 0x1f, voice->accum);
11791277         break;
11801278
11811279      case 0x20/8:    /* O4(n-1) */
11821280         voice->o4n1 = (INT32)(data << 14) >> 14;
1183         if (LOG_COMMANDS && eslog)
1184            fprintf(eslog, "voice %d, O4(n-1)=%05x\n", chip->current_page & 0x1f, voice->o4n1 & 0x3ffff);
1281         if (LOG_COMMANDS && m_eslog)
1282            fprintf(m_eslog, "voice %d, O4(n-1)=%05x\n", m_current_page & 0x1f, voice->o4n1 & 0x3ffff);
11851283         break;
11861284
11871285      case 0x28/8:    /* O3(n-1) */
11881286         voice->o3n1 = (INT32)(data << 14) >> 14;
1189         if (LOG_COMMANDS && eslog)
1190            fprintf(eslog, "voice %d, O3(n-1)=%05x\n", chip->current_page & 0x1f, voice->o3n1 & 0x3ffff);
1287         if (LOG_COMMANDS && m_eslog)
1288            fprintf(m_eslog, "voice %d, O3(n-1)=%05x\n", m_current_page & 0x1f, voice->o3n1 & 0x3ffff);
11911289         break;
11921290
11931291      case 0x30/8:    /* O3(n-2) */
11941292         voice->o3n2 = (INT32)(data << 14) >> 14;
1195         if (LOG_COMMANDS && eslog)
1196            fprintf(eslog, "voice %d, O3(n-2)=%05x\n", chip->current_page & 0x1f, voice->o3n2 & 0x3ffff);
1293         if (LOG_COMMANDS && m_eslog)
1294            fprintf(m_eslog, "voice %d, O3(n-2)=%05x\n", m_current_page & 0x1f, voice->o3n2 & 0x3ffff);
11971295         break;
11981296
11991297      case 0x38/8:    /* O2(n-1) */
12001298         voice->o2n1 = (INT32)(data << 14) >> 14;
1201         if (LOG_COMMANDS && eslog)
1202            fprintf(eslog, "voice %d, O2(n-1)=%05x\n", chip->current_page & 0x1f, voice->o2n1 & 0x3ffff);
1299         if (LOG_COMMANDS && m_eslog)
1300            fprintf(m_eslog, "voice %d, O2(n-1)=%05x\n", m_current_page & 0x1f, voice->o2n1 & 0x3ffff);
12031301         break;
12041302
12051303      case 0x40/8:    /* O2(n-2) */
12061304         voice->o2n2 = (INT32)(data << 14) >> 14;
1207         if (LOG_COMMANDS && eslog)
1208            fprintf(eslog, "voice %d, O2(n-2)=%05x\n", chip->current_page & 0x1f, voice->o2n2 & 0x3ffff);
1305         if (LOG_COMMANDS && m_eslog)
1306            fprintf(m_eslog, "voice %d, O2(n-2)=%05x\n", m_current_page & 0x1f, voice->o2n2 & 0x3ffff);
12091307         break;
12101308
12111309      case 0x48/8:    /* O1(n-1) */
12121310         voice->o1n1 = (INT32)(data << 14) >> 14;
1213         if (LOG_COMMANDS && eslog)
1214            fprintf(eslog, "voice %d, O1(n-1)=%05x\n", chip->current_page & 0x1f, voice->o1n1 & 0x3ffff);
1311         if (LOG_COMMANDS && m_eslog)
1312            fprintf(m_eslog, "voice %d, O1(n-1)=%05x\n", m_current_page & 0x1f, voice->o1n1 & 0x3ffff);
12151313         break;
12161314
12171315      case 0x50/8:    /* W_ST */
1218         chip->wst = data & 0x7f;
1316         m_wst = data & 0x7f;
12191317         break;
12201318
12211319      case 0x58/8:    /* W_END */
1222         chip->wend = data & 0x7f;
1320         m_wend = data & 0x7f;
12231321         break;
12241322
12251323      case 0x60/8:    /* LR_END */
1226         chip->lrend = data & 0x7f;
1324         m_lrend = data & 0x7f;
12271325         break;
12281326
12291327      case 0x68/8:    /* PAR - read only */
r26107r26108
12311329         break;
12321330
12331331      case 0x78/8:    /* PAGE */
1234         chip->current_page = data & 0x7f;
1332         m_current_page = data & 0x7f;
12351333         break;
12361334   }
12371335}
12381336
1239INLINE void es5506_reg_write_test(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT32 data)
1337inline void es5506_device::reg_write_test(es550x_voice *voice, offs_t offset, UINT32 data)
12401338{
12411339   switch (offset)
12421340   {
12431341      case 0x00/8:    /* CHANNEL 0 LEFT */
1244         if (LOG_COMMANDS && eslog)
1245            fprintf(eslog, "Channel 0 left test write %08x\n", data);
1342         if (LOG_COMMANDS && m_eslog)
1343            fprintf(m_eslog, "Channel 0 left test write %08x\n", data);
12461344         break;
12471345
12481346      case 0x08/8:    /* CHANNEL 0 RIGHT */
1249         if (LOG_COMMANDS && eslog)
1250            fprintf(eslog, "Channel 0 right test write %08x\n", data);
1347         if (LOG_COMMANDS && m_eslog)
1348            fprintf(m_eslog, "Channel 0 right test write %08x\n", data);
12511349         break;
12521350
12531351      case 0x10/8:    /* CHANNEL 1 LEFT */
1254         if (LOG_COMMANDS && eslog)
1255            fprintf(eslog, "Channel 1 left test write %08x\n", data);
1352         if (LOG_COMMANDS && m_eslog)
1353            fprintf(m_eslog, "Channel 1 left test write %08x\n", data);
12561354         break;
12571355
12581356      case 0x18/8:    /* CHANNEL 1 RIGHT */
1259         if (LOG_COMMANDS && eslog)
1260            fprintf(eslog, "Channel 1 right test write %08x\n", data);
1357         if (LOG_COMMANDS && m_eslog)
1358            fprintf(m_eslog, "Channel 1 right test write %08x\n", data);
12611359         break;
12621360
12631361      case 0x20/8:    /* CHANNEL 2 LEFT */
1264         if (LOG_COMMANDS && eslog)
1265            fprintf(eslog, "Channel 2 left test write %08x\n", data);
1362         if (LOG_COMMANDS && m_eslog)
1363            fprintf(m_eslog, "Channel 2 left test write %08x\n", data);
12661364         break;
12671365
12681366      case 0x28/8:    /* CHANNEL 2 RIGHT */
1269         if (LOG_COMMANDS && eslog)
1270            fprintf(eslog, "Channel 2 right test write %08x\n", data);
1367         if (LOG_COMMANDS && m_eslog)
1368            fprintf(m_eslog, "Channel 2 right test write %08x\n", data);
12711369         break;
12721370
12731371      case 0x30/8:    /* CHANNEL 3 LEFT */
1274         if (LOG_COMMANDS && eslog)
1275            fprintf(eslog, "Channel 3 left test write %08x\n", data);
1372         if (LOG_COMMANDS && m_eslog)
1373            fprintf(m_eslog, "Channel 3 left test write %08x\n", data);
12761374         break;
12771375
12781376      case 0x38/8:    /* CHANNEL 3 RIGHT */
1279         if (LOG_COMMANDS && eslog)
1280            fprintf(eslog, "Channel 3 right test write %08x\n", data);
1377         if (LOG_COMMANDS && m_eslog)
1378            fprintf(m_eslog, "Channel 3 right test write %08x\n", data);
12811379         break;
12821380
12831381      case 0x40/8:    /* CHANNEL 4 LEFT */
1284         if (LOG_COMMANDS && eslog)
1285            fprintf(eslog, "Channel 4 left test write %08x\n", data);
1382         if (LOG_COMMANDS && m_eslog)
1383            fprintf(m_eslog, "Channel 4 left test write %08x\n", data);
12861384         break;
12871385
12881386      case 0x48/8:    /* CHANNEL 4 RIGHT */
1289         if (LOG_COMMANDS && eslog)
1290            fprintf(eslog, "Channel 4 right test write %08x\n", data);
1387         if (LOG_COMMANDS && m_eslog)
1388            fprintf(m_eslog, "Channel 4 right test write %08x\n", data);
12911389         break;
12921390
12931391      case 0x50/8:    /* CHANNEL 5 LEFT */
1294         if (LOG_COMMANDS && eslog)
1295            fprintf(eslog, "Channel 5 left test write %08x\n", data);
1392         if (LOG_COMMANDS && m_eslog)
1393            fprintf(m_eslog, "Channel 5 left test write %08x\n", data);
12961394         break;
12971395
12981396      case 0x58/8:    /* CHANNEL 6 RIGHT */
1299         if (LOG_COMMANDS && eslog)
1300            fprintf(eslog, "Channel 5 right test write %08x\n", data);
1397         if (LOG_COMMANDS && m_eslog)
1398            fprintf(m_eslog, "Channel 5 right test write %08x\n", data);
13011399         break;
13021400
13031401      case 0x60/8:    /* EMPTY */
1304         if (LOG_COMMANDS && eslog)
1305            fprintf(eslog, "Test write EMPTY %08x\n", data);
1402         if (LOG_COMMANDS && m_eslog)
1403            fprintf(m_eslog, "Test write EMPTY %08x\n", data);
13061404         break;
13071405
13081406      case 0x68/8:    /* PAR - read only */
r26107r26108
13101408         break;
13111409
13121410      case 0x78/8:    /* PAGE */
1313         chip->current_page = data & 0x7f;
1411         m_current_page = data & 0x7f;
13141412         break;
13151413   }
13161414}
13171415
1318WRITE8_DEVICE_HANDLER( es5506_w )
1416WRITE8_MEMBER( es5506_device::write )
13191417{
1320   es5506_state *chip = get_safe_token(device);
1321   es5506_voice *voice = &chip->voice[chip->current_page & 0x1f];
1418   es550x_voice *voice = &m_voice[m_current_page & 0x1f];
13221419   int shift = 8 * (offset & 3);
13231420
13241421   /* accumulate the data */
1325   chip->write_latch = (chip->write_latch & ~(0xff000000 >> shift)) | (data << (24 - shift));
1422   m_write_latch = (m_write_latch & ~(0xff000000 >> shift)) | (data << (24 - shift));
13261423
13271424   /* wait for a write to complete */
13281425   if (shift != 24)
13291426      return;
13301427
13311428   /* force an update */
1332   chip->stream->update();
1429   m_stream->update();
13331430
13341431   /* switch off the page and register */
1335   if (chip->current_page < 0x20)
1336      es5506_reg_write_low(chip, voice, offset / 4, chip->write_latch);
1337   else if (chip->current_page < 0x40)
1338      es5506_reg_write_high(chip, voice, offset / 4, chip->write_latch);
1432   if (m_current_page < 0x20)
1433      reg_write_low(voice, offset / 4, m_write_latch);
1434   else if (m_current_page < 0x40)
1435      reg_write_high(voice, offset / 4, m_write_latch);
13391436   else
1340      es5506_reg_write_test(chip, voice, offset / 4, chip->write_latch);
1437      reg_write_test(voice, offset / 4, m_write_latch);
13411438
13421439   /* clear the write latch when done */
1343   chip->write_latch = 0;
1440   m_write_latch = 0;
13441441}
13451442
13461443
13471444
13481445/**********************************************************************************************
13491446
1350     es5506_reg_read -- read from the specified ES5506 register
1447     reg_read -- read from the specified ES5506 register
13511448
13521449***********************************************************************************************/
13531450
1354INLINE UINT32 es5506_reg_read_low(es5506_state *chip, es5506_voice *voice, offs_t offset)
1451inline UINT32 es5506_device::reg_read_low(es550x_voice *voice, offs_t offset)
13551452{
13561453   UINT32 result = 0;
13571454
r26107r26108
14021499         break;
14031500
14041501      case 0x58/8:    /* ACTV */
1405         result = chip->active_voices;
1502         result = m_active_voices;
14061503         break;
14071504
14081505      case 0x60/8:    /* MODE */
1409         result = chip->mode;
1506         result = m_mode;
14101507         break;
14111508
14121509      case 0x68/8:    /* PAR */
1413         if (!chip->port_read.isnull())
1414            result = chip->port_read(0);
1510         if (!m_port_read_func.isnull())
1511            result = m_port_read_func(0);
14151512         break;
14161513
14171514      case 0x70/8:    /* IRQV */
1418         result = chip->irqv;
1419         update_internal_irq_state(chip);
1515         result = m_irqv;
1516         update_internal_irq_state();
14201517         break;
14211518
14221519      case 0x78/8:    /* PAGE */
1423         result = chip->current_page;
1520         result = m_current_page;
14241521         break;
14251522   }
14261523   return result;
14271524}
14281525
14291526
1430INLINE UINT32 es5506_reg_read_high(es5506_state *chip, es5506_voice *voice, offs_t offset)
1527inline UINT32 es5506_device::reg_read_high(es550x_voice *voice, offs_t offset)
14311528{
14321529   UINT32 result = 0;
14331530
r26107r26108
14741571         break;
14751572
14761573      case 0x50/8:    /* W_ST */
1477         result = chip->wst;
1574         result = m_wst;
14781575         break;
14791576
14801577      case 0x58/8:    /* W_END */
1481         result = chip->wend;
1578         result = m_wend;
14821579         break;
14831580
14841581      case 0x60/8:    /* LR_END */
1485         result = chip->lrend;
1582         result = m_lrend;
14861583         break;
14871584
14881585      case 0x68/8:    /* PAR */
1489         if (!chip->port_read.isnull())
1490            result = chip->port_read(0);
1586         if (!m_port_read_func.isnull())
1587            result = m_port_read_func(0);
14911588         break;
14921589
14931590      case 0x70/8:    /* IRQV */
1494         result = chip->irqv;
1495         update_internal_irq_state(chip);
1591         result = m_irqv;
1592         update_internal_irq_state();
14961593         break;
14971594
14981595      case 0x78/8:    /* PAGE */
1499         result = chip->current_page;
1596         result = m_current_page;
15001597         break;
15011598   }
15021599   return result;
15031600}
1504
1505INLINE UINT32 es5506_reg_read_test(es5506_state *chip, es5506_voice *voice, offs_t offset)
1601inline UINT32 es5506_device::reg_read_test(es550x_voice *voice, offs_t offset)
15061602{
15071603   UINT32 result = 0;
15081604
15091605   switch (offset)
15101606   {
15111607      case 0x68/8:    /* PAR */
1512         if (!chip->port_read.isnull())
1513            result = chip->port_read(0);
1608         if (!m_port_read_func.isnull())
1609            result = m_port_read_func(0);
15141610         break;
15151611
15161612      case 0x70/8:    /* IRQV */
1517         result = chip->irqv;
1613         result = m_irqv;
15181614         break;
15191615
15201616      case 0x78/8:    /* PAGE */
1521         result = chip->current_page;
1617         result = m_current_page;
15221618         break;
15231619   }
15241620   return result;
15251621}
15261622
1527READ8_DEVICE_HANDLER( es5506_r )
1623READ8_MEMBER( es5506_device::read )
15281624{
1529   es5506_state *chip = get_safe_token(device);
1530   es5506_voice *voice = &chip->voice[chip->current_page & 0x1f];
1625   es550x_voice *voice = &m_voice[m_current_page & 0x1f];
15311626   int shift = 8 * (offset & 3);
15321627
15331628   /* only read on offset 0 */
15341629   if (shift != 0)
1535      return chip->read_latch >> (24 - shift);
1630      return m_read_latch >> (24 - shift);
15361631
1537   if (LOG_COMMANDS && eslog)
1538      fprintf(eslog, "read from %02x/%02x -> ", chip->current_page, offset / 4 * 8);
1632   if (LOG_COMMANDS && m_eslog)
1633      fprintf(m_eslog, "read from %02x/%02x -> ", m_current_page, offset / 4 * 8);
15391634
15401635   /* force an update */
1541   chip->stream->update();
1636   m_stream->update();
15421637
15431638   /* switch off the page and register */
1544   if (chip->current_page < 0x20)
1545      chip->read_latch = es5506_reg_read_low(chip, voice, offset / 4);
1546   else if (chip->current_page < 0x40)
1547      chip->read_latch = es5506_reg_read_high(chip, voice, offset / 4);
1639   if (m_current_page < 0x20)
1640      m_read_latch = reg_read_low(voice, offset / 4);
1641   else if (m_current_page < 0x40)
1642      m_read_latch = reg_read_high(voice, offset / 4);
15481643   else
1549      chip->read_latch = es5506_reg_read_test(chip, voice, offset / 4);
1644      m_read_latch = reg_read_test(voice, offset / 4);
15501645
1551   if (LOG_COMMANDS && eslog)
1552      fprintf(eslog, "%08x\n", chip->read_latch);
1646   if (LOG_COMMANDS && m_eslog)
1647      fprintf(m_eslog, "%08x\n", m_read_latch);
15531648
15541649   /* return the high byte */
1555   return chip->read_latch >> 24;
1650   return m_read_latch >> 24;
15561651}
15571652
15581653
15591654
1560void es5506_voice_bank_w(device_t *device, int voice, int bank)
1655void es5506_device::voice_bank_w(int voice, int bank)
15611656{
1562   es5506_state *chip = get_safe_token(device);
1563   chip->voice[voice].exbank=bank;
1657   m_voice[voice].exbank=bank;
15641658}
15651659
15661660
15671661/**********************************************************************************************
15681662
1569     DEVICE_START( es5505 ) -- start emulation of the ES5505
1663     reg_write -- handle a write to the selected ES5505 register
15701664
15711665***********************************************************************************************/
15721666
1573static DEVICE_START( es5505 )
1667inline void es5505_device::reg_write_low(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask)
15741668{
1575   const es5505_interface *intf = (const es5505_interface *)device->static_config();
1576   es5506_interface es5506intf;
1577   int channels = 1;  /* 1 channel by default, for backward compatibility */
1578
1579   /* only override the number of channels if the value is in the valid range 1 .. 4 */
1580   if (1 <= intf->channels && intf->channels <= 4)
1581      channels = intf->channels;
1582
1583   memset(&es5506intf, 0, sizeof(es5506intf));
1584
1585   es5506intf.region0 = intf->region0;
1586   es5506intf.region1 = intf->region1;
1587   es5506intf.channels = channels;
1588   es5506intf.irq_callback = intf->irq_callback;
1589   es5506intf.read_port = intf->read_port;
1590
1591   es5506_start_common(device, &es5506intf, ES5505);
1592}
1593
1594
1595/**********************************************************************************************
1596
1597     es5505_reg_write -- handle a write to the selected ES5505 register
1598
1599***********************************************************************************************/
1600
1601INLINE void es5505_reg_write_low(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask)
1602{
1603   running_machine &machine = chip->device->machine();
1604
16051669   switch (offset)
16061670   {
16071671      case 0x00:  /* CR */
r26107r26108
16221686                           ((data << 2) & (CONTROL_CA0 | CONTROL_CA1));
16231687         }
16241688
1625         if (LOG_COMMANDS && eslog)
1626            fprintf(eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine.describe_context(), chip->current_page & 0x1f, voice->control, data, mem_mask ^ 0xffff);
1689         if (LOG_COMMANDS && m_eslog)
1690            fprintf(m_eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine().describe_context(), m_current_page & 0x1f, voice->control, data, mem_mask ^ 0xffff);
16271691         break;
16281692
16291693      case 0x01:  /* FC */
r26107r26108
16311695            voice->freqcount = (voice->freqcount & ~0x001fe) | ((data & 0x00ff) << 1);
16321696         if (ACCESSING_BITS_8_15)
16331697            voice->freqcount = (voice->freqcount & ~0x1fe00) | ((data & 0xff00) << 1);
1634         if (LOG_COMMANDS && eslog)
1635            fprintf(eslog, "%s:voice %d, freq count=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->freqcount);
1698         if (LOG_COMMANDS && m_eslog)
1699            fprintf(m_eslog, "%s:voice %d, freq count=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->freqcount);
16361700         break;
16371701
16381702      case 0x02:  /* STRT (hi) */
r26107r26108
16401704            voice->start = (voice->start & ~0x03fc0000) | ((data & 0x00ff) << 18);
16411705         if (ACCESSING_BITS_8_15)
16421706            voice->start = (voice->start & ~0x7c000000) | ((data & 0x1f00) << 18);
1643         if (LOG_COMMANDS && eslog)
1644            fprintf(eslog, "%s:voice %d, loop start=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->start);
1707         if (LOG_COMMANDS && m_eslog)
1708            fprintf(m_eslog, "%s:voice %d, loop start=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->start);
16451709         break;
16461710
16471711      case 0x03:  /* STRT (lo) */
r26107r26108
16491713            voice->start = (voice->start & ~0x00000380) | ((data & 0x00e0) << 2);
16501714         if (ACCESSING_BITS_8_15)
16511715            voice->start = (voice->start & ~0x0003fc00) | ((data & 0xff00) << 2);
1652         if (LOG_COMMANDS && eslog)
1653            fprintf(eslog, "%s:voice %d, loop start=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->start);
1716         if (LOG_COMMANDS && m_eslog)
1717            fprintf(m_eslog, "%s:voice %d, loop start=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->start);
16541718         break;
16551719
16561720      case 0x04:  /* END (hi) */
r26107r26108
16611725#if RAINE_CHECK
16621726         voice->control |= CONTROL_STOP0;
16631727#endif
1664         if (LOG_COMMANDS && eslog)
1665            fprintf(eslog, "%s:voice %d, loop end=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->end);
1728         if (LOG_COMMANDS && m_eslog)
1729            fprintf(m_eslog, "%s:voice %d, loop end=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->end);
16661730         break;
16671731
16681732      case 0x05:  /* END (lo) */
r26107r26108
16731737#if RAINE_CHECK
16741738         voice->control |= CONTROL_STOP0;
16751739#endif
1676         if (LOG_COMMANDS && eslog)
1677            fprintf(eslog, "%s:voice %d, loop end=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->end);
1740         if (LOG_COMMANDS && m_eslog)
1741            fprintf(m_eslog, "%s:voice %d, loop end=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->end);
16781742         break;
16791743
16801744      case 0x06:  /* K2 */
r26107r26108
16821746            voice->k2 = (voice->k2 & ~0x00f0) | (data & 0x00f0);
16831747         if (ACCESSING_BITS_8_15)
16841748            voice->k2 = (voice->k2 & ~0xff00) | (data & 0xff00);
1685         if (LOG_COMMANDS && eslog)
1686            fprintf(eslog, "%s:voice %d, K2=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->k2);
1749         if (LOG_COMMANDS && m_eslog)
1750            fprintf(m_eslog, "%s:voice %d, K2=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->k2);
16871751         break;
16881752
16891753      case 0x07:  /* K1 */
r26107r26108
16911755            voice->k1 = (voice->k1 & ~0x00f0) | (data & 0x00f0);
16921756         if (ACCESSING_BITS_8_15)
16931757            voice->k1 = (voice->k1 & ~0xff00) | (data & 0xff00);
1694         if (LOG_COMMANDS && eslog)
1695            fprintf(eslog, "%s:voice %d, K1=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->k1);
1758         if (LOG_COMMANDS && m_eslog)
1759            fprintf(m_eslog, "%s:voice %d, K1=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->k1);
16961760         break;
16971761
16981762      case 0x08:  /* LVOL */
16991763         if (ACCESSING_BITS_8_15)
17001764            voice->lvol = (voice->lvol & ~0xff00) | (data & 0xff00);
1701         if (LOG_COMMANDS && eslog)
1702            fprintf(eslog, "%s:voice %d, left vol=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->lvol);
1765         if (LOG_COMMANDS && m_eslog)
1766            fprintf(m_eslog, "%s:voice %d, left vol=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->lvol);
17031767         break;
17041768
17051769      case 0x09:  /* RVOL */
17061770         if (ACCESSING_BITS_8_15)
17071771            voice->rvol = (voice->rvol & ~0xff00) | (data & 0xff00);
1708         if (LOG_COMMANDS && eslog)
1709            fprintf(eslog, "%s:voice %d, right vol=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->rvol);
1772         if (LOG_COMMANDS && m_eslog)
1773            fprintf(m_eslog, "%s:voice %d, right vol=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->rvol);
17101774         break;
17111775
17121776      case 0x0a:  /* ACC (hi) */
r26107r26108
17141778            voice->accum = (voice->accum & ~0x03fc0000) | ((data & 0x00ff) << 18);
17151779         if (ACCESSING_BITS_8_15)
17161780            voice->accum = (voice->accum & ~0x7c000000) | ((data & 0x1f00) << 18);
1717         if (LOG_COMMANDS && eslog)
1718            fprintf(eslog, "%s:voice %d, accum=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->accum);
1781         if (LOG_COMMANDS && m_eslog)
1782            fprintf(m_eslog, "%s:voice %d, accum=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->accum);
17191783         break;
17201784
17211785      case 0x0b:  /* ACC (lo) */
r26107r26108
17231787            voice->accum = (voice->accum & ~0x000003fc) | ((data & 0x00ff) << 2);
17241788         if (ACCESSING_BITS_8_15)
17251789            voice->accum = (voice->accum & ~0x0003fc00) | ((data & 0xff00) << 2);
1726         if (LOG_COMMANDS && eslog)
1727            fprintf(eslog, "%s:voice %d, accum=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->accum);
1790         if (LOG_COMMANDS && m_eslog)
1791            fprintf(m_eslog, "%s:voice %d, accum=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->accum);
17281792         break;
17291793
17301794      case 0x0c:  /* unused */
r26107r26108
17331797      case 0x0d:  /* ACT */
17341798         if (ACCESSING_BITS_0_7)
17351799         {
1736            chip->active_voices = data & 0x1f;
1737            chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1));
1738            chip->stream->set_sample_rate(chip->sample_rate);
1800            m_active_voices = data & 0x1f;
1801            m_sample_rate = m_master_clock / (16 * (m_active_voices + 1));
1802            m_stream->set_sample_rate(m_sample_rate);
17391803
1740            if (LOG_COMMANDS && eslog)
1741               fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate);
1804            if (LOG_COMMANDS && m_eslog)
1805               fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate);
17421806         }
17431807         break;
17441808
r26107r26108
17471811
17481812      case 0x0f:  /* PAGE */
17491813         if (ACCESSING_BITS_0_7)
1750            chip->current_page = data & 0x7f;
1814            m_current_page = data & 0x7f;
17511815         break;
17521816   }
17531817}
17541818
17551819
1756INLINE void es5505_reg_write_high(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask)
1820inline void es5505_device::reg_write_high(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask)
17571821{
1758   running_machine &machine = chip->device->machine();
1759
17601822   switch (offset)
17611823   {
17621824      case 0x00:  /* CR */
r26107r26108
17721834            voice->control |= ((data >> 2) & CONTROL_LPMASK) |
17731835                           ((data << 2) & (CONTROL_CA0 | CONTROL_CA1));
17741836         }
1775         if (LOG_COMMANDS && eslog)
1776            fprintf(eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine.describe_context(), chip->current_page & 0x1f, voice->control, data, mem_mask);
1837         if (LOG_COMMANDS && m_eslog)
1838            fprintf(m_eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine().describe_context(), m_current_page & 0x1f, voice->control, data, mem_mask);
17771839         break;
17781840
17791841      case 0x01:  /* O4(n-1) */
r26107r26108
17811843            voice->o4n1 = (voice->o4n1 & ~0x00ff) | (data & 0x00ff);
17821844         if (ACCESSING_BITS_8_15)
17831845            voice->o4n1 = (INT16)((voice->o4n1 & ~0xff00) | (data & 0xff00));
1784         if (LOG_COMMANDS && eslog)
1785            fprintf(eslog, "%s:voice %d, O4(n-1)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o4n1 & 0x3ffff);
1846         if (LOG_COMMANDS && m_eslog)
1847            fprintf(m_eslog, "%s:voice %d, O4(n-1)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o4n1 & 0x3ffff);
17861848         break;
17871849
17881850      case 0x02:  /* O3(n-1) */
r26107r26108
17901852            voice->o3n1 = (voice->o3n1 & ~0x00ff) | (data & 0x00ff);
17911853         if (ACCESSING_BITS_8_15)
17921854            voice->o3n1 = (INT16)((voice->o3n1 & ~0xff00) | (data & 0xff00));
1793         if (LOG_COMMANDS && eslog)
1794            fprintf(eslog, "%s:voice %d, O3(n-1)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o3n1 & 0x3ffff);
1855         if (LOG_COMMANDS && m_eslog)
1856            fprintf(m_eslog, "%s:voice %d, O3(n-1)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o3n1 & 0x3ffff);
17951857         break;
17961858
17971859      case 0x03:  /* O3(n-2) */
r26107r26108
17991861            voice->o3n2 = (voice->o3n2 & ~0x00ff) | (data & 0x00ff);
18001862         if (ACCESSING_BITS_8_15)
18011863            voice->o3n2 = (INT16)((voice->o3n2 & ~0xff00) | (data & 0xff00));
1802         if (LOG_COMMANDS && eslog)
1803            fprintf(eslog, "%s:voice %d, O3(n-2)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o3n2 & 0x3ffff);
1864         if (LOG_COMMANDS && m_eslog)
1865            fprintf(m_eslog, "%s:voice %d, O3(n-2)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o3n2 & 0x3ffff);
18041866         break;
18051867
18061868      case 0x04:  /* O2(n-1) */
r26107r26108
18081870            voice->o2n1 = (voice->o2n1 & ~0x00ff) | (data & 0x00ff);
18091871         if (ACCESSING_BITS_8_15)
18101872            voice->o2n1 = (INT16)((voice->o2n1 & ~0xff00) | (data & 0xff00));
1811         if (LOG_COMMANDS && eslog)
1812            fprintf(eslog, "%s:voice %d, O2(n-1)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o2n1 & 0x3ffff);
1873         if (LOG_COMMANDS && m_eslog)
1874            fprintf(m_eslog, "%s:voice %d, O2(n-1)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o2n1 & 0x3ffff);
18131875         break;
18141876
18151877      case 0x05:  /* O2(n-2) */
r26107r26108
18171879            voice->o2n2 = (voice->o2n2 & ~0x00ff) | (data & 0x00ff);
18181880         if (ACCESSING_BITS_8_15)
18191881            voice->o2n2 = (INT16)((voice->o2n2 & ~0xff00) | (data & 0xff00));
1820         if (LOG_COMMANDS && eslog)
1821            fprintf(eslog, "%s:voice %d, O2(n-2)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o2n2 & 0x3ffff);
1882         if (LOG_COMMANDS && m_eslog)
1883            fprintf(m_eslog, "%s:voice %d, O2(n-2)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o2n2 & 0x3ffff);
18221884         break;
18231885
18241886      case 0x06:  /* O1(n-1) */
r26107r26108
18261888            voice->o1n1 = (voice->o1n1 & ~0x00ff) | (data & 0x00ff);
18271889         if (ACCESSING_BITS_8_15)
18281890            voice->o1n1 = (INT16)((voice->o1n1 & ~0xff00) | (data & 0xff00));
1829         if (LOG_COMMANDS && eslog)
1830            fprintf(eslog, "%s:voice %d, O1(n-1)=%05x (accum=%08x)\n", machine.describe_context(), chip->current_page & 0x1f, voice->o2n1 & 0x3ffff, voice->accum);
1891         if (LOG_COMMANDS && m_eslog)
1892            fprintf(m_eslog, "%s:voice %d, O1(n-1)=%05x (accum=%08x)\n", machine().describe_context(), m_current_page & 0x1f, voice->o2n1 & 0x3ffff, voice->accum);
18311893         break;
18321894
18331895      case 0x07:
r26107r26108
18411903      case 0x0d:  /* ACT */
18421904         if (ACCESSING_BITS_0_7)
18431905         {
1844            chip->active_voices = data & 0x1f;
1845            chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1));
1846            chip->stream->set_sample_rate(chip->sample_rate);
1906            m_active_voices = data & 0x1f;
1907            m_sample_rate = m_master_clock / (16 * (m_active_voices + 1));
1908            m_stream->set_sample_rate(m_sample_rate);
18471909
1848            if (LOG_COMMANDS && eslog)
1849               fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate);
1910            if (LOG_COMMANDS && m_eslog)
1911               fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate);
18501912         }
18511913         break;
18521914
r26107r26108
18551917
18561918      case 0x0f:  /* PAGE */
18571919         if (ACCESSING_BITS_0_7)
1858            chip->current_page = data & 0x7f;
1920            m_current_page = data & 0x7f;
18591921         break;
18601922   }
18611923}
18621924
18631925
1864INLINE void es5505_reg_write_test(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask)
1926inline void es5505_device::reg_write_test(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask)
18651927{
18661928   switch (offset)
18671929   {
r26107r26108
18761938         break;
18771939
18781940      case 0x08:  /* SERMODE */
1879         chip->mode = data & 0x0007;
1941         m_mode = data & 0x0007;
18801942         break;
18811943
18821944      case 0x09:  /* PAR */
r26107r26108
18851947      case 0x0d:  /* ACT */
18861948         if (ACCESSING_BITS_0_7)
18871949         {
1888            chip->active_voices = data & 0x1f;
1889            chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1));
1890            chip->stream->set_sample_rate(chip->sample_rate);
1950            m_active_voices = data & 0x1f;
1951            m_sample_rate = m_master_clock / (16 * (m_active_voices + 1));
1952            m_stream->set_sample_rate(m_sample_rate);
18911953
1892            if (LOG_COMMANDS && eslog)
1893               fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate);
1954            if (LOG_COMMANDS && m_eslog)
1955               fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate);
18941956         }
18951957         break;
18961958
r26107r26108
18991961
19001962      case 0x0f:  /* PAGE */
19011963         if (ACCESSING_BITS_0_7)
1902            chip->current_page = data & 0x7f;
1964            m_current_page = data & 0x7f;
19031965         break;
19041966   }
19051967}
19061968
19071969
1908WRITE16_DEVICE_HANDLER( es5505_w )
1970WRITE16_MEMBER( es5505_device::write )
19091971{
1910   es5506_state *chip = get_safe_token(device);
1911   es5506_voice *voice = &chip->voice[chip->current_page & 0x1f];
1972   es550x_voice *voice = &m_voice[m_current_page & 0x1f];
19121973
1913//  logerror("%s:ES5505 write %02x/%02x = %04x & %04x\n", machine.describe_context(), chip->current_page, offset, data, mem_mask);
1974//  logerror("%s:ES5505 write %02x/%02x = %04x & %04x\n", machine().describe_context(), m_current_page, offset, data, mem_mask);
19141975
19151976   /* force an update */
1916   chip->stream->update();
1977   m_stream->update();
19171978
19181979   /* switch off the page and register */
1919   if (chip->current_page < 0x20)
1920      es5505_reg_write_low(chip, voice, offset, data, mem_mask);
1921   else if (chip->current_page < 0x40)
1922      es5505_reg_write_high(chip, voice, offset, data, mem_mask);
1980   if (m_current_page < 0x20)
1981      reg_write_low(voice, offset, data, mem_mask);
1982   else if (m_current_page < 0x40)
1983      reg_write_high(voice, offset, data, mem_mask);
19231984   else
1924      es5505_reg_write_test(chip, voice, offset, data, mem_mask);
1985      reg_write_test(voice, offset, data, mem_mask);
19251986}
19261987
19271988
19281989
19291990/**********************************************************************************************
19301991
1931     es5505_reg_read -- read from the specified ES5505 register
1992     reg_read -- read from the specified ES5505 register
19321993
19331994***********************************************************************************************/
19341995
1935INLINE UINT16 es5505_reg_read_low(es5506_state *chip, es5506_voice *voice, offs_t offset)
1996inline UINT16 es5505_device::reg_read_low(es550x_voice *voice, offs_t offset)
19361997{
19371998   UINT16 result = 0;
19381999
r26107r26108
19942055         break;
19952056
19962057      case 0x0d:  /* ACT */
1997         result = chip->active_voices;
2058         result = m_active_voices;
19982059         break;
19992060
20002061      case 0x0e:  /* IRQV */
2001         result = chip->irqv;
2002         update_internal_irq_state(chip);
2062         result = m_irqv;
2063         update_internal_irq_state();
20032064         break;
20042065
20052066      case 0x0f:  /* PAGE */
2006         result = chip->current_page;
2067         result = m_current_page;
20072068         break;
20082069   }
20092070   return result;
20102071}
20112072
20122073
2013INLINE UINT16 es5505_reg_read_high(es5506_state *chip, es5506_voice *voice, offs_t offset)
2074inline UINT16 es5505_device::reg_read_high(es550x_voice *voice, offs_t offset)
20142075{
20152076   UINT16 result = 0;
20162077
r26107r26108
20512112         /* want to waste time filtering stopped channels, we just look for a read from */
20522113         /* this register on a stopped voice, and return the raw sample data at the */
20532114         /* accumulator */
2054         if ((voice->control & CONTROL_STOPMASK) && chip->region_base[voice->control >> 14])
2115         if ((voice->control & CONTROL_STOPMASK) && m_region_base[voice->control >> 14])
20552116         {
2056            voice->o1n1 = chip->region_base[voice->control >> 14][voice->exbank + (voice->accum >> 11)];
2117            voice->o1n1 = m_region_base[voice->control >> 14][voice->exbank + (voice->accum >> 11)];
20572118            // logerror("%02x %08x ==> %08x\n",voice->o1n1,voice->control >> 14,voice->exbank + (voice->accum >> 11));
20582119         }
20592120         result = voice->o1n1;
r26107r26108
20682129         break;
20692130
20702131      case 0x0d:  /* ACT */
2071         result = chip->active_voices;
2132         result = m_active_voices;
20722133         break;
20732134
20742135      case 0x0e:  /* IRQV */
2075         result = chip->irqv;
2076         update_internal_irq_state(chip);
2136         result = m_irqv;
2137         update_internal_irq_state();
20772138         break;
20782139
20792140      case 0x0f:  /* PAGE */
2080         result = chip->current_page;
2141         result = m_current_page;
20812142         break;
20822143   }
20832144   return result;
20842145}
20852146
20862147
2087INLINE UINT16 es5505_reg_read_test(es5506_state *chip, es5506_voice *voice, offs_t offset)
2148inline UINT16 es5505_device::reg_read_test(es550x_voice *voice, offs_t offset)
20882149{
20892150   UINT16 result = 0;
20902151
r26107r26108
21012162         break;
21022163
21032164      case 0x08:  /* SERMODE */
2104         result = chip->mode;
2165         result = m_mode;
21052166         break;
21062167
21072168      case 0x09:  /* PAR */
2108         if (!chip->port_read.isnull())
2109            result = chip->port_read(0);
2169         if (!m_port_read_func.isnull())
2170            result = m_port_read_func(0);
21102171         break;
21112172
21122173      case 0x0f:  /* PAGE */
2113         result = chip->current_page;
2174         result = m_current_page;
21142175         break;
21152176   }
21162177   return result;
21172178}
21182179
21192180
2120READ16_DEVICE_HANDLER( es5505_r )
2181READ16_MEMBER( es5505_device::read )
21212182{
2122   es5506_state *chip = get_safe_token(device);
2123   es5506_voice *voice = &chip->voice[chip->current_page & 0x1f];
2183   es550x_voice *voice = &m_voice[m_current_page & 0x1f];
21242184   UINT16 result = 0;
21252185
2126   if (LOG_COMMANDS && eslog)
2127      fprintf(eslog, "read from %02x/%02x -> ", chip->current_page, offset);
2186   if (LOG_COMMANDS && m_eslog)
2187      fprintf(m_eslog, "read from %02x/%02x -> ", m_current_page, offset);
21282188
21292189   /* force an update */
2130   chip->stream->update();
2190   m_stream->update();
21312191
21322192   /* switch off the page and register */
2133   if (chip->current_page < 0x20)
2134      result = es5505_reg_read_low(chip, voice, offset);
2135   else if (chip->current_page < 0x40)
2136      result = es5505_reg_read_high(chip, voice, offset);
2193   if (m_current_page < 0x20)
2194      result = reg_read_low(voice, offset);
2195   else if (m_current_page < 0x40)
2196      result = reg_read_high(voice, offset);
21372197   else
2138      result = es5505_reg_read_test(chip, voice, offset);
2198      result = reg_read_test(voice, offset);
21392199
2140   if (LOG_COMMANDS && eslog)
2141      fprintf(eslog, "%04x (accum=%08x)\n", result, voice->accum);
2200   if (LOG_COMMANDS && m_eslog)
2201      fprintf(m_eslog, "%04x (accum=%08x)\n", result, voice->accum);
21422202
21432203   /* return the high byte */
21442204   return result;
r26107r26108
21462206
21472207
21482208
2149void es5505_voice_bank_w(device_t *device, int voice, int bank)
2209void es5505_device::voice_bank_w(int voice, int bank)
21502210{
2151   es5506_state *chip = get_safe_token(device);
2211   
21522212#if RAINE_CHECK
2153   chip->voice[voice].control = CONTROL_STOPMASK;
2213   m_voice[voice].control = CONTROL_STOPMASK;
21542214#endif
2155   chip->voice[voice].exbank=bank;
2215   m_voice[voice].exbank=bank;
21562216}
21572217
2158const device_type ES5506 = &device_creator<es5506_device>;
21592218
2160es5506_device::es5506_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
2161   : device_t(mconfig, ES5506, "ES5506", tag, owner, clock, "es5506", __FILE__),
2162      device_sound_interface(mconfig, *this)
2163{
2164   m_token = global_alloc_clear(es5506_state);
2165}
2166
2167es5506_device::es5506_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source)
2168   : device_t(mconfig, type, name, tag, owner, clock, shortname, source),
2169      device_sound_interface(mconfig, *this)
2170{
2171   m_token = global_alloc_clear(es5506_state);
2172}
2173
21742219//-------------------------------------------------
2175//  device_config_complete - perform any
2176//  operations now that the configuration is
2177//  complete
2220//  sound_stream_update - handle a stream update
21782221//-------------------------------------------------
21792222
2180void es5506_device::device_config_complete()
2223void es550x_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
21812224{
21822225}
21832226
2184//-------------------------------------------------
2185//  device_start - device-specific startup
2186//-------------------------------------------------
2187
2188void es5506_device::device_start()
2227void es5506_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
21892228{
2190   DEVICE_START_NAME( es5506 )(this);
2191}
2229     
2230#if MAKE_WAVS
2231   /* start the logging once we have a sample rate */
2232   if (m_sample_rate)
2233   {
2234      if (!m_wavraw)
2235         m_wavraw = wav_open("raw.wav", m_sample_rate, 2);
2236   }
2237#endif
21922238
2193//-------------------------------------------------
2194//  device_reset - device-specific reset
2195//-------------------------------------------------
2239   /* loop until all samples are output */
2240   int offset = 0;
2241   while (samples)
2242   {
2243      int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples;
21962244
2197void es5506_device::device_reset()
2198{
2199}
2245      generate_samples(outputs, offset, length);
22002246
2201//-------------------------------------------------
2202//  device_stop - device-specific stop
2203//-------------------------------------------------
2247#if MAKE_WAVS
2248      /* log the raw data */
2249      if (m_wavraw) {
2250         /* determine left/right source data */
2251         INT32 *lsrc = m_scratch, *rsrc = m_scratch + length;
2252         int channel;
2253         memset(lsrc, 0, sizeof(INT32) * length * 2);
2254         /* loop over the output channels */
2255         for (channel = 0; channel < m_channels; channel++) {
2256            INT32 *l = outputs[(channel << 1)] + offset;
2257            INT32 *r = outputs[(channel << 1) + 1] + offset;
2258            /* add the current channel's samples to the WAV data */
2259            for (samp = 0; samp < length; samp++) {
2260               lsrc[samp] += l[samp];
2261               rsrc[samp] += r[samp];
2262            }
2263         }
2264         wav_add_data_32lr(m_wavraw, lsrc, rsrc, length, 4);
2265      }
2266#endif
22042267
2205void es5506_device::device_stop()
2206{
2207   DEVICE_STOP_NAME( es5506 )(this);
2268      /* account for these samples */
2269      offset += length;
2270      samples -= length;
2271   }
22082272}
22092273
2210//-------------------------------------------------
2211//  sound_stream_update - handle a stream update
2212//-------------------------------------------------
2213
2214void es5506_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
2274void es5505_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
22152275{
2216   // should never get here
2217   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
2218}
2276     
2277#if MAKE_WAVS
2278   /* start the logging once we have a sample rate */
2279   if (m_sample_rate)
2280   {
2281      if (!m_wavraw)
2282         m_wavraw = wav_open("raw.wav", m_sample_rate, 2);
2283   }
2284#endif
22192285
2220const device_type ES5505 = &device_creator<es5505_device>;
2286   /* loop until all samples are output */
2287   int offset = 0;
2288   while (samples)
2289   {
2290      int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples;
22212291
2222es5505_device::es5505_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
2223   : es5506_device(mconfig, ES5505, "ES5505", tag, owner, clock, "es5505", __FILE__)
2224{
2225}
2292      generate_samples(outputs, offset, length);
22262293
2227//-------------------------------------------------
2228//  device_start - device-specific startup
2229//-------------------------------------------------
2294#if MAKE_WAVS
2295      /* log the raw data */
2296      if (m_wavraw) {
2297         /* determine left/right source data */
2298         INT32 *lsrc = m_scratch, *rsrc = m_scratch + length;
2299         int channel;
2300         memset(lsrc, 0, sizeof(INT32) * length * 2);
2301         /* loop over the output channels */
2302         for (channel = 0; channel < m_channels; channel++) {
2303            INT32 *l = outputs[(channel << 1)] + offset;
2304            INT32 *r = outputs[(channel << 1) + 1] + offset;
2305            /* add the current channel's samples to the WAV data */
2306            for (samp = 0; samp < length; samp++) {
2307               lsrc[samp] += l[samp];
2308               rsrc[samp] += r[samp];
2309            }
2310         }
2311         wav_add_data_32lr(m_wavraw, lsrc, rsrc, length, 4);
2312      }
2313#endif
22302314
2231void es5505_device::device_start()
2232{
2233   DEVICE_START_NAME( es5505 )(this);
2234}
2315      /* account for these samples */
2316      offset += length;
2317      samples -= length;
2318   }
2319}
No newline at end of file
trunk/src/emu/sound/es5506.h
r26107r26108
1212#ifndef __ES5506_H__
1313#define __ES5506_H__
1414
15#define MAKE_WAVS               0
1516
17
1618struct es5505_interface
1719{
18   const char * region0;                       /* memory region where the sample ROM lives */
19   const char * region1;                       /* memory region where the sample ROM lives */
20   int channels;                               /* number of output channels: 1 .. 4 */
21   devcb_write_line irq_callback;  /* irq callback */
22   devcb_read16 read_port;          /* input port read */
20   const char * m_es5505_region0;                       /* memory region where the sample ROM lives */
21   const char * m_es5505_region1;                       /* memory region where the sample ROM lives */
22   int m_es5505_channels;                               /* number of output channels: 1 .. 4 */
23   devcb_write_line m_es5505_irq_callback;  /* irq callback */
24   devcb_read16 m_es5505_read_port;          /* input port read */
2325};
2426
25DECLARE_READ16_DEVICE_HANDLER( es5505_r );
26DECLARE_WRITE16_DEVICE_HANDLER( es5505_w );
27void es5505_voice_bank_w(device_t *device, int voice, int bank);
27struct es5506_interface
28{
29   const char * m_region0;                       /* memory region where the sample ROM lives */
30   const char * m_region1;                       /* memory region where the sample ROM lives */
31   const char * m_region2;                       /* memory region where the sample ROM lives */
32   const char * m_region3;                       /* memory region where the sample ROM lives */
33   int m_channels;                               /* number of output channels: 1 .. 6 */
34   devcb_write_line m_irq_callback;  /* irq callback */
35   devcb_read16 m_read_port;          /* input port read */
36};
2837
29class es5506_device : public device_t,
38/* struct describing a single playing voice */
39
40struct es550x_voice
41{
42      es550x_voice():
43      control(0),
44      freqcount(0),
45      start(0),
46      lvol(0),
47      end(0),
48      lvramp(0),
49      accum(0),
50      rvol(0),
51      rvramp(0),
52      ecount(0),
53      k2(0),
54      k2ramp(0),
55      k1(0),
56      k1ramp(0),
57      o4n1(0),
58      o3n1(0),
59      o3n2(0),
60      o2n1(0),
61      o2n2(0),
62      o1n1(0),
63      exbank(0),
64      index(0),
65      filtcount(0),
66      accum_mask(0) {}
67   
68   /* external state */
69   UINT32      control;                /* control register */
70   UINT32      freqcount;              /* frequency count register */
71   UINT32      start;                  /* start register */
72   UINT32      lvol;                   /* left volume register */
73   UINT32      end;                    /* end register */
74   UINT32      lvramp;                 /* left volume ramp register */
75   UINT32      accum;                  /* accumulator register */
76   UINT32      rvol;                   /* right volume register */
77   UINT32      rvramp;                 /* right volume ramp register */
78   UINT32      ecount;                 /* envelope count register */
79   UINT32      k2;                     /* k2 register */
80   UINT32      k2ramp;                 /* k2 ramp register */
81   UINT32      k1;                     /* k1 register */
82   UINT32      k1ramp;                 /* k1 ramp register */
83   INT32       o4n1;                   /* filter storage O4(n-1) */
84   INT32       o3n1;                   /* filter storage O3(n-1) */
85   INT32       o3n2;                   /* filter storage O3(n-2) */
86   INT32       o2n1;                   /* filter storage O2(n-1) */
87   INT32       o2n2;                   /* filter storage O2(n-2) */
88   INT32       o1n1;                   /* filter storage O1(n-1) */
89   UINT32      exbank;                 /* external address bank */
90
91   /* internal state */
92   UINT8       index;                  /* index of this voice */
93   UINT8       filtcount;              /* filter count */
94   UINT32      accum_mask;
95};
96
97class es550x_device : public device_t,
3098                           public device_sound_interface
3199{
32100public:
33   es5506_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
34   es5506_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
35   ~es5506_device() { global_free(m_token); }
101   es550x_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
102   ~es550x_device() {}
36103
37   // access to legacy token
38   void *token() const { assert(m_token != NULL); return m_token; }
39104protected:
40105   // device-level overrides
41106   virtual void device_config_complete();
r26107r26108
45110
46111   // sound stream update overrides
47112   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
48private:
113
49114   // internal state
50   void *m_token;
115   sound_stream *m_stream;               /* which stream are we using */
116   int         m_sample_rate;            /* current sample rate */
117   UINT16 *    m_region_base[4];         /* pointer to the base of the region */
118   UINT32      m_write_latch;            /* currently accumulated data for write */
119   UINT32      m_read_latch;             /* currently accumulated data for read */
120   UINT32      m_master_clock;           /* master clock frequency */
121   devcb_resolved_write_line m_irq_callback_func;   /* IRQ callback */
122   devcb_resolved_read16     m_port_read_func;       /* input port read */
123
124   UINT8       m_current_page;           /* current register page */
125   UINT8       m_active_voices;          /* number of active voices */
126   UINT8       m_mode;                   /* MODE register */
127   UINT8       m_wst;                    /* W_ST register */
128   UINT8       m_wend;                   /* W_END register */
129   UINT8       m_lrend;                  /* LR_END register */
130   UINT8       m_irqv;                   /* IRQV register */
131
132   es550x_voice m_voice[32];             /* the 32 voices */
133
134   INT32 *     m_scratch;
135
136   INT16 *     m_ulaw_lookup;
137   UINT16 *    m_volume_lookup;
138
139   #if MAKE_WAVS
140   void *      m_wavraw;                 /* raw waveform */
141   #endif
142   
143   FILE *m_eslog;
144   
145   void update_irq_state();
146   void update_internal_irq_state();
147   void compute_tables();
148
149   void generate_dummy(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples);
150   void generate_ulaw(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples);
151   void generate_pcm(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples);
51152};
52153
53extern const device_type ES5506;
54154
155class es5506_device : public es550x_device,
156                           public es5506_interface
157{
158public:
159   es5506_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
160   ~es5506_device() {}
161   
162   DECLARE_READ8_MEMBER( read );
163   DECLARE_WRITE8_MEMBER( write );
164   void voice_bank_w(int voice, int bank);
55165
166protected:
167   // device-level overrides
168   virtual void device_config_complete();
169   virtual void device_start();
56170
57struct es5506_interface
58{
59   const char * region0;                       /* memory region where the sample ROM lives */
60   const char * region1;                       /* memory region where the sample ROM lives */
61   const char * region2;                       /* memory region where the sample ROM lives */
62   const char * region3;                       /* memory region where the sample ROM lives */
63   int channels;                               /* number of output channels: 1 .. 6 */
64   devcb_write_line irq_callback;  /* irq callback */
65   devcb_read16 read_port;          /* input port read */
171   // sound stream update overrides
172   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
173   
174   
175   void generate_samples(INT32 **outputs, int offset, int samples);
176
177private:
178   inline void reg_write_low(es550x_voice *voice, offs_t offset, UINT32 data);
179   inline void reg_write_high(es550x_voice *voice, offs_t offset, UINT32 data);
180   inline void reg_write_test(es550x_voice *voice, offs_t offset, UINT32 data);
181   inline UINT32 reg_read_low(es550x_voice *voice, offs_t offset);
182   inline UINT32 reg_read_high(es550x_voice *voice, offs_t offset);
183   inline UINT32 reg_read_test(es550x_voice *voice, offs_t offset);
66184};
67185
68DECLARE_READ8_DEVICE_HANDLER( es5506_r );
69DECLARE_WRITE8_DEVICE_HANDLER( es5506_w );
70void es5506_voice_bank_w(device_t *device, int voice, int bank);
186extern const device_type ES5506;
71187
72class es5505_device : public es5506_device
188
189class es5505_device : public es550x_device,
190                           public es5505_interface
73191{
74192public:
75193   es5505_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
194   
195   DECLARE_READ16_MEMBER( read );
196   DECLARE_WRITE16_MEMBER( write );
197   void voice_bank_w(int voice, int bank);
198
76199protected:
77200   // device-level overrides
201   virtual void device_config_complete();
78202   virtual void device_start();
203   
204   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
205   
206   void generate_samples(INT32 **outputs, int offset, int samples);
207   
79208private:
80209   // internal state
210   inline void reg_write_low(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask);
211   inline void reg_write_high(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask);
212   inline void reg_write_test(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask);
213   inline UINT16 reg_read_low(es550x_voice *voice, offs_t offset);
214   inline UINT16 reg_read_high(es550x_voice *voice, offs_t offset);
215   inline UINT16 reg_read_test(es550x_voice *voice, offs_t offset);
81216};
82217
83218extern const device_type ES5505;
84219
85extern STREAM_UPDATE( es5506_update );
86220
87221#endif /* __ES5506_H__ */
trunk/src/mess/drivers/esqkt.c
r26107r26108
128128
129129static ADDRESS_MAP_START( kt_map, AS_PROGRAM, 32, esqkt_state )
130130   AM_RANGE(0x000000, 0x07ffff) AM_ROM AM_REGION("osrom", 0)
131   AM_RANGE(0x200000, 0x20003f) AM_DEVREADWRITE8_LEGACY("ensoniq", es5506_r, es5506_w, 0xffffffff)
132   AM_RANGE(0x240000, 0x24003f) AM_DEVREADWRITE8_LEGACY("ensoniq2", es5506_r, es5506_w, 0xffffffff)
131   AM_RANGE(0x200000, 0x20003f) AM_DEVREADWRITE8("ensoniq", es5506_device, read, write, 0xffffffff)
132   AM_RANGE(0x240000, 0x24003f) AM_DEVREADWRITE8("ensoniq2", es5506_device, read, write, 0xffffffff)
133133   AM_RANGE(0x280000, 0x2801ff) AM_DEVREADWRITE8("esp", es5510_device, host_r, host_w, 0xffffffff)
134134   AM_RANGE(0x300000, 0x30001f) AM_DEVREADWRITE8("duart", duartn68681_device, read, write, 0xffffffff)
135135   AM_RANGE(0xff0000, 0xffffff) AM_RAM AM_SHARE("osram")
trunk/src/mess/drivers/esq5505.c
r26107r26108
352352
353353static ADDRESS_MAP_START( vfx_map, AS_PROGRAM, 16, esq5505_state )
354354   AM_RANGE(0x000000, 0x007fff) AM_READWRITE(lower_r, lower_w)
355   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE_LEGACY("otis", es5505_r, es5505_w)
355   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE("otis", es5505_device, read, write)
356356   AM_RANGE(0x280000, 0x28001f) AM_DEVREADWRITE8("duart", duartn68681_device, read, write, 0x00ff)
357357   AM_RANGE(0x260000, 0x2601ff) AM_DEVREADWRITE8("esp", es5510_device, host_r, host_w, 0x00ff)
358358   AM_RANGE(0xc00000, 0xc1ffff) AM_ROM AM_REGION("osrom", 0)
r26107r26108
361361
362362static ADDRESS_MAP_START( vfxsd_map, AS_PROGRAM, 16, esq5505_state )
363363   AM_RANGE(0x000000, 0x00ffff) AM_READWRITE(lower_r, lower_w)
364   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE_LEGACY("otis", es5505_r, es5505_w)
364   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE("otis", es5505_device, read, write)
365365   AM_RANGE(0x280000, 0x28001f) AM_DEVREADWRITE8("duart", duartn68681_device, read, write, 0x00ff)
366366   AM_RANGE(0x260000, 0x2601ff) AM_DEVREADWRITE8("esp", es5510_device, host_r, host_w, 0x00ff)
367367   AM_RANGE(0x2c0000, 0x2c0007) AM_DEVREADWRITE8("wd1772", wd1772_t, read, write, 0x00ff)
r26107r26108
372372
373373static ADDRESS_MAP_START( eps_map, AS_PROGRAM, 16, esq5505_state )
374374   AM_RANGE(0x000000, 0x007fff) AM_READWRITE(lower_r, lower_w)
375   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE_LEGACY("otis", es5505_r, es5505_w)
375   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE("otis", es5505_device, read, write)
376376   AM_RANGE(0x240000, 0x2400ff) AM_DEVREADWRITE_LEGACY("mc68450", hd63450_r, hd63450_w)
377377   AM_RANGE(0x280000, 0x28001f) AM_DEVREADWRITE8("duart", duartn68681_device, read, write, 0x00ff)
378378   AM_RANGE(0x2c0000, 0x2c0007) AM_DEVREADWRITE8("wd1772", wd1772_t, read, write, 0x00ff)
r26107r26108
383383
384384static ADDRESS_MAP_START( sq1_map, AS_PROGRAM, 16, esq5505_state )
385385   AM_RANGE(0x000000, 0x03ffff) AM_READWRITE(lower_r, lower_w)
386   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE_LEGACY("otis", es5505_r, es5505_w)
386   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE("otis", es5505_device, read, write)
387387   AM_RANGE(0x260000, 0x2601ff) AM_DEVREADWRITE8("esp", es5510_device, host_r, host_w, 0x0ff)
388388   AM_RANGE(0x280000, 0x28001f) AM_DEVREADWRITE8("duart", duartn68681_device, read, write, 0x00ff)
389389   AM_RANGE(0x330000, 0x3bffff) AM_RAM // sequencer memory?
trunk/src/mame/drivers/ssv.c
r26107r26108
163163#include "cpu/v810/v810.h"
164164#include "cpu/v60/v60.h"
165165#include "machine/nvram.h"
166#include "sound/es5506.h"
167166#include "includes/ssv.h"
168167
169168/***************************************************************************
r26107r26108
412411   AM_RANGE(0x230000, 0x230071) AM_WRITEONLY AM_SHARE("irq_vectors")                       /*  IRQ Vec */  \
413412   AM_RANGE(0x240000, 0x240071) AM_WRITE(ssv_irq_ack_w )                                           /*  IRQ Ack */  \
414413   AM_RANGE(0x260000, 0x260001) AM_WRITE(ssv_irq_enable_w)                                         /*  IRQ En  */  \
415   AM_RANGE(0x300000, 0x30007f) AM_DEVREADWRITE8_LEGACY("ensoniq", es5506_r, es5506_w, 0x00ff)         /*  Sound   */  \
414   AM_RANGE(0x300000, 0x30007f) AM_DEVREADWRITE8("ensoniq", es5506_device, read, write, 0x00ff)         /*  Sound   */  \
416415   AM_RANGE(_ROM, 0xffffff) AM_ROMBANK("bank1")                                                        /*  ROM     */
417416/***************************************************************************
418417                                Drift Out '94
r26107r26108
666665      int bank = 0x400000/2 * (data & 1); // UINT16 address
667666      int voice;
668667      for (voice = 0; voice < 32; voice++)
669         es5506_voice_bank_w(m_ensoniq, voice, bank);
668         m_ensoniq->voice_bank_w(voice, bank);
670669   }
671670//  popmessage("%04X",data);
672671}
trunk/src/mame/drivers/itech32.c
r26107r26108
10481048static ADDRESS_MAP_START( sound_map, AS_PROGRAM, 8, itech32_state )
10491049   AM_RANGE(0x0000, 0x0000) AM_WRITE(sound_return_w)
10501050   AM_RANGE(0x0400, 0x0400) AM_READ(sound_data_r)
1051   AM_RANGE(0x0800, 0x083f) AM_MIRROR(0x80) AM_DEVREADWRITE_LEGACY("ensoniq", es5506_r, es5506_w)
1051   AM_RANGE(0x0800, 0x083f) AM_MIRROR(0x80) AM_DEVREADWRITE("ensoniq", es5506_device, read, write)
10521052   AM_RANGE(0x0c00, 0x0c00) AM_WRITE(sound_bank_w)
10531053   AM_RANGE(0x1000, 0x1000) AM_WRITENOP    /* noisy */
10541054   AM_RANGE(0x1400, 0x140f) AM_DEVREADWRITE("via6522_0", via6522_device, read, write)
r26107r26108
10611061/*------ Rev 2 sound board memory layout ------*/
10621062static ADDRESS_MAP_START( sound_020_map, AS_PROGRAM, 8, itech32_state )
10631063   AM_RANGE(0x0000, 0x0000) AM_MIRROR(0x400) AM_READ(sound_data_r)
1064   AM_RANGE(0x0800, 0x083f) AM_MIRROR(0x80) AM_DEVREADWRITE_LEGACY("ensoniq", es5506_r, es5506_w)
1064   AM_RANGE(0x0800, 0x083f) AM_MIRROR(0x80) AM_DEVREADWRITE("ensoniq", es5506_device, read, write)
10651065   AM_RANGE(0x0c00, 0x0c00) AM_WRITE(sound_bank_w)
10661066   AM_RANGE(0x1400, 0x1400) AM_WRITE(firq_clear_w)
10671067   AM_RANGE(0x1800, 0x1800) AM_READ(sound_data_buffer_r) AM_WRITENOP
trunk/src/mame/drivers/macrossp.c
r26107r26108
417417static ADDRESS_MAP_START( macrossp_sound_map, AS_PROGRAM, 16, macrossp_state )
418418   AM_RANGE(0x000000, 0x0fffff) AM_ROM
419419   AM_RANGE(0x200000, 0x207fff) AM_RAM
420   AM_RANGE(0x400000, 0x40007f) AM_DEVREADWRITE8_LEGACY("ensoniq", es5506_r, es5506_w, 0x00ff)
420   AM_RANGE(0x400000, 0x40007f) AM_DEVREADWRITE8("ensoniq", es5506_device, read, write, 0x00ff)
421421   AM_RANGE(0x600000, 0x600001) AM_READ(macrossp_soundcmd_r)
422422ADDRESS_MAP_END
423423
trunk/src/mame/audio/taito_en.c
r26107r26108
124124
125125   /* mask out unused bits */
126126   data &= max_banks_this_game;
127   es5505_voice_bank_w(space.machine().device("ensoniq"),offset,data<<20);
127   space.machine().device<es5505_device>("ensoniq")->voice_bank_w(offset,data<<20);
128128}
129129
130130WRITE16_MEMBER( taito_en_device::en_volume_w )
r26107r26108
250250static ADDRESS_MAP_START( en_sound_map, AS_PROGRAM, 16, driver_device )
251251   AM_RANGE(0x000000, 0x00ffff) AM_RAM AM_MIRROR(0x30000) AM_SHARE("share1")
252252   AM_RANGE(0x140000, 0x140fff) AM_DEVREADWRITE("taito_en", taito_en_device, en_68000_share_r, en_68000_share_w)
253   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE_LEGACY("ensoniq", es5505_r, es5505_w)
253   AM_RANGE(0x200000, 0x20001f) AM_DEVREADWRITE("ensoniq", es5505_device, read, write)
254254   AM_RANGE(0x260000, 0x2601ff) AM_DEVREADWRITE("taito_en", taito_en_device, es5510_dsp_r, es5510_dsp_w) //todo: hook up cpu/es5510
255255   AM_RANGE(0x280000, 0x28001f) AM_DEVREADWRITE8_LEGACY("duart68681", duart68681_r, duart68681_w, 0x00ff)
256256   AM_RANGE(0x300000, 0x30003f) AM_DEVWRITE("taito_en", taito_en_device, en_es5505_bank_w)
trunk/src/mame/includes/ssv.h
r26107r26108
11#include "cpu/upd7725/upd7725.h"
22#include "video/st0020.h"
33#include "machine/eepromser.h"
4#include "sound/es5506.h"
45
5
66class ssv_state : public driver_device
77{
88public:
r26107r26108
3737   { }
3838
3939   required_device<cpu_device> m_maincpu;
40   required_device<device_t> m_ensoniq;
40   required_device<es5506_device> m_ensoniq;
4141   optional_device<eeprom_serial_93cxx_device> m_eeprom;
4242   optional_device<upd96050_device> m_dsp;
4343

Previous 199869 Revisions Next


© 1997-2024 The MAME Team