1
/**********************************************************************************************
5
Written for MAME by Frank Palazzolo
6
With help from Neill Corlett
7
Additional tweaking by Aaron Giles
8
Speech ROM support and a few bug fixes by R Nabet
10
***********************************************************************************************/
20
#define MAX_SAMPLE_CHUNK 10000
23
/* the state of the streamed output */
24
typedef struct _tms5220_state tms5220_state;
27
const tms5220_interface *intf;
34
INLINE tms5220_state *get_safe_token(const device_config *device)
36
assert(device != NULL);
37
assert(device->token != NULL);
38
assert(device->type == SOUND);
39
assert(sound_get_type(device) == SOUND_TMS5220 ||
40
sound_get_type(device) == SOUND_TMC0285 ||
41
sound_get_type(device) == SOUND_TMS5200);
42
return (tms5220_state *)device->token;
46
/* static function prototypes */
47
static STREAM_UPDATE( tms5220_update );
51
/**********************************************************************************************
53
DEVICE_START( tms5220 ) -- allocate buffers and reset the 5220
55
***********************************************************************************************/
57
static DEVICE_START( tms5220 )
59
static const tms5220_interface dummy = { 0 };
60
tms5220_state *info = get_safe_token(device);
62
info->intf = device->static_config ? (const tms5220_interface *)device->static_config : &dummy;
64
info->chip = tms5220_create(device);
65
assert_always(info->chip != NULL, "Error creating TMS5220 chip");
67
/* initialize a info->stream */
68
info->stream = stream_create(device, 0, 1, device->clock / 80, info, tms5220_update);
69
info->clock = device->clock;
72
tms5220_reset_chip(info->chip);
73
tms5220_set_irq(info->chip, info->intf->irq);
75
/* init the speech ROM handlers */
76
tms5220_set_read(info->chip, info->intf->read);
77
tms5220_set_load_address(info->chip, info->intf->load_address);
78
tms5220_set_read_and_branch(info->chip, info->intf->read_and_branch);
82
#if (HAS_TMC0285 || HAS_TMS5200)
83
static DEVICE_START( tms5200 )
85
tms5220_state *info = get_safe_token(device);
86
DEVICE_START_CALL( tms5220 );
87
tms5220_set_variant(info->chip, variant_tmc0285);
89
#endif /* (HAS_TMC0285) && (HAS_TMS5200) */
93
/**********************************************************************************************
95
DEVICE_STOP( tms5220 ) -- free buffers
97
***********************************************************************************************/
99
static DEVICE_STOP( tms5220 )
101
tms5220_state *info = get_safe_token(device);
102
tms5220_destroy(info->chip);
107
static DEVICE_RESET( tms5220 )
109
tms5220_state *info = get_safe_token(device);
110
tms5220_reset_chip(info->chip);
115
/**********************************************************************************************
117
tms5220_data_w -- write data to the sound chip
119
***********************************************************************************************/
121
WRITE8_DEVICE_HANDLER( tms5220_data_w )
123
tms5220_state *info = get_safe_token(device);
124
/* bring up to date first */
125
stream_update(info->stream);
126
tms5220_data_write(info->chip, data);
131
/**********************************************************************************************
133
tms5220_status_r -- read status or data from the sound chip
135
***********************************************************************************************/
137
READ8_DEVICE_HANDLER( tms5220_status_r )
139
tms5220_state *info = get_safe_token(device);
140
/* bring up to date first */
141
stream_update(info->stream);
142
return tms5220_status_read(info->chip);
147
/**********************************************************************************************
149
tms5220_ready_r -- return the not ready status from the sound chip
151
***********************************************************************************************/
153
int tms5220_ready_r(const device_config *device)
155
tms5220_state *info = get_safe_token(device);
156
/* bring up to date first */
157
stream_update(info->stream);
158
return tms5220_ready_read(info->chip);
163
/**********************************************************************************************
165
tms5220_time_to_ready -- return the time in seconds until the ready line is asserted
167
***********************************************************************************************/
169
double tms5220_time_to_ready(const device_config *device)
171
tms5220_state *info = get_safe_token(device);
174
/* bring up to date first */
175
stream_update(info->stream);
176
cycles = tms5220_cycles_to_ready(info->chip);
177
return cycles * 80.0 / info->clock;
182
/**********************************************************************************************
184
tms5220_int_r -- return the int status from the sound chip
186
***********************************************************************************************/
188
int tms5220_int_r(const device_config *device)
190
tms5220_state *info = get_safe_token(device);
191
/* bring up to date first */
192
stream_update(info->stream);
193
return tms5220_int_read(info->chip);
198
/**********************************************************************************************
200
tms5220_update -- update the sound chip so that it is in sync with CPU execution
202
***********************************************************************************************/
204
static STREAM_UPDATE( tms5220_update )
206
tms5220_state *info = (tms5220_state *)param;
207
INT16 sample_data[MAX_SAMPLE_CHUNK];
208
stream_sample_t *buffer = outputs[0];
210
/* loop while we still have samples to generate */
213
int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples;
216
/* generate the samples and copy to the target buffer */
217
tms5220_process(info->chip, sample_data, length);
218
for (index = 0; index < length; index++)
219
*buffer++ = sample_data[index];
221
/* account for the samples */
228
/**********************************************************************************************
230
tms5220_set_frequency -- adjusts the playback frequency
232
***********************************************************************************************/
234
void tms5220_set_frequency(const device_config *device, int frequency)
236
tms5220_state *info = get_safe_token(device);
237
stream_set_sample_rate(info->stream, frequency / 80);
238
info->clock = frequency;
243
/**************************************************************************
245
**************************************************************************/
247
DEVICE_GET_INFO( tms5220 )
251
/* --- the following bits of info are returned as 64-bit signed integers --- */
252
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(tms5220_state); break;
254
/* --- the following bits of info are returned as pointers to data or functions --- */
255
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( tms5220 ); break;
256
case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME( tms5220 ); break;
257
case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( tms5220 ); break;
259
/* --- the following bits of info are returned as NULL-terminated strings --- */
260
case DEVINFO_STR_NAME: strcpy(info->s, "TMS5220"); break;
261
case DEVINFO_STR_FAMILY: strcpy(info->s, "TI Speech"); break;
262
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
263
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
264
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
269
DEVICE_GET_INFO( tmc0285 )
273
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( tms5200 ); break;
274
case DEVINFO_STR_NAME: strcpy(info->s, "TMC0285"); break;
275
default: DEVICE_GET_INFO_CALL( tms5220 ); break;
281
DEVICE_GET_INFO( tms5200 )
285
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( tms5200 ); break;
286
case DEVINFO_STR_NAME: strcpy(info->s, "TMS5200"); break;
287
default: DEVICE_GET_INFO_CALL( tms5220 ); break;