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 "attotime.h"
21 //#include "sndintrf.h"
22 //#include "streams.h"
23 //#include "cpuintrf.h"
24 #include "3526intf.h"
25 #include "fmopl.h"
26 
27 typedef struct _ym3526_state ym3526_state;
28 struct _ym3526_state
29 {
30 	//sound_stream *	stream;
31 	//emu_timer *		timer[2];
32 	void *			chip;
33 	//const ym3526_interface *intf;
34 	//const device_config *device;
35 };
36 
37 
38 extern UINT8 CHIP_SAMPLING_MODE;
39 extern INT32 CHIP_SAMPLE_RATE;
40 #define MAX_CHIPS	0x02
41 static ym3526_state YM3526Data[MAX_CHIPS];
42 
43 /*INLINE ym3526_state *get_safe_token(const device_config *device)
44 {
45 	assert(device != NULL);
46 	assert(device->token != NULL);
47 	assert(device->type == SOUND);
48 	assert(sound_get_type(device) == SOUND_YM3526);
49 	return (ym3526_state *)device->token;
50 }*/
51 
52 
53 /* IRQ Handler */
IRQHandler(void * param,int irq)54 static void IRQHandler(void *param,int irq)
55 {
56 	ym3526_state *info = (ym3526_state *)param;
57 	//if (info->intf->handler) (info->intf->handler)(info->device, irq ? ASSERT_LINE : CLEAR_LINE);
58 	//if (info->intf->handler) (info->intf->handler)(irq ? ASSERT_LINE : CLEAR_LINE);
59 }
60 /* Timer overflow callback from timer.c */
61 /*static TIMER_CALLBACK( timer_callback_0 )
62 {
63 	ym3526_state *info = (ym3526_state *)ptr;
64 	ym3526_timer_over(info->chip,0);
65 }
66 static TIMER_CALLBACK( timer_callback_1 )
67 {
68 	ym3526_state *info = (ym3526_state *)ptr;
69 	ym3526_timer_over(info->chip,1);
70 }*/
71 /* TimerHandler from fm.c */
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 	ym3526_state *info = (ym3526_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 
88 //static STREAM_UPDATE( ym3526_stream_update )
ym3526_stream_update(UINT8 ChipID,stream_sample_t ** outputs,int samples)89 void ym3526_stream_update(UINT8 ChipID, stream_sample_t **outputs, int samples)
90 {
91 	//ym3526_state *info = (ym3526_state *)param;
92 	ym3526_state *info = &YM3526Data[ChipID];
93 	ym3526_update_one(info->chip, outputs, samples);
94 }
95 
_stream_update(void * param)96 static void _stream_update(void *param/*, int interval*/)
97 {
98 	ym3526_state *info = (ym3526_state *)param;
99 	//stream_update(info->stream);
100 
101 	ym3526_update_one(info->chip, DUMMYBUF, 0);
102 }
103 
104 
105 //static DEVICE_START( ym3526 )
device_start_ym3526(UINT8 ChipID,int clock)106 int device_start_ym3526(UINT8 ChipID, int clock)
107 {
108 	//static const ym3526_interface dummy = { 0 };
109 	//ym3526_state *info = get_safe_token(device);
110 	ym3526_state *info;
111 	int rate;
112 
113 	if (ChipID >= MAX_CHIPS)
114 		return 0;
115 
116 	info = &YM3526Data[ChipID];
117 	rate = clock/72;
118 	if ((CHIP_SAMPLING_MODE == 0x01 && rate < CHIP_SAMPLE_RATE) ||
119 		CHIP_SAMPLING_MODE == 0x02)
120 		rate = CHIP_SAMPLE_RATE;
121 	//info->intf = device->static_config ? (const ym3526_interface *)device->static_config : &dummy;
122 	//info->intf = &dummy;
123 	//info->device = device;
124 
125 	/* stream system initialize */
126 	info->chip = ym3526_init(clock,rate);
127 	//assert_always(info->chip != NULL, "Error creating YM3526 chip");
128 
129 	//info->stream = stream_create(device,0,1,rate,info,ym3526_stream_update);
130 	/* YM3526 setup */
131 	ym3526_set_timer_handler (info->chip, TimerHandler, info);
132 	ym3526_set_irq_handler   (info->chip, IRQHandler, info);
133 	ym3526_set_update_handler(info->chip, _stream_update, info);
134 
135 	//info->timer[0] = timer_alloc(device->machine, timer_callback_0, info);
136 	//info->timer[1] = timer_alloc(device->machine, timer_callback_1, info);
137 
138 	return rate;
139 }
140 
141 //static DEVICE_STOP( ym3526 )
device_stop_ym3526(UINT8 ChipID)142 void device_stop_ym3526(UINT8 ChipID)
143 {
144 	//ym3526_state *info = get_safe_token(device);
145 	ym3526_state *info = &YM3526Data[ChipID];
146 	ym3526_shutdown(info->chip);
147 }
148 
149 //static DEVICE_RESET( ym3526 )
device_reset_ym3526(UINT8 ChipID)150 void device_reset_ym3526(UINT8 ChipID)
151 {
152 	//ym3526_state *info = get_safe_token(device);
153 	ym3526_state *info = &YM3526Data[ChipID];
154 	ym3526_reset_chip(info->chip);
155 }
156 
157 
158 //READ8_DEVICE_HANDLER( ym3526_r )
ym3526_r(UINT8 ChipID,offs_t offset)159 UINT8 ym3526_r(UINT8 ChipID, offs_t offset)
160 {
161 	//ym3526_state *info = get_safe_token(device);
162 	ym3526_state *info = &YM3526Data[ChipID];
163 	return ym3526_read(info->chip, offset & 1);
164 }
165 
166 //WRITE8_DEVICE_HANDLER( ym3526_w )
ym3526_w(UINT8 ChipID,offs_t offset,UINT8 data)167 void ym3526_w(UINT8 ChipID, offs_t offset, UINT8 data)
168 {
169 	//ym3526_state *info = get_safe_token(device);
170 	ym3526_state *info = &YM3526Data[ChipID];
171 	ym3526_write(info->chip, offset & 1, data);
172 }
173 
174 //READ8_DEVICE_HANDLER( ym3526_status_port_r )
ym3526_status_port_r(UINT8 ChipID,offs_t offset)175 UINT8 ym3526_status_port_r(UINT8 ChipID, offs_t offset)
176 {
177 	return ym3526_r(ChipID, 0);
178 }
179 //READ8_DEVICE_HANDLER( ym3526_read_port_r )
ym3526_read_port_r(UINT8 ChipID,offs_t offset)180 UINT8 ym3526_read_port_r(UINT8 ChipID, offs_t offset)
181 {
182 	return ym3526_r(ChipID, 1);
183 }
184 //WRITE8_DEVICE_HANDLER( ym3526_control_port_w )
ym3526_control_port_w(UINT8 ChipID,offs_t offset,UINT8 data)185 void ym3526_control_port_w(UINT8 ChipID, offs_t offset, UINT8 data)
186 {
187 	ym3526_w(ChipID, 0, data);
188 }
189 //WRITE8_DEVICE_HANDLER( ym3526_write_port_w )
ym3526_write_port_w(UINT8 ChipID,offs_t offset,UINT8 data)190 void ym3526_write_port_w(UINT8 ChipID, offs_t offset, UINT8 data)
191 {
192 	ym3526_w(ChipID, 1, data);
193 }
194 
195 
ym3526_set_mute_mask(UINT8 ChipID,UINT32 MuteMask)196 void ym3526_set_mute_mask(UINT8 ChipID, UINT32 MuteMask)
197 {
198 	ym3526_state *info = &YM3526Data[ChipID];
199 	opl_set_mute_mask(info->chip, MuteMask);
200 }
201 
202 
203 /**************************************************************************
204  * Generic get_info
205  **************************************************************************/
206 
207 /*DEVICE_GET_INFO( ym3526 )
208 {
209 	switch (state)
210 	{
211 		// --- the following bits of info are returned as 64-bit signed integers ---
212 		case DEVINFO_INT_TOKEN_BYTES:					info->i = sizeof(ym3526_state);				break;
213 
214 		// --- the following bits of info are returned as pointers to data or functions ---
215 		case DEVINFO_FCT_START:							info->start = DEVICE_START_NAME( ym3526 );				break;
216 		case DEVINFO_FCT_STOP:							info->stop = DEVICE_STOP_NAME( ym3526 );				break;
217 		case DEVINFO_FCT_RESET:							info->reset = DEVICE_RESET_NAME( ym3526 );				break;
218 
219 		// --- the following bits of info are returned as NULL-terminated strings ---
220 		case DEVINFO_STR_NAME:							strcpy(info->s, "YM3526");							break;
221 		case DEVINFO_STR_FAMILY:					strcpy(info->s, "Yamaha FM");						break;
222 		case DEVINFO_STR_VERSION:					strcpy(info->s, "1.0");								break;
223 		case DEVINFO_STR_SOURCE_FILE:						strcpy(info->s, __FILE__);							break;
224 		case DEVINFO_STR_CREDITS:					strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
225 	}
226 }*/
227