Previous 15994 Revisions Next

r1468 Monday 31st December, 2007 at 04:39:24 UTC by Dirk Best
Removed some files deleted in the 0.122u2 update
[src/emu/sound]m58817.c m58817.h

src/emu/sound/m58817.c
r1467r1468
1/******************************************************************************
2
3     M58817 interface
4
5     Written for MAME by couriersud
6
7     - structure from TMS5110 interface
8     - this is a wrapper around the TMS5110 interface
9     - M58817 & TMS5110 seem to be similar, however it is very probable
10       that they use different "coding" tables for energy, pitch
11     - Speech is understandable, but off
12     - This driver supports to use a "sample" interface instead as well
13
14******************************************************************************/
15
16#include <math.h>
17
18#include "sndintrf.h"
19#include "streams.h"
20#include "tms5110.h"
21#include "m58817.h"
22#include "sound/samples.h"
23
24
25#define MAX_SAMPLE_CHUNK   10000
26
27enum {
28   WAIT_CMD,
29   WAIT_WRITE,
30   WAIT_DONE1,
31   WAIT_DONE2
32} m58817_states;
33
34/* the state of the streamed output */
35struct m58817_info
36{
37   const struct M58817interface *intf;
38   sound_stream *stream;
39   void *chip;
40   UINT8 state;
41   UINT8 drq;
42   UINT8 nibbles[4];
43   UINT8 command_latch;
44   INT32 count;
45   INT32 address;
46   INT32 speech_rom_bitnum;
47};
48
49
50/* static function prototypes */
51static void m58817_update(void *param, stream_sample_t **inputs, stream_sample_t **buffer, int length);
52
53static int speech_rom_read_bit(void)
54{
55   struct m58817_info *info = sndti_token(SOUND_M58817, 0);
56   const UINT8 *table = memory_region(info->intf->rom_region);
57
58   int r;
59
60   if (info->speech_rom_bitnum<0)
61      r = 0;
62   else
63      r = (table[info->speech_rom_bitnum >> 3] >> (0x07 - (info->speech_rom_bitnum & 0x07))) & 1;
64   //r = (table[speech_rom_bitnum >> 3] >> ((speech_rom_bitnum & 0x07))) & 1;
65   info->speech_rom_bitnum++;
66   //printf("Byte: 0x%02x\n", speech_rom_bitnum>>3);
67   return r;
68}
69
70/******************************************************************************
71
72     m58817_state_loop -- process commands
73
74******************************************************************************/
75
76static void m58817_state_loop(void *chip, int data)
77{
78   struct m58817_info *info = chip;
79   int i;
80   switch (info->state)
81   {
82      case WAIT_CMD:
83         switch (data)
84         {
85            case 0x00: // reset ????
86               info->count=0;
87               /*To be extremely accurate there should be a delays between each of
88                      the function calls below. In real they happen with the frequency of 160 kHz.
89                    */
90
91               if (info->intf->rom_region != -1)
92               {
93                  tms5110_CTL_set(info->chip, TMS5110_CMD_RESET);
94                  tms5110_PDC_set(info->chip, 0);
95                  tms5110_PDC_set(info->chip, 1);
96                  tms5110_PDC_set(info->chip, 0);
97
98                  tms5110_PDC_set(info->chip, 0);
99                  tms5110_PDC_set(info->chip, 1);
100                  tms5110_PDC_set(info->chip, 0);
101
102                  tms5110_PDC_set(info->chip, 0);
103                  tms5110_PDC_set(info->chip, 1);
104                  tms5110_PDC_set(info->chip, 0);
105
106                  info->speech_rom_bitnum = 0x0;
107               }
108               break;
109            case 0x02: // latch next nibbel
110               info->state=WAIT_WRITE;
111               break;
112            case 0x08: // play ????
113               info->state=WAIT_DONE1;
114               break;
115            default:
116               logerror("m58817: unknown cmd : 0x%02x\n", data);
117         }
118         break;
119      case WAIT_WRITE:
120         info->nibbles[info->count++] = data & 0x0f;
121         info->state=WAIT_CMD;
122         break;
123      case WAIT_DONE1:
124         if (data != 0x0A)
125            logerror("m58817: expected 0x0A got 0x%02x\n", data);
126         info->address = 0;
127         for (i=0;i<info->count;i++)
128         {
129            info->address |= (info->nibbles[i] << (i*4));
130         }
131         logerror("m58817: address: 0x%04x\n", info->address);
132
133
134         if (info->intf->rom_region != -1)
135         {
136            info->speech_rom_bitnum = info->address * 8 - 1;
137            tms5110_CTL_set(info->chip, TMS5110_CMD_SPEAK);
138            tms5110_PDC_set(info->chip, 0);
139            tms5110_PDC_set(info->chip, 1);
140            tms5110_PDC_set(info->chip, 0);
141         }
142         else
143         {
144            for (i=0;i<M58817_MAX_SAMPLES;i++)
145               if (info->intf->sample_addr[i] == info->address)
146               {
147                  sample_start(0,i,0);
148                  break;
149               }
150         }
151
152         info->state=WAIT_CMD;
153         break;
154   }
155}
156
157
158/******************************************************************************
159
160     m58817_start -- allocate buffers and reset the 5110
161
162******************************************************************************/
163
164static void *m58817_start(int sndindex, int clock, const void *config)
165{
166   static const struct M58817interface dummy = { 0 };
167   struct m58817_info *info;
168
169   info = auto_malloc(sizeof(*info));
170   memset(info, 0, sizeof(*info));
171   info->intf = config ? config : &dummy;
172
173   if (info->intf->rom_region != -1)
174   {
175      info->chip = tms5110_create(sndindex);
176      if (!info->chip)
177         return NULL;
178   }
179   sndintrf_register_token(info);
180
181   /* initialize a stream */
182   if (info->intf->rom_region != -1)
183   {
184      info->stream = stream_create(0, 1, clock / 80, info, m58817_update);
185      tms5110_set_M0_callback(info->chip, speech_rom_read_bit );
186       /* reset the 58817 */
187       tms5110_reset_chip(info->chip);
188   }
189
190   state_save_register_item("m58817", sndindex, info->state);
191   state_save_register_item("m58817", sndindex, info->drq);
192   state_save_register_item_array("m58817", sndindex, info->nibbles);
193   state_save_register_item("m58817", sndindex, info->count);
194   state_save_register_item("m58817", sndindex, info->address);
195   state_save_register_item("m58817", sndindex, info->speech_rom_bitnum);
196
197    /* request a sound channel */
198    return info;
199}
200
201
202
203/******************************************************************************
204
205     m58817_stop -- free buffers
206
207******************************************************************************/
208
209static void m58817_stop(void *chip)
210{
211   struct m58817_info *info = chip;
212   if (info->intf->rom_region != -1)
213      tms5110_destroy(info->chip);
214}
215
216
217static void m58817_reset(void *chip)
218{
219   struct m58817_info *info = chip;
220   if (info->intf->rom_region != -1)
221      tms5110_reset_chip(info->chip);
222   info->state = WAIT_CMD;
223   info->drq = 0;
224   info->command_latch = 0;
225   info->count=0;
226}
227
228
229
230/******************************************************************************
231
232     m58817_CTL_w -- write Control Command to the sound chip
233     commands like Speech, Reset, etc., are loaded into the chip via the CTL pins
234
235******************************************************************************/
236
237WRITE8_HANDLER( m58817_CTL_w )
238{
239   struct m58817_info *info = sndti_token(SOUND_M58817, 0);
240
241    /* bring up to date first */
242    //stream_update(info->stream);
243    info->command_latch = data & 0x0f;
244}
245
246/******************************************************************************
247
248     m58817_DRQ_w -- write to DRQ pin on the sound chip
249
250******************************************************************************/
251
252WRITE8_HANDLER( m58817_DRQ_w )
253{
254   struct m58817_info *info = sndti_token(SOUND_M58817, 0);
255
256    /* bring up to date first */
257   if (info->intf->rom_region != -1)
258       stream_update(info->stream);
259   if (!data & info->drq)
260      m58817_state_loop(info, info->command_latch);
261   info->drq = data;
262}
263
264
265
266/******************************************************************************
267
268     m58817_status_r -- read status from the sound chip
269
270******************************************************************************/
271
272READ8_HANDLER( m58817_status_r )
273{
274   struct m58817_info *info = sndti_token(SOUND_M58817, 0);
275
276    /* bring up to date first */
277   if (info->intf->rom_region != -1)
278       stream_update(info->stream);
279   if (info->intf->rom_region != -1)
280       return tms5110_status_read(info->chip);
281   else
282      return sample_playing(0);
283}
284
285
286
287/******************************************************************************
288
289     m58817_update -- update the sound chip so that it is in sync with CPU execution
290
291******************************************************************************/
292
293static void m58817_update(void *param, stream_sample_t **inputs, stream_sample_t **_buffer, int length)
294{
295   struct m58817_info *info = param;
296   INT16 sample_data[MAX_SAMPLE_CHUNK];
297   stream_sample_t *buffer = _buffer[0];
298
299   /* loop while we still have samples to generate */
300   while (length)
301   {
302      int samples = (length > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : length;
303      int index;
304
305      /* generate the samples and copy to the target buffer */
306      tms5110_process(info->chip, sample_data, samples);
307      for (index = 0; index < samples; index++)
308         *buffer++ = sample_data[index];
309
310      /* account for the samples */
311      length -= samples;
312   }
313}
314
315
316
317/******************************************************************************
318
319     m58817_set_frequency -- adjusts the playback frequency
320
321******************************************************************************/
322
323void m58817_set_frequency(int frequency)
324{
325   struct m58817_info *info = sndti_token(SOUND_M58817, 0);
326   stream_set_sample_rate(info->stream, frequency / 80);
327}
328
329
330
331
332/**************************************************************************
333 * Generic get_info
334 **************************************************************************/
335
336static void m58817_set_info(void *token, UINT32 state, sndinfo *info)
337{
338   switch (state)
339   {
340      /* no parameters to set */
341   }
342}
343
344
345void m58817_get_info(void *token, UINT32 state, sndinfo *info)
346{
347   switch (state)
348   {
349      /* --- the following bits of info are returned as 64-bit signed integers --- */
350
351      /* --- the following bits of info are returned as pointers to data or functions --- */
352      case SNDINFO_PTR_SET_INFO:                  info->set_info = m58817_set_info;   break;
353      case SNDINFO_PTR_START:                     info->start = m58817_start;         break;
354      case SNDINFO_PTR_STOP:                     info->stop = m58817_stop;         break;
355      case SNDINFO_PTR_RESET:                     info->reset = m58817_reset;         break;
356
357      /* --- the following bits of info are returned as NULL-terminated strings --- */
358      case SNDINFO_STR_NAME:                     info->s = "M58817";               break;
359      case SNDINFO_STR_CORE_FAMILY:               info->s = "Mitsubishi Speech";      break;
360      case SNDINFO_STR_CORE_VERSION:               info->s = "1.0";               break;
361      case SNDINFO_STR_CORE_FILE:                  info->s = __FILE__;               break;
362      case SNDINFO_STR_CORE_CREDITS:               info->s = "Copyright (c) 2007, The MAME Team"; break;
363   }
364}
365
src/emu/sound/m58817.h
r1467r1468
1#ifndef m58817_h
2#define m58817_h
3
4/* clock rate = 80 * output sample rate,     */
5/* usually 640000 for 8000 Hz sample rate or */
6/* usually 800000 for 10000 Hz sample rate.  */
7
8#define M58817_MAX_SAMPLES 20
9
10struct M58817interface
11{
12   int rom_region;                     /* set to -1 to use samples */
13   int sample_addr[M58817_MAX_SAMPLES];
14};
15
16WRITE8_HANDLER( m58817_CTL_w );
17WRITE8_HANDLER( m58817_DRQ_w );
18
19READ8_HANDLER( m58817_status_r );
20
21void m58817_set_frequency(int frequency);
22
23#endif
24

Previous 15994 Revisions Next


© 1998-2018 The MESS Team