forked from vgmrips/vgmplay-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3812intf.c
334 lines (292 loc) · 8.25 KB
/
3812intf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/******************************************************************************
* FILE
* Yamaha 3812 emulator interface - MAME VERSION
*
* CREATED BY
* Ernesto Corvi
*
* UPDATE LOG
* JB 28-04-2002 Fixed simultaneous usage of all three different chip types.
* Used real sample rate when resample filter is active.
* AAT 12-28-2001 Protected Y8950 from accessing unmapped port and keyboard handlers.
* CHS 1999-01-09 Fixes new ym3812 emulation interface.
* CHS 1998-10-23 Mame streaming sound chip update
* EC 1998 Created Interface
*
* NOTES
*
******************************************************************************/
#include <stddef.h> // for NULL
#include "mamedef.h"
//#include "attotime.h"
//#include "sndintrf.h"
//#include "streams.h"
//#include "cpuintrf.h"
#include "3812intf.h"
#ifdef ENABLE_ALL_CORES
#include "fmopl.h"
#endif
#define OPLTYPE_IS_OPL2
#include "adlibemu.h"
#define EC_DBOPL 0x00 // DosBox OPL (AdLibEmu)
#ifdef ENABLE_ALL_CORES
#define EC_MAME 0x01 // YM3826 core from MAME
#endif
typedef struct _ym3812_state ym3812_state;
struct _ym3812_state
{
//sound_stream * stream;
//emu_timer * timer[2];
void * chip;
//const ym3812_interface *intf;
//const device_config *device;
};
extern UINT8 CHIP_SAMPLING_MODE;
extern INT32 CHIP_SAMPLE_RATE;
static UINT8 EMU_CORE = 0x00;
#define MAX_CHIPS 0x02
static ym3812_state YM3812Data[MAX_CHIPS];
/*INLINE ym3812_state *get_safe_token(const device_config *device)
{
assert(device != NULL);
assert(device->token != NULL);
assert(device->type == SOUND);
assert(sound_get_type(device) == SOUND_YM3812);
return (ym3812_state *)device->token;
}*/
static void IRQHandler(void *param,int irq)
{
ym3812_state *info = (ym3812_state *)param;
//if (info->intf->handler) (info->intf->handler)(info->device, irq ? ASSERT_LINE : CLEAR_LINE);
//if (info->intf->handler) (info->intf->handler)(irq ? ASSERT_LINE : CLEAR_LINE);
}
/*static TIMER_CALLBACK( timer_callback_0 )
{
ym3812_state *info = (ym3812_state *)ptr;
ym3812_timer_over(info->chip,0);
}
static TIMER_CALLBACK( timer_callback_1 )
{
ym3812_state *info = (ym3812_state *)ptr;
ym3812_timer_over(info->chip,1);
}*/
//static void TimerHandler(void *param,int c,attotime period)
static void TimerHandler(void *param,int c,int period)
{
ym3812_state *info = (ym3812_state *)param;
//if( attotime_compare(period, attotime_zero) == 0 )
if( period == 0 )
{ /* Reset FM Timer */
//timer_enable(info->timer[c], 0);
}
else
{ /* Start FM Timer */
//timer_adjust_oneshot(info->timer[c], period, 0);
}
}
//static STREAM_UPDATE( ym3812_stream_update )
void ym3812_stream_update(UINT8 ChipID, stream_sample_t **outputs, int samples)
{
//ym3812_state *info = (ym3812_state *)param;
ym3812_state *info = &YM3812Data[ChipID];
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
ym3812_update_one(info->chip, outputs, samples);
break;
#endif
case EC_DBOPL:
adlib_OPL2_getsample(info->chip, outputs, samples);
break;
}
}
static void _stream_update(void * param/*, int interval*/)
{
ym3812_state *info = (ym3812_state *)param;
//stream_update(info->stream);
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
ym3812_update_one(info->chip, DUMMYBUF, 0);
break;
#endif
case EC_DBOPL:
adlib_OPL2_getsample(info->chip, DUMMYBUF, 0);
break;
}
}
//static DEVICE_START( ym3812 )
int device_start_ym3812(UINT8 ChipID, int clock)
{
//static const ym3812_interface dummy = { 0 };
//ym3812_state *info = get_safe_token(device);
ym3812_state *info;
int rate;
if (ChipID >= MAX_CHIPS)
return 0;
info = &YM3812Data[ChipID];
rate = (clock & 0x7FFFFFFF)/72;
if ((CHIP_SAMPLING_MODE == 0x01 && rate < CHIP_SAMPLE_RATE) ||
CHIP_SAMPLING_MODE == 0x02)
rate = CHIP_SAMPLE_RATE;
//info->intf = device->static_config ? (const ym3812_interface *)device->static_config : &dummy;
//info->intf = &dummy;
//info->device = device;
/* stream system initialize */
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
info->chip = ym3812_init(clock & 0x7FFFFFFF,rate);
//assert_always(info->chip != NULL, "Error creating YM3812 chip");
//info->stream = stream_create(device,0,1,rate,info,ym3812_stream_update);
/* YM3812 setup */
ym3812_set_timer_handler (info->chip, TimerHandler, info);
ym3812_set_irq_handler (info->chip, IRQHandler, info);
ym3812_set_update_handler(info->chip, _stream_update, info);
//info->timer[0] = timer_alloc(device->machine, timer_callback_0, info);
//info->timer[1] = timer_alloc(device->machine, timer_callback_1, info);
break;
#endif
case EC_DBOPL:
info->chip = adlib_OPL2_init(clock & 0x7FFFFFFF, rate, _stream_update, info);
break;
}
return rate;
}
//static DEVICE_STOP( ym3812 )
void device_stop_ym3812(UINT8 ChipID)
{
//ym3812_state *info = get_safe_token(device);
ym3812_state *info = &YM3812Data[ChipID];
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
ym3812_shutdown(info->chip);
break;
#endif
case EC_DBOPL:
adlib_OPL2_stop(info->chip);
break;
}
}
//static DEVICE_RESET( ym3812 )
void device_reset_ym3812(UINT8 ChipID)
{
//ym3812_state *info = get_safe_token(device);
ym3812_state *info = &YM3812Data[ChipID];
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
ym3812_reset_chip(info->chip);
break;
#endif
case EC_DBOPL:
adlib_OPL2_reset(info->chip);
break;
}
}
//READ8_DEVICE_HANDLER( ym3812_r )
UINT8 ym3812_r(UINT8 ChipID, offs_t offset)
{
//ym3812_state *info = get_safe_token(device);
ym3812_state *info = &YM3812Data[ChipID];
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
return ym3812_read(info->chip, offset & 1);
#endif
case EC_DBOPL:
return adlib_OPL2_reg_read(info->chip, offset & 0x01);
default:
return 0x00;
}
}
//WRITE8_DEVICE_HANDLER( ym3812_w )
void ym3812_w(UINT8 ChipID, offs_t offset, UINT8 data)
{
//ym3812_state *info = get_safe_token(device);
ym3812_state *info = &YM3812Data[ChipID];
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
ym3812_write(info->chip, offset & 1, data);
break;
#endif
case EC_DBOPL:
adlib_OPL2_writeIO(info->chip, offset & 1, data);
break;
}
}
//READ8_DEVICE_HANDLER( ym3812_status_port_r )
UINT8 ym3812_status_port_r(UINT8 ChipID, offs_t offset)
{
return ym3812_r(ChipID, 0);
}
//READ8_DEVICE_HANDLER( ym3812_read_port_r )
UINT8 ym3812_read_port_r(UINT8 ChipID, offs_t offset)
{
return ym3812_r(ChipID, 1);
}
//WRITE8_DEVICE_HANDLER( ym3812_control_port_w )
void ym3812_control_port_w(UINT8 ChipID, offs_t offset, UINT8 data)
{
ym3812_w(ChipID, 0, data);
}
//WRITE8_DEVICE_HANDLER( ym3812_write_port_w )
void ym3812_write_port_w(UINT8 ChipID, offs_t offset, UINT8 data)
{
ym3812_w(ChipID, 1, data);
}
void ym3812_set_emu_core(UINT8 Emulator)
{
#ifdef ENABLE_ALL_CORES
EMU_CORE = (Emulator < 0x02) ? Emulator : 0x00;
#else
EMU_CORE = EC_DBOPL;
#endif
return;
}
void ym3812_set_mute_mask(UINT8 ChipID, UINT32 MuteMask)
{
ym3812_state *info = &YM3812Data[ChipID];
switch(EMU_CORE)
{
#ifdef ENABLE_ALL_CORES
case EC_MAME:
opl_set_mute_mask(info->chip, MuteMask);
break;
#endif
case EC_DBOPL:
adlib_OPL2_set_mute_mask(info->chip, MuteMask);
break;
}
return;
}
/**************************************************************************
* Generic get_info
**************************************************************************/
/*DEVICE_GET_INFO( ym3812 )
{
switch (state)
{
// --- the following bits of info are returned as 64-bit signed integers ---
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ym3812_state); break;
// --- the following bits of info are returned as pointers to data or functions ---
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( ym3812 ); break;
case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME( ym3812 ); break;
case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( ym3812 ); break;
// --- the following bits of info are returned as NULL-terminated strings ---
case DEVINFO_STR_NAME: strcpy(info->s, "YM3812"); break;
case DEVINFO_STR_FAMILY: strcpy(info->s, "Yamaha FM"); break;
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
}
}*/