~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/emu/sound/5220intf.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************************************
2
 
 
3
 
     TMS5220 interface
4
 
 
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
9
 
 
10
 
***********************************************************************************************/
11
 
 
12
 
#include <math.h>
13
 
 
14
 
#include "sndintrf.h"
15
 
#include "streams.h"
16
 
#include "tms5220.h"
17
 
#include "5220intf.h"
18
 
 
19
 
 
20
 
#define MAX_SAMPLE_CHUNK        10000
21
 
 
22
 
 
23
 
/* the state of the streamed output */
24
 
typedef struct _tms5220_state tms5220_state;
25
 
struct _tms5220_state
26
 
{
27
 
        const tms5220_interface *intf;
28
 
        sound_stream *stream;
29
 
        int clock;
30
 
        void *chip;
31
 
};
32
 
 
33
 
 
34
 
INLINE tms5220_state *get_safe_token(const device_config *device)
35
 
{
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;
43
 
}
44
 
 
45
 
 
46
 
/* static function prototypes */
47
 
static STREAM_UPDATE( tms5220_update );
48
 
 
49
 
 
50
 
 
51
 
/**********************************************************************************************
52
 
 
53
 
     DEVICE_START( tms5220 ) -- allocate buffers and reset the 5220
54
 
 
55
 
***********************************************************************************************/
56
 
 
57
 
static DEVICE_START( tms5220 )
58
 
{
59
 
        static const tms5220_interface dummy = { 0 };
60
 
        tms5220_state *info = get_safe_token(device);
61
 
 
62
 
        info->intf = device->static_config ? (const tms5220_interface *)device->static_config : &dummy;
63
 
 
64
 
        info->chip = tms5220_create(device);
65
 
        assert_always(info->chip != NULL, "Error creating TMS5220 chip");
66
 
 
67
 
        /* initialize a info->stream */
68
 
        info->stream = stream_create(device, 0, 1, device->clock / 80, info, tms5220_update);
69
 
        info->clock = device->clock;
70
 
 
71
 
    /* reset the 5220 */
72
 
    tms5220_reset_chip(info->chip);
73
 
    tms5220_set_irq(info->chip, info->intf->irq);
74
 
 
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);
79
 
}
80
 
 
81
 
 
82
 
#if (HAS_TMC0285 || HAS_TMS5200)
83
 
static DEVICE_START( tms5200 )
84
 
{
85
 
        tms5220_state *info = get_safe_token(device);
86
 
        DEVICE_START_CALL( tms5220 );
87
 
        tms5220_set_variant(info->chip, variant_tmc0285);
88
 
}
89
 
#endif /* (HAS_TMC0285) && (HAS_TMS5200) */
90
 
 
91
 
 
92
 
 
93
 
/**********************************************************************************************
94
 
 
95
 
     DEVICE_STOP( tms5220 ) -- free buffers
96
 
 
97
 
***********************************************************************************************/
98
 
 
99
 
static DEVICE_STOP( tms5220 )
100
 
{
101
 
        tms5220_state *info = get_safe_token(device);
102
 
        tms5220_destroy(info->chip);
103
 
}
104
 
 
105
 
 
106
 
 
107
 
static DEVICE_RESET( tms5220 )
108
 
{
109
 
        tms5220_state *info = get_safe_token(device);
110
 
        tms5220_reset_chip(info->chip);
111
 
}
112
 
 
113
 
 
114
 
 
115
 
/**********************************************************************************************
116
 
 
117
 
     tms5220_data_w -- write data to the sound chip
118
 
 
119
 
***********************************************************************************************/
120
 
 
121
 
WRITE8_DEVICE_HANDLER( tms5220_data_w )
122
 
{
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);
127
 
}
128
 
 
129
 
 
130
 
 
131
 
/**********************************************************************************************
132
 
 
133
 
     tms5220_status_r -- read status or data from the sound chip
134
 
 
135
 
***********************************************************************************************/
136
 
 
137
 
READ8_DEVICE_HANDLER( tms5220_status_r )
138
 
{
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);
143
 
}
144
 
 
145
 
 
146
 
 
147
 
/**********************************************************************************************
148
 
 
149
 
     tms5220_ready_r -- return the not ready status from the sound chip
150
 
 
151
 
***********************************************************************************************/
152
 
 
153
 
int tms5220_ready_r(const device_config *device)
154
 
{
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);
159
 
}
160
 
 
161
 
 
162
 
 
163
 
/**********************************************************************************************
164
 
 
165
 
     tms5220_time_to_ready -- return the time in seconds until the ready line is asserted
166
 
 
167
 
***********************************************************************************************/
168
 
 
169
 
double tms5220_time_to_ready(const device_config *device)
170
 
{
171
 
        tms5220_state *info = get_safe_token(device);
172
 
        double cycles;
173
 
 
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;
178
 
}
179
 
 
180
 
 
181
 
 
182
 
/**********************************************************************************************
183
 
 
184
 
     tms5220_int_r -- return the int status from the sound chip
185
 
 
186
 
***********************************************************************************************/
187
 
 
188
 
int tms5220_int_r(const device_config *device)
189
 
{
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);
194
 
}
195
 
 
196
 
 
197
 
 
198
 
/**********************************************************************************************
199
 
 
200
 
     tms5220_update -- update the sound chip so that it is in sync with CPU execution
201
 
 
202
 
***********************************************************************************************/
203
 
 
204
 
static STREAM_UPDATE( tms5220_update )
205
 
{
206
 
        tms5220_state *info = (tms5220_state *)param;
207
 
        INT16 sample_data[MAX_SAMPLE_CHUNK];
208
 
        stream_sample_t *buffer = outputs[0];
209
 
 
210
 
        /* loop while we still have samples to generate */
211
 
        while (samples)
212
 
        {
213
 
                int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples;
214
 
                int index;
215
 
 
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];
220
 
 
221
 
                /* account for the samples */
222
 
                samples -= length;
223
 
        }
224
 
}
225
 
 
226
 
 
227
 
 
228
 
/**********************************************************************************************
229
 
 
230
 
     tms5220_set_frequency -- adjusts the playback frequency
231
 
 
232
 
***********************************************************************************************/
233
 
 
234
 
void tms5220_set_frequency(const device_config *device, int frequency)
235
 
{
236
 
        tms5220_state *info = get_safe_token(device);
237
 
        stream_set_sample_rate(info->stream, frequency / 80);
238
 
        info->clock = frequency;
239
 
}
240
 
 
241
 
 
242
 
 
243
 
/**************************************************************************
244
 
 * Generic get_info
245
 
 **************************************************************************/
246
 
 
247
 
DEVICE_GET_INFO( tms5220 )
248
 
{
249
 
        switch (state)
250
 
        {
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;
253
 
 
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;
258
 
 
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;
265
 
        }
266
 
}
267
 
 
268
 
#if (HAS_TMC0285)
269
 
DEVICE_GET_INFO( tmc0285 )
270
 
{
271
 
        switch (state)
272
 
        {
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;
276
 
        }
277
 
}
278
 
#endif
279
 
 
280
 
#if (HAS_TMS5200)
281
 
DEVICE_GET_INFO( tms5200 )
282
 
{
283
 
        switch (state)
284
 
        {
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;
288
 
        }
289
 
}
290
 
#endif