-
Notifications
You must be signed in to change notification settings - Fork 0
/
fm.h
244 lines (202 loc) · 7.12 KB
/
fm.h
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
/*
File: fm.h -- header file for software emulation for FM sound generator
*/
#ifndef _H_FM_FM_
#define _H_FM_FM_
#include <stdint.h>
/* --- select emulation chips --- */
#define BUILD_YM2203 (HAS_YM2203) /* build YM2203(OPN) emulator */
#define BUILD_YM2608 (HAS_YM2608) /* build YM2608(OPNA) emulator */
#define BUILD_YM2610 (HAS_YM2610) /* build YM2610(OPNB) emulator */
#define BUILD_YM2610B (HAS_YM2610B) /* build YM2610B(OPNB?)emulator */
#define BUILD_YM2612 1 /* build YM2612(OPN2) emulator */
//#define BUILD_YM2151 (HAS_YM2151) /* build YM2151(OPM) emulator */
#define FM_SSG_PRESCALER 0
/* select bit size of output : 8 or 16 */
#define FM_SAMPLE_BITS 16
/* select timer system internal or external */
#define FM_INTERNAL_TIMER 0
/* --- speedup optimize --- */
/* busy flag enulation , The definition of FM_GET_TIME_NOW() is necessary. */
#define FM_BUSY_FLAG_SUPPORT 0
/* --- external SSG(YM2149/AY-3-8910)emulator interface port */
/* used by YM2203,YM2608,and YM2610 */
/* SSGClk : Set SSG Clock */
/* int n = chip number */
/* int clk = MasterClock(Hz) */
/* int rate = sample rate(Hz) */
#define SSGClk(chip,clock) AY8910_set_clock((chip)+ay8910_index_ym,clock)
/* SSGWrite : Write SSG port */
/* int n = chip number */
/* int a = address */
/* int v = data */
#define SSGWrite(n,a,v) AY8910Write((n)+ay8910_index_ym,a,v)
/* SSGRead : Read SSG port */
/* int n = chip number */
/* return = Read data */
#define SSGRead(n) AY8910Read((n)+ay8910_index_ym)
/* SSGReset : Reset SSG chip */
/* int n = chip number */
#define SSGReset(chip) AY8910Reset((chip)+ay8910_index_ym)
/* --- external callback funstions for realtime update --- */
/* for busy flag emulation , function FM_GET_TIME_NOW() should */
/* return present time in seconds with "double" precision */
/* in timer.c */
#define FM_GET_TIME_NOW() timer_get_time()
#if 0
#if BUILD_YM2203
/* in 2203intf.c */
void BurnYM2203UpdateRequest(void);
#define YM2203UpdateReq(chip) BurnYM2203UpdateRequest()
#endif
#if BUILD_YM2608
/* in 2608intf.c */
void BurnYM2608UpdateRequest(void);
#define YM2608UpdateReq(chip) BurnYM2608UpdateRequest()
#endif
#if BUILD_YM2610
/* in 2610intf.c */
void BurnYM2610UpdateRequest(void);
#define YM2610UpdateReq(chip) BurnYM2610UpdateRequest()
#endif
#if BUILD_YM2612
/* in 2612intf.c */
void BurnYM2612UpdateRequest(void);
#define YM2612UpdateReq(chip) BurnYM2612UpdateRequest()
#endif
#if 0 //BUILD_YM2151
/* in 2151intf.c */
#define YM2151UpdateReq(chip) YM2151UpdateRequest(chip);
#endif
#else
#define YM2612UpdateReq(chip) (void)0
#endif
/* compiler dependence */
typedef uint8_t UINT8; /* unsigned 8bit */
typedef uint16_t UINT16; /* unsigned 16bit */
typedef uint32_t UINT32; /* unsigned 32bit */
typedef int8_t INT8; /* signed 8bit */
typedef int16_t INT16; /* signed 16bit */
typedef int32_t INT32; /* signed 32bit */
#ifndef INLINE
#define INLINE static inline
#endif
#if (FM_SAMPLE_BITS==16)
typedef INT16 FMSAMPLE;
#endif
#if (FM_SAMPLE_BITS==8)
typedef UINT8 FMSAMPLE;
#endif
typedef void (*FM_TIMERHANDLER)(int n,int c,int cnt,double stepTime);
typedef void (*FM_IRQHANDLER)(int n,int irq);
/* FM_TIMERHANDLER : Stop or Start timer */
/* int n = chip number */
/* int c = Channel 0=TimerA,1=TimerB */
/* int count = timer count (0=stop) */
/* doube stepTime = step time of one count (sec.)*/
/* FM_IRQHHANDLER : IRQ level changing sense */
/* int n = chip number */
/* int irq = IRQ level 0=OFF,1=ON */
//#if BUILD_YM2203
#if 1
/* -------------------- YM2203(OPN) Interface -------------------- */
/*
** Initialize YM2203 emulator(s).
**
** 'num' is the number of virtual YM2203's to allocate
** 'baseclock'
** 'rate' is sampling rate
** 'TimerHandler' timer callback handler when timer start and clear
** 'IRQHandler' IRQ callback handler when changed IRQ level
** return 0 = success
*/
int YM2203Init(int num, int baseclock, int rate,
FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler);
/*
** shutdown the YM2203 emulators
*/
void YM2203Shutdown(void);
/*
** reset all chip registers for YM2203 number 'num'
*/
void YM2203ResetChip(int num);
/*
** update one of chip
*/
void YM2203UpdateOne(int num, INT16 *buffer, int length);
/*
** Write
** return : InterruptLevel
*/
int YM2203Write(int n,int a,unsigned char v);
/*
** Read
** return : InterruptLevel
*/
unsigned char YM2203Read(int n,int a);
/*
** Timer OverFlow
*/
int YM2203TimerOver(int n, int c);
#endif /* BUILD_YM2203 */
#if BUILD_YM2608
/* -------------------- YM2608(OPNA) Interface -------------------- */
int YM2608Init(int num, int baseclock, int rate,
void **pcmroma,int *pcmsizea,
FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler);
void YM2608Shutdown(void);
void YM2608ResetChip(int num);
void YM2608UpdateOne(int num, INT16 **buffer, int length);
int YM2608Write(int n, int a,unsigned char v);
unsigned char YM2608Read(int n,int a);
int YM2608TimerOver(int n, int c );
#endif /* BUILD_YM2608 */
#if (BUILD_YM2610||BUILD_YM2610B)
/* -------------------- YM2610(OPNB) Interface -------------------- */
int YM2610Init(int num, int baseclock, int rate,
void **pcmroma,int *pcmasize,void **pcmromb,int *pcmbsize,
FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler);
void YM2610SetRom(int num,
void *pcmroma,int pcmsizea,void *pcmromb,int pcmsizeb);
void YM2610Shutdown(void);
void YM2610ResetChip(int num);
void YM2610UpdateOne(int num, INT16 **buffer, int length);
#if BUILD_YM2610B
void YM2610BUpdateOne(int num, INT16 **buffer, int length);
#endif
int YM2610Write(int n, int a,unsigned char v);
unsigned char YM2610Read(int n,int a);
int YM2610TimerOver(int n, int c );
#endif /* BUILD_YM2610 */
#if BUILD_YM2612
int YM2612Init(int num, int baseclock, int rate, int mjazz,
FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler);
void YM2612Shutdown(void);
void YM2612ResetChip(int num);
void YM2612UpdateOne(int num, INT16 *buffer, unsigned int length,
unsigned int volume, int loud);
int YM2612Write(int n, int a,unsigned char v);
unsigned char YM2612Read(int n,int a);
int YM2612TimerOver(int n, int c );
void YM2612_dump(int num, uint8_t buf[512]);
void YM2612_restore(int num, uint8_t buf[512]);
#endif /* BUILD_YM2612 */
#if 0 //BUILD_YM2151
/* -------------------- YM2151(OPM) Interface -------------------- */
int OPMInit(int num, int baseclock, int rate,
FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler);
void OPMShutdown(void);
void OPMResetChip(int num);
void OPMUpdateOne(int num, INT16 **buffer, int length );
/* ---- set callback hander when port CT0/1 write ----- */
/* CT.bit0 = CT0 , CT.bit1 = CT1 */
/*
typedef void (*write8_handler)(int offset,int data);
*/
void OPMSetPortHander(int n,write8_handler PortWrite);
/* JB 981119 - so it will match MAME's memory write functions scheme*/
int YM2151Write(int n,int a,unsigned char v);
unsigned char YM2151Read(int n,int a);
int YM2151TimerOver(int n,int c);
#endif /* BUILD_YM2151 */
#endif /* _H_FM_FM_ */