cc68a136 |
1 | /*\r |
2 | header file for software emulation for FM sound generator\r |
3 | \r |
4 | */\r |
5 | #ifndef _H_FM_FM_\r |
6 | #define _H_FM_FM_\r |
7 | \r |
8 | /* compiler dependence */\r |
9 | #ifndef UINT8\r |
10 | typedef unsigned char UINT8; /* unsigned 8bit */\r |
11 | typedef unsigned short UINT16; /* unsigned 16bit */\r |
12 | typedef unsigned int UINT32; /* unsigned 32bit */\r |
13 | #endif\r |
14 | #ifndef INT8\r |
15 | typedef signed char INT8; /* signed 8bit */\r |
16 | typedef signed short INT16; /* signed 16bit */\r |
17 | typedef signed int INT32; /* signed 32bit */\r |
18 | #endif\r |
19 | \r |
20 | #if 1\r |
21 | /* struct describing a single operator (SLOT) */\r |
22 | typedef struct\r |
23 | {\r |
24 | INT32 *DT; /* #0x00 detune :dt_tab[DT] */\r |
25 | UINT8 ar; /* #0x04 attack rate */\r |
26 | UINT8 d1r; /* #0x05 decay rate */\r |
27 | UINT8 d2r; /* #0x06 sustain rate */\r |
28 | UINT8 rr; /* #0x07 release rate */\r |
29 | UINT32 mul; /* #0x08 multiple :ML_TABLE[ML] */\r |
30 | \r |
31 | /* Phase Generator */\r |
32 | UINT32 phase; /* #0x0c phase counter */\r |
33 | UINT32 Incr; /* #0x10 phase step */\r |
34 | \r |
35 | UINT8 KSR; /* #0x14 key scale rate :3-KSR */\r |
36 | UINT8 ksr; /* #0x15 key scale rate :kcode>>(3-KSR) */\r |
37 | \r |
38 | UINT8 key; /* #0x16 0=last key was KEY OFF, 1=KEY ON */\r |
39 | \r |
40 | /* Envelope Generator */\r |
41 | UINT8 state; /* #0x17 phase type: EG_OFF=0, EG_REL, EG_SUS, EG_DEC, EG_ATT */\r |
42 | UINT16 tl; /* #0x18 total level: TL << 3 */\r |
43 | INT16 volume; /* #0x1a envelope counter */\r |
44 | UINT32 sl; /* #0x1c sustain level:sl_table[SL] */\r |
45 | \r |
46 | UINT32 eg_pack_ar; /* #0x20 (attack state) */\r |
47 | UINT32 eg_pack_d1r; /* #0x24 (decay state) */\r |
48 | UINT32 eg_pack_d2r; /* #0x28 (sustain state) */\r |
49 | UINT32 eg_pack_rr; /* #0x2c (release state) */\r |
50 | } FM_SLOT;\r |
51 | \r |
52 | \r |
53 | typedef struct\r |
54 | {\r |
55 | FM_SLOT SLOT[4]; /* four SLOTs (operators) */\r |
56 | \r |
57 | UINT8 ALGO; /* algorithm */\r |
58 | UINT8 FB; /* feedback shift */\r |
59 | INT32 op1_out; /* op1 output for feedback */\r |
60 | \r |
61 | INT32 mem_value; /* delayed sample (MEM) value */\r |
62 | \r |
63 | INT32 pms; /* channel PMS */\r |
64 | UINT8 ams; /* channel AMS */\r |
65 | \r |
66 | UINT8 kcode; /* key code: */\r |
67 | UINT32 fc; /* fnum,blk:adjusted to sample rate */\r |
68 | UINT32 block_fnum; /* current blk/fnum value for this slot (can be different betweeen slots of one channel in 3slot mode) */\r |
69 | \r |
70 | /* LFO */\r |
71 | UINT8 AMmasks; /* AM enable flag */\r |
72 | \r |
73 | } FM_CH;\r |
74 | \r |
75 | typedef struct\r |
76 | {\r |
77 | int clock; /* master clock (Hz) */\r |
78 | int rate; /* sampling rate (Hz) */\r |
b542be46 |
79 | double freqbase; /* 08 frequency base */\r |
80 | UINT8 address; /* 10 address register */\r |
81 | UINT8 status; /* 11 status flag */\r |
cc68a136 |
82 | UINT8 mode; /* mode CSM / 3SLOT */\r |
83 | UINT8 fn_h; /* freq latch */\r |
84 | int TA; /* timer a */\r |
85 | int TAC; /* timer a maxval */\r |
86 | int TAT; /* timer a ticker */\r |
87 | UINT8 TB; /* timer b */\r |
b542be46 |
88 | UINT8 pad[3];\r |
cc68a136 |
89 | int TBC; /* timer b maxval */\r |
90 | int TBT; /* timer b ticker */\r |
91 | /* local time tables */\r |
92 | INT32 dt_tab[8][32];/* DeTune table */\r |
93 | } FM_ST;\r |
94 | \r |
95 | /***********************************************************/\r |
96 | /* OPN unit */\r |
97 | /***********************************************************/\r |
98 | \r |
99 | /* OPN 3slot struct */\r |
100 | typedef struct\r |
101 | {\r |
102 | UINT32 fc[3]; /* fnum3,blk3: calculated */\r |
103 | UINT8 fn_h; /* freq3 latch */\r |
104 | UINT8 kcode[3]; /* key code */\r |
105 | UINT32 block_fnum[3]; /* current fnum value for this slot (can be different betweeen slots of one channel in 3slot mode) */\r |
106 | } FM_3SLOT;\r |
107 | \r |
108 | /* OPN/A/B common state */\r |
109 | typedef struct\r |
110 | {\r |
111 | FM_ST ST; /* general state */\r |
112 | FM_3SLOT SL3; /* 3 slot mode state */\r |
113 | UINT32 pan; /* fm channels output mask (bit 1 = enable) */\r |
114 | \r |
115 | UINT32 eg_cnt; /* #0xb38 global envelope generator counter */\r |
116 | UINT32 eg_timer; /* #0xb3c global envelope generator counter works at frequency = chipclock/64/3 */\r |
117 | UINT32 eg_timer_add; /* #0xb40 step of eg_timer */\r |
118 | \r |
119 | /* LFO */\r |
120 | UINT32 lfo_cnt;\r |
121 | UINT32 lfo_inc;\r |
122 | \r |
123 | UINT32 lfo_freq[8]; /* LFO FREQ table */\r |
124 | } FM_OPN;\r |
125 | \r |
126 | /* here's the virtual YM2612 */\r |
127 | typedef struct\r |
128 | {\r |
129 | UINT8 REGS[0x200]; /* registers (for save states) */\r |
130 | INT32 addr_A1; /* address line A1 */\r |
131 | \r |
132 | FM_CH CH[6]; /* channel state (0x168 bytes each)? */\r |
133 | \r |
134 | /* dac output (YM2612) */\r |
135 | int dacen;\r |
136 | INT32 dacout;\r |
137 | \r |
138 | FM_OPN OPN; /* OPN state */\r |
b542be46 |
139 | \r |
140 | UINT32 slot_mask; /* active slot mask (performance hack) */\r |
cc68a136 |
141 | } YM2612;\r |
142 | #endif\r |
143 | \r |
b542be46 |
144 | extern int *ym2612_dacen;\r |
145 | extern INT32 *ym2612_dacout;\r |
146 | extern FM_ST *ym2612_st;\r |
147 | \r |
148 | \r |
149 | #define YM2612Read() ym2612_st->status\r |
150 | \r |
151 | #define YM2612PicoTick(n) \\r |
152 | { \\r |
153 | /* timer A */ \\r |
154 | if(ym2612_st->mode & 0x01 && (ym2612_st->TAT+=64*n) >= ym2612_st->TAC) { \\r |
155 | ym2612_st->TAT -= ym2612_st->TAC; \\r |
156 | if(ym2612_st->mode & 0x04) ym2612_st->status |= 1; \\r |
157 | } \\r |
158 | \\r |
159 | /* timer B */ \\r |
160 | if(ym2612_st->mode & 0x02 && (ym2612_st->TBT+=64*n) >= ym2612_st->TBC) { \\r |
161 | ym2612_st->TBT -= ym2612_st->TBC; \\r |
162 | if(ym2612_st->mode & 0x08) ym2612_st->status |= 2; \\r |
163 | } \\r |
164 | }\r |
cc68a136 |
165 | \r |
166 | \r |
167 | void YM2612Init_(int baseclock, int rate);\r |
168 | void YM2612ResetChip_(void);\r |
4f265db7 |
169 | int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty);\r |
cc68a136 |
170 | \r |
171 | int YM2612Write_(unsigned int a, unsigned int v);\r |
172 | unsigned char YM2612Read_(void);\r |
173 | \r |
174 | int YM2612PicoTick_(int n);\r |
175 | void YM2612PicoStateLoad_(void);\r |
176 | \r |
177 | void *YM2612GetRegs(void);\r |
178 | \r |
179 | #ifndef __GP2X__\r |
180 | #define YM2612Init YM2612Init_\r |
181 | #define YM2612ResetChip YM2612ResetChip_\r |
182 | #define YM2612UpdateOne YM2612UpdateOne_\r |
183 | #define YM2612Write YM2612Write_\r |
cc68a136 |
184 | #define YM2612PicoStateLoad YM2612PicoStateLoad_\r |
185 | #else\r |
186 | /* GP2X specific */\r |
85f8e929 |
187 | #include "../../platform/gp2x/940ctl.h"\r |
cc68a136 |
188 | extern int PicoOpt;\r |
189 | #define YM2612Init(baseclock,rate) { \\r |
190 | if (PicoOpt&0x200) YM2612Init_940(baseclock, rate); \\r |
191 | else YM2612Init_(baseclock, rate); \\r |
192 | }\r |
193 | #define YM2612ResetChip() { \\r |
194 | if (PicoOpt&0x200) YM2612ResetChip_940(); \\r |
195 | else YM2612ResetChip_(); \\r |
196 | }\r |
85f8e929 |
197 | #define YM2612UpdateOne(buffer,length,stereo,is_buf_empty) \\r |
198 | (PicoOpt&0x200) ? YM2612UpdateOne_940(buffer, length, stereo, is_buf_empty) : \\r |
199 | YM2612UpdateOne_(buffer, length, stereo, is_buf_empty);\r |
cc68a136 |
200 | #define YM2612Write(a,v) \\r |
201 | (PicoOpt&0x200) ? YM2612Write_940(a, v) : YM2612Write_(a, v)\r |
cc68a136 |
202 | #define YM2612PicoStateLoad() { \\r |
203 | if (PicoOpt&0x200) YM2612PicoStateLoad_940(); \\r |
204 | else YM2612PicoStateLoad_(); \\r |
205 | }\r |
206 | #endif /* __GP2X__ */\r |
207 | \r |
208 | \r |
209 | #endif /* _H_FM_FM_ */\r |