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 <stddef.h> // for NULL
20 #include "mamedef.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
30 typedef struct _y8950_state y8950_state;
31 struct _y8950_state
32 {
33 //sound_stream * stream;
34 //emu_timer * timer[2];
35 void * chip;
36 //const y8950_interface *intf;
37 //const device_config *device;
38 };
39
40
41 extern UINT8 CHIP_SAMPLING_MODE;
42 extern INT32 CHIP_SAMPLE_RATE;
43 #define MAX_CHIPS 0x02
44 static y8950_state Y8950Data[MAX_CHIPS];
45
46 /*INLINE y8950_state *get_safe_token(const device_config *device)
47 {
48 assert(device != NULL);
49 assert(device->token != NULL);
50 assert(device->type == SOUND);
51 assert(sound_get_type(device) == SOUND_Y8950);
52 return (y8950_state *)device->token;
53 }*/
54
55
IRQHandler(void * param,int irq)56 static void IRQHandler(void *param,int irq)
57 {
58 y8950_state *info = (y8950_state *)param;
59 //if (info->intf->handler) (info->intf->handler)(info->device, irq ? ASSERT_LINE : CLEAR_LINE);
60 //if (info->intf->handler) (info->intf->handler)(irq ? ASSERT_LINE : CLEAR_LINE);
61 }
62 /*static TIMER_CALLBACK( timer_callback_0 )
63 {
64 y8950_state *info = (y8950_state *)ptr;
65 y8950_timer_over(info->chip,0);
66 }
67 static TIMER_CALLBACK( timer_callback_1 )
68 {
69 y8950_state *info = (y8950_state *)ptr;
70 y8950_timer_over(info->chip,1);
71 }*/
72 //static void TimerHandler(void *param,int c,attotime period)
TimerHandler(void * param,int c,int period)73 static void TimerHandler(void *param,int c,int period)
74 {
75 y8950_state *info = (y8950_state *)param;
76 //if( attotime_compare(period, attotime_zero) == 0 )
77 if( period == 0 )
78 { /* Reset FM Timer */
79 //timer_enable(info->timer[c], 0);
80 }
81 else
82 { /* Start FM Timer */
83 //timer_adjust_oneshot(info->timer[c], period, 0);
84 }
85 }
86
87
Y8950PortHandler_r(void * param)88 static unsigned char Y8950PortHandler_r(void *param)
89 {
90 y8950_state *info = (y8950_state *)param;
91 /*if (info->intf->portread)
92 return info->intf->portread(0);*/
93 return 0;
94 }
95
Y8950PortHandler_w(void * param,unsigned char data)96 static void Y8950PortHandler_w(void *param,unsigned char data)
97 {
98 y8950_state *info = (y8950_state *)param;
99 /*if (info->intf->portwrite)
100 info->intf->portwrite(0,data);*/
101 }
102
Y8950KeyboardHandler_r(void * param)103 static unsigned char Y8950KeyboardHandler_r(void *param)
104 {
105 y8950_state *info = (y8950_state *)param;
106 /*if (info->intf->keyboardread)
107 return info->intf->keyboardread(0);*/
108 return 0;
109 }
110
Y8950KeyboardHandler_w(void * param,unsigned char data)111 static void Y8950KeyboardHandler_w(void *param,unsigned char data)
112 {
113 y8950_state *info = (y8950_state *)param;
114 /*if (info->intf->keyboardwrite)
115 info->intf->keyboardwrite(0,data);*/
116 }
117
118 //static STREAM_UPDATE( y8950_stream_update )
y8950_stream_update(UINT8 ChipID,stream_sample_t ** outputs,int samples)119 void y8950_stream_update(UINT8 ChipID, stream_sample_t **outputs, int samples)
120 {
121 //y8950_state *info = (y8950_state *)param;
122 y8950_state *info = &Y8950Data[ChipID];
123 y8950_update_one(info->chip, outputs, samples);
124 }
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(UINT8 ChipID,int clock)136 int device_start_y8950(UINT8 ChipID, int clock)
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 if (ChipID >= MAX_CHIPS)
144 return 0;
145
146 info = &Y8950Data[ChipID];
147 rate = clock/72;
148 if ((CHIP_SAMPLING_MODE == 0x01 && rate < CHIP_SAMPLE_RATE) ||
149 CHIP_SAMPLING_MODE == 0x02)
150 rate = CHIP_SAMPLE_RATE;
151 //info->intf = device->static_config ? (const y8950_interface *)device->static_config : &dummy;
152 //info->intf = &dummy;
153 //info->device = device;
154
155 /* stream system initialize */
156 info->chip = y8950_init(clock,rate);
157 //assert_always(info->chip != NULL, "Error creating Y8950 chip");
158
159 /* ADPCM ROM data */
160 //y8950_set_delta_t_memory(info->chip, device->region, device->regionbytes);
161 y8950_set_delta_t_memory(info->chip, NULL, 0x00);
162
163 //info->stream = stream_create(device,0,1,rate,info,y8950_stream_update);
164
165 /* port and keyboard handler */
166 y8950_set_port_handler(info->chip, Y8950PortHandler_w, Y8950PortHandler_r, info);
167 y8950_set_keyboard_handler(info->chip, Y8950KeyboardHandler_w, Y8950KeyboardHandler_r, info);
168
169 /* Y8950 setup */
170 y8950_set_timer_handler (info->chip, TimerHandler, info);
171 y8950_set_irq_handler (info->chip, IRQHandler, info);
172 y8950_set_update_handler(info->chip, _stream_update, info);
173
174 //info->timer[0] = timer_alloc(device->machine, timer_callback_0, info);
175 //info->timer[1] = timer_alloc(device->machine, timer_callback_1, info);
176
177 return rate;
178 }
179
180 //static DEVICE_STOP( y8950 )
device_stop_y8950(UINT8 ChipID)181 void device_stop_y8950(UINT8 ChipID)
182 {
183 //y8950_state *info = get_safe_token(device);
184 y8950_state *info = &Y8950Data[ChipID];
185 y8950_shutdown(info->chip);
186 }
187
188 //static DEVICE_RESET( y8950 )
device_reset_y8950(UINT8 ChipID)189 void device_reset_y8950(UINT8 ChipID)
190 {
191 //y8950_state *info = get_safe_token(device);
192 y8950_state *info = &Y8950Data[ChipID];
193 y8950_reset_chip(info->chip);
194 }
195
196
197 //READ8_DEVICE_HANDLER( y8950_r )
y8950_r(UINT8 ChipID,offs_t offset)198 UINT8 y8950_r(UINT8 ChipID, offs_t offset)
199 {
200 //y8950_state *info = get_safe_token(device);
201 y8950_state *info = &Y8950Data[ChipID];
202 return y8950_read(info->chip, offset & 1);
203 }
204
205 //WRITE8_DEVICE_HANDLER( y8950_w )
y8950_w(UINT8 ChipID,offs_t offset,UINT8 data)206 void y8950_w(UINT8 ChipID, offs_t offset, UINT8 data)
207 {
208 //y8950_state *info = get_safe_token(device);
209 y8950_state *info = &Y8950Data[ChipID];
210 y8950_write(info->chip, offset & 1, data);
211 }
212
213 //READ8_DEVICE_HANDLER( y8950_status_port_r )
y8950_status_port_r(UINT8 ChipID,offs_t offset)214 UINT8 y8950_status_port_r(UINT8 ChipID, offs_t offset)
215 {
216 return y8950_r(ChipID, 0);
217 }
218 //READ8_DEVICE_HANDLER( y8950_read_port_r )
y8950_read_port_r(UINT8 ChipID,offs_t offset)219 UINT8 y8950_read_port_r(UINT8 ChipID, offs_t offset)
220 {
221 return y8950_r(ChipID, 1);
222 }
223 //WRITE8_DEVICE_HANDLER( y8950_control_port_w )
y8950_control_port_w(UINT8 ChipID,offs_t offset,UINT8 data)224 void y8950_control_port_w(UINT8 ChipID, offs_t offset, UINT8 data)
225 {
226 y8950_w(ChipID, 0, data);
227 }
228 //WRITE8_DEVICE_HANDLER( y8950_write_port_w )
y8950_write_port_w(UINT8 ChipID,offs_t offset,UINT8 data)229 void y8950_write_port_w(UINT8 ChipID, offs_t offset, UINT8 data)
230 {
231 y8950_w(ChipID, 1, data);
232 }
233
234
y8950_write_data_pcmrom(UINT8 ChipID,offs_t ROMSize,offs_t DataStart,offs_t DataLength,const UINT8 * ROMData)235 void y8950_write_data_pcmrom(UINT8 ChipID, offs_t ROMSize, offs_t DataStart,
236 offs_t DataLength, const UINT8* ROMData)
237 {
238 y8950_state* info = &Y8950Data[ChipID];
239
240 y8950_write_pcmrom(info->chip, ROMSize, DataStart, DataLength, ROMData);
241
242 return;
243 }
244
y8950_set_mute_mask(UINT8 ChipID,UINT32 MuteMask)245 void y8950_set_mute_mask(UINT8 ChipID, UINT32 MuteMask)
246 {
247 y8950_state *info = &Y8950Data[ChipID];
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