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