1
/***************************************************************************
5
The YM2610 emulator supports up to 2 chips.
6
Each chip has the following connections:
7
- Status Read / Control Write A
8
- Port Read / Data Write A
12
***************************************************************************/
19
typedef struct _ym2610_state ym2610_state;
22
sound_stream * stream;
26
const ym2610_interface *intf;
31
INLINE ym2610_state *get_safe_token(device_t *device)
33
assert(device != NULL);
34
assert(device->type() == YM2610 || device->type() == YM2610B);
35
return (ym2610_state *)downcast<legacy_device_base *>(device)->token();
39
static void psg_set_clock(void *param, int clock)
41
ym2610_state *info = (ym2610_state *)param;
42
ay8910_set_clock_ym(info->psg, clock);
45
static void psg_write(void *param, int address, int data)
47
ym2610_state *info = (ym2610_state *)param;
48
ay8910_write_ym(info->psg, address, data);
51
static int psg_read(void *param)
53
ym2610_state *info = (ym2610_state *)param;
54
return ay8910_read_ym(info->psg);
57
static void psg_reset(void *param)
59
ym2610_state *info = (ym2610_state *)param;
60
ay8910_reset_ym(info->psg);
63
static const ssg_callbacks psgintf =
71
/*------------------------- TM2610 -------------------------------*/
73
static void IRQHandler(void *param,int irq)
75
ym2610_state *info = (ym2610_state *)param;
76
if(info->intf->handler) info->intf->handler(info->device, irq);
79
/* Timer overflow callback from timer.c */
80
static TIMER_CALLBACK( timer_callback_0 )
82
ym2610_state *info = (ym2610_state *)ptr;
83
ym2610_timer_over(info->chip,0);
86
static TIMER_CALLBACK( timer_callback_1 )
88
ym2610_state *info = (ym2610_state *)ptr;
89
ym2610_timer_over(info->chip,1);
92
static void timer_handler(void *param,int c,int count,int clock)
94
ym2610_state *info = (ym2610_state *)param;
96
{ /* Reset FM Timer */
97
info->timer[c]->enable(false);
100
{ /* Start FM Timer */
101
attotime period = attotime::from_hz(clock) * count;
103
if (!info->timer[c]->enable(true))
104
info->timer[c]->adjust(period);
108
/* update request from fm.c */
109
void ym2610_update_request(void *param)
111
ym2610_state *info = (ym2610_state *)param;
112
info->stream->update();
116
static STREAM_UPDATE( ym2610_stream_update )
118
ym2610_state *info = (ym2610_state *)param;
119
ym2610_update_one(info->chip, outputs, samples);
122
static STREAM_UPDATE( ym2610b_stream_update )
124
ym2610_state *info = (ym2610_state *)param;
125
ym2610b_update_one(info->chip, outputs, samples);
129
static void ym2610_intf_postload(ym2610_state *info)
131
ym2610_postload(info->chip);
135
static DEVICE_START( ym2610 )
137
static const ym2610_interface generic_2610 = { 0 };
138
static const ay8910_interface generic_ay8910 =
140
AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
141
AY8910_DEFAULT_LOADS,
142
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
144
const ym2610_interface *intf = device->static_config() ? (const ym2610_interface *)device->static_config() : &generic_2610;
145
int rate = device->clock()/72;
146
void *pcmbufa,*pcmbufb;
147
int pcmsizea,pcmsizeb;
148
ym2610_state *info = get_safe_token(device);
150
device_type type = device->type();
153
info->device = device;
154
info->psg = ay8910_start_ym(NULL, device->type(), device, device->clock(), &generic_ay8910);
155
assert_always(info->psg != NULL, "Error creating YM2610/AY8910 chip");
157
/* Timer Handler set */
158
info->timer[0] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_0), info);
159
info->timer[1] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_1), info);
161
/* stream system initialize */
162
info->stream = device->machine().sound().stream_alloc(*device,0,2,rate,info,(type == YM2610) ? ym2610_stream_update : ym2610b_stream_update);
163
/* setup adpcm buffers */
164
pcmbufa = *device->region();
165
pcmsizea = device->region()->bytes();
166
name.printf("%s.deltat", device->tag());
167
pcmbufb = (void *)(device->machine().region(name)->base());
168
pcmsizeb = device->machine().region(name)->bytes();
169
if (pcmbufb == NULL || pcmsizeb == 0)
175
/**** initialize YM2610 ****/
176
info->chip = ym2610_init(info,device,device->clock(),rate,
177
pcmbufa,pcmsizea,pcmbufb,pcmsizeb,
178
timer_handler,IRQHandler,&psgintf);
179
assert_always(info->chip != NULL, "Error creating YM2610 chip");
181
device->machine().save().register_postload(save_prepost_delegate(FUNC(ym2610_intf_postload), info));
184
static DEVICE_STOP( ym2610 )
186
ym2610_state *info = get_safe_token(device);
187
ym2610_shutdown(info->chip);
188
ay8910_stop_ym(info->psg);
191
static DEVICE_RESET( ym2610 )
193
ym2610_state *info = get_safe_token(device);
194
ym2610_reset_chip(info->chip);
198
READ8_DEVICE_HANDLER( ym2610_r )
200
ym2610_state *info = get_safe_token(device);
201
return ym2610_read(info->chip, offset & 3);
204
WRITE8_DEVICE_HANDLER( ym2610_w )
206
ym2610_state *info = get_safe_token(device);
207
ym2610_write(info->chip, offset & 3, data);
211
READ8_DEVICE_HANDLER( ym2610_status_port_a_r ) { return ym2610_r(device, 0); }
212
READ8_DEVICE_HANDLER( ym2610_status_port_b_r ) { return ym2610_r(device, 2); }
213
READ8_DEVICE_HANDLER( ym2610_read_port_r ) { return ym2610_r(device, 1); }
215
WRITE8_DEVICE_HANDLER( ym2610_control_port_a_w ) { ym2610_w(device, 0, data); }
216
WRITE8_DEVICE_HANDLER( ym2610_control_port_b_w ) { ym2610_w(device, 2, data); }
217
WRITE8_DEVICE_HANDLER( ym2610_data_port_a_w ) { ym2610_w(device, 1, data); }
218
WRITE8_DEVICE_HANDLER( ym2610_data_port_b_w ) { ym2610_w(device, 3, data); }
222
/**************************************************************************
224
**************************************************************************/
226
DEVICE_GET_INFO( ym2610 )
230
/* --- the following bits of info are returned as 64-bit signed integers --- */
231
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ym2610_state); break;
233
/* --- the following bits of info are returned as pointers to data or functions --- */
234
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( ym2610 ); break;
235
case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME( ym2610 ); break;
236
case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( ym2610 ); break;
238
/* --- the following bits of info are returned as NULL-terminated strings --- */
239
case DEVINFO_STR_NAME: strcpy(info->s, "YM2610"); break;
240
case DEVINFO_STR_FAMILY: strcpy(info->s, "Yamaha FM"); break;
241
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
242
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
243
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
247
DEVICE_GET_INFO( ym2610b )
251
/* --- the following bits of info are returned as NULL-terminated strings --- */
252
case DEVINFO_STR_NAME: strcpy(info->s, "YM2610B"); break;
254
default: DEVICE_GET_INFO_CALL(ym2610); break;
259
DEFINE_LEGACY_SOUND_DEVICE(YM2610, ym2610);
260
DEFINE_LEGACY_SOUND_DEVICE(YM2610B, ym2610b);