1 /*
2   File: fm.h -- header file for software emulation for FM sound generator
3 
4 */
5 
6 #ifndef FM_HHHHH
7 #define FM_HHHHH
8 
9 #include <stdint.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #include "mamedef.h"
16 
17 /* --- select emulation chips --- */
18 /*
19 #define BUILD_YM2203  (HAS_YM2203)		// build YM2203(OPN)   emulator
20 #define BUILD_YM2608  (HAS_YM2608)		// build YM2608(OPNA)  emulator
21 #define BUILD_YM2610  (HAS_YM2610)		// build YM2610(OPNB)  emulator
22 #define BUILD_YM2610B (HAS_YM2610B)		// build YM2610B(OPNB?)emulator
23 #define BUILD_YM2612  (HAS_YM2612)		// build YM2612(OPN2)  emulator
24 #define BUILD_YM3438  (HAS_YM3438)		// build YM3438(OPN) emulator
25 */
26 #define BUILD_YM2203  0
27 #define BUILD_YM2608  0
28 #define BUILD_YM2610  0
29 #define BUILD_YM2610B 0
30 #define BUILD_YM2612  1
31 #define BUILD_YM3438  0
32 
33 #define FM_BUSY_FLAG_SUPPORT 0
34 
35 /* select bit size of output : 8 or 16 */
36 #define FM_SAMPLE_BITS 16
37 
38 /* select timer system internal or external */
39 #define FM_INTERNAL_TIMER 1
40 
41 /* --- speedup optimize --- */
42 /* busy flag enulation , The definition of FM_GET_TIME_NOW() is necessary. */
43 /* #define FM_BUSY_FLAG_SUPPORT 1 */
44 
45 /* --- external SSG(YM2149/AY-3-8910)emulator interface port */
46 /* used by YM2203,YM2608,and YM2610 */
47 typedef struct _ssg_callbacks ssg_callbacks;
48 struct _ssg_callbacks
49 {
50 	void (*set_clock)(void *param, int clock);
51 	void (*write)(void *param, int address, int data);
52 	int (*read)(void *param);
53 	void (*reset)(void *param);
54 };
55 
56 /* --- external callback funstions for realtime update --- */
57 
58 #if FM_BUSY_FLAG_SUPPORT
59 #define TIME_TYPE					attotime
60 #define UNDEFINED_TIME				attotime_zero
61 #define FM_GET_TIME_NOW(machine)			timer_get_time(machine)
62 #define ADD_TIMES(t1, t2)   		attotime_add((t1), (t2))
63 #define COMPARE_TIMES(t1, t2)		attotime_compare((t1), (t2))
64 #define MULTIPLY_TIME_BY_INT(t,i)	attotime_mul(t, i)
65 #endif
66 
67 /* compiler dependence */
68 #if 0
69 #ifndef OSD_CPU_H
70 #define OSD_CPU_H
71 typedef unsigned char	UINT8;   /* unsigned  8bit */
72 typedef unsigned short	UINT16;  /* unsigned 16bit */
73 typedef unsigned int	UINT32;  /* unsigned 32bit */
74 typedef signed char		INT8;    /* signed  8bit   */
75 typedef signed short	INT16;   /* signed 16bit   */
76 typedef signed int		INT32;   /* signed 32bit   */
77 #endif /* OSD_CPU_H */
78 #endif
79 
80 
81 
82 typedef stream_sample_t FMSAMPLE;
83 /*
84 #if (FM_SAMPLE_BITS==16)
85 typedef INT16 FMSAMPLE;
86 #endif
87 #if (FM_SAMPLE_BITS==8)
88 typedef unsigned char  FMSAMPLE;
89 #endif
90 */
91 
92 typedef void (*FM_TIMERHANDLER)(void *param,int c,int cnt,int clock);
93 typedef void (*FM_IRQHANDLER)(void *param,int irq);
94 /* FM_TIMERHANDLER : Stop or Start timer         */
95 /* int n          = chip number                  */
96 /* int c          = Channel 0=TimerA,1=TimerB    */
97 /* int count      = timer count (0=stop)         */
98 /* doube stepTime = step time of one count (sec.)*/
99 
100 /* FM_IRQHHANDLER : IRQ level changing sense     */
101 /* int n       = chip number                     */
102 /* int irq     = IRQ level 0=OFF,1=ON            */
103 
104 #if (BUILD_YM2612||BUILD_YM3438)
105 
106 /**
107  * @brief Initialize chip and return the instance
108  * @param param Unused, keep NULL
109  * @param baseclock YM2612 clock
110  * @param rate Output sample rate
111  * @param TimerHandler Keep NULL
112  * @param IRQHandler Keep NULL
113  * @return Chip instance or NULL on any error
114  */
115 void * ym2612_init(void *param, int baseclock, int rate,
116                FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler);
117 /**
118  * @brief Free chip instance
119  * @param chip Chip instance
120  */
121 void ym2612_shutdown(void *chip);
122 /**
123  * @brief Reset state of the chip
124  * @param chip Chip instance
125  */
126 void ym2612_reset_chip(void *chip);
127 /**
128  * @brief Generate stereo output of specified length
129  * @param chip Chip instance
130  * @param buffer Output sound buffer
131  * @param frames Output buffer size in frames (one frame - two array entries of the buffer)
132  * @param mix 0 - override buffer data, 1 - mix output data with a content of the buffer
133  */
134 void ym2612_generate(void *chip, FMSAMPLE *buffer, int frames, int mix);
135 #define ym2612_update_one(chip, buffer, length) ym2612_generate(chip, buffer, length, 0)
136 
137 /**
138  * @brief Single-Sample generation prepare
139  * @param chip Chip instance
140  */
141 void ym2612_pre_generate(void *chip);
142 /**
143  * @brief Generate single stereo PCM frame. Will be used native sample rate of 53267 Hz
144  * @param chip Chip instance
145  * @param buffer One stereo PCM frame
146  */
147 void ym2612_generate_one_native(void *chip, FMSAMPLE buffer[2]);
148 
149 /* void ym2612_post_generate(void *chip, int length); */
150 
151 int ym2612_write(void *chip, int a, unsigned char v);
152 void ym2612_write_pan(void *chip, int c, unsigned char v);
153 unsigned char ym2612_read(void *chip, int a);
154 int ym2612_timer_over(void *chip, int c );
155 void ym2612_postload(void *chip);
156 
157 void ym2612_set_mutemask(void *chip, UINT32 MuteMask);
158 void ym2612_setoptions(UINT8 Flags);
159 #endif /* (BUILD_YM2612||BUILD_YM3438) */
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* FM_HHHHH */
166