1 /******************************************************************************
2 * FILE
3 * Yamaha 3812 emulator interface - MAME VERSION
4 *
5 * CREATED BY
6 * Ernesto Corvi
7 *
8 * UPDATE LOG
9 * JB 28-04-2002 Fixed simultaneous usage of all three different chip types.
10 * Used real sample rate when resample filter is active.
11 * AAT 12-28-2001 Protected Y8950 from accessing unmapped port and keyboard handlers.
12 * CHS 1999-01-09 Fixes new ym3812 emulation interface.
13 * CHS 1998-10-23 Mame streaming sound chip update
14 * EC 1998 Created Interface
15 *
16 * NOTES
17 *
18 ******************************************************************************/
19 #include "mamedef.h"
20 #include <stdlib.h>
21 //#include "attotime.h"
22 //#include "sndintrf.h"
23 //#include "streams.h"
24 //#include "cpuintrf.h"
25 #include "8950intf.h"
26 //#include "fm.h"
27 #include "fmopl.h"
28
29 #include <memory.h>
30
31 #define NULL ((void *)0)
32
33
34 typedef struct _y8950_state y8950_state;
35 struct _y8950_state
36 {
37 //sound_stream * stream;
38 //emu_timer * timer[2];
39 void * chip;
40 //const y8950_interface *intf;
41 //const device_config *device;
42 };
43
44
45 /*INLINE y8950_state *get_safe_token(const device_config *device)
46 {
47 assert(device != NULL);
48 assert(device->token != NULL);
49 assert(device->type == SOUND);
50 assert(sound_get_type(device) == SOUND_Y8950);
51 return (y8950_state *)device->token;
52 }*/
53
54
IRQHandler(void * param,int irq)55 static void IRQHandler(void *param,int irq)
56 {
57 y8950_state *info = (y8950_state *)param;
58 //if (info->intf->handler) (info->intf->handler)(info->device, irq ? ASSERT_LINE : CLEAR_LINE);
59 //if (info->intf->handler) (info->intf->handler)(irq ? ASSERT_LINE : CLEAR_LINE);
60 }
61 /*static TIMER_CALLBACK( timer_callback_0 )
62 {
63 y8950_state *info = (y8950_state *)ptr;
64 y8950_timer_over(info->chip,0);
65 }
66 static TIMER_CALLBACK( timer_callback_1 )
67 {
68 y8950_state *info = (y8950_state *)ptr;
69 y8950_timer_over(info->chip,1);
70 }*/
71 //static void TimerHandler(void *param,int c,attotime period)
TimerHandler(void * param,int c,int period)72 static void TimerHandler(void *param,int c,int period)
73 {
74 y8950_state *info = (y8950_state *)param;
75 //if( attotime_compare(period, attotime_zero) == 0 )
76 if( period == 0 )
77 { /* Reset FM Timer */
78 //timer_enable(info->timer[c], 0);
79 }
80 else
81 { /* Start FM Timer */
82 //timer_adjust_oneshot(info->timer[c], period, 0);
83 }
84 }
85
86
Y8950PortHandler_r(void * param)87 static unsigned char Y8950PortHandler_r(void *param)
88 {
89 y8950_state *info = (y8950_state *)param;
90 /*if (info->intf->portread)
91 return info->intf->portread(0);*/
92 return 0;
93 }
94
Y8950PortHandler_w(void * param,unsigned char data)95 static void Y8950PortHandler_w(void *param,unsigned char data)
96 {
97 y8950_state *info = (y8950_state *)param;
98 /*if (info->intf->portwrite)
99 info->intf->portwrite(0,data);*/
100 }
101
Y8950KeyboardHandler_r(void * param)102 static unsigned char Y8950KeyboardHandler_r(void *param)
103 {
104 y8950_state *info = (y8950_state *)param;
105 /*if (info->intf->keyboardread)
106 return info->intf->keyboardread(0);*/
107 return 0;
108 }
109
Y8950KeyboardHandler_w(void * param,unsigned char data)110 static void Y8950KeyboardHandler_w(void *param,unsigned char data)
111 {
112 y8950_state *info = (y8950_state *)param;
113 /*if (info->intf->keyboardwrite)
114 info->intf->keyboardwrite(0,data);*/
115 }
116
117 //static STREAM_UPDATE( y8950_stream_update )
y8950_stream_update(void * param,stream_sample_t ** outputs,int samples)118 void y8950_stream_update(void *param, stream_sample_t **outputs, int samples)
119 {
120 y8950_state *info = (y8950_state *)param;
121 y8950_update_one(info->chip, outputs, samples);
122 }
123
124 static stream_sample_t* DUMMYBUF[0x02] = {NULL, NULL};
125
_stream_update(void * param)126 static void _stream_update(void *param/*, int interval*/)
127 {
128 y8950_state *info = (y8950_state *)param;
129 //stream_update(info->stream);
130
131 y8950_update_one(info->chip, DUMMYBUF, 0);
132 }
133
134
135 //static DEVICE_START( y8950 )
device_start_y8950(void ** _info,int clock,int CHIP_SAMPLING_MODE,int CHIP_SAMPLE_RATE)136 int device_start_y8950(void **_info, int clock, int CHIP_SAMPLING_MODE, int CHIP_SAMPLE_RATE)
137 {
138 //static const y8950_interface dummy = { 0 };
139 //y8950_state *info = get_safe_token(device);
140 y8950_state *info;
141 int rate;
142
143 info = (y8950_state *) calloc(1, sizeof(y8950_state));
144 *_info = (void *) info;
145
146 rate = clock/72;
147 if ((CHIP_SAMPLING_MODE == 0x01 && rate < CHIP_SAMPLE_RATE) ||
148 CHIP_SAMPLING_MODE == 0x02)
149 rate = CHIP_SAMPLE_RATE;
150 //info->intf = device->static_config ? (const y8950_interface *)device->static_config : &dummy;
151 //info->intf = &dummy;
152 //info->device = device;
153
154 /* stream system initialize */
155 info->chip = y8950_init(clock,rate);
156 //assert_always(info->chip != NULL, "Error creating Y8950 chip");
157
158 /* ADPCM ROM data */
159 //y8950_set_delta_t_memory(info->chip, device->region, device->regionbytes);
160 y8950_set_delta_t_memory(info->chip, NULL, 0x00);
161
162 //info->stream = stream_create(device,0,1,rate,info,y8950_stream_update);
163
164 /* port and keyboard handler */
165 y8950_set_port_handler(info->chip, Y8950PortHandler_w, Y8950PortHandler_r, info);
166 y8950_set_keyboard_handler(info->chip, Y8950KeyboardHandler_w, Y8950KeyboardHandler_r, info);
167
168 /* Y8950 setup */
169 y8950_set_timer_handler (info->chip, TimerHandler, info);
170 y8950_set_irq_handler (info->chip, IRQHandler, info);
171 y8950_set_update_handler(info->chip, _stream_update, info);
172
173 //info->timer[0] = timer_alloc(device->machine, timer_callback_0, info);
174 //info->timer[1] = timer_alloc(device->machine, timer_callback_1, info);
175
176 return rate;
177 }
178
179 //static DEVICE_STOP( y8950 )
device_stop_y8950(void * _info)180 void device_stop_y8950(void *_info)
181 {
182 //y8950_state *info = get_safe_token(device);
183 y8950_state *info = (y8950_state *)_info;
184 y8950_shutdown(info->chip);
185 free(info);
186 }
187
188 //static DEVICE_RESET( y8950 )
device_reset_y8950(void * _info)189 void device_reset_y8950(void *_info)
190 {
191 //y8950_state *info = get_safe_token(device);
192 y8950_state *info = (y8950_state *)_info;
193 y8950_reset_chip(info->chip);
194 }
195
196
197 //READ8_DEVICE_HANDLER( y8950_r )
y8950_r(void * _info,offs_t offset)198 UINT8 y8950_r(void *_info, offs_t offset)
199 {
200 //y8950_state *info = get_safe_token(device);
201 y8950_state *info = (y8950_state *)_info;
202 return y8950_read(info->chip, offset & 1);
203 }
204
205 //WRITE8_DEVICE_HANDLER( y8950_w )
y8950_w(void * _info,offs_t offset,UINT8 data)206 void y8950_w(void *_info, offs_t offset, UINT8 data)
207 {
208 //y8950_state *info = get_safe_token(device);
209 y8950_state *info = (y8950_state *)_info;
210 y8950_write(info->chip, offset & 1, data);
211 }
212
213 //READ8_DEVICE_HANDLER( y8950_status_port_r )
y8950_status_port_r(void * info,offs_t offset)214 UINT8 y8950_status_port_r(void *info, offs_t offset)
215 {
216 return y8950_r(info, 0);
217 }
218 //READ8_DEVICE_HANDLER( y8950_read_port_r )
y8950_read_port_r(void * info,offs_t offset)219 UINT8 y8950_read_port_r(void *info, offs_t offset)
220 {
221 return y8950_r(info, 1);
222 }
223 //WRITE8_DEVICE_HANDLER( y8950_control_port_w )
y8950_control_port_w(void * info,offs_t offset,UINT8 data)224 void y8950_control_port_w(void *info, offs_t offset, UINT8 data)
225 {
226 y8950_w(info, 0, data);
227 }
228 //WRITE8_DEVICE_HANDLER( y8950_write_port_w )
y8950_write_port_w(void * info,offs_t offset,UINT8 data)229 void y8950_write_port_w(void *info, offs_t offset, UINT8 data)
230 {
231 y8950_w(info, 1, data);
232 }
233
234
y8950_write_data_pcmrom(void * _info,offs_t ROMSize,offs_t DataStart,offs_t DataLength,const UINT8 * ROMData)235 void y8950_write_data_pcmrom(void *_info, offs_t ROMSize, offs_t DataStart,
236 offs_t DataLength, const UINT8* ROMData)
237 {
238 y8950_state* info = (y8950_state *)_info;
239
240 y8950_write_pcmrom(info->chip, ROMSize, DataStart, DataLength, ROMData);
241
242 return;
243 }
244
y8950_set_mute_mask(void * _info,UINT32 MuteMask)245 void y8950_set_mute_mask(void *_info, UINT32 MuteMask)
246 {
247 y8950_state *info = (y8950_state *)_info;
248 opl_set_mute_mask(info->chip, MuteMask);
249 }
250
251
252 /**************************************************************************
253 * Generic get_info
254 **************************************************************************/
255
256 /*DEVICE_GET_INFO( y8950 )
257 {
258 switch (state)
259 {
260 // --- the following bits of info are returned as 64-bit signed integers ---
261 case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(y8950_state); break;
262
263 // --- the following bits of info are returned as pointers to data or functions ---
264 case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( y8950 ); break;
265 case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME( y8950 ); break;
266 case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( y8950 ); break;
267
268 // --- the following bits of info are returned as NULL-terminated strings ---
269 case DEVINFO_STR_NAME: strcpy(info->s, "Y8950"); break;
270 case DEVINFO_STR_FAMILY: strcpy(info->s, "Yamaha FM"); break;
271 case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
272 case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
273 case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
274 }
275 }*/
276