OpenCores
URL https://opencores.org/ocsvn/sqmusic/sqmusic/trunk

Subversion Repositories sqmusic

[/] [sqmusic/] [trunk/] [mame/] [fm.c] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 gryzor
#define YM2610B_WARNING
2
 
3
/*
4
**
5
** File: fm.c -- software implementation of Yamaha FM sound generator
6
**
7
** Copyright Jarek Burczynski (bujar at mame dot net)
8
** Copyright Tatsuyuki Satoh , MultiArcadeMachineEmulator development
9
**
10
** Version 1.4.2 (final beta)
11
**
12
*/
13
 
14
/*
15
** History:
16
**
17
** 2006-2008 Eke-Eke (Genesis Plus GX), MAME backport by R. Belmont.
18
**  - implemented PG overflow, aka "detune bug" (Ariel, Comix Zone, Shaq Fu, Spiderman,...), credits to Nemesis
19
**  - fixed SSG-EG support, credits to Nemesis and additional fixes from Alone Coder
20
**  - modified EG rates and frequency, tested by Nemesis on real hardware
21
**  - implemented LFO phase update for CH3 special mode (Warlock birds, Alladin bug sound)
22
**  - fixed Attack Rate update (Batman & Robin intro)
23
**  - fixed attenuation level at the start of Substain (Gynoug explosions)
24
**  - fixed EG decay->substain transition to handle special cases, like SL=0 and Decay rate is very slow (Mega Turrican tracks 03,09...)
25
**
26
** 06-23-2007 Zsolt Vasvari:
27
**  - changed the timing not to require the use of floating point calculations
28
**
29
** 03-08-2003 Jarek Burczynski:
30
**  - fixed YM2608 initial values (after the reset)
31
**  - fixed flag and irqmask handling (YM2608)
32
**  - fixed BUFRDY flag handling (YM2608)
33
**
34
** 14-06-2003 Jarek Burczynski:
35
**  - implemented all of the YM2608 status register flags
36
**  - implemented support for external memory read/write via YM2608
37
**  - implemented support for deltat memory limit register in YM2608 emulation
38
**
39
** 22-05-2003 Jarek Burczynski:
40
**  - fixed LFO PM calculations (copy&paste bugfix)
41
**
42
** 08-05-2003 Jarek Burczynski:
43
**  - fixed SSG support
44
**
45
** 22-04-2003 Jarek Burczynski:
46
**  - implemented 100% correct LFO generator (verified on real YM2610 and YM2608)
47
**
48
** 15-04-2003 Jarek Burczynski:
49
**  - added support for YM2608's register 0x110 - status mask
50
**
51
** 01-12-2002 Jarek Burczynski:
52
**  - fixed register addressing in YM2608, YM2610, YM2610B chips. (verified on real YM2608)
53
**    The addressing patch used for early Neo-Geo games can be removed now.
54
**
55
** 26-11-2002 Jarek Burczynski, Nicola Salmoria:
56
**  - recreated YM2608 ADPCM ROM using data from real YM2608's output which leads to:
57
**  - added emulation of YM2608 drums.
58
**  - output of YM2608 is two times lower now - same as YM2610 (verified on real YM2608)
59
**
60
** 16-08-2002 Jarek Burczynski:
61
**  - binary exact Envelope Generator (verified on real YM2203);
62
**    identical to YM2151
63
**  - corrected 'off by one' error in feedback calculations (when feedback is off)
64
**  - corrected connection (algorithm) calculation (verified on real YM2203 and YM2610)
65
**
66
** 18-12-2001 Jarek Burczynski:
67
**  - added SSG-EG support (verified on real YM2203)
68
**
69
** 12-08-2001 Jarek Burczynski:
70
**  - corrected sin_tab and tl_tab data (verified on real chip)
71
**  - corrected feedback calculations (verified on real chip)
72
**  - corrected phase generator calculations (verified on real chip)
73
**  - corrected envelope generator calculations (verified on real chip)
74
**  - corrected FM volume level (YM2610 and YM2610B).
75
**  - changed YMxxxUpdateOne() functions (YM2203, YM2608, YM2610, YM2610B, YM2612) :
76
**    this was needed to calculate YM2610 FM channels output correctly.
77
**    (Each FM channel is calculated as in other chips, but the output of the channel
78
**    gets shifted right by one *before* sending to accumulator. That was impossible to do
79
**    with previous implementation).
80
**
81
** 23-07-2001 Jarek Burczynski, Nicola Salmoria:
82
**  - corrected YM2610 ADPCM type A algorithm and tables (verified on real chip)
83
**
84
** 11-06-2001 Jarek Burczynski:
85
**  - corrected end of sample bug in ADPCMA_calc_cha().
86
**    Real YM2610 checks for equality between current and end addresses (only 20 LSB bits).
87
**
88
** 08-12-98 hiro-shi:
89
** rename ADPCMA -> ADPCMB, ADPCMB -> ADPCMA
90
** move ROM limit check.(CALC_CH? -> 2610Write1/2)
91
** test program (ADPCMB_TEST)
92
** move ADPCM A/B end check.
93
** ADPCMB repeat flag(no check)
94
** change ADPCM volume rate (8->16) (32->48).
95
**
96
** 09-12-98 hiro-shi:
97
** change ADPCM volume. (8->16, 48->64)
98
** replace ym2610 ch0/3 (YM-2610B)
99
** change ADPCM_SHIFT (10->8) missing bank change 0x4000-0xffff.
100
** add ADPCM_SHIFT_MASK
101
** change ADPCMA_DECODE_MIN/MAX.
102
*/
103
 
104
 
105
 
106
 
107
/************************************************************************/
108
/*    comment of hiro-shi(Hiromitsu Shioya)                             */
109
/*    YM2610(B) = OPN-B                                                 */
110
/*    YM2610  : PSG:3ch FM:4ch ADPCM(18.5KHz):6ch DeltaT ADPCM:1ch      */
111
/*    YM2610B : PSG:3ch FM:6ch ADPCM(18.5KHz):6ch DeltaT ADPCM:1ch      */
112
/************************************************************************/
113
 
114
#include "emu.h"
115
#include "fm.h"
116
 
117
 
118
/* include external DELTA-T unit (when needed) */
119
#if (BUILD_YM2608||BUILD_YM2610||BUILD_YM2610B)
120
        #include "ymdeltat.h"
121
#endif
122
 
123
/* shared function building option */
124
#define BUILD_OPN (BUILD_YM2203||BUILD_YM2608||BUILD_YM2610||BUILD_YM2610B)
125
#define BUILD_OPN_PRESCALER (BUILD_YM2203||BUILD_YM2608)
126
 
127
 
128
/* globals */
129
#define TYPE_SSG    0x01    /* SSG support          */
130
#define TYPE_LFOPAN 0x02    /* OPN type LFO and PAN */
131
#define TYPE_6CH    0x04    /* FM 6CH / 3CH         */
132
#define TYPE_DAC    0x08    /* YM2612's DAC device  */
133
#define TYPE_ADPCM  0x10    /* two ADPCM units      */
134
#define TYPE_2610   0x20    /* bogus flag to differentiate 2608 from 2610 */
135
 
136
 
137
#define TYPE_YM2203 (TYPE_SSG)
138
#define TYPE_YM2608 (TYPE_SSG |TYPE_LFOPAN |TYPE_6CH |TYPE_ADPCM)
139
#define TYPE_YM2610 (TYPE_SSG |TYPE_LFOPAN |TYPE_6CH |TYPE_ADPCM |TYPE_2610)
140
 
141
 
142
 
143
#define FREQ_SH         16  /* 16.16 fixed point (frequency calculations) */
144
#define EG_SH           16  /* 16.16 fixed point (envelope generator timing) */
145
#define LFO_SH          24  /*  8.24 fixed point (LFO calculations)       */
146
#define TIMER_SH        16  /* 16.16 fixed point (timers calculations)    */
147
 
148
#define FREQ_MASK       ((1<<FREQ_SH)-1)
149
 
150
#define ENV_BITS        10
151
#define ENV_LEN         (1<<ENV_BITS)
152
#define ENV_STEP        (128.0/ENV_LEN)
153
 
154
#define MAX_ATT_INDEX   (ENV_LEN-1) /* 1023 */
155
#define MIN_ATT_INDEX   (0)         /* 0 */
156
 
157
#define EG_ATT          4
158
#define EG_DEC          3
159
#define EG_SUS          2
160
#define EG_REL          1
161
#define EG_OFF          0
162
 
163
#define SIN_BITS        10
164
#define SIN_LEN         (1<<SIN_BITS)
165
#define SIN_MASK        (SIN_LEN-1)
166
 
167
#define TL_RES_LEN      (256) /* 8 bits addressing (real chip) */
168
 
169
 
170
#if (FM_SAMPLE_BITS==16)
171
        #define FINAL_SH    (0)
172
        #define MAXOUT      (+32767)
173
        #define MINOUT      (-32768)
174
#else
175
        #define FINAL_SH    (8)
176
        #define MAXOUT      (+127)
177
        #define MINOUT      (-128)
178
#endif
179
 
180
 
181
/*  TL_TAB_LEN is calculated as:
182
*   13 - sinus amplitude bits     (Y axis)
183
*   2  - sinus sign bit           (Y axis)
184
*   TL_RES_LEN - sinus resolution (X axis)
185
*/
186
#define TL_TAB_LEN (13*2*TL_RES_LEN)
187
static signed int tl_tab[TL_TAB_LEN];
188
 
189
#define ENV_QUIET       (TL_TAB_LEN>>3)
190
 
191
/* sin waveform table in 'decibel' scale */
192
static unsigned int sin_tab[SIN_LEN];
193
 
194
/* sustain level table (3dB per step) */
195
/* bit0, bit1, bit2, bit3, bit4, bit5, bit6 */
196
/* 1,    2,    4,    8,    16,   32,   64   (value)*/
197
/* 0.75, 1.5,  3,    6,    12,   24,   48   (dB)*/
198
 
199
/* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/
200
#define SC(db) (UINT32) ( db * (4.0/ENV_STEP) )
201
static const UINT32 sl_table[16]={
202
        SC( 0),SC( 1),SC( 2),SC(3 ),SC(4 ),SC(5 ),SC(6 ),SC( 7),
203
        SC( 8),SC( 9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31)
204
};
205
#undef SC
206
 
207
 
208
#define RATE_STEPS (8)
209
static const UINT8 eg_inc[19*RATE_STEPS]={
210
 
211
/*cycle:0 1  2 3  4 5  6 7*/
212
 
213
/* 0 */ 0,1, 0,1, 0,1, 0,1, /* rates 00..11 0 (increment by 0 or 1) */
214
/* 1 */ 0,1, 0,1, 1,1, 0,1, /* rates 00..11 1 */
215
/* 2 */ 0,1, 1,1, 0,1, 1,1, /* rates 00..11 2 */
216
/* 3 */ 0,1, 1,1, 1,1, 1,1, /* rates 00..11 3 */
217
 
218
/* 4 */ 1,1, 1,1, 1,1, 1,1, /* rate 12 0 (increment by 1) */
219
/* 5 */ 1,1, 1,2, 1,1, 1,2, /* rate 12 1 */
220
/* 6 */ 1,2, 1,2, 1,2, 1,2, /* rate 12 2 */
221
/* 7 */ 1,2, 2,2, 1,2, 2,2, /* rate 12 3 */
222
 
223
/* 8 */ 2,2, 2,2, 2,2, 2,2, /* rate 13 0 (increment by 2) */
224
/* 9 */ 2,2, 2,4, 2,2, 2,4, /* rate 13 1 */
225
/*10 */ 2,4, 2,4, 2,4, 2,4, /* rate 13 2 */
226
/*11 */ 2,4, 4,4, 2,4, 4,4, /* rate 13 3 */
227
 
228
/*12 */ 4,4, 4,4, 4,4, 4,4, /* rate 14 0 (increment by 4) */
229
/*13 */ 4,4, 4,8, 4,4, 4,8, /* rate 14 1 */
230
/*14 */ 4,8, 4,8, 4,8, 4,8, /* rate 14 2 */
231
/*15 */ 4,8, 8,8, 4,8, 8,8, /* rate 14 3 */
232
 
233
/*16 */ 8,8, 8,8, 8,8, 8,8, /* rates 15 0, 15 1, 15 2, 15 3 (increment by 8) */
234
/*17 */ 16,16,16,16,16,16,16,16, /* rates 15 2, 15 3 for attack */
235
/*18 */ 0,0, 0,0, 0,0, 0,0, /* infinity rates for attack and decay(s) */
236
};
237
 
238
 
239
#define O(a) (a*RATE_STEPS)
240
 
241
/*note that there is no O(17) in this table - it's directly in the code */
242
static const UINT8 eg_rate_select[32+64+32]={   /* Envelope Generator rates (32 + 64 rates + 32 RKS) */
243
/* 32 infinite time rates */
244
O(18),O(18),O(18),O(18),O(18),O(18),O(18),O(18),
245
O(18),O(18),O(18),O(18),O(18),O(18),O(18),O(18),
246
O(18),O(18),O(18),O(18),O(18),O(18),O(18),O(18),
247
O(18),O(18),O(18),O(18),O(18),O(18),O(18),O(18),
248
 
249
/* rates 00-11 */
250
O( 0),O( 1),O( 2),O( 3),
251
O( 0),O( 1),O( 2),O( 3),
252
O( 0),O( 1),O( 2),O( 3),
253
O( 0),O( 1),O( 2),O( 3),
254
O( 0),O( 1),O( 2),O( 3),
255
O( 0),O( 1),O( 2),O( 3),
256
O( 0),O( 1),O( 2),O( 3),
257
O( 0),O( 1),O( 2),O( 3),
258
O( 0),O( 1),O( 2),O( 3),
259
O( 0),O( 1),O( 2),O( 3),
260
O( 0),O( 1),O( 2),O( 3),
261
O( 0),O( 1),O( 2),O( 3),
262
 
263
/* rate 12 */
264
O( 4),O( 5),O( 6),O( 7),
265
 
266
/* rate 13 */
267
O( 8),O( 9),O(10),O(11),
268
 
269
/* rate 14 */
270
O(12),O(13),O(14),O(15),
271
 
272
/* rate 15 */
273
O(16),O(16),O(16),O(16),
274
 
275
/* 32 dummy rates (same as 15 3) */
276
O(16),O(16),O(16),O(16),O(16),O(16),O(16),O(16),
277
O(16),O(16),O(16),O(16),O(16),O(16),O(16),O(16),
278
O(16),O(16),O(16),O(16),O(16),O(16),O(16),O(16),
279
O(16),O(16),O(16),O(16),O(16),O(16),O(16),O(16)
280
 
281
};
282
 
283
#undef O
284
 
285
/*rate  0,    1,    2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15*/
286
/*shift 11,  10,  9,  8,  7,  6,  5,  4,  3,  2, 1,  0,  0,  0,  0,  0 */
287
/*mask  2047, 1023, 511, 255, 127, 63, 31, 15, 7,  3, 1,  0,  0,  0,  0,  0 */
288
 
289
#define O(a) (a*1)
290
static const UINT8 eg_rate_shift[32+64+32]={    /* Envelope Generator counter shifts (32 + 64 rates + 32 RKS) */
291
/* 32 infinite time rates */
292
O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0),
293
O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0),
294
O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0),
295
O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0),
296
 
297
/* rates 00-11 */
298
O(11),O(11),O(11),O(11),
299
O(10),O(10),O(10),O(10),
300
O( 9),O( 9),O( 9),O( 9),
301
O( 8),O( 8),O( 8),O( 8),
302
O( 7),O( 7),O( 7),O( 7),
303
O( 6),O( 6),O( 6),O( 6),
304
O( 5),O( 5),O( 5),O( 5),
305
O( 4),O( 4),O( 4),O( 4),
306
O( 3),O( 3),O( 3),O( 3),
307
O( 2),O( 2),O( 2),O( 2),
308
O( 1),O( 1),O( 1),O( 1),
309
O( 0),O( 0),O( 0),O( 0),
310
 
311
/* rate 12 */
312
O( 0),O( 0),O( 0),O( 0),
313
 
314
/* rate 13 */
315
O( 0),O( 0),O( 0),O( 0),
316
 
317
/* rate 14 */
318
O( 0),O( 0),O( 0),O( 0),
319
 
320
/* rate 15 */
321
O( 0),O( 0),O( 0),O( 0),
322
 
323
/* 32 dummy rates (same as 15 3) */
324
O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),
325
O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),
326
O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),
327
O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0)
328
 
329
};
330
#undef O
331
 
332
static const UINT8 dt_tab[4 * 32]={
333
/* this is YM2151 and YM2612 phase increment data (in 10.10 fixed point format)*/
334
/* FD=0 */
335
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
336
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
337
/* FD=1 */
338
        0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
339
        2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
340
/* FD=2 */
341
        1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5,
342
        5, 6, 6, 7, 8, 8, 9,10,11,12,13,14,16,16,16,16,
343
/* FD=3 */
344
        2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7,
345
        8 , 8, 9,10,11,12,13,14,16,17,19,20,22,22,22,22
346
};
347
 
348
 
349
/* OPN key frequency number -> key code follow table */
350
/* fnum higher 4bit -> keycode lower 2bit */
351
static const UINT8 opn_fktable[16] = {0,0,0,0,0,0,0,1,2,3,3,3,3,3,3,3};
352
 
353
 
354
/* 8 LFO speed parameters */
355
/* each value represents number of samples that one LFO level will last for */
356
static const UINT32 lfo_samples_per_step[8] = {108, 77, 71, 67, 62, 44, 8, 5};
357
 
358
 
359
 
360
/*There are 4 different LFO AM depths available, they are:
361
 
362
  Here is how it is generated (in EG steps):
363
 
364
  11.8 dB = 0, 2, 4, 6, 8, 10,12,14,16...126,126,124,122,120,118,....4,2,0
365
   5.9 dB = 0, 1, 2, 3, 4, 5, 6, 7, 8....63, 63, 62, 61, 60, 59,.....2,1,0
366
   1.4 dB = 0, 0, 0, 0, 1, 1, 1, 1, 2,...15, 15, 15, 15, 14, 14,.....0,0,0
367
 
368
  (1.4 dB is losing precision as you can see)
369
 
370
  It's implemented as generator from 0..126 with step 2 then a shift
371
  right N times, where N is:
372
    8 for 0 dB
373
    3 for 1.4 dB
374
    1 for 5.9 dB
375
 
376
*/
377
static const UINT8 lfo_ams_depth_shift[4] = {8, 3, 1, 0};
378
 
379
 
380
 
381
/*There are 8 different LFO PM depths available, they are:
382
  0, 3.4, 6.7, 10, 14, 20, 40, 80 (cents)
383
 
384
  Modulation level at each depth depends on F-NUMBER bits: 4,5,6,7,8,9,10
385
  (bits 8,9,10 = FNUM MSB from OCT/FNUM register)
386
 
387
  Here we store only first quarter (positive one) of full waveform.
388
  Full table (lfo_pm_table) containing all 128 waveforms is build
389
  at run (init) time.
390
 
391
  One value in table below represents 4 (four) basic LFO steps
392
  (1 PM step = 4 AM steps).
393
 
394
  For example:
395
   at LFO SPEED=0 (which is 108 samples per basic LFO step)
396
   one value from "lfo_pm_output" table lasts for 432 consecutive
397
   samples (4*108=432) and one full LFO waveform cycle lasts for 13824
398
   samples (32*432=13824; 32 because we store only a quarter of whole
399
            waveform in the table below)
400
*/
401
static const UINT8 lfo_pm_output[7*8][8]={ /* 7 bits meaningful (of F-NUMBER), 8 LFO output levels per one depth (out of 32), 8 LFO depths */
402
/* FNUM BIT 4: 000 0001xxxx */
403
/* DEPTH 0 */ {0,   0,   0,   0,   0,   0,   0,   0},
404
/* DEPTH 1 */ {0,   0,   0,   0,   0,   0,   0,   0},
405
/* DEPTH 2 */ {0,   0,   0,   0,   0,   0,   0,   0},
406
/* DEPTH 3 */ {0,   0,   0,   0,   0,   0,   0,   0},
407
/* DEPTH 4 */ {0,   0,   0,   0,   0,   0,   0,   0},
408
/* DEPTH 5 */ {0,   0,   0,   0,   0,   0,   0,   0},
409
/* DEPTH 6 */ {0,   0,   0,   0,   0,   0,   0,   0},
410
/* DEPTH 7 */ {0,   0,   0,   0,   1,   1,   1,   1},
411
 
412
/* FNUM BIT 5: 000 0010xxxx */
413
/* DEPTH 0 */ {0,   0,   0,   0,   0,   0,   0,   0},
414
/* DEPTH 1 */ {0,   0,   0,   0,   0,   0,   0,   0},
415
/* DEPTH 2 */ {0,   0,   0,   0,   0,   0,   0,   0},
416
/* DEPTH 3 */ {0,   0,   0,   0,   0,   0,   0,   0},
417
/* DEPTH 4 */ {0,   0,   0,   0,   0,   0,   0,   0},
418
/* DEPTH 5 */ {0,   0,   0,   0,   0,   0,   0,   0},
419
/* DEPTH 6 */ {0,   0,   0,   0,   1,   1,   1,   1},
420
/* DEPTH 7 */ {0,   0,   1,   1,   2,   2,   2,   3},
421
 
422
/* FNUM BIT 6: 000 0100xxxx */
423
/* DEPTH 0 */ {0,   0,   0,   0,   0,   0,   0,   0},
424
/* DEPTH 1 */ {0,   0,   0,   0,   0,   0,   0,   0},
425
/* DEPTH 2 */ {0,   0,   0,   0,   0,   0,   0,   0},
426
/* DEPTH 3 */ {0,   0,   0,   0,   0,   0,   0,   0},
427
/* DEPTH 4 */ {0,   0,   0,   0,   0,   0,   0,   1},
428
/* DEPTH 5 */ {0,   0,   0,   0,   1,   1,   1,   1},
429
/* DEPTH 6 */ {0,   0,   1,   1,   2,   2,   2,   3},
430
/* DEPTH 7 */ {0,   0,   2,   3,   4,   4,   5,   6},
431
 
432
/* FNUM BIT 7: 000 1000xxxx */
433
/* DEPTH 0 */ {0,   0,   0,   0,   0,   0,   0,   0},
434
/* DEPTH 1 */ {0,   0,   0,   0,   0,   0,   0,   0},
435
/* DEPTH 2 */ {0,   0,   0,   0,   0,   0,   1,   1},
436
/* DEPTH 3 */ {0,   0,   0,   0,   1,   1,   1,   1},
437
/* DEPTH 4 */ {0,   0,   0,   1,   1,   1,   1,   2},
438
/* DEPTH 5 */ {0,   0,   1,   1,   2,   2,   2,   3},
439
/* DEPTH 6 */ {0,   0,   2,   3,   4,   4,   5,   6},
440
/* DEPTH 7 */ {0,   0,   4,   6,   8,   8, 0xa, 0xc},
441
 
442
/* FNUM BIT 8: 001 0000xxxx */
443
/* DEPTH 0 */ {0,   0,   0,   0,   0,   0,   0,   0},
444
/* DEPTH 1 */ {0,   0,   0,   0,   1,   1,   1,   1},
445
/* DEPTH 2 */ {0,   0,   0,   1,   1,   1,   2,   2},
446
/* DEPTH 3 */ {0,   0,   1,   1,   2,   2,   3,   3},
447
/* DEPTH 4 */ {0,   0,   1,   2,   2,   2,   3,   4},
448
/* DEPTH 5 */ {0,   0,   2,   3,   4,   4,   5,   6},
449
/* DEPTH 6 */ {0,   0,   4,   6,   8,   8, 0xa, 0xc},
450
/* DEPTH 7 */ {0,   0,   8, 0xc,0x10,0x10,0x14,0x18},
451
 
452
/* FNUM BIT 9: 010 0000xxxx */
453
/* DEPTH 0 */ {0,   0,   0,   0,   0,   0,   0,   0},
454
/* DEPTH 1 */ {0,   0,   0,   0,   2,   2,   2,   2},
455
/* DEPTH 2 */ {0,   0,   0,   2,   2,   2,   4,   4},
456
/* DEPTH 3 */ {0,   0,   2,   2,   4,   4,   6,   6},
457
/* DEPTH 4 */ {0,   0,   2,   4,   4,   4,   6,   8},
458
/* DEPTH 5 */ {0,   0,   4,   6,   8,   8, 0xa, 0xc},
459
/* DEPTH 6 */ {0,   0,   8, 0xc,0x10,0x10,0x14,0x18},
460
/* DEPTH 7 */ {0,   0,0x10,0x18,0x20,0x20,0x28,0x30},
461
 
462
/* FNUM BIT10: 100 0000xxxx */
463
/* DEPTH 0 */ {0,   0,   0,   0,   0,   0,   0,   0},
464
/* DEPTH 1 */ {0,   0,   0,   0,   4,   4,   4,   4},
465
/* DEPTH 2 */ {0,   0,   0,   4,   4,   4,   8,   8},
466
/* DEPTH 3 */ {0,   0,   4,   4,   8,   8, 0xc, 0xc},
467
/* DEPTH 4 */ {0,   0,   4,   8,   8,   8, 0xc,0x10},
468
/* DEPTH 5 */ {0,   0,   8, 0xc,0x10,0x10,0x14,0x18},
469
/* DEPTH 6 */ {0,   0,0x10,0x18,0x20,0x20,0x28,0x30},
470
/* DEPTH 7 */ {0,   0,0x20,0x30,0x40,0x40,0x50,0x60},
471
 
472
};
473
 
474
/* all 128 LFO PM waveforms */
475
static INT32 lfo_pm_table[128*8*32]; /* 128 combinations of 7 bits meaningful (of F-NUMBER), 8 LFO depths, 32 LFO output levels per one depth */
476
 
477
 
478
 
479
 
480
 
481
/* register number to channel number , slot offset */
482
#define OPN_CHAN(N) (N&3)
483
#define OPN_SLOT(N) ((N>>2)&3)
484
 
485
/* slot number */
486
#define SLOT1 0
487
#define SLOT2 2
488
#define SLOT3 1
489
#define SLOT4 3
490
 
491
/* bit0 = Right enable , bit1 = Left enable */
492
#define OUTD_RIGHT  1
493
#define OUTD_LEFT   2
494
#define OUTD_CENTER 3
495
 
496
 
497
/* save output as raw 16-bit sample */
498
/* #define SAVE_SAMPLE */
499
 
500
#ifdef SAVE_SAMPLE
501
static FILE *sample[1];
502
        #if 1   /*save to MONO file */
503
                #define SAVE_ALL_CHANNELS \
504
                {   signed int pom = lt; \
505
                        fputc((unsigned short)pom&0xff,sample[0]); \
506
                        fputc(((unsigned short)pom>>8)&0xff,sample[0]); \
507
                }
508
        #else   /*save to STEREO file */
509
                #define SAVE_ALL_CHANNELS \
510
                {   signed int pom = lt; \
511
                        fputc((unsigned short)pom&0xff,sample[0]); \
512
                        fputc(((unsigned short)pom>>8)&0xff,sample[0]); \
513
                        pom = rt; \
514
                        fputc((unsigned short)pom&0xff,sample[0]); \
515
                        fputc(((unsigned short)pom>>8)&0xff,sample[0]); \
516
                }
517
        #endif
518
#endif
519
 
520
 
521
/* struct describing a single operator (SLOT) */
522
struct FM_SLOT
523
{
524
        INT32   *DT;        /* detune          :dt_tab[DT] */
525
        UINT8   KSR;        /* key scale rate  :3-KSR */
526
        UINT32  ar;         /* attack rate  */
527
        UINT32  d1r;        /* decay rate   */
528
        UINT32  d2r;        /* sustain rate */
529
        UINT32  rr;         /* release rate */
530
        UINT8   ksr;        /* key scale rate  :kcode>>(3-KSR) */
531
        UINT32  mul;        /* multiple        :ML_TABLE[ML] */
532
 
533
        /* Phase Generator */
534
        UINT32  phase;      /* phase counter */
535
        INT32   Incr;       /* phase step */
536
 
537
        /* Envelope Generator */
538
        UINT8   state;      /* phase type */
539
        UINT32  tl;         /* total level: TL << 3 */
540
        INT32   volume;     /* envelope counter */
541
        UINT32  sl;         /* sustain level:sl_table[SL] */
542
        UINT32  vol_out;    /* current output from EG circuit (without AM from LFO) */
543
 
544
        UINT8   eg_sh_ar;   /*  (attack state) */
545
        UINT8   eg_sel_ar;  /*  (attack state) */
546
        UINT8   eg_sh_d1r;  /*  (decay state) */
547
        UINT8   eg_sel_d1r; /*  (decay state) */
548
        UINT8   eg_sh_d2r;  /*  (sustain state) */
549
        UINT8   eg_sel_d2r; /*  (sustain state) */
550
        UINT8   eg_sh_rr;   /*  (release state) */
551
        UINT8   eg_sel_rr;  /*  (release state) */
552
 
553
        UINT8   ssg;        /* SSG-EG waveform */
554
        UINT8   ssgn;       /* SSG-EG negated output */
555
 
556
        UINT32  key;        /* 0=last key was KEY OFF, 1=KEY ON */
557
 
558
        /* LFO */
559
        UINT32  AMmask;     /* AM enable flag */
560
 
561
};
562
 
563
struct FM_CH
564
{
565
        FM_SLOT SLOT[4];    /* four SLOTs (operators) */
566
 
567
        UINT8   ALGO;       /* algorithm */
568
        UINT8   FB;         /* feedback shift */
569
        INT32   op1_out[2]; /* op1 output for feedback */
570
 
571
        INT32   *connect1;  /* SLOT1 output pointer */
572
        INT32   *connect3;  /* SLOT3 output pointer */
573
        INT32   *connect2;  /* SLOT2 output pointer */
574
        INT32   *connect4;  /* SLOT4 output pointer */
575
 
576
        INT32   *mem_connect;/* where to put the delayed sample (MEM) */
577
        INT32   mem_value;  /* delayed sample (MEM) value */
578
 
579
        INT32   pms;        /* channel PMS */
580
        UINT8   ams;        /* channel AMS */
581
 
582
        UINT32  fc;         /* fnum,blk:adjusted to sample rate */
583
        UINT8   kcode;      /* key code:                        */
584
        UINT32  block_fnum; /* current blk/fnum value for this slot (can be different betweeen slots of one channel in 3slot mode) */
585
};
586
 
587
 
588
struct FM_ST
589
{
590
        device_t *device;
591
        void *      param;              /* this chip parameter  */
592
        int         clock;              /* master clock  (Hz)   */
593
        int         rate;               /* sampling rate (Hz)   */
594
        double      freqbase;           /* frequency base       */
595
        int         timer_prescaler;    /* timer prescaler      */
596
#if FM_BUSY_FLAG_SUPPORT
597
        TIME_TYPE   busy_expiry_time;   /* expiry time of the busy status */
598
#endif
599
        UINT8       address;            /* address register     */
600
        UINT8       irq;                /* interrupt level      */
601
        UINT8       irqmask;            /* irq mask             */
602
        UINT8       status;             /* status flag          */
603
        UINT32      mode;               /* mode  CSM / 3SLOT    */
604
        UINT8       prescaler_sel;      /* prescaler selector   */
605
        UINT8       fn_h;               /* freq latch           */
606
        INT32       TA;                 /* timer a              */
607
        INT32       TAC;                /* timer a counter      */
608
        UINT8       TB;                 /* timer b              */
609
        INT32       TBC;                /* timer b counter      */
610
        /* local time tables */
611
        INT32       dt_tab[8][32];      /* DeTune table         */
612
        /* Extention Timer and IRQ handler */
613
        FM_TIMERHANDLER timer_handler;
614
        FM_IRQHANDLER   IRQ_Handler;
615
        const ssg_callbacks *SSG;
616
};
617
 
618
 
619
 
620
/***********************************************************/
621
/* OPN unit                                                */
622
/***********************************************************/
623
 
624
/* OPN 3slot struct */
625
struct FM_3SLOT
626
{
627
        UINT32  fc[3];          /* fnum3,blk3: calculated */
628
        UINT8   fn_h;           /* freq3 latch */
629
        UINT8   kcode[3];       /* key code */
630
        UINT32  block_fnum[3];  /* current fnum value for this slot (can be different betweeen slots of one channel in 3slot mode) */
631
};
632
 
633
/* OPN/A/B common state */
634
struct FM_OPN
635
{
636
        UINT8   type;           /* chip type */
637
        FM_ST   ST;             /* general state */
638
        FM_3SLOT SL3;           /* 3 slot mode state */
639
        FM_CH   *P_CH;          /* pointer of CH */
640
        unsigned int pan[6*2];  /* fm channels output masks (0xffffffff = enable) */
641
 
642
        UINT32  eg_cnt;         /* global envelope generator counter */
643
        UINT32  eg_timer;       /* global envelope generator counter works at frequency = chipclock/64/3 */
644
        UINT32  eg_timer_add;   /* step of eg_timer */
645
        UINT32  eg_timer_overflow;/* envelope generator timer overlfows every 3 samples (on real chip) */
646
 
647
 
648
        /* there are 2048 FNUMs that can be generated using FNUM/BLK registers
649
            but LFO works with one more bit of a precision so we really need 4096 elements */
650
 
651
        UINT32  fn_table[4096]; /* fnumber->increment counter */
652
        UINT32 fn_max;    /* maximal phase increment (used for phase overflow) */
653
 
654
        /* LFO */
655
        UINT32  LFO_AM;         /* runtime LFO calculations helper */
656
        INT32   LFO_PM;         /* runtime LFO calculations helper */
657
 
658
        UINT32  lfo_cnt;
659
        UINT32  lfo_inc;
660
 
661
        UINT32  lfo_freq[8];    /* LFO FREQ table */
662
 
663
        INT32   m2,c1,c2;       /* Phase Modulation input for operators 2,3,4 */
664
        INT32   mem;            /* one sample delay memory */
665
 
666
        INT32   out_fm[8];      /* outputs of working channels */
667
 
668
#if (BUILD_YM2608||BUILD_YM2610||BUILD_YM2610B)
669
        INT32   out_adpcm[4];   /* channel output NONE,LEFT,RIGHT or CENTER for YM2608/YM2610 ADPCM */
670
        INT32   out_delta[4];   /* channel output NONE,LEFT,RIGHT or CENTER for YM2608/YM2610 DELTAT*/
671
#endif
672
};
673
 
674
 
675
 
676
/* current chip state */
677
 
678
/* log output level */
679
#define LOG_ERR  3      /* ERROR       */
680
#define LOG_WAR  2      /* WARNING     */
681
#define LOG_INF  1      /* INFORMATION */
682
#define LOG_LEVEL LOG_INF
683
 
684
#ifndef __RAINE__
685
#define LOG(n,x) do { if( (n)>=LOG_LEVEL ) logerror x; } while (0)
686
#endif
687
 
688
/* limitter */
689
#define Limit(val, max,min) { \
690
        if ( val > max )      val = max; \
691
        else if ( val < min ) val = min; \
692
}
693
 
694
 
695
/* status set and IRQ handling */
696
INLINE void FM_STATUS_SET(FM_ST *ST,int flag)
697
{
698
        /* set status flag */
699
        ST->status |= flag;
700
        if ( !(ST->irq) && (ST->status & ST->irqmask) )
701
        {
702
                ST->irq = 1;
703
                /* callback user interrupt handler (IRQ is OFF to ON) */
704
                if(ST->IRQ_Handler) (ST->IRQ_Handler)(ST->param,1);
705
        }
706
}
707
 
708
/* status reset and IRQ handling */
709
INLINE void FM_STATUS_RESET(FM_ST *ST,int flag)
710
{
711
        /* reset status flag */
712
        ST->status &=~flag;
713
        if ( (ST->irq) && !(ST->status & ST->irqmask) )
714
        {
715
                ST->irq = 0;
716
                /* callback user interrupt handler (IRQ is ON to OFF) */
717
                if(ST->IRQ_Handler) (ST->IRQ_Handler)(ST->param,0);
718
        }
719
}
720
 
721
/* IRQ mask set */
722
INLINE void FM_IRQMASK_SET(FM_ST *ST,int flag)
723
{
724
        ST->irqmask = flag;
725
        /* IRQ handling check */
726
        FM_STATUS_SET(ST,0);
727
        FM_STATUS_RESET(ST,0);
728
}
729
 
730
/* OPN Mode Register Write */
731
INLINE void set_timers( FM_ST *ST, void *n, int v )
732
{
733
        /* b7 = CSM MODE */
734
        /* b6 = 3 slot mode */
735
        /* b5 = reset b */
736
        /* b4 = reset a */
737
        /* b3 = timer enable b */
738
        /* b2 = timer enable a */
739
        /* b1 = load b */
740
        /* b0 = load a */
741
        ST->mode = v;
742
 
743
        /* reset Timer b flag */
744
        if( v & 0x20 )
745
                FM_STATUS_RESET(ST,0x02);
746
        /* reset Timer a flag */
747
        if( v & 0x10 )
748
                FM_STATUS_RESET(ST,0x01);
749
        /* load b */
750
        if( v & 0x02 )
751
        {
752
                if( ST->TBC == 0 )
753
                {
754
                        ST->TBC = ( 256-ST->TB)<<4;
755
                        /* External timer handler */
756
                        if (ST->timer_handler) (ST->timer_handler)(n,1,ST->TBC * ST->timer_prescaler,ST->clock);
757
                }
758
        }
759
        else
760
        {   /* stop timer b */
761
                if( ST->TBC != 0 )
762
                {
763
                        ST->TBC = 0;
764
                        if (ST->timer_handler) (ST->timer_handler)(n,1,0,ST->clock);
765
                }
766
        }
767
        /* load a */
768
        if( v & 0x01 )
769
        {
770
                if( ST->TAC == 0 )
771
                {
772
                        ST->TAC = (1024-ST->TA);
773
                        /* External timer handler */
774
                        if (ST->timer_handler) (ST->timer_handler)(n,0,ST->TAC * ST->timer_prescaler,ST->clock);
775
                }
776
        }
777
        else
778
        {   /* stop timer a */
779
                if( ST->TAC != 0 )
780
                {
781
                        ST->TAC = 0;
782
                        if (ST->timer_handler) (ST->timer_handler)(n,0,0,ST->clock);
783
                }
784
        }
785
}
786
 
787
 
788
/* Timer A Overflow */
789
INLINE void TimerAOver(FM_ST *ST)
790
{
791
        /* set status (if enabled) */
792
        if(ST->mode & 0x04) FM_STATUS_SET(ST,0x01);
793
        /* clear or reload the counter */
794
        ST->TAC = (1024-ST->TA);
795
        if (ST->timer_handler) (ST->timer_handler)(ST->param,0,ST->TAC * ST->timer_prescaler,ST->clock);
796
}
797
/* Timer B Overflow */
798
INLINE void TimerBOver(FM_ST *ST)
799
{
800
        /* set status (if enabled) */
801
        if(ST->mode & 0x08) FM_STATUS_SET(ST,0x02);
802
        /* clear or reload the counter */
803
        ST->TBC = ( 256-ST->TB)<<4;
804
        if (ST->timer_handler) (ST->timer_handler)(ST->param,1,ST->TBC * ST->timer_prescaler,ST->clock);
805
}
806
 
807
 
808
#if FM_INTERNAL_TIMER
809
/* ----- internal timer mode , update timer */
810
 
811
/* ---------- calculate timer A ---------- */
812
        #define INTERNAL_TIMER_A(ST,CSM_CH)                 \
813
        {                                                   \
814
                if( ST->TAC &&  (ST->timer_handler==0) )        \
815
                        if( (ST->TAC -= (int)(ST->freqbase*4096)) <= 0 )    \
816
                        {                                           \
817
                                TimerAOver( ST );                       \
818
                                /* CSM mode total level latch and auto key on */    \
819
                                if( ST->mode & 0x80 )                   \
820
                                        CSMKeyControll( CSM_CH );           \
821
                        }                                           \
822
        }
823
/* ---------- calculate timer B ---------- */
824
        #define INTERNAL_TIMER_B(ST,step)                       \
825
        {                                                       \
826
                if( ST->TBC && (ST->timer_handler==0) )             \
827
                        if( (ST->TBC -= (int)(ST->freqbase*4096*step)) <= 0 )   \
828
                                TimerBOver( ST );                           \
829
        }
830
#else /* FM_INTERNAL_TIMER */
831
/* external timer mode */
832
#define INTERNAL_TIMER_A(ST,CSM_CH)
833
#define INTERNAL_TIMER_B(ST,step)
834
#endif /* FM_INTERNAL_TIMER */
835
 
836
 
837
 
838
#if FM_BUSY_FLAG_SUPPORT
839
#define FM_BUSY_CLEAR(ST) ((ST)->busy_expiry_time = UNDEFINED_TIME)
840
INLINE UINT8 FM_STATUS_FLAG(FM_ST *ST)
841
{
842
        if( COMPARE_TIMES(ST->busy_expiry_time, UNDEFINED_TIME) != 0 )
843
        {
844
                if (COMPARE_TIMES(ST->busy_expiry_time, FM_GET_TIME_NOW(&ST->device->machine())) > 0)
845
                        return ST->status | 0x80;   /* with busy */
846
                /* expire */
847
                FM_BUSY_CLEAR(ST);
848
        }
849
        return ST->status;
850
}
851
INLINE void FM_BUSY_SET(FM_ST *ST,int busyclock )
852
{
853
        TIME_TYPE expiry_period = MULTIPLY_TIME_BY_INT(attotime::from_hz(ST->clock), busyclock * ST->timer_prescaler);
854
        ST->busy_expiry_time = ADD_TIMES(FM_GET_TIME_NOW(&ST->device->machine()), expiry_period);
855
}
856
#else
857
#define FM_STATUS_FLAG(ST) ((ST)->status)
858
#define FM_BUSY_SET(ST,bclock) {}
859
#define FM_BUSY_CLEAR(ST) {}
860
#endif
861
 
862
 
863
 
864
 
865
INLINE void FM_KEYON(UINT8 type, FM_CH *CH , int s )
866
{
867
        FM_SLOT *SLOT = &CH->SLOT[s];
868
        if( !SLOT->key )
869
        {
870
                SLOT->key = 1;
871
                SLOT->phase = 0;        /* restart Phase Generator */
872
                SLOT->ssgn = (SLOT->ssg & 0x04) >> 1;
873
                SLOT->state = EG_ATT;
874
        }
875
}
876
 
877
INLINE void FM_KEYOFF(FM_CH *CH , int s )
878
{
879
        FM_SLOT *SLOT = &CH->SLOT[s];
880
        if( SLOT->key )
881
        {
882
                SLOT->key = 0;
883
                if (SLOT->state>EG_REL)
884
                        SLOT->state = EG_REL;/* phase -> Release */
885
        }
886
}
887
 
888
/* set algorithm connection */
889
static void setup_connection( FM_OPN *OPN, FM_CH *CH, int ch )
890
{
891
        INT32 *carrier = &OPN->out_fm[ch];
892
 
893
        INT32 **om1 = &CH->connect1;
894
        INT32 **om2 = &CH->connect3;
895
        INT32 **oc1 = &CH->connect2;
896
 
897
        INT32 **memc = &CH->mem_connect;
898
 
899
        switch( CH->ALGO )
900
        {
901
        case 0:
902
                /* M1---C1---MEM---M2---C2---OUT */
903
                *om1 = &OPN->c1;
904
                *oc1 = &OPN->mem;
905
                *om2 = &OPN->c2;
906
                *memc= &OPN->m2;
907
                break;
908
        case 1:
909
                /* M1------+-MEM---M2---C2---OUT */
910
                /*      C1-+                     */
911
                *om1 = &OPN->mem;
912
                *oc1 = &OPN->mem;
913
                *om2 = &OPN->c2;
914
                *memc= &OPN->m2;
915
                break;
916
        case 2:
917
                /* M1-----------------+-C2---OUT */
918
                /*      C1---MEM---M2-+          */
919
                *om1 = &OPN->c2;
920
                *oc1 = &OPN->mem;
921
                *om2 = &OPN->c2;
922
                *memc= &OPN->m2;
923
                break;
924
        case 3:
925
                /* M1---C1---MEM------+-C2---OUT */
926
                /*                 M2-+          */
927
                *om1 = &OPN->c1;
928
                *oc1 = &OPN->mem;
929
                *om2 = &OPN->c2;
930
                *memc= &OPN->c2;
931
                break;
932
        case 4:
933
                /* M1---C1-+-OUT */
934
                /* M2---C2-+     */
935
                /* MEM: not used */
936
                *om1 = &OPN->c1;
937
                *oc1 = carrier;
938
                *om2 = &OPN->c2;
939
                *memc= &OPN->mem;   /* store it anywhere where it will not be used */
940
                break;
941
        case 5:
942
                /*    +----C1----+     */
943
                /* M1-+-MEM---M2-+-OUT */
944
                /*    +----C2----+     */
945
                *om1 = 0;   /* special mark */
946
                *oc1 = carrier;
947
                *om2 = carrier;
948
                *memc= &OPN->m2;
949
                break;
950
        case 6:
951
                /* M1---C1-+     */
952
                /*      M2-+-OUT */
953
                /*      C2-+     */
954
                /* MEM: not used */
955
                *om1 = &OPN->c1;
956
                *oc1 = carrier;
957
                *om2 = carrier;
958
                *memc= &OPN->mem;   /* store it anywhere where it will not be used */
959
                break;
960
        case 7:
961
                /* M1-+     */
962
                /* C1-+-OUT */
963
                /* M2-+     */
964
                /* C2-+     */
965
                /* MEM: not used*/
966
                *om1 = carrier;
967
                *oc1 = carrier;
968
                *om2 = carrier;
969
                *memc= &OPN->mem;   /* store it anywhere where it will not be used */
970
                break;
971
        }
972
 
973
        CH->connect4 = carrier;
974
}
975
 
976
/* set detune & multiple */
977
INLINE void set_det_mul(FM_ST *ST,FM_CH *CH,FM_SLOT *SLOT,int v)
978
{
979
        SLOT->mul = (v&0x0f)? (v&0x0f)*2 : 1;
980
        SLOT->DT  = ST->dt_tab[(v>>4)&7];
981
        CH->SLOT[SLOT1].Incr=-1;
982
}
983
 
984
/* set total level */
985
INLINE void set_tl(FM_CH *CH,FM_SLOT *SLOT , int v)
986
{
987
        SLOT->tl = (v&0x7f)<<(ENV_BITS-7); /* 7bit TL */
988
}
989
 
990
/* set attack rate & key scale  */
991
INLINE void set_ar_ksr(UINT8 type, FM_CH *CH,FM_SLOT *SLOT,int v)
992
{
993
        UINT8 old_KSR = SLOT->KSR;
994
 
995
        SLOT->ar = (v&0x1f) ? 32 + ((v&0x1f)<<1) : 0;
996
 
997
        SLOT->KSR = 3-(v>>6);
998
        if (SLOT->KSR != old_KSR)
999
        {
1000
                CH->SLOT[SLOT1].Incr=-1;
1001
        }
1002
 
1003
        /* refresh Attack rate */
1004
        if ((SLOT->ar + SLOT->ksr) < 32+62)
1005
        {
1006
                SLOT->eg_sh_ar  = eg_rate_shift [SLOT->ar  + SLOT->ksr ];
1007
                SLOT->eg_sel_ar = eg_rate_select[SLOT->ar  + SLOT->ksr ];
1008
        }
1009
        else
1010
        {
1011
                SLOT->eg_sh_ar  = 0;
1012
                SLOT->eg_sel_ar = 17*RATE_STEPS;
1013
        }
1014
}
1015
 
1016
/* set decay rate */
1017
INLINE void set_dr(UINT8 type, FM_SLOT *SLOT,int v)
1018
{
1019
        SLOT->d1r = (v&0x1f) ? 32 + ((v&0x1f)<<1) : 0;
1020
 
1021
        SLOT->eg_sh_d1r = eg_rate_shift [SLOT->d1r + SLOT->ksr];
1022
        SLOT->eg_sel_d1r= eg_rate_select[SLOT->d1r + SLOT->ksr];
1023
}
1024
 
1025
/* set sustain rate */
1026
INLINE void set_sr(UINT8 type, FM_SLOT *SLOT,int v)
1027
{
1028
        SLOT->d2r = (v&0x1f) ? 32 + ((v&0x1f)<<1) : 0;
1029
 
1030
        SLOT->eg_sh_d2r = eg_rate_shift [SLOT->d2r + SLOT->ksr];
1031
        SLOT->eg_sel_d2r= eg_rate_select[SLOT->d2r + SLOT->ksr];
1032
}
1033
 
1034
/* set release rate */
1035
INLINE void set_sl_rr(UINT8 type, FM_SLOT *SLOT,int v)
1036
{
1037
        SLOT->sl = sl_table[ v>>4 ];
1038
 
1039
        SLOT->rr  = 34 + ((v&0x0f)<<2);
1040
 
1041
        SLOT->eg_sh_rr  = eg_rate_shift [SLOT->rr  + SLOT->ksr];
1042
        SLOT->eg_sel_rr = eg_rate_select[SLOT->rr  + SLOT->ksr];
1043
}
1044
 
1045
 
1046
 
1047
INLINE signed int op_calc(UINT32 phase, unsigned int env, signed int pm)
1048
{
1049
        UINT32 p;
1050
 
1051
        p = (env<<3) + sin_tab[ ( ((signed int)((phase & ~FREQ_MASK) + (pm<<15))) >> FREQ_SH ) & SIN_MASK ];
1052
 
1053
        if (p >= TL_TAB_LEN)
1054
                return 0;
1055
        return tl_tab[p];
1056
}
1057
 
1058
INLINE signed int op_calc1(UINT32 phase, unsigned int env, signed int pm)
1059
{
1060
        UINT32 p;
1061
 
1062
        p = (env<<3) + sin_tab[ ( ((signed int)((phase & ~FREQ_MASK) + pm      )) >> FREQ_SH ) & SIN_MASK ];
1063
 
1064
        if (p >= TL_TAB_LEN)
1065
                return 0;
1066
        return tl_tab[p];
1067
}
1068
 
1069
/* advance LFO to next sample */
1070
INLINE void advance_lfo(FM_OPN *OPN)
1071
{
1072
        UINT8 pos;
1073
 
1074
        if (OPN->lfo_inc)   /* LFO enabled ? */
1075
        {
1076
                OPN->lfo_cnt += OPN->lfo_inc;
1077
 
1078
                pos = (OPN->lfo_cnt >> LFO_SH) & 127;
1079
 
1080
 
1081
                /* update AM when LFO output changes */
1082
 
1083
                /* actually I can't optimize is this way without rewriting chan_calc()
1084
                to use chip->lfo_am instead of global lfo_am */
1085
                {
1086
 
1087
                        /* triangle */
1088
                        /* AM: 0 to 126 step +2, 126 to 0 step -2 */
1089
                        if (pos<64)
1090
                                OPN->LFO_AM = (pos&63) * 2;
1091
                        else
1092
                                OPN->LFO_AM = 126 - ((pos&63) * 2);
1093
                }
1094
 
1095
                /* PM works with 4 times slower clock */
1096
                pos >>= 2;
1097
                /* update PM when LFO output changes */
1098
                /*if (prev_pos != pos)*/ /* can't use global lfo_pm for this optimization, must be chip->lfo_pm instead*/
1099
                {
1100
                        OPN->LFO_PM = pos;
1101
                }
1102
 
1103
        }
1104
        else
1105
        {
1106
                OPN->LFO_AM = 0;
1107
                OPN->LFO_PM = 0;
1108
        }
1109
}
1110
 
1111
/* changed from INLINE to static here to work around gcc 4.2.1 codegen bug */
1112
static void advance_eg_channel(FM_OPN *OPN, FM_SLOT *SLOT)
1113
{
1114
        unsigned int out;
1115
        unsigned int swap_flag = 0;
1116
        unsigned int i;
1117
 
1118
 
1119
        i = 4; /* four operators per channel */
1120
        do
1121
        {
1122
                /* reset SSG-EG swap flag */
1123
                swap_flag = 0;
1124
 
1125
                switch(SLOT->state)
1126
                {
1127
                case EG_ATT:        /* attack phase */
1128
                        if ( !(OPN->eg_cnt & ((1<<SLOT->eg_sh_ar)-1) ) )
1129
                        {
1130
                                SLOT->volume += (~SLOT->volume *
1131
                                                                        (eg_inc[SLOT->eg_sel_ar + ((OPN->eg_cnt>>SLOT->eg_sh_ar)&7)])
1132
                                                                ) >>4;
1133
 
1134
                                if (SLOT->volume <= MIN_ATT_INDEX)
1135
                                {
1136
                                        SLOT->volume = MIN_ATT_INDEX;
1137
                                        SLOT->state = EG_DEC;
1138
                                }
1139
                        }
1140
                break;
1141
 
1142
                case EG_DEC:    /* decay phase */
1143
                        {
1144
                                if (SLOT->ssg&0x08) /* SSG EG type envelope selected */
1145
                                {
1146
                                        if ( !(OPN->eg_cnt & ((1<<SLOT->eg_sh_d1r)-1) ) )
1147
                                        {
1148
                                                SLOT->volume += 4 * eg_inc[SLOT->eg_sel_d1r + ((OPN->eg_cnt>>SLOT->eg_sh_d1r)&7)];
1149
 
1150
                                                if ( SLOT->volume >= (INT32)(SLOT->sl) )
1151
                                                        SLOT->state = EG_SUS;
1152
                                        }
1153
                                }
1154
                                else
1155
                                {
1156
                                        if ( !(OPN->eg_cnt & ((1<<SLOT->eg_sh_d1r)-1) ) )
1157
                                        {
1158
                                                SLOT->volume += eg_inc[SLOT->eg_sel_d1r + ((OPN->eg_cnt>>SLOT->eg_sh_d1r)&7)];
1159
 
1160
                                                if ( SLOT->volume >= (INT32)(SLOT->sl) )
1161
                                                        SLOT->state = EG_SUS;
1162
                                        }
1163
                                }
1164
                        }
1165
                break;
1166
 
1167
                case EG_SUS:    /* sustain phase */
1168
                        if (SLOT->ssg&0x08) /* SSG EG type envelope selected */
1169
                        {
1170
                                if ( !(OPN->eg_cnt & ((1<<SLOT->eg_sh_d2r)-1) ) )
1171
                                {
1172
 
1173
                                        SLOT->volume += 4 * eg_inc[SLOT->eg_sel_d2r + ((OPN->eg_cnt>>SLOT->eg_sh_d2r)&7)];
1174
 
1175
                                        if ( SLOT->volume >= ENV_QUIET )
1176
                                        {
1177
                                                SLOT->volume = MAX_ATT_INDEX;
1178
 
1179
                                                if (SLOT->ssg&0x01) /* bit 0 = hold */
1180
                                                {
1181
                                                        if (SLOT->ssgn&1)   /* have we swapped once ??? */
1182
                                                        {
1183
                                                                /* yes, so do nothing, just hold current level */
1184
                                                        }
1185
                                                        else
1186
                                                                swap_flag = (SLOT->ssg&0x02) | 1 ; /* bit 1 = alternate */
1187
 
1188
                                                }
1189
                                                else
1190
                                                {
1191
                                                        /* same as KEY-ON operation */
1192
 
1193
                                                        /* restart of the Phase Generator should be here */
1194
                                                        SLOT->phase = 0;
1195
 
1196
                                                        {
1197
                                                                /* phase -> Attack */
1198
                                                                SLOT->volume = 511;
1199
                                                                SLOT->state = EG_ATT;
1200
                                                        }
1201
 
1202
                                                        swap_flag = (SLOT->ssg&0x02); /* bit 1 = alternate */
1203
                                                }
1204
                                        }
1205
                                }
1206
                        }
1207
                        else
1208
                        {
1209
                                if ( !(OPN->eg_cnt & ((1<<SLOT->eg_sh_d2r)-1) ) )
1210
                                {
1211
                                        SLOT->volume += eg_inc[SLOT->eg_sel_d2r + ((OPN->eg_cnt>>SLOT->eg_sh_d2r)&7)];
1212
 
1213
                                        if ( SLOT->volume >= MAX_ATT_INDEX )
1214
                                        {
1215
                                                SLOT->volume = MAX_ATT_INDEX;
1216
                                                /* do not change SLOT->state (verified on real chip) */
1217
                                        }
1218
                                }
1219
 
1220
                        }
1221
                break;
1222
 
1223
                case EG_REL:    /* release phase */
1224
                                if ( !(OPN->eg_cnt & ((1<<SLOT->eg_sh_rr)-1) ) )
1225
                                {
1226
                                        /* SSG-EG affects Release phase also (Nemesis) */
1227
                                        SLOT->volume += eg_inc[SLOT->eg_sel_rr + ((OPN->eg_cnt>>SLOT->eg_sh_rr)&7)];
1228
 
1229
                                        if ( SLOT->volume >= MAX_ATT_INDEX )
1230
                                        {
1231
                                                SLOT->volume = MAX_ATT_INDEX;
1232
                                                SLOT->state = EG_OFF;
1233
                                        }
1234
                                }
1235
                break;
1236
 
1237
                }
1238
 
1239
 
1240
                out = ((UINT32)SLOT->volume);
1241
 
1242
                                /* negate output (changes come from alternate bit, init comes from attack bit) */
1243
                if ((SLOT->ssg&0x08) && (SLOT->ssgn&2) && (SLOT->state > EG_REL))
1244
                        out ^= MAX_ATT_INDEX;
1245
 
1246
                /* we need to store the result here because we are going to change ssgn
1247
                    in next instruction */
1248
                SLOT->vol_out = out + SLOT->tl;
1249
 
1250
                                /* reverse SLOT inversion flag */
1251
                SLOT->ssgn ^= swap_flag;
1252
 
1253
                SLOT++;
1254
                i--;
1255
        }while (i);
1256
 
1257
}
1258
 
1259
 
1260
 
1261
#define volume_calc(OP) ((OP)->vol_out + (AM & (OP)->AMmask))
1262
 
1263
INLINE void update_phase_lfo_slot(FM_OPN *OPN, FM_SLOT *SLOT, INT32 pms, UINT32 block_fnum)
1264
{
1265
        UINT32 fnum_lfo  = ((block_fnum & 0x7f0) >> 4) * 32 * 8;
1266
        INT32  lfo_fn_table_index_offset = lfo_pm_table[ fnum_lfo + pms + OPN->LFO_PM ];
1267
 
1268
        if (lfo_fn_table_index_offset)    /* LFO phase modulation active */
1269
        {
1270
                UINT8 blk;
1271
                UINT32 fn;
1272
                int kc, fc;
1273
 
1274
                block_fnum = block_fnum*2 + lfo_fn_table_index_offset;
1275
 
1276
                blk = (block_fnum&0x7000) >> 12;
1277
                fn  = block_fnum & 0xfff;
1278
 
1279
                /* keyscale code */
1280
                kc = (blk<<2) | opn_fktable[fn >> 8];
1281
 
1282
                /* phase increment counter */
1283
                fc = (OPN->fn_table[fn]>>(7-blk)) + SLOT->DT[kc];
1284
 
1285
                /* detects frequency overflow (credits to Nemesis) */
1286
                if (fc < 0) fc += OPN->fn_max;
1287
 
1288
                /* update phase */
1289
                SLOT->phase += (fc * SLOT->mul) >> 1;
1290
        }
1291
        else    /* LFO phase modulation  = zero */
1292
        {
1293
                SLOT->phase += SLOT->Incr;
1294
        }
1295
}
1296
 
1297
INLINE void update_phase_lfo_channel(FM_OPN *OPN, FM_CH *CH)
1298
{
1299
        UINT32 block_fnum = CH->block_fnum;
1300
 
1301
        UINT32 fnum_lfo  = ((block_fnum & 0x7f0) >> 4) * 32 * 8;
1302
        INT32  lfo_fn_table_index_offset = lfo_pm_table[ fnum_lfo + CH->pms + OPN->LFO_PM ];
1303
 
1304
        if (lfo_fn_table_index_offset)    /* LFO phase modulation active */
1305
        {
1306
                        UINT8 blk;
1307
                        UINT32 fn;
1308
                int kc, fc, finc;
1309
 
1310
                block_fnum = block_fnum*2 + lfo_fn_table_index_offset;
1311
 
1312
                        blk = (block_fnum&0x7000) >> 12;
1313
                        fn  = block_fnum & 0xfff;
1314
 
1315
                /* keyscale code */
1316
                        kc = (blk<<2) | opn_fktable[fn >> 8];
1317
 
1318
                        /* phase increment counter */
1319
                fc = (OPN->fn_table[fn]>>(7-blk));
1320
 
1321
                /* detects frequency overflow (credits to Nemesis) */
1322
                finc = fc + CH->SLOT[SLOT1].DT[kc];
1323
 
1324
                if (finc < 0) finc += OPN->fn_max;
1325
                CH->SLOT[SLOT1].phase += (finc*CH->SLOT[SLOT1].mul) >> 1;
1326
 
1327
                finc = fc + CH->SLOT[SLOT2].DT[kc];
1328
                if (finc < 0) finc += OPN->fn_max;
1329
                CH->SLOT[SLOT2].phase += (finc*CH->SLOT[SLOT2].mul) >> 1;
1330
 
1331
                finc = fc + CH->SLOT[SLOT3].DT[kc];
1332
                if (finc < 0) finc += OPN->fn_max;
1333
                CH->SLOT[SLOT3].phase += (finc*CH->SLOT[SLOT3].mul) >> 1;
1334
 
1335
                finc = fc + CH->SLOT[SLOT4].DT[kc];
1336
                if (finc < 0) finc += OPN->fn_max;
1337
                CH->SLOT[SLOT4].phase += (finc*CH->SLOT[SLOT4].mul) >> 1;
1338
        }
1339
        else    /* LFO phase modulation  = zero */
1340
        {
1341
                        CH->SLOT[SLOT1].phase += CH->SLOT[SLOT1].Incr;
1342
                        CH->SLOT[SLOT2].phase += CH->SLOT[SLOT2].Incr;
1343
                        CH->SLOT[SLOT3].phase += CH->SLOT[SLOT3].Incr;
1344
                        CH->SLOT[SLOT4].phase += CH->SLOT[SLOT4].Incr;
1345
        }
1346
}
1347
 
1348
INLINE void chan_calc(FM_OPN *OPN, FM_CH *CH, int chnum)
1349
{
1350
        unsigned int eg_out;
1351
 
1352
        UINT32 AM = OPN->LFO_AM >> CH->ams;
1353
 
1354
 
1355
        OPN->m2 = OPN->c1 = OPN->c2 = OPN->mem = 0;
1356
 
1357
        *CH->mem_connect = CH->mem_value;   /* restore delayed sample (MEM) value to m2 or c2 */
1358
 
1359
        eg_out = volume_calc(&CH->SLOT[SLOT1]);
1360
        {
1361
                INT32 out = CH->op1_out[0] + CH->op1_out[1];
1362
                CH->op1_out[0] = CH->op1_out[1];
1363
 
1364
                if( !CH->connect1 )
1365
                {
1366
                        /* algorithm 5  */
1367
                        OPN->mem = OPN->c1 = OPN->c2 = CH->op1_out[0];
1368
                }
1369
                else
1370
                {
1371
                        /* other algorithms */
1372
                        *CH->connect1 += CH->op1_out[0];
1373
                }
1374
 
1375
                CH->op1_out[1] = 0;
1376
                if( eg_out < ENV_QUIET )    /* SLOT 1 */
1377
                {
1378
                        if (!CH->FB)
1379
                                out=0;
1380
 
1381
                        CH->op1_out[1] = op_calc1(CH->SLOT[SLOT1].phase, eg_out, (out<<CH->FB) );
1382
                }
1383
        }
1384
 
1385
        eg_out = volume_calc(&CH->SLOT[SLOT3]);
1386
        if( eg_out < ENV_QUIET )        /* SLOT 3 */
1387
                *CH->connect3 += op_calc(CH->SLOT[SLOT3].phase, eg_out, OPN->m2);
1388
 
1389
        eg_out = volume_calc(&CH->SLOT[SLOT2]);
1390
        if( eg_out < ENV_QUIET )        /* SLOT 2 */
1391
                *CH->connect2 += op_calc(CH->SLOT[SLOT2].phase, eg_out, OPN->c1);
1392
 
1393
        eg_out = volume_calc(&CH->SLOT[SLOT4]);
1394
        if( eg_out < ENV_QUIET )        /* SLOT 4 */
1395
                *CH->connect4 += op_calc(CH->SLOT[SLOT4].phase, eg_out, OPN->c2);
1396
 
1397
 
1398
        /* store current MEM */
1399
        CH->mem_value = OPN->mem;
1400
 
1401
        /* update phase counters AFTER output calculations */
1402
        if(CH->pms)
1403
        {
1404
                /* add support for 3 slot mode */
1405
                if ((OPN->ST.mode & 0xC0) && (chnum == 2))
1406
                {
1407
                                update_phase_lfo_slot(OPN, &CH->SLOT[SLOT1], CH->pms, OPN->SL3.block_fnum[1]);
1408
                                update_phase_lfo_slot(OPN, &CH->SLOT[SLOT2], CH->pms, OPN->SL3.block_fnum[2]);
1409
                                update_phase_lfo_slot(OPN, &CH->SLOT[SLOT3], CH->pms, OPN->SL3.block_fnum[0]);
1410
                                update_phase_lfo_slot(OPN, &CH->SLOT[SLOT4], CH->pms, CH->block_fnum);
1411
                }
1412
                else update_phase_lfo_channel(OPN, CH);
1413
        }
1414
        else    /* no LFO phase modulation */
1415
        {
1416
                CH->SLOT[SLOT1].phase += CH->SLOT[SLOT1].Incr;
1417
                CH->SLOT[SLOT2].phase += CH->SLOT[SLOT2].Incr;
1418
                CH->SLOT[SLOT3].phase += CH->SLOT[SLOT3].Incr;
1419
                CH->SLOT[SLOT4].phase += CH->SLOT[SLOT4].Incr;
1420
        }
1421
}
1422
 
1423
/* update phase increment and envelope generator */
1424
INLINE void refresh_fc_eg_slot(FM_OPN *OPN, FM_SLOT *SLOT , int fc , int kc )
1425
{
1426
        int ksr = kc >> SLOT->KSR;
1427
 
1428
        fc += SLOT->DT[kc];
1429
 
1430
        /* detects frequency overflow (credits to Nemesis) */
1431
        if (fc < 0) fc += OPN->fn_max;
1432
 
1433
        /* (frequency) phase increment counter */
1434
        SLOT->Incr = (fc * SLOT->mul) >> 1;
1435
 
1436
        if( SLOT->ksr != ksr )
1437
        {
1438
                SLOT->ksr = ksr;
1439
 
1440
                /* calculate envelope generator rates */
1441
                if ((SLOT->ar + SLOT->ksr) < 32+62)
1442
                {
1443
                        SLOT->eg_sh_ar  = eg_rate_shift [SLOT->ar  + SLOT->ksr ];
1444
                        SLOT->eg_sel_ar = eg_rate_select[SLOT->ar  + SLOT->ksr ];
1445
                }
1446
                else
1447
                {
1448
                        SLOT->eg_sh_ar  = 0;
1449
                        SLOT->eg_sel_ar = 17*RATE_STEPS;
1450
                }
1451
 
1452
                SLOT->eg_sh_d1r = eg_rate_shift [SLOT->d1r + SLOT->ksr];
1453
                SLOT->eg_sh_d2r = eg_rate_shift [SLOT->d2r + SLOT->ksr];
1454
                SLOT->eg_sh_rr  = eg_rate_shift [SLOT->rr  + SLOT->ksr];
1455
 
1456
                SLOT->eg_sel_d1r= eg_rate_select[SLOT->d1r + SLOT->ksr];
1457
                SLOT->eg_sel_d2r= eg_rate_select[SLOT->d2r + SLOT->ksr];
1458
                SLOT->eg_sel_rr = eg_rate_select[SLOT->rr  + SLOT->ksr];
1459
        }
1460
}
1461
 
1462
/* update phase increment counters */
1463
/* Changed from INLINE to static to work around gcc 4.2.1 codegen bug */
1464
static void refresh_fc_eg_chan(FM_OPN *OPN, FM_CH *CH )
1465
{
1466
        if( CH->SLOT[SLOT1].Incr==-1)
1467
        {
1468
                int fc = CH->fc;
1469
                int kc = CH->kcode;
1470
                refresh_fc_eg_slot(OPN, &CH->SLOT[SLOT1] , fc , kc );
1471
                refresh_fc_eg_slot(OPN, &CH->SLOT[SLOT2] , fc , kc );
1472
                refresh_fc_eg_slot(OPN, &CH->SLOT[SLOT3] , fc , kc );
1473
                refresh_fc_eg_slot(OPN, &CH->SLOT[SLOT4] , fc , kc );
1474
        }
1475
}
1476
 
1477
/* initialize time tables */
1478
static void init_timetables( FM_ST *ST , const UINT8 *dttable )
1479
{
1480
        int i,d;
1481
        double rate;
1482
 
1483
#if 0
1484
        logerror("FM.C: samplerate=%8i chip clock=%8i  freqbase=%f  \n",
1485
                                ST->rate, ST->clock, ST->freqbase );
1486
#endif
1487
 
1488
        /* DeTune table */
1489
        for (d = 0;d <= 3;d++)
1490
        {
1491
                for (i = 0;i <= 31;i++)
1492
                {
1493
                        rate = ((double)dttable[d*32 + i]) * SIN_LEN  * ST->freqbase  * (1<<FREQ_SH) / ((double)(1<<20));
1494
                        ST->dt_tab[d][i]   = (INT32) rate;
1495
                        ST->dt_tab[d+4][i] = -ST->dt_tab[d][i];
1496
#if 0
1497
                        logerror("FM.C: DT [%2i %2i] = %8x  \n", d, i, ST->dt_tab[d][i] );
1498
#endif
1499
                }
1500
        }
1501
 
1502
}
1503
 
1504
 
1505
static void reset_channels( FM_ST *ST , FM_CH *CH , int num )
1506
{
1507
        int c,s;
1508
 
1509
        ST->mode   = 0; /* normal mode */
1510
        ST->TA     = 0;
1511
        ST->TAC    = 0;
1512
        ST->TB     = 0;
1513
        ST->TBC    = 0;
1514
 
1515
        for( c = 0 ; c < num ; c++ )
1516
        {
1517
                CH[c].fc = 0;
1518
                for(s = 0 ; s < 4 ; s++ )
1519
                {
1520
                        CH[c].SLOT[s].ssg = 0;
1521
                        CH[c].SLOT[s].ssgn = 0;
1522
                        CH[c].SLOT[s].state= EG_OFF;
1523
                        CH[c].SLOT[s].volume = MAX_ATT_INDEX;
1524
                        CH[c].SLOT[s].vol_out= MAX_ATT_INDEX;
1525
                }
1526
        }
1527
}
1528
 
1529
/* initialize generic tables */
1530
static int init_tables(void)
1531
{
1532
        signed int i,x;
1533
        signed int n;
1534
        double o,m;
1535
 
1536
        for (x=0; x<TL_RES_LEN; x++)
1537
        {
1538
                m = (1<<16) / pow(2, (x+1) * (ENV_STEP/4.0) / 8.0);
1539
                m = floor(m);
1540
 
1541
                /* we never reach (1<<16) here due to the (x+1) */
1542
                /* result fits within 16 bits at maximum */
1543
 
1544
                n = (int)m;     /* 16 bits here */
1545
                n >>= 4;        /* 12 bits here */
1546
                if (n&1)        /* round to nearest */
1547
                        n = (n>>1)+1;
1548
                else
1549
                        n = n>>1;
1550
                                                /* 11 bits here (rounded) */
1551
                n <<= 2;        /* 13 bits here (as in real chip) */
1552
                tl_tab[ x*2 + 0 ] = n;
1553
                tl_tab[ x*2 + 1 ] = -tl_tab[ x*2 + 0 ];
1554
 
1555
                for (i=1; i<13; i++)
1556
                {
1557
                        tl_tab[ x*2+0 + i*2*TL_RES_LEN ] =  tl_tab[ x*2+0 ]>>i;
1558
                        tl_tab[ x*2+1 + i*2*TL_RES_LEN ] = -tl_tab[ x*2+0 + i*2*TL_RES_LEN ];
1559
                }
1560
        #if 0
1561
                        logerror("tl %04i", x);
1562
                        for (i=0; i<13; i++)
1563
                                logerror(", [%02i] %4x", i*2, tl_tab[ x*2 /*+1*/ + i*2*TL_RES_LEN ]);
1564
                        logerror("\n");
1565
        #endif
1566
        }
1567
        /*logerror("FM.C: TL_TAB_LEN = %i elements (%i bytes)\n",TL_TAB_LEN, (int)sizeof(tl_tab));*/
1568
 
1569
 
1570
        for (i=0; i<SIN_LEN; i++)
1571
        {
1572
                /* non-standard sinus */
1573
                m = sin( ((i*2)+1) * M_PI / SIN_LEN ); /* checked against the real chip */
1574
 
1575
                /* we never reach zero here due to ((i*2)+1) */
1576
 
1577
                if (m>0.0)
1578
                        o = 8*log(1.0/m)/log(2.0);  /* convert to 'decibels' */
1579
                else
1580
                        o = 8*log(-1.0/m)/log(2.0); /* convert to 'decibels' */
1581
 
1582
                o = o / (ENV_STEP/4);
1583
 
1584
                n = (int)(2.0*o);
1585
                if (n&1)                        /* round to nearest */
1586
                        n = (n>>1)+1;
1587
                else
1588
                        n = n>>1;
1589
 
1590
                sin_tab[ i ] = n*2 + (m>=0.0? 0: 1 );
1591
                /*logerror("FM.C: sin [%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[i],tl_tab[sin_tab[i]]);*/
1592
        }
1593
 
1594
        /*logerror("FM.C: ENV_QUIET= %08x\n",ENV_QUIET );*/
1595
 
1596
 
1597
        /* build LFO PM modulation table */
1598
        for(i = 0; i < 8; i++) /* 8 PM depths */
1599
        {
1600
                UINT8 fnum;
1601
                for (fnum=0; fnum<128; fnum++) /* 7 bits meaningful of F-NUMBER */
1602
                {
1603
                        UINT8 value;
1604
                        UINT8 step;
1605
                        UINT32 offset_depth = i;
1606
                        UINT32 offset_fnum_bit;
1607
                        UINT32 bit_tmp;
1608
 
1609
                        for (step=0; step<8; step++)
1610
                        {
1611
                                value = 0;
1612
                                for (bit_tmp=0; bit_tmp<7; bit_tmp++) /* 7 bits */
1613
                                {
1614
                                        if (fnum & (1<<bit_tmp)) /* only if bit "bit_tmp" is set */
1615
                                        {
1616
                                                offset_fnum_bit = bit_tmp * 8;
1617
                                                value += lfo_pm_output[offset_fnum_bit + offset_depth][step];
1618
                                        }
1619
                                }
1620
                                lfo_pm_table[(fnum*32*8) + (i*32) + step   + 0] = value;
1621
                                lfo_pm_table[(fnum*32*8) + (i*32) +(step^7)+ 8] = value;
1622
                                lfo_pm_table[(fnum*32*8) + (i*32) + step   +16] = -value;
1623
                                lfo_pm_table[(fnum*32*8) + (i*32) +(step^7)+24] = -value;
1624
                        }
1625
#if 0
1626
                        logerror("LFO depth=%1x FNUM=%04x (<<4=%4x): ", i, fnum, fnum<<4);
1627
                        for (step=0; step<16; step++) /* dump only positive part of waveforms */
1628
                                logerror("%02x ", lfo_pm_table[(fnum*32*8) + (i*32) + step] );
1629
                        logerror("\n");
1630
#endif
1631
 
1632
                }
1633
        }
1634
 
1635
 
1636
 
1637
#ifdef SAVE_SAMPLE
1638
        sample[0]=fopen("sampsum.pcm","wb");
1639
#endif
1640
 
1641
        return 1;
1642
 
1643
}
1644
 
1645
 
1646
 
1647
static void FMCloseTable( void )
1648
{
1649
#ifdef SAVE_SAMPLE
1650
        fclose(sample[0]);
1651
#endif
1652
        return;
1653
}
1654
 
1655
 
1656
/* CSM Key Controll */
1657
INLINE void CSMKeyControll(UINT8 type, FM_CH *CH)
1658
{
1659
        /* all key on then off (only for operators which were OFF!) */
1660
        if (!CH->SLOT[SLOT1].key)
1661
        {
1662
                FM_KEYON(type, CH,SLOT1);
1663
                FM_KEYOFF(CH, SLOT1);
1664
        }
1665
        if (!CH->SLOT[SLOT2].key)
1666
        {
1667
                FM_KEYON(type, CH,SLOT2);
1668
                FM_KEYOFF(CH, SLOT2);
1669
        }
1670
        if (!CH->SLOT[SLOT3].key)
1671
        {
1672
                FM_KEYON(type, CH,SLOT3);
1673
                FM_KEYOFF(CH, SLOT3);
1674
        }
1675
        if (!CH->SLOT[SLOT4].key)
1676
        {
1677
                FM_KEYON(type, CH,SLOT4);
1678
                FM_KEYOFF(CH, SLOT4);
1679
        }
1680
}
1681
 
1682
#ifdef __SAVE_H__
1683
/* FM channel save , internal state only */
1684
static void FMsave_state_channel(device_t *device,FM_CH *CH,int num_ch)
1685
{
1686
        int slot , ch;
1687
 
1688
        for(ch=0;ch<num_ch;ch++,CH++)
1689
        {
1690
                /* channel */
1691
                device->save_item(NAME(CH->op1_out), ch);
1692
                device->save_item(NAME(CH->fc), ch);
1693
                /* slots */
1694
                for(slot=0;slot<4;slot++)
1695
                {
1696
                        FM_SLOT *SLOT = &CH->SLOT[slot];
1697
                        device->save_item(NAME(SLOT->phase), ch * 4 + slot);
1698
                        device->save_item(NAME(SLOT->state), ch * 4 + slot);
1699
                        device->save_item(NAME(SLOT->volume), ch * 4 + slot);
1700
                }
1701
        }
1702
}
1703
 
1704
static void FMsave_state_st(device_t *device,FM_ST *ST)
1705
{
1706
#if FM_BUSY_FLAG_SUPPORT
1707
        device->save_item(NAME(ST->busy_expiry_time) );
1708
#endif
1709
        device->save_item(NAME(ST->address) );
1710
        device->save_item(NAME(ST->irq)     );
1711
        device->save_item(NAME(ST->irqmask) );
1712
        device->save_item(NAME(ST->status)  );
1713
        device->save_item(NAME(ST->mode)    );
1714
        device->save_item(NAME(ST->prescaler_sel) );
1715
        device->save_item(NAME(ST->fn_h) );
1716
        device->save_item(NAME(ST->TA)   );
1717
        device->save_item(NAME(ST->TAC)  );
1718
        device->save_item(NAME(ST->TB)  );
1719
        device->save_item(NAME(ST->TBC)  );
1720
}
1721
#endif /* _STATE_H */
1722
 
1723
#if BUILD_OPN
1724
 
1725
 
1726
 
1727
/* prescaler set (and make time tables) */
1728
static void OPNSetPres(FM_OPN *OPN, int pres, int timer_prescaler, int SSGpres)
1729
{
1730
        int i;
1731
 
1732
        /* frequency base */
1733
        OPN->ST.freqbase = (OPN->ST.rate) ? ((double)OPN->ST.clock / OPN->ST.rate) / pres : 0;
1734
 
1735
#if 0
1736
        OPN->ST.rate = (double)OPN->ST.clock / pres;
1737
        OPN->ST.freqbase = 1.0;
1738
#endif
1739
 
1740
        OPN->eg_timer_add  = (1<<EG_SH)  *  OPN->ST.freqbase;
1741
        OPN->eg_timer_overflow = ( 3 ) * (1<<EG_SH);
1742
 
1743
 
1744
        /* Timer base time */
1745
        OPN->ST.timer_prescaler = timer_prescaler;
1746
 
1747
        /* SSG part  prescaler set */
1748
        if( SSGpres ) (*OPN->ST.SSG->set_clock)( OPN->ST.param, OPN->ST.clock * 2 / SSGpres );
1749
 
1750
        /* make time tables */
1751
        init_timetables( &OPN->ST, dt_tab );
1752
 
1753
        /* there are 2048 FNUMs that can be generated using FNUM/BLK registers
1754
            but LFO works with one more bit of a precision so we really need 4096 elements */
1755
        /* calculate fnumber -> increment counter table */
1756
        for(i = 0; i < 4096; i++)
1757
        {
1758
                /* freq table for octave 7 */
1759
                /* OPN phase increment counter = 20bit */
1760
                OPN->fn_table[i] = (UINT32)( (double)i * 32 * OPN->ST.freqbase * (1<<(FREQ_SH-10)) ); /* -10 because chip works with 10.10 fixed point, while we use 16.16 */
1761
#if 0
1762
                logerror("FM.C: fn_table[%4i] = %08x (dec=%8i)\n",
1763
                                        i, OPN->fn_table[i]>>6,OPN->fn_table[i]>>6 );
1764
#endif
1765
        }
1766
 
1767
        /* maximal frequency is required for Phase overflow calculation, register size is 17 bits (Nemesis) */
1768
        OPN->fn_max = (UINT32)( (double)0x20000 * OPN->ST.freqbase * (1<<(FREQ_SH-10)) );
1769
 
1770
        /* LFO freq. table */
1771
        for(i = 0; i < 8; i++)
1772
        {
1773
                /* Amplitude modulation: 64 output levels (triangle waveform); 1 level lasts for one of "lfo_samples_per_step" samples */
1774
                /* Phase modulation: one entry from lfo_pm_output lasts for one of 4 * "lfo_samples_per_step" samples  */
1775
                OPN->lfo_freq[i] = (1.0 / lfo_samples_per_step[i]) * (1<<LFO_SH) * OPN->ST.freqbase;
1776
#if 0
1777
                logerror("FM.C: lfo_freq[%i] = %08x (dec=%8i)\n",
1778
                                        i, OPN->lfo_freq[i],OPN->lfo_freq[i] );
1779
#endif
1780
        }
1781
}
1782
 
1783
 
1784
 
1785
/* write a OPN mode register 0x20-0x2f */
1786
static void OPNWriteMode(FM_OPN *OPN, int r, int v)
1787
{
1788
        UINT8 c;
1789
        FM_CH *CH;
1790
 
1791
        switch(r)
1792
        {
1793
        case 0x21:  /* Test */
1794
                break;
1795
        case 0x22:  /* LFO FREQ (YM2608/YM2610/YM2610B/YM2612) */
1796
                if( OPN->type & TYPE_LFOPAN )
1797
                {
1798
                        if (v&0x08) /* LFO enabled ? */
1799
                        {
1800
                                OPN->lfo_inc = OPN->lfo_freq[v&7];
1801
                        }
1802
                        else
1803
                        {
1804
                                OPN->lfo_inc = 0;
1805
                        }
1806
                }
1807
                break;
1808
        case 0x24:  /* timer A High 8*/
1809
                OPN->ST.TA = (OPN->ST.TA & 0x03)|(((int)v)<<2);
1810
                break;
1811
        case 0x25:  /* timer A Low 2*/
1812
                OPN->ST.TA = (OPN->ST.TA & 0x3fc)|(v&3);
1813
                break;
1814
        case 0x26:  /* timer B */
1815
                OPN->ST.TB = v;
1816
                break;
1817
        case 0x27:  /* mode, timer control */
1818
                set_timers( &(OPN->ST),OPN->ST.param,v );
1819
                break;
1820
        case 0x28:  /* key on / off */
1821
                c = v & 0x03;
1822
                if( c == 3 ) break;
1823
                if( (v&0x04) && (OPN->type & TYPE_6CH) ) c+=3;
1824
                CH = OPN->P_CH;
1825
                CH = &CH[c];
1826
                if(v&0x10) FM_KEYON(OPN->type,CH,SLOT1); else FM_KEYOFF(CH,SLOT1);
1827
                if(v&0x20) FM_KEYON(OPN->type,CH,SLOT2); else FM_KEYOFF(CH,SLOT2);
1828
                if(v&0x40) FM_KEYON(OPN->type,CH,SLOT3); else FM_KEYOFF(CH,SLOT3);
1829
                if(v&0x80) FM_KEYON(OPN->type,CH,SLOT4); else FM_KEYOFF(CH,SLOT4);
1830
                break;
1831
        }
1832
}
1833
 
1834
/* write a OPN register (0x30-0xff) */
1835
static void OPNWriteReg(FM_OPN *OPN, int r, int v)
1836
{
1837
        FM_CH *CH;
1838
        FM_SLOT *SLOT;
1839
 
1840
        UINT8 c = OPN_CHAN(r);
1841
 
1842
        if (c == 3) return; /* 0xX3,0xX7,0xXB,0xXF */
1843
 
1844
        if (r >= 0x100) c+=3;
1845
 
1846
        CH = OPN->P_CH;
1847
        CH = &CH[c];
1848
 
1849
        SLOT = &(CH->SLOT[OPN_SLOT(r)]);
1850
 
1851
        switch( r & 0xf0 )
1852
        {
1853
        case 0x30:  /* DET , MUL */
1854
                set_det_mul(&OPN->ST,CH,SLOT,v);
1855
                break;
1856
 
1857
        case 0x40:  /* TL */
1858
                set_tl(CH,SLOT,v);
1859
                break;
1860
 
1861
        case 0x50:  /* KS, AR */
1862
                set_ar_ksr(OPN->type,CH,SLOT,v);
1863
                break;
1864
 
1865
        case 0x60:  /* bit7 = AM ENABLE, DR */
1866
                set_dr(OPN->type, SLOT,v);
1867
 
1868
                if(OPN->type & TYPE_LFOPAN) /* YM2608/2610/2610B/2612 */
1869
                {
1870
                        SLOT->AMmask = (v&0x80) ? ~0 : 0;
1871
                }
1872
                break;
1873
 
1874
        case 0x70:  /*     SR */
1875
                set_sr(OPN->type,SLOT,v);
1876
                break;
1877
 
1878
        case 0x80:  /* SL, RR */
1879
                set_sl_rr(OPN->type,SLOT,v);
1880
                break;
1881
 
1882
        case 0x90:  /* SSG-EG */
1883
                SLOT->ssg  =  v&0x0f;
1884
                SLOT->ssgn = (v&0x04)>>1; /* bit 1 in ssgn = attack */
1885
 
1886
                /* SSG-EG envelope shapes :
1887
 
1888
                E AtAlH
1889
                1 0 0 0  \\\\
1890
 
1891
                1 0 0 1  \___
1892
 
1893
                1 0 1 0  \/\/
1894
                          ___
1895
                1 0 1 1  \
1896
 
1897
                1 1 0 0  ////
1898
                          ___
1899
                1 1 0 1  /
1900
 
1901
                1 1 1 0  /\/\
1902
 
1903
                1 1 1 1  /___
1904
 
1905
 
1906
                E = SSG-EG enable
1907
 
1908
 
1909
                The shapes are generated using Attack, Decay and Sustain phases.
1910
 
1911
                Each single character in the diagrams above represents this whole
1912
                sequence:
1913
 
1914
                - when KEY-ON = 1, normal Attack phase is generated (*without* any
1915
                  difference when compared to normal mode),
1916
 
1917
                - later, when envelope level reaches minimum level (max volume),
1918
                  the EG switches to Decay phase (which works with bigger steps
1919
                  when compared to normal mode - see below),
1920
 
1921
                - later when envelope level passes the SL level,
1922
                  the EG swithes to Sustain phase (which works with bigger steps
1923
                  when compared to normal mode - see below),
1924
 
1925
                - finally when envelope level reaches maximum level (min volume),
1926
                  the EG switches to Attack phase again (depends on actual waveform).
1927
 
1928
                Important is that when switch to Attack phase occurs, the phase counter
1929
                of that operator will be zeroed-out (as in normal KEY-ON) but not always.
1930
                (I havent found the rule for that - perhaps only when the output level is low)
1931
 
1932
                The difference (when compared to normal Envelope Generator mode) is
1933
                that the resolution in Decay and Sustain phases is 4 times lower;
1934
                this results in only 256 steps instead of normal 1024.
1935
                In other words:
1936
                when SSG-EG is disabled, the step inside of the EG is one,
1937
                when SSG-EG is enabled, the step is four (in Decay and Sustain phases).
1938
 
1939
                Times between the level changes are the same in both modes.
1940
 
1941
 
1942
                Important:
1943
                Decay 1 Level (so called SL) is compared to actual SSG-EG output, so
1944
                it is the same in both SSG and no-SSG modes, with this exception:
1945
 
1946
                when the SSG-EG is enabled and is generating raising levels
1947
                (when the EG output is inverted) the SL will be found at wrong level !!!
1948
                For example, when SL=02:
1949
 
1950
                    96-6 = -90dB in inverted EG output
1951
                Which means that EG compares its level to SL as usual, and that the
1952
                output is simply inverted afterall.
1953
 
1954
 
1955
                The Yamaha's manuals say that AR should be set to 0x1f (max speed).
1956
                That is not necessary, but then EG will be generating Attack phase.
1957
 
1958
                */
1959
 
1960
 
1961
                break;
1962
 
1963
        case 0xa0:
1964
                switch( OPN_SLOT(r) )
1965
                {
1966
                case 0:     /* 0xa0-0xa2 : FNUM1 */
1967
                        {
1968
                                UINT32 fn = (((UINT32)( (OPN->ST.fn_h)&7))<<8) + v;
1969
                                UINT8 blk = OPN->ST.fn_h>>3;
1970
                                /* keyscale code */
1971
                                CH->kcode = (blk<<2) | opn_fktable[fn >> 7];
1972
                                /* phase increment counter */
1973
                                CH->fc = OPN->fn_table[fn*2]>>(7-blk);
1974
 
1975
                                /* store fnum in clear form for LFO PM calculations */
1976
                                CH->block_fnum = (blk<<11) | fn;
1977
 
1978
                                CH->SLOT[SLOT1].Incr=-1;
1979
                        }
1980
                        break;
1981
                case 1:     /* 0xa4-0xa6 : FNUM2,BLK */
1982
                        OPN->ST.fn_h = v&0x3f;
1983
                        break;
1984
                case 2:     /* 0xa8-0xaa : 3CH FNUM1 */
1985
                        if(r < 0x100)
1986
                        {
1987
                                UINT32 fn = (((UINT32)(OPN->SL3.fn_h&7))<<8) + v;
1988
                                UINT8 blk = OPN->SL3.fn_h>>3;
1989
                                /* keyscale code */
1990
                                OPN->SL3.kcode[c]= (blk<<2) | opn_fktable[fn >> 7];
1991
                                /* phase increment counter */
1992
                                OPN->SL3.fc[c] = OPN->fn_table[fn*2]>>(7-blk);
1993
                                OPN->SL3.block_fnum[c] = (blk<<11) | fn;
1994
                                (OPN->P_CH)[2].SLOT[SLOT1].Incr=-1;
1995
                        }
1996
                        break;
1997
                case 3:     /* 0xac-0xae : 3CH FNUM2,BLK */
1998
                        if(r < 0x100)
1999
                                OPN->SL3.fn_h = v&0x3f;
2000
                        break;
2001
                }
2002
                break;
2003
 
2004
        case 0xb0:
2005
                switch( OPN_SLOT(r) )
2006
                {
2007
                case 0:     /* 0xb0-0xb2 : FB,ALGO */
2008
                        {
2009
                                int feedback = (v>>3)&7;
2010
                                CH->ALGO = v&7;
2011
                                CH->FB   = feedback ? feedback+6 : 0;
2012
                                setup_connection( OPN, CH, c );
2013
                        }
2014
                        break;
2015
                case 1:     /* 0xb4-0xb6 : L , R , AMS , PMS (YM2612/YM2610B/YM2610/YM2608) */
2016
                        if( OPN->type & TYPE_LFOPAN)
2017
                        {
2018
                                /* b0-2 PMS */
2019
                                CH->pms = (v & 7) * 32; /* CH->pms = PM depth * 32 (index in lfo_pm_table) */
2020
 
2021
                                /* b4-5 AMS */
2022
                                CH->ams = lfo_ams_depth_shift[(v>>4) & 0x03];
2023
 
2024
                                /* PAN :  b7 = L, b6 = R */
2025
                                OPN->pan[ c*2   ] = (v & 0x80) ? ~0 : 0;
2026
                                OPN->pan[ c*2+1 ] = (v & 0x40) ? ~0 : 0;
2027
 
2028
                        }
2029
                        break;
2030
                }
2031
                break;
2032
        }
2033
}
2034
 
2035
#endif /* BUILD_OPN */
2036
 
2037
#if BUILD_OPN_PRESCALER
2038
/*
2039
  prescaler circuit (best guess to verified chip behaviour)
2040
 
2041
               +--------------+  +-sel2-+
2042
               |              +--|in20  |
2043
         +---+ |  +-sel1-+       |      |
2044
M-CLK -+-|1/2|-+--|in10  | +---+ |   out|--INT_CLOCK
2045
       | +---+    |   out|-|1/3|-|in21  |
2046
       +----------|in11  | +---+ +------+
2047
                  +------+
2048
 
2049
reg.2d : sel2 = in21 (select sel2)
2050
reg.2e : sel1 = in11 (select sel1)
2051
reg.2f : sel1 = in10 , sel2 = in20 (clear selector)
2052
reset  : sel1 = in11 , sel2 = in21 (clear both)
2053
 
2054
*/
2055
static void OPNPrescaler_w(FM_OPN *OPN , int addr, int pre_divider)
2056
{
2057
        static const int opn_pres[4] = { 2*12 , 2*12 , 6*12 , 3*12 };
2058
        static const int ssg_pres[4] = { 1    ,    1 ,    4 ,    2 };
2059
        int sel;
2060
 
2061
        switch(addr)
2062
        {
2063
        case 0:     /* when reset */
2064
                OPN->ST.prescaler_sel = 2;
2065
                break;
2066
        case 1:     /* when postload */
2067
                break;
2068
        case 0x2d:  /* divider sel : select 1/1 for 1/3line    */
2069
                OPN->ST.prescaler_sel |= 0x02;
2070
                break;
2071
        case 0x2e:  /* divider sel , select 1/3line for output */
2072
                OPN->ST.prescaler_sel |= 0x01;
2073
                break;
2074
        case 0x2f:  /* divider sel , clear both selector to 1/2,1/2 */
2075
                OPN->ST.prescaler_sel = 0;
2076
                break;
2077
        }
2078
        sel = OPN->ST.prescaler_sel & 3;
2079
        /* update prescaler */
2080
        OPNSetPres( OPN,    opn_pres[sel]*pre_divider,
2081
                                                opn_pres[sel]*pre_divider,
2082
                                                ssg_pres[sel]*pre_divider );
2083
}
2084
#endif /* BUILD_OPN_PRESCALER */
2085
 
2086
#if BUILD_YM2203
2087
/*****************************************************************************/
2088
/*      YM2203 local section                                                 */
2089
/*****************************************************************************/
2090
 
2091
/* here's the virtual YM2203(OPN) */
2092
struct YM2203
2093
{
2094
        UINT8 REGS[256];        /* registers         */
2095
        FM_OPN OPN;             /* OPN state         */
2096
        FM_CH CH[3];            /* channel state     */
2097
};
2098
 
2099
/* Generate samples for one of the YM2203s */
2100
void ym2203_update_one(void *chip, FMSAMPLE *buffer, int length)
2101
{
2102
        YM2203 *F2203 = (YM2203 *)chip;
2103
        FM_OPN *OPN =   &F2203->OPN;
2104
        int i;
2105
        FMSAMPLE *buf = buffer;
2106
        FM_CH   *cch[3];
2107
 
2108
        cch[0]   = &F2203->CH[0];
2109
        cch[1]   = &F2203->CH[1];
2110
        cch[2]   = &F2203->CH[2];
2111
 
2112
 
2113
        /* refresh PG and EG */
2114
        refresh_fc_eg_chan( OPN, cch[0] );
2115
        refresh_fc_eg_chan( OPN, cch[1] );
2116
        if( (F2203->OPN.ST.mode & 0xc0) )
2117
        {
2118
                /* 3SLOT MODE */
2119
                if( cch[2]->SLOT[SLOT1].Incr==-1)
2120
                {
2121
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT1] , OPN->SL3.fc[1] , OPN->SL3.kcode[1] );
2122
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT2] , OPN->SL3.fc[2] , OPN->SL3.kcode[2] );
2123
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT3] , OPN->SL3.fc[0] , OPN->SL3.kcode[0] );
2124
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT4] , cch[2]->fc , cch[2]->kcode );
2125
                }
2126
        }
2127
        else
2128
                refresh_fc_eg_chan( OPN, cch[2] );
2129
 
2130
 
2131
        /* YM2203 doesn't have LFO so we must keep these globals at 0 level */
2132
        OPN->LFO_AM = 0;
2133
        OPN->LFO_PM = 0;
2134
 
2135
        /* buffering */
2136
        for (i=0; i < length ; i++)
2137
        {
2138
                /* clear outputs */
2139
                OPN->out_fm[0] = 0;
2140
                OPN->out_fm[1] = 0;
2141
                OPN->out_fm[2] = 0;
2142
 
2143
                /* advance envelope generator */
2144
                OPN->eg_timer += OPN->eg_timer_add;
2145
                while (OPN->eg_timer >= OPN->eg_timer_overflow)
2146
                {
2147
                        OPN->eg_timer -= OPN->eg_timer_overflow;
2148
                        OPN->eg_cnt++;
2149
 
2150
                        advance_eg_channel(OPN, &cch[0]->SLOT[SLOT1]);
2151
                        advance_eg_channel(OPN, &cch[1]->SLOT[SLOT1]);
2152
                        advance_eg_channel(OPN, &cch[2]->SLOT[SLOT1]);
2153
                }
2154
 
2155
                /* calculate FM */
2156
                chan_calc(OPN, cch[0], 0 );
2157
                chan_calc(OPN, cch[1], 1 );
2158
                chan_calc(OPN, cch[2], 2 );
2159
 
2160
                /* buffering */
2161
                {
2162
                        int lt;
2163
 
2164
                        lt = OPN->out_fm[0] + OPN->out_fm[1] + OPN->out_fm[2];
2165
 
2166
                        lt >>= FINAL_SH;
2167
 
2168
                        Limit( lt , MAXOUT, MINOUT );
2169
 
2170
                        #ifdef SAVE_SAMPLE
2171
                                SAVE_ALL_CHANNELS
2172
                        #endif
2173
 
2174
                        /* buffering */
2175
                        buf[i] = lt;
2176
                }
2177
 
2178
                /* timer A control */
2179
                INTERNAL_TIMER_A( &F2203->OPN.ST , cch[2] )
2180
        }
2181
        INTERNAL_TIMER_B(&F2203->OPN.ST,length)
2182
}
2183
 
2184
/* ---------- reset one of chip ---------- */
2185
void ym2203_reset_chip(void *chip)
2186
{
2187
        int i;
2188
        YM2203 *F2203 = (YM2203 *)chip;
2189
        FM_OPN *OPN = &F2203->OPN;
2190
 
2191
        /* Reset Prescaler */
2192
        OPNPrescaler_w(OPN, 0 , 1 );
2193
        /* reset SSG section */
2194
        (*OPN->ST.SSG->reset)(OPN->ST.param);
2195
        /* status clear */
2196
        FM_IRQMASK_SET(&OPN->ST,0x03);
2197
        FM_BUSY_CLEAR(&OPN->ST);
2198
        OPNWriteMode(OPN,0x27,0x30); /* mode 0 , timer reset */
2199
 
2200
        OPN->eg_timer = 0;
2201
        OPN->eg_cnt   = 0;
2202
 
2203
        FM_STATUS_RESET(&OPN->ST, 0xff);
2204
 
2205
        reset_channels( &OPN->ST , F2203->CH , 3 );
2206
        /* reset OPerator paramater */
2207
        for(i = 0xb2 ; i >= 0x30 ; i-- ) OPNWriteReg(OPN,i,0);
2208
        for(i = 0x26 ; i >= 0x20 ; i-- ) OPNWriteReg(OPN,i,0);
2209
}
2210
 
2211
#ifdef __SAVE_H__
2212
void ym2203_postload(void *chip)
2213
{
2214
        if (chip)
2215
        {
2216
                YM2203 *F2203 = (YM2203 *)chip;
2217
                int r;
2218
 
2219
                /* prescaler */
2220
                OPNPrescaler_w(&F2203->OPN,1,1);
2221
 
2222
                /* SSG registers */
2223
                for(r=0;r<16;r++)
2224
                {
2225
                        (*F2203->OPN.ST.SSG->write)(F2203->OPN.ST.param,0,r);
2226
                        (*F2203->OPN.ST.SSG->write)(F2203->OPN.ST.param,1,F2203->REGS[r]);
2227
                }
2228
 
2229
                /* OPN registers */
2230
                /* DT / MULTI , TL , KS / AR , AMON / DR , SR , SL / RR , SSG-EG */
2231
                for(r=0x30;r<0x9e;r++)
2232
                        if((r&3) != 3)
2233
                                OPNWriteReg(&F2203->OPN,r,F2203->REGS[r]);
2234
                /* FB / CONNECT , L / R / AMS / PMS */
2235
                for(r=0xb0;r<0xb6;r++)
2236
                        if((r&3) != 3)
2237
                                OPNWriteReg(&F2203->OPN,r,F2203->REGS[r]);
2238
 
2239
                /* channels */
2240
                /*FM_channel_postload(F2203->CH,3);*/
2241
        }
2242
}
2243
 
2244
static void YM2203_save_state(YM2203 *F2203, device_t *device)
2245
{
2246
        device->save_item(NAME(F2203->REGS));
2247
        FMsave_state_st(device,&F2203->OPN.ST);
2248
        FMsave_state_channel(device,F2203->CH,3);
2249
        /* 3slots */
2250
        device->save_item (NAME(F2203->OPN.SL3.fc));
2251
        device->save_item  (NAME(F2203->OPN.SL3.fn_h));
2252
        device->save_item  (NAME(F2203->OPN.SL3.kcode));
2253
}
2254
#endif /* _STATE_H */
2255
 
2256
/* ----------  Initialize YM2203 emulator(s) ----------
2257
   'num' is the number of virtual YM2203s to allocate
2258
   'clock' is the chip clock in Hz
2259
   'rate' is sampling rate
2260
*/
2261
void * ym2203_init(void *param, device_t *device, int clock, int rate,
2262
                                FM_TIMERHANDLER timer_handler,FM_IRQHANDLER IRQHandler, const ssg_callbacks *ssg)
2263
{
2264
        YM2203 *F2203;
2265
 
2266
        /* allocate ym2203 state space */
2267
        F2203 = auto_alloc_clear(device->machine(), YM2203);
2268
 
2269
        if( !init_tables() )
2270
        {
2271
                auto_free( device->machine(), F2203 );
2272
                return NULL;
2273
        }
2274
 
2275
        F2203->OPN.ST.param = param;
2276
        F2203->OPN.type = TYPE_YM2203;
2277
        F2203->OPN.P_CH = F2203->CH;
2278
        F2203->OPN.ST.device = device;
2279
        F2203->OPN.ST.clock = clock;
2280
        F2203->OPN.ST.rate = rate;
2281
 
2282
        F2203->OPN.ST.timer_handler = timer_handler;
2283
        F2203->OPN.ST.IRQ_Handler   = IRQHandler;
2284
        F2203->OPN.ST.SSG           = ssg;
2285
 
2286
#ifdef __SAVE_H__
2287
        YM2203_save_state(F2203, device);
2288
#endif
2289
        return F2203;
2290
}
2291
 
2292
/* shut down emulator */
2293
void ym2203_shutdown(void *chip)
2294
{
2295
        YM2203 *FM2203 = (YM2203 *)chip;
2296
 
2297
        FMCloseTable();
2298
        auto_free(FM2203->OPN.ST.device->machine(), FM2203);
2299
}
2300
 
2301
/* YM2203 I/O interface */
2302
int ym2203_write(void *chip,int a,UINT8 v)
2303
{
2304
        YM2203 *F2203 = (YM2203 *)chip;
2305
        FM_OPN *OPN = &F2203->OPN;
2306
 
2307
        if( !(a&1) )
2308
        {   /* address port */
2309
                OPN->ST.address = (v &= 0xff);
2310
 
2311
                /* Write register to SSG emulator */
2312
                if( v < 16 ) (*OPN->ST.SSG->write)(OPN->ST.param,0,v);
2313
 
2314
                /* prescaler select : 2d,2e,2f  */
2315
                if( v >= 0x2d && v <= 0x2f )
2316
                        OPNPrescaler_w(OPN , v , 1);
2317
        }
2318
        else
2319
        {   /* data port */
2320
                int addr = OPN->ST.address;
2321
                F2203->REGS[addr] = v;
2322
                switch( addr & 0xf0 )
2323
                {
2324
                case 0x00:  /* 0x00-0x0f : SSG section */
2325
                        /* Write data to SSG emulator */
2326
                        (*OPN->ST.SSG->write)(OPN->ST.param,a,v);
2327
                        break;
2328
                case 0x20:  /* 0x20-0x2f : Mode section */
2329
                        ym2203_update_req(OPN->ST.param);
2330
                        /* write register */
2331
                        OPNWriteMode(OPN,addr,v);
2332
                        break;
2333
                default:    /* 0x30-0xff : OPN section */
2334
                        ym2203_update_req(OPN->ST.param);
2335
                        /* write register */
2336
                        OPNWriteReg(OPN,addr,v);
2337
                }
2338
                FM_BUSY_SET(&OPN->ST,1);
2339
        }
2340
        return OPN->ST.irq;
2341
}
2342
 
2343
UINT8 ym2203_read(void *chip,int a)
2344
{
2345
        YM2203 *F2203 = (YM2203 *)chip;
2346
        int addr = F2203->OPN.ST.address;
2347
        UINT8 ret = 0;
2348
 
2349
        if( !(a&1) )
2350
        {   /* status port */
2351
                ret = FM_STATUS_FLAG(&F2203->OPN.ST);
2352
        }
2353
        else
2354
        {   /* data port (only SSG) */
2355
                if( addr < 16 ) ret = (*F2203->OPN.ST.SSG->read)(F2203->OPN.ST.param);
2356
        }
2357
        return ret;
2358
}
2359
 
2360
int ym2203_timer_over(void *chip,int c)
2361
{
2362
        YM2203 *F2203 = (YM2203 *)chip;
2363
 
2364
        if( c )
2365
        {   /* Timer B */
2366
                TimerBOver( &(F2203->OPN.ST) );
2367
        }
2368
        else
2369
        {   /* Timer A */
2370
                ym2203_update_req(F2203->OPN.ST.param);
2371
                /* timer update */
2372
                TimerAOver( &(F2203->OPN.ST) );
2373
                /* CSM mode key,TL control */
2374
                if( F2203->OPN.ST.mode & 0x80 )
2375
                {   /* CSM mode auto key on */
2376
                        CSMKeyControll( F2203->OPN.type, &(F2203->CH[2]) );
2377
                }
2378
        }
2379
        return F2203->OPN.ST.irq;
2380
}
2381
#endif /* BUILD_YM2203 */
2382
 
2383
 
2384
 
2385
#if (BUILD_YM2608||BUILD_YM2610||BUILD_YM2610B)
2386
 
2387
/* ADPCM type A channel struct */
2388
struct ADPCM_CH
2389
{
2390
        UINT8       flag;           /* port state               */
2391
        UINT8       flagMask;       /* arrived flag mask        */
2392
        UINT8       now_data;       /* current ROM data         */
2393
        UINT32      now_addr;       /* current ROM address      */
2394
        UINT32      now_step;
2395
        UINT32      step;
2396
        UINT32      start;          /* sample data start address*/
2397
        UINT32      end;            /* sample data end address  */
2398
        UINT8       IL;             /* Instrument Level         */
2399
        INT32       adpcm_acc;      /* accumulator              */
2400
        INT32       adpcm_step;     /* step                     */
2401
        INT32       adpcm_out;      /* (speedup) hiro-shi!!     */
2402
        INT8        vol_mul;        /* volume in "0.75dB" steps */
2403
        UINT8       vol_shift;      /* volume in "-6dB" steps   */
2404
        INT32       *pan;           /* &out_adpcm[OPN_xxxx]     */
2405
};
2406
 
2407
/* here's the virtual YM2610 */
2408
struct YM2610
2409
{
2410
        UINT8       REGS[512];          /* registers            */
2411
        FM_OPN      OPN;                /* OPN state            */
2412
        FM_CH       CH[6];              /* channel state        */
2413
        UINT8       addr_A1;            /* address line A1      */
2414
 
2415
        /* ADPCM-A unit */
2416
        const UINT8 *pcmbuf;            /* pcm rom buffer       */
2417
        UINT32      pcm_size;           /* size of pcm rom      */
2418
        UINT8       adpcmTL;            /* adpcmA total level   */
2419
        ADPCM_CH    adpcm[6];           /* adpcm channels       */
2420
        UINT32      adpcmreg[0x30];     /* registers            */
2421
        UINT8       adpcm_arrivedEndAddress;
2422
        YM_DELTAT   deltaT;             /* Delta-T ADPCM unit   */
2423
 
2424
        UINT8       flagmask;           /* YM2608 only */
2425
        UINT8       irqmask;            /* YM2608 only */
2426
};
2427
 
2428
/* here is the virtual YM2608 */
2429
typedef YM2610 YM2608;
2430
 
2431
 
2432
/**** YM2610 ADPCM defines ****/
2433
#define ADPCM_SHIFT    (16)      /* frequency step rate   */
2434
#define ADPCMA_ADDRESS_SHIFT 8   /* adpcm A address shift */
2435
 
2436
/* Algorithm and tables verified on real YM2608 and YM2610 */
2437
 
2438
/* usual ADPCM table (16 * 1.1^N) */
2439
static const int steps[49] =
2440
{
2441
                16,  17,   19,   21,   23,   25,   28,
2442
                31,  34,   37,   41,   45,   50,   55,
2443
                60,  66,   73,   80,   88,   97,  107,
2444
        118, 130,  143,  157,  173,  190,  209,
2445
        230, 253,  279,  307,  337,  371,  408,
2446
        449, 494,  544,  598,  658,  724,  796,
2447
        876, 963, 1060, 1166, 1282, 1411, 1552
2448
};
2449
 
2450
/* different from the usual ADPCM table */
2451
static const int step_inc[8] = { -1*16, -1*16, -1*16, -1*16, 2*16, 5*16, 7*16, 9*16 };
2452
 
2453
/* speedup purposes only */
2454
static int jedi_table[ 49*16 ];
2455
 
2456
 
2457
static void Init_ADPCMATable(void)
2458
{
2459
        int step, nib;
2460
 
2461
        for (step = 0; step < 49; step++)
2462
        {
2463
                /* loop over all nibbles and compute the difference */
2464
                for (nib = 0; nib < 16; nib++)
2465
                {
2466
                        int value = (2*(nib & 0x07) + 1) * steps[step] / 8;
2467
                        jedi_table[step*16 + nib] = (nib&0x08) ? -value : value;
2468
                }
2469
        }
2470
}
2471
 
2472
/* ADPCM A (Non control type) : calculate one channel output */
2473
INLINE void ADPCMA_calc_chan( YM2610 *F2610, ADPCM_CH *ch )
2474
{
2475
        UINT32 step;
2476
        UINT8  data;
2477
 
2478
 
2479
        ch->now_step += ch->step;
2480
        if ( ch->now_step >= (1<<ADPCM_SHIFT) )
2481
        {
2482
                step = ch->now_step >> ADPCM_SHIFT;
2483
                ch->now_step &= (1<<ADPCM_SHIFT)-1;
2484
                do{
2485
                        /* end check */
2486
                        /* 11-06-2001 JB: corrected comparison. Was > instead of == */
2487
                        /* YM2610 checks lower 20 bits only, the 4 MSB bits are sample bank */
2488
                        /* Here we use 1<<21 to compensate for nibble calculations */
2489
 
2490
                        if (   (ch->now_addr & ((1<<21)-1)) == ((ch->end<<1) & ((1<<21)-1))    )
2491
                        {
2492
                                ch->flag = 0;
2493
                                F2610->adpcm_arrivedEndAddress |= ch->flagMask;
2494
                                return;
2495
                        }
2496
#if 0
2497
                        if ( ch->now_addr > (F2610->pcmsizeA<<1) )
2498
                        {
2499
                                LOG(LOG_WAR,("YM2610: Attempting to play past adpcm rom size!\n" ));
2500
                                return;
2501
                        }
2502
#endif
2503
                        if ( ch->now_addr&1 )
2504
                                data = ch->now_data & 0x0f;
2505
                        else
2506
                        {
2507
                                ch->now_data = *(F2610->pcmbuf+(ch->now_addr>>1));
2508
                                data = (ch->now_data >> 4) & 0x0f;
2509
                        }
2510
 
2511
                        ch->now_addr++;
2512
 
2513
                        ch->adpcm_acc += jedi_table[ch->adpcm_step + data];
2514
 
2515
                        /* extend 12-bit signed int */
2516
                        if (ch->adpcm_acc & ~0x7ff)
2517
                                ch->adpcm_acc |= ~0xfff;
2518
                        else
2519
                                ch->adpcm_acc &= 0xfff;
2520
 
2521
                        ch->adpcm_step += step_inc[data & 7];
2522
                        Limit( ch->adpcm_step, 48*16, 0*16 );
2523
 
2524
                }while(--step);
2525
 
2526
                /* calc pcm * volume data */
2527
                ch->adpcm_out = ((ch->adpcm_acc * ch->vol_mul) >> ch->vol_shift) & ~3;  /* multiply, shift and mask out 2 LSB bits */
2528
        }
2529
 
2530
        /* output for work of output channels (out_adpcm[OPNxxxx])*/
2531
        *(ch->pan) += ch->adpcm_out;
2532
}
2533
 
2534
/* ADPCM type A Write */
2535
static void FM_ADPCMAWrite(YM2610 *F2610,int r,int v)
2536
{
2537
        ADPCM_CH *adpcm = F2610->adpcm;
2538
        UINT8 c = r&0x07;
2539
 
2540
        F2610->adpcmreg[r] = v&0xff; /* stock data */
2541
        switch( r )
2542
        {
2543
        case 0x00: /* DM,--,C5,C4,C3,C2,C1,C0 */
2544
                if( !(v&0x80) )
2545
                {
2546
                        /* KEY ON */
2547
                        for( c = 0; c < 6; c++ )
2548
                        {
2549
                                if( (v>>c)&1 )
2550
                                {
2551
                                        /**** start adpcm ****/
2552
                                        adpcm[c].step      = (UINT32)((float)(1<<ADPCM_SHIFT)*((float)F2610->OPN.ST.freqbase)/3.0);
2553
                                        adpcm[c].now_addr  = adpcm[c].start<<1;
2554
                                        adpcm[c].now_step  = 0;
2555
                                        adpcm[c].adpcm_acc = 0;
2556
                                        adpcm[c].adpcm_step= 0;
2557
                                        adpcm[c].adpcm_out = 0;
2558
                                        adpcm[c].flag      = 1;
2559
 
2560
                                        if(F2610->pcmbuf==NULL)
2561
                                        {                   /* Check ROM Mapped */
2562
                                                logerror("YM2608-YM2610: ADPCM-A rom not mapped\n");
2563
                                                adpcm[c].flag = 0;
2564
                                        }
2565
                                        else
2566
                                        {
2567
                                                if(adpcm[c].end >= F2610->pcm_size)
2568
                                                {   /* Check End in Range */
2569
                                                        logerror("YM2610: ADPCM-A end out of range: $%08x\n",adpcm[c].end);
2570
                                                        /*adpcm[c].end = F2610->pcm_size-1;*/ /* JB: DO NOT uncomment this, otherwise you will break the comparison in the ADPCM_CALC_CHA() */
2571
                                                }
2572
                                                if(adpcm[c].start >= F2610->pcm_size)   /* Check Start in Range */
2573
                                                {
2574
                                                        logerror("YM2608-YM2610: ADPCM-A start out of range: $%08x\n",adpcm[c].start);
2575
                                                        adpcm[c].flag = 0;
2576
                                                }
2577
                                        }
2578
                                }
2579
                        }
2580
                }
2581
                else
2582
                {
2583
                        /* KEY OFF */
2584
                        for( c = 0; c < 6; c++ )
2585
                                if( (v>>c)&1 )
2586
                                        adpcm[c].flag = 0;
2587
                }
2588
                break;
2589
        case 0x01:  /* B0-5 = TL */
2590
                F2610->adpcmTL = (v & 0x3f) ^ 0x3f;
2591
                for( c = 0; c < 6; c++ )
2592
                {
2593
                        int volume = F2610->adpcmTL + adpcm[c].IL;
2594
 
2595
                        if ( volume >= 63 ) /* This is correct, 63 = quiet */
2596
                        {
2597
                                adpcm[c].vol_mul   = 0;
2598
                                adpcm[c].vol_shift = 0;
2599
                        }
2600
                        else
2601
                        {
2602
                                adpcm[c].vol_mul   = 15 - (volume & 7);     /* so called 0.75 dB */
2603
                                adpcm[c].vol_shift =  1 + (volume >> 3);    /* Yamaha engineers used the approximation: each -6 dB is close to divide by two (shift right) */
2604
                        }
2605
 
2606
                        /* calc pcm * volume data */
2607
                        adpcm[c].adpcm_out = ((adpcm[c].adpcm_acc * adpcm[c].vol_mul) >> adpcm[c].vol_shift) & ~3;  /* multiply, shift and mask out low 2 bits */
2608
                }
2609
                break;
2610
        default:
2611
                c = r&0x07;
2612
                if( c >= 0x06 ) return;
2613
                switch( r&0x38 )
2614
                {
2615
                case 0x08:  /* B7=L,B6=R, B4-0=IL */
2616
                {
2617
                        int volume;
2618
 
2619
                        adpcm[c].IL = (v & 0x1f) ^ 0x1f;
2620
 
2621
                        volume = F2610->adpcmTL + adpcm[c].IL;
2622
 
2623
                        if ( volume >= 63 ) /* This is correct, 63 = quiet */
2624
                        {
2625
                                adpcm[c].vol_mul   = 0;
2626
                                adpcm[c].vol_shift = 0;
2627
                        }
2628
                        else
2629
                        {
2630
                                adpcm[c].vol_mul   = 15 - (volume & 7);     /* so called 0.75 dB */
2631
                                adpcm[c].vol_shift =  1 + (volume >> 3);    /* Yamaha engineers used the approximation: each -6 dB is close to divide by two (shift right) */
2632
                        }
2633
 
2634
                        adpcm[c].pan    = &F2610->OPN.out_adpcm[(v>>6)&0x03];
2635
 
2636
                        /* calc pcm * volume data */
2637
                        adpcm[c].adpcm_out = ((adpcm[c].adpcm_acc * adpcm[c].vol_mul) >> adpcm[c].vol_shift) & ~3;  /* multiply, shift and mask out low 2 bits */
2638
                }
2639
                        break;
2640
                case 0x10:
2641
                case 0x18:
2642
                        adpcm[c].start  = ( (F2610->adpcmreg[0x18 + c]*0x0100 | F2610->adpcmreg[0x10 + c]) << ADPCMA_ADDRESS_SHIFT);
2643
                        break;
2644
                case 0x20:
2645
                case 0x28:
2646
                        adpcm[c].end    = ( (F2610->adpcmreg[0x28 + c]*0x0100 | F2610->adpcmreg[0x20 + c]) << ADPCMA_ADDRESS_SHIFT);
2647
                        adpcm[c].end   += (1<<ADPCMA_ADDRESS_SHIFT) - 1;
2648
                        break;
2649
                }
2650
        }
2651
}
2652
 
2653
#ifdef __SAVE_H__
2654
/* FM channel save , internal state only */
2655
static void FMsave_state_adpcma(device_t *device,ADPCM_CH *adpcm)
2656
{
2657
        int ch;
2658
 
2659
        for(ch=0;ch<6;ch++,adpcm++)
2660
        {
2661
                device->save_item(NAME(adpcm->flag), ch);
2662
                device->save_item(NAME(adpcm->now_data), ch);
2663
                device->save_item(NAME(adpcm->now_addr), ch);
2664
                device->save_item(NAME(adpcm->now_step), ch);
2665
                device->save_item(NAME(adpcm->adpcm_acc), ch);
2666
                device->save_item(NAME(adpcm->adpcm_step), ch);
2667
                device->save_item(NAME(adpcm->adpcm_out), ch);
2668
        }
2669
}
2670
#endif /* _STATE_H */
2671
 
2672
#endif /* (BUILD_YM2608||BUILD_YM2610||BUILD_YM2610B) */
2673
 
2674
 
2675
#if BUILD_YM2608
2676
/*****************************************************************************/
2677
/*      YM2608 local section                                                 */
2678
/*****************************************************************************/
2679
 
2680
 
2681
 
2682
static const unsigned int YM2608_ADPCM_ROM_addr[2*6] = {
2683
0x0000, 0x01bf, /* bass drum  */
2684
0x01c0, 0x043f, /* snare drum */
2685
0x0440, 0x1b7f, /* top cymbal */
2686
0x1b80, 0x1cff, /* high hat */
2687
0x1d00, 0x1f7f, /* tom tom  */
2688
0x1f80, 0x1fff  /* rim shot */
2689
};
2690
 
2691
 
2692
/*
2693
    This data is derived from the chip's output - internal ROM can't be read.
2694
    It was verified, using real YM2608, that this ADPCM stream produces 100% correct output signal.
2695
*/
2696
 
2697
static const unsigned char YM2608_ADPCM_ROM[0x2000] = {
2698
 
2699
/* Source: 01BD.ROM */
2700
/* Length: 448 / 0x000001C0 */
2701
 
2702
0x88,0x08,0x08,0x08,0x00,0x88,0x16,0x76,0x99,0xB8,0x22,0x3A,0x84,0x3C,0xB1,0x54,
2703
0x10,0xA9,0x98,0x32,0x80,0x33,0x9A,0xA7,0x4A,0xB4,0x58,0xBC,0x15,0x29,0x8A,0x97,
2704
0x9B,0x44,0xAC,0x80,0x12,0xDE,0x13,0x1B,0xC0,0x58,0xC8,0x11,0x0A,0xA2,0x1A,0xA0,
2705
0x00,0x98,0x0B,0x93,0x9E,0x92,0x0A,0x88,0xBE,0x14,0x1B,0x98,0x08,0xA1,0x4A,0xC1,
2706
0x30,0xD9,0x33,0x98,0x10,0x89,0x17,0x1A,0x82,0x29,0x37,0x0C,0x83,0x50,0x9A,0x24,
2707
0x1A,0x83,0x10,0x23,0x19,0xB3,0x72,0x8A,0x16,0x10,0x0A,0x93,0x70,0x99,0x23,0x99,
2708
0x02,0x20,0x91,0x18,0x02,0x41,0xAB,0x24,0x18,0x81,0x99,0x4A,0xE8,0x28,0x9A,0x99,
2709
0xA1,0x2F,0xA8,0x9D,0x90,0x08,0xCC,0xA3,0x1D,0xCA,0x82,0x0B,0xD8,0x08,0xB9,0x09,
2710
0xBC,0xB8,0x00,0xBE,0x90,0x1B,0xCA,0x00,0x9B,0x8A,0xA8,0x91,0x0F,0xB3,0x3D,0xB8,
2711
0x31,0x0B,0xA5,0x0A,0x11,0xA1,0x48,0x92,0x10,0x50,0x91,0x30,0x23,0x09,0x37,0x39,
2712
0xA2,0x72,0x89,0x92,0x30,0x83,0x1C,0x96,0x28,0xB9,0x24,0x8C,0xA1,0x31,0xAD,0xA9,
2713
0x13,0x9C,0xBA,0xA8,0x0B,0xBF,0xB8,0x9B,0xCA,0x88,0xDB,0xB8,0x19,0xFC,0x92,0x0A,
2714
0xBA,0x89,0xAB,0xB8,0xAB,0xD8,0x08,0xAD,0xBA,0x33,0x9D,0xAA,0x83,0x3A,0xC0,0x40,
2715
0xB9,0x15,0x39,0xA2,0x52,0x89,0x02,0x63,0x88,0x13,0x23,0x03,0x52,0x02,0x54,0x00,
2716
0x11,0x23,0x23,0x35,0x20,0x01,0x44,0x41,0x80,0x24,0x40,0xA9,0x45,0x19,0x81,0x12,
2717
0x81,0x02,0x11,0x21,0x19,0x02,0x61,0x8A,0x13,0x3A,0x10,0x12,0x23,0x8B,0x37,0x18,
2718
0x91,0x24,0x10,0x81,0x34,0x20,0x05,0x32,0x82,0x53,0x20,0x14,0x33,0x31,0x34,0x52,
2719
0x00,0x43,0x32,0x13,0x52,0x22,0x13,0x52,0x11,0x43,0x11,0x32,0x32,0x32,0x22,0x02,
2720
0x13,0x12,0x89,0x22,0x19,0x81,0x81,0x08,0xA8,0x08,0x8B,0x90,0x1B,0xBA,0x8A,0x9B,
2721
0xB9,0x89,0xCA,0xB9,0xAB,0xCA,0x9B,0xCA,0xB9,0xAB,0xDA,0x99,0xAC,0xBB,0x9B,0xAC,
2722
0xAA,0xBA,0xAC,0xAB,0x9A,0xAA,0xAA,0xBA,0xB8,0xA9,0xBA,0x99,0xA9,0x9A,0xA0,0x8A,
2723
0xA9,0x08,0x8A,0xA9,0x00,0x99,0x89,0x88,0x98,0x08,0x99,0x00,0x89,0x80,0x08,0x98,
2724
0x00,0x88,0x88,0x80,0x90,0x80,0x90,0x80,0x81,0x99,0x08,0x88,0x99,0x09,0x00,0x1A,
2725
0xA8,0x10,0x9A,0x88,0x08,0x0A,0x8A,0x89,0x99,0xA8,0x98,0xA9,0x99,0x99,0xA9,0x99,
2726
0xAA,0x8A,0xAA,0x9B,0x8A,0x9A,0xA9,0x9A,0xBA,0x99,0x9A,0xAA,0x99,0x89,0xA9,0x99,
2727
0x98,0x9A,0x98,0x88,0x09,0x89,0x09,0x08,0x08,0x09,0x18,0x18,0x00,0x12,0x00,0x11,
2728
0x11,0x11,0x12,0x12,0x21,0x21,0x22,0x22,0x22,0x22,0x22,0x22,0x32,0x31,0x32,0x31,
2729
0x32,0x32,0x21,0x31,0x21,0x32,0x21,0x12,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
2730
 
2731
/* Source: 02SD.ROM */
2732
/* Length: 640 / 0x00000280 */
2733
 
2734
0x0A,0xDC,0x14,0x0B,0xBA,0xBC,0x01,0x0F,0xF5,0x2F,0x87,0x19,0xC9,0x24,0x1B,0xA1,
2735
0x31,0x99,0x90,0x32,0x32,0xFE,0x83,0x48,0xA8,0xA9,0x23,0x19,0xBC,0x91,0x02,0x41,
2736
0xDE,0x81,0x28,0xA8,0x0A,0xB1,0x72,0xDA,0x23,0xBC,0x04,0x19,0xB8,0x21,0x8A,0x03,
2737
0x29,0xBA,0x14,0x21,0x0B,0xC0,0x43,0x08,0x91,0x50,0x93,0x0F,0x86,0x1A,0x91,0x18,
2738
0x21,0xCB,0x27,0x0A,0xA1,0x42,0x8C,0xA9,0x21,0x10,0x08,0xAB,0x94,0x2A,0xDA,0x02,
2739
0x8B,0x91,0x09,0x98,0xAE,0x80,0xA9,0x02,0x0A,0xE9,0x21,0xBB,0x15,0x20,0xBE,0x92,
2740
0x42,0x09,0xA9,0x11,0x34,0x08,0x12,0x0A,0x27,0x29,0xA1,0x52,0x12,0x8E,0x92,0x28,
2741
0x92,0x2B,0xD1,0x23,0xBF,0x81,0x10,0x99,0xA8,0x0A,0xC4,0x3B,0xB9,0xB0,0x00,0x62,
2742
0xCF,0x92,0x29,0x92,0x2B,0xB1,0x1C,0xB2,0x72,0xAA,0x88,0x11,0x18,0x80,0x13,0x9E,
2743
0x03,0x18,0xB0,0x60,0xA1,0x28,0x88,0x08,0x04,0x10,0x8F,0x96,0x19,0x90,0x01,0x09,
2744
0xC8,0x50,0x91,0x8A,0x01,0xAB,0x03,0x50,0xBA,0x9D,0x93,0x68,0xBA,0x80,0x22,0xCB,
2745
0x41,0xBC,0x92,0x60,0xB9,0x1A,0x95,0x4A,0xC8,0x20,0x88,0x33,0xAC,0x92,0x38,0x83,
2746
0x09,0x80,0x16,0x09,0x29,0xD0,0x54,0x8C,0xA2,0x28,0x91,0x89,0x93,0x60,0xCD,0x85,
2747
0x1B,0xA1,0x49,0x90,0x8A,0x80,0x34,0x0C,0xC9,0x14,0x19,0x98,0xA0,0x40,0xA9,0x21,
2748
0xD9,0x34,0x0A,0xA9,0x10,0x23,0xCB,0x25,0xAA,0x25,0x9B,0x13,0xCD,0x16,0x09,0xA0,
2749
0x80,0x01,0x19,0x90,0x88,0x21,0xAC,0x33,0x8B,0xD8,0x27,0x3B,0xB8,0x81,0x31,0x80,
2750
0xAF,0x97,0x0A,0x82,0x0A,0xA0,0x21,0x89,0x8A,0xA2,0x32,0x8D,0xBB,0x87,0x19,0x21,
2751
0xC9,0xBC,0x45,0x09,0x90,0x09,0xA1,0x24,0x1A,0xD0,0x10,0x08,0x11,0xA9,0x21,0xE8,
2752
0x60,0xA9,0x14,0x0C,0xD1,0x32,0xAB,0x04,0x0C,0x81,0x90,0x29,0x83,0x9B,0x01,0x8F,
2753
0x97,0x0B,0x82,0x18,0x88,0xBA,0x06,0x39,0xC8,0x23,0xBC,0x04,0x09,0x92,0x08,0x1A,
2754
0xBB,0x74,0x8C,0x81,0x18,0x81,0x9D,0x83,0x41,0xCD,0x81,0x40,0x9A,0x90,0x10,0x12,
2755
0x9C,0xA1,0x68,0xD8,0x33,0x9C,0x91,0x01,0x12,0xBE,0x02,0x09,0x12,0x99,0x9A,0x36,
2756
0x0A,0xB0,0x30,0x88,0xA3,0x2D,0x12,0xBC,0x03,0x3A,0x11,0xBD,0x08,0xC8,0x62,0x80,
2757
0x8B,0xD8,0x23,0x38,0xF9,0x12,0x08,0x99,0x91,0x21,0x99,0x85,0x2F,0xB2,0x30,0x90,
2758
0x88,0xD9,0x53,0xAC,0x82,0x19,0x91,0x20,0xCC,0x96,0x29,0xC9,0x24,0x89,0x80,0x99,
2759
0x12,0x08,0x18,0x88,0x99,0x23,0xAB,0x73,0xCB,0x33,0x9F,0x04,0x2B,0xB1,0x08,0x03,
2760
0x1B,0xC9,0x21,0x32,0xFA,0x33,0xDB,0x02,0x33,0xAE,0xB9,0x54,0x8B,0xA1,0x20,0x89,
2761
0x90,0x11,0x88,0x09,0x98,0x23,0xBE,0x37,0x8D,0x81,0x20,0xAA,0x34,0xBB,0x13,0x18,
2762
0xB9,0x40,0xB1,0x18,0x83,0x8E,0xB2,0x72,0xBC,0x82,0x30,0xA9,0x9A,0x24,0x8B,0x27,
2763
0x0E,0x91,0x20,0x90,0x08,0xB0,0x32,0xB9,0x21,0xB0,0xAC,0x45,0x9A,0xA1,0x50,0xA9,
2764
0x80,0x0A,0x26,0x9B,0x11,0xBB,0x23,0x71,0xCB,0x12,0x10,0xB8,0x40,0xA9,0xA5,0x39,
2765
0xC0,0x30,0xB2,0x20,0xAA,0xBA,0x76,0x1C,0xC1,0x48,0x98,0x80,0x18,0x81,0xAA,0x23,
2766
0x9C,0xA2,0x32,0xAC,0x9A,0x43,0x9C,0x12,0xAD,0x82,0x72,0xBC,0x00,0x82,0x39,0xD1,
2767
0x3A,0xB8,0x35,0x9B,0x10,0x40,0xF9,0x22,0x0A,0xC0,0x51,0xB9,0x82,0x18,0x98,0xA3,
2768
0x79,0xD0,0x20,0x88,0x09,0x01,0x99,0x82,0x11,0x38,0xFC,0x33,0x09,0xC8,0x40,0xA9,
2769
0x11,0x29,0xAA,0x94,0x3A,0xC2,0x4A,0xC0,0x89,0x52,0xBC,0x11,0x08,0x09,0xB8,0x71,
2770
0xA9,0x08,0xA8,0x62,0x8D,0x92,0x10,0x00,0x9E,0x94,0x38,0xBA,0x13,0x88,0x90,0x4A,
2771
0xE2,0x30,0xBA,0x02,0x00,0x19,0xD9,0x62,0xBB,0x04,0x0B,0xA3,0x68,0xB9,0x21,0x88,
2772
0x9D,0x04,0x10,0x8C,0xC8,0x62,0x99,0xAA,0x24,0x1A,0x80,0x9A,0x14,0x9B,0x26,0x8C,
2773
0x92,0x30,0xB9,0x09,0xA3,0x71,0xBB,0x10,0x19,0x82,0x39,0xDB,0x02,0x44,0x9F,0x10,
2774
 
2775
/* Source: 04TOP.ROM */
2776
/* Length: 5952 / 0x00001740 */
2777
 
2778
0x07,0xFF,0x7C,0x3C,0x31,0xC6,0xC4,0xBB,0x7F,0x7F,0x7B,0x82,0x8A,0x4D,0x5F,0x7C,
2779
0x3E,0x44,0xD2,0xB3,0xA0,0x19,0x1B,0x6C,0x81,0x28,0xC4,0xA1,0x1C,0x4B,0x18,0x00,
2780
0x2A,0xA2,0x0A,0x7C,0x2A,0x00,0x01,0x89,0x98,0x48,0x8A,0x3C,0x28,0x2A,0x5B,0x3E,
2781
0x3A,0x1A,0x3B,0x3D,0x4B,0x3B,0x4A,0x08,0x2A,0x1A,0x2C,0x4A,0x3B,0x82,0x99,0x3C,
2782
0x5D,0x29,0x2B,0x39,0x0B,0x23,0xAB,0x1A,0x4C,0x79,0xA3,0x01,0xC1,0x2A,0x0A,0x38,
2783
0xA7,0xB9,0x12,0x1F,0x29,0x08,0x82,0xA1,0x08,0xA9,0x42,0xAA,0x95,0xB3,0x90,0x81,
2784
0x09,0xD4,0x1A,0x80,0x1B,0x07,0xB8,0x12,0x8E,0x49,0x81,0x92,0xD3,0x90,0xA1,0x2A,
2785
0x02,0xE1,0xA3,0x99,0x02,0xB3,0x94,0xB3,0xB0,0xF4,0x98,0x93,0x90,0x13,0xE1,0x81,
2786
0x99,0x38,0x91,0xA6,0xD3,0x99,0x94,0xC1,0x83,0xB1,0x92,0x98,0x49,0xC4,0xB2,0xA4,
2787
0xA3,0xD0,0x1A,0x30,0xBA,0x59,0x02,0xD4,0xA0,0xA4,0xA2,0x8A,0x01,0x00,0xB7,0xA8,
2788
0x18,0x2A,0x2B,0x1E,0x23,0xC8,0x1A,0x00,0x39,0xA0,0x18,0x92,0x4F,0x2D,0x5A,0x10,
2789
0x89,0x81,0x2A,0x8B,0x6A,0x02,0x09,0xB3,0x8D,0x48,0x1B,0x80,0x19,0x34,0xF8,0x29,
2790
0x0A,0x7B,0x2A,0x28,0x81,0x0C,0x02,0x1E,0x29,0x09,0x12,0xC2,0x94,0xE1,0x18,0x98,
2791
0x02,0xC4,0x89,0x91,0x1A,0x20,0xA9,0x02,0x1B,0x48,0x8E,0x20,0x88,0x2D,0x08,0x59,
2792
0x1B,0x02,0xA3,0xB1,0x8A,0x1E,0x58,0x80,0xC2,0xB6,0x88,0x91,0x88,0x11,0xA1,0xA3,
2793
0xE2,0x01,0xB0,0x19,0x11,0x09,0xF4,0x88,0x09,0x88,0x19,0x89,0x12,0xF1,0x2A,0x28,
2794
0x8C,0x25,0x99,0xA4,0x98,0x39,0xA1,0x00,0xD0,0x58,0xAA,0x59,0x01,0x0C,0x00,0x2B,
2795
0x00,0x08,0x89,0x6B,0x69,0x90,0x01,0x90,0x98,0x12,0xB3,0xF3,0xA0,0x89,0x02,0x3B,
2796
0x0C,0x50,0xA9,0x4E,0x6B,0x19,0x28,0x09,0xA2,0x08,0x2F,0x20,0x88,0x92,0x8A,0x11,
2797
0xC4,0x93,0xF1,0x18,0x88,0x11,0xF2,0x80,0x92,0xA8,0x02,0xA8,0xB7,0xB3,0xA3,0xA0,
2798
0x88,0x1A,0x40,0xE2,0x91,0x19,0x88,0x18,0x91,0x83,0xC1,0xB5,0x92,0xA9,0xC6,0x90,
2799
0x01,0xC2,0x81,0x98,0x03,0xF0,0x00,0x2C,0x2A,0x92,0x2C,0x83,0x1F,0x3A,0x29,0x00,
2800
0xB8,0x70,0xAB,0x69,0x18,0x89,0x10,0x0D,0x12,0x0B,0x88,0x4A,0x3A,0x9B,0x70,0xA8,
2801
0x28,0x2F,0x2A,0x3A,0x1B,0x85,0x88,0x8B,0x6A,0x29,0x00,0x91,0x91,0x1B,0x7C,0x29,
2802
0x01,0x88,0x90,0x19,0x2B,0x2B,0x00,0x39,0xA8,0x5E,0x21,0x89,0x91,0x09,0x3A,0x6F,
2803
0x2A,0x18,0x18,0x8B,0x50,0x89,0x2B,0x19,0x49,0x88,0x29,0xF5,0x89,0x08,0x09,0x12,
2804
0xAA,0x15,0xB0,0x82,0xAC,0x38,0x00,0x3F,0x81,0x10,0xB0,0x49,0xA2,0x81,0x3A,0xC8,
2805
0x87,0x90,0xC4,0xA3,0x99,0x19,0x83,0xE1,0x84,0xE2,0xA2,0x90,0x80,0x93,0xB5,0xC4,
2806
0xB3,0xA1,0x0A,0x18,0x92,0xC4,0xA0,0x93,0x0C,0x3A,0x18,0x01,0x1E,0x20,0xB1,0x82,
2807
0x8C,0x03,0xB5,0x2E,0x82,0x19,0xB2,0x1B,0x1B,0x6B,0x4C,0x19,0x12,0x8B,0x5A,0x11,
2808
0x0C,0x3A,0x2C,0x18,0x3D,0x08,0x2A,0x5C,0x18,0x00,0x88,0x3D,0x29,0x80,0x2A,0x09,
2809
0x00,0x7A,0x0A,0x10,0x0B,0x69,0x98,0x10,0x81,0x3F,0x00,0x18,0x19,0x91,0xB7,0x9A,
2810
0x28,0x8A,0x48,0x92,0xF3,0xA2,0x88,0x98,0x87,0xA1,0x88,0x80,0x81,0x95,0xD1,0xA3,
2811
0x1B,0x1C,0x39,0x10,0xA1,0x2A,0x0B,0x7A,0x4B,0x80,0x13,0xC1,0xD1,0x2B,0x2A,0x85,
2812
0xB2,0xA2,0x93,0xB2,0xD3,0x80,0xD1,0x18,0x08,0x08,0xB7,0x98,0x81,0x3F,0x01,0x88,
2813
0x01,0xE2,0x00,0x9A,0x59,0x08,0x10,0xC3,0x99,0x84,0xA9,0xA5,0x91,0x91,0x91,0x80,
2814
0xB5,0x94,0xC0,0x01,0x98,0x09,0x84,0xB0,0x80,0x7A,0x08,0x18,0x90,0xA8,0x6A,0x1C,
2815
0x39,0x2A,0xB7,0x98,0x19,0x10,0x2A,0xA1,0x10,0xBD,0x39,0x18,0x2D,0x39,0x3F,0x10,
2816
0x3F,0x01,0x09,0x19,0x0A,0x38,0x8C,0x40,0xB3,0xB4,0x93,0xAD,0x20,0x2B,0xD4,0x81,
2817
0xC3,0xB0,0x39,0xA0,0x23,0xD8,0x04,0xB1,0x9B,0xA7,0x1A,0x92,0x08,0xA5,0x88,0x81,
2818
0xE2,0x01,0xB8,0x01,0x81,0xC1,0xC7,0x90,0x92,0x80,0xA1,0x97,0xA0,0xA2,0x82,0xB8,
2819
0x18,0x00,0x9C,0x78,0x98,0x83,0x0B,0x0B,0x32,0x7D,0x19,0x10,0xA1,0x19,0x09,0x0A,
2820
0x78,0xA8,0x10,0x1B,0x29,0x29,0x1A,0x14,0x2F,0x88,0x4A,0x1B,0x10,0x10,0xAB,0x79,
2821
0x0D,0x49,0x18,0xA0,0x02,0x1F,0x19,0x3A,0x2B,0x11,0x8A,0x88,0x79,0x8A,0x20,0x49,
2822
0x9B,0x58,0x0B,0x28,0x18,0xA9,0x3A,0x7D,0x00,0x29,0x88,0x82,0x3D,0x1A,0x38,0xBA,
2823
0x15,0x09,0xAA,0x51,0x8B,0x83,0x3C,0x8A,0x58,0x1B,0xB5,0x01,0xBB,0x50,0x19,0x99,
2824
0x24,0xCA,0x21,0x1B,0xA2,0x87,0xA8,0xB1,0x68,0xA1,0xA6,0xA2,0xA8,0x29,0x8B,0x24,
2825
0xB4,0xE2,0x92,0x8A,0x00,0x19,0x93,0xB5,0xB4,0xB1,0x81,0xB1,0x03,0x9A,0x82,0xA7,
2826
0x90,0xD6,0xA0,0x80,0x1B,0x29,0x01,0xA4,0xE1,0x18,0x0A,0x2A,0x29,0x92,0xC7,0xA8,
2827
0x81,0x19,0x89,0x30,0x10,0xE0,0x30,0xB8,0x10,0x0C,0x1A,0x79,0x1B,0xA7,0x80,0xA0,
2828
0x00,0x0B,0x28,0x18,0xB1,0x85,0x1E,0x00,0x20,0xA9,0x18,0x18,0x1C,0x13,0xBC,0x15,
2829
0x99,0x2E,0x12,0x00,0xE1,0x00,0x0B,0x3B,0x21,0x90,0x06,0xC9,0x2A,0x49,0x0A,0x18,
2830
0x20,0xD1,0x3C,0x08,0x00,0x83,0xC9,0x41,0x8E,0x18,0x08,0x02,0xA0,0x09,0xA4,0x7B,
2831
0x90,0x19,0x2A,0x10,0x2A,0xA8,0x71,0xBA,0x10,0x4A,0x0E,0x22,0xB2,0xB2,0x1B,0x8C,
2832
0x78,0x1A,0xB5,0x93,0xA9,0x1B,0x49,0x19,0x29,0xA3,0xC6,0x88,0xAA,0x32,0x0D,0x1B,
2833
0x22,0x08,0xC2,0x18,0xB9,0x79,0x3F,0x01,0x10,0xA9,0x84,0x1C,0x09,0x21,0xB0,0xA7,
2834
0x0A,0x99,0x50,0x0C,0x81,0x28,0x8B,0x48,0x2E,0x00,0x08,0x99,0x38,0x5B,0x88,0x14,
2835
0xA9,0x08,0x11,0xAA,0x72,0xC1,0xB3,0x09,0x8A,0x05,0x91,0xF2,0x81,0xA1,0x09,0x02,
2836
0xF2,0x92,0x99,0x1A,0x49,0x80,0xC5,0x90,0x90,0x18,0x09,0x12,0xA1,0xF2,0x81,0x98,
2837
0xC6,0x91,0xA0,0x11,0xA0,0x94,0xB4,0xF2,0x81,0x8B,0x03,0x80,0xD2,0x93,0xA8,0x88,
2838
0x69,0xA0,0x03,0xB8,0x88,0x32,0xBC,0x97,0x80,0xB1,0x3B,0x1A,0xA6,0x00,0xD1,0x01,
2839
0x0B,0x3B,0x30,0x9B,0x31,0x3E,0x92,0x19,0x8A,0xD3,0x5C,0x1B,0x41,0xA0,0x93,0xA2,
2840
0xAF,0x39,0x4C,0x01,0x92,0xA8,0x81,0x3C,0x0D,0x78,0x98,0x00,0x19,0x0A,0x20,0x2D,
2841
0x29,0x3C,0x1B,0x48,0x88,0x99,0x7A,0x2D,0x29,0x2A,0x82,0x80,0xA8,0x49,0x3E,0x19,
2842
0x11,0x98,0x82,0x9A,0x3B,0x28,0x2F,0x20,0x4C,0x90,0x29,0x19,0x9A,0x7A,0x29,0x28,
2843
0x98,0x88,0x33,0xCD,0x11,0x3A,0xC1,0xA4,0xA0,0xC4,0x82,0xC8,0x50,0x98,0xB2,0x21,
2844
0xC0,0xB6,0x98,0x82,0x80,0x9C,0x23,0x00,0xF8,0x30,0xA8,0x1A,0x68,0xA8,0x86,0x9A,
2845
0x01,0x2A,0x0A,0x97,0x91,0xC1,0x18,0x89,0x02,0x83,0xE0,0x01,0x8B,0x29,0x30,0xE2,
2846
0x91,0x0B,0x18,0x3B,0x1C,0x11,0x28,0xAC,0x78,0x80,0x93,0x91,0xA9,0x49,0x8B,0x87,
2847
0x90,0x99,0x3D,0x5A,0x81,0x08,0xA1,0x11,0x2F,0x1A,0x21,0x9B,0x15,0xA2,0xB0,0x11,
2848
0xC0,0x91,0x5B,0x98,0x24,0xA2,0xF2,0x92,0x8B,0x6A,0x18,0x81,0xB5,0xB1,0x88,0x4C,
2849
0x00,0x00,0xA4,0xC1,0x2B,0x1A,0x59,0x0A,0x02,0x80,0x1E,0x02,0x08,0xB3,0x80,0x9A,
2850
0x23,0xB8,0xF2,0x84,0xAB,0x01,0x48,0x90,0xA7,0x90,0x0A,0x29,0x09,0x95,0x99,0xA0,
2851
0x59,0x2B,0x00,0x97,0xB0,0x29,0x89,0x2A,0x03,0xD0,0xB7,0x1B,0x81,0x00,0xA6,0xB1,
2852
0x90,0x09,0x48,0xC0,0x11,0x00,0x8A,0x00,0x5B,0x83,0x9A,0x18,0x2F,0x3C,0x18,0x11,
2853
0xA9,0x04,0x1A,0x4F,0x01,0x98,0x81,0x09,0x09,0x4A,0x18,0xB4,0xA2,0x0B,0x59,0x90,
2854
0x3B,0x49,0xBC,0x40,0x6A,0x88,0x3A,0x08,0x3E,0x3A,0x80,0x93,0xB0,0xE1,0x5A,0x00,
2855
0xA4,0xB3,0xE3,0x90,0x0D,0x38,0x09,0x82,0xC4,0xA1,0xB1,0x4C,0x18,0x10,0x91,0xB2,
2856
0x13,0xEA,0x34,0x99,0x88,0xA6,0x89,0x92,0x91,0xC1,0x20,0xB2,0xC2,0x86,0xD2,0xB3,
2857
0x80,0xB2,0x08,0x09,0x87,0x91,0xC0,0x11,0x89,0x90,0x28,0xB9,0x79,0x19,0xA4,0x82,
2858
0xD0,0x03,0x0C,0xA3,0xA5,0xB2,0xB2,0x1B,0x29,0x13,0xF1,0xB4,0x81,0x9D,0x38,0x00,
2859
0xC4,0xA1,0x89,0x59,0x1A,0x81,0xA4,0xA9,0x1C,0x6A,0x19,0x02,0xB1,0x1A,0x4A,0x0B,
2860
0x78,0x89,0x81,0x1C,0x2A,0x29,0x4A,0xA3,0x3E,0x1C,0x49,0x1A,0x08,0x21,0xAE,0x28,
2861
0x4B,0x19,0x20,0x8C,0x10,0x3A,0xAB,0x26,0x8B,0x18,0x59,0x99,0x13,0xA2,0xAB,0x79,
2862
0x2F,0x18,0x10,0xB2,0x80,0x1B,0x4D,0x5A,0x80,0x82,0x98,0x81,0x80,0x09,0xA5,0x90,
2863
0x91,0x03,0xC2,0xE2,0x81,0xA8,0x82,0x09,0xC6,0xA3,0xB1,0x08,0x5B,0x08,0x05,0xD1,
2864
0xA2,0x89,0x2A,0x28,0x91,0xA6,0x88,0xB0,0x49,0x80,0x09,0x08,0x88,0x07,0xB8,0x05,
2865
0x99,0x81,0x88,0x18,0xE2,0x00,0xC3,0x18,0x0D,0x10,0x30,0xD0,0x93,0x8A,0x09,0x10,
2866
0x2F,0x11,0x90,0xA1,0x20,0x9B,0xB1,0x73,0xC8,0x94,0x98,0x3B,0x01,0x0C,0x30,0x19,
2867
0xF8,0x12,0x90,0xBA,0x78,0x0A,0x11,0x98,0xA0,0x79,0x8A,0x30,0x2B,0xC2,0x11,0x0D,
2868
0x09,0x7A,0x00,0x82,0xB9,0x01,0x7A,0x89,0x21,0x09,0xA1,0x0A,0x7C,0x10,0x88,0xB5,
2869
0x88,0x0A,0x2B,0x69,0x1A,0x10,0xA0,0x5B,0x19,0x1A,0x10,0x19,0x1A,0x6C,0x20,0x90,
2870
0xA5,0x98,0x1B,0x0A,0x69,0x82,0xD1,0x18,0x09,0x19,0x2A,0x93,0xD4,0x9A,0x01,0x49,
2871
0xA2,0xA2,0x82,0xD8,0x22,0xAA,0x97,0xA9,0x2D,0x38,0x2A,0xB6,0x80,0x90,0x0A,0x3C,
2872
0x82,0x94,0xB8,0x21,0x0E,0x2A,0x22,0xB8,0x00,0x4F,0x2B,0x3A,0x81,0xA1,0x29,0x2C,
2873
0x6A,0x13,0xD1,0xA2,0x98,0x28,0x0C,0x01,0xD5,0x08,0xA9,0x31,0xB3,0xB0,0xA7,0xB0,
2874
0x29,0x1B,0x87,0xA2,0xA1,0xB2,0x4A,0x89,0x11,0xC3,0xF3,0x98,0x08,0x03,0xA0,0xA3,
2875
0xC5,0x90,0xB3,0xB5,0xB4,0xB8,0x02,0x91,0x91,0xD3,0xA4,0xC1,0x1B,0x82,0x28,0xA4,
2876
0xD1,0x94,0x8A,0x28,0x08,0x03,0xE0,0x80,0xD4,0x90,0x91,0xA1,0x3B,0x3D,0x02,0xE4,
2877
0xA1,0x92,0x89,0x1A,0x4B,0x95,0xB3,0x90,0x99,0x6A,0x0A,0x30,0xA1,0x93,0xA6,0xA9,
2878
0x85,0x8B,0x82,0x10,0xB1,0xA3,0x94,0xF8,0x38,0x9A,0x30,0x1A,0x8B,0xA7,0x89,0x01,
2879
0x5B,0x19,0x18,0x11,0xF0,0x18,0x1C,0x39,0x19,0x0C,0x12,0x1C,0x2A,0x7B,0x3A,0x88,
2880
0x2B,0x18,0x2B,0x5C,0x20,0x92,0x8D,0x38,0x8A,0x3A,0x5B,0x2E,0x3A,0x2B,0x10,0x12,
2881
0xBB,0x6A,0x4D,0x18,0x10,0xB1,0x81,0x2A,0x8B,0x79,0x80,0x01,0x0A,0x09,0x5B,0x2D,
2882
0x84,0x8A,0x08,0x02,0xA2,0x91,0x82,0xE8,0x50,0x9B,0x85,0xA3,0xB0,0xA3,0x1B,0x02,
2883
0x18,0xF3,0xA2,0x88,0xAB,0x53,0xD1,0xB4,0xA3,0x09,0x09,0x18,0xD4,0x08,0xB0,0x09,
2884
0x58,0xD1,0x82,0x89,0x81,0x1A,0x18,0x05,0xB9,0xC3,0x30,0xC0,0x95,0x80,0xC3,0x89,
2885
0x89,0x13,0x88,0xF2,0x93,0x0E,0x18,0x01,0x92,0xA5,0xB8,0x2A,0x39,0xAA,0x33,0x9A,
2886
0xB1,0x11,0xF5,0xA1,0xA1,0x0A,0x50,0xB8,0x03,0xC4,0xA0,0x4E,0x29,0x10,0x88,0xC2,
2887
0x1A,0x39,0x1D,0x28,0x98,0x94,0x0E,0x10,0x2A,0x3C,0x02,0x2D,0x1B,0x4B,0x3B,0x49,
2888
0x19,0xA9,0x48,0x2F,0x29,0x10,0x89,0x02,0x0C,0x10,0x09,0xB9,0x70,0x1B,0x8A,0x50,
2889
0xA8,0x2B,0x49,0x89,0x69,0x88,0x95,0x89,0x90,0x92,0x4C,0x19,0x82,0xC1,0x01,0x80,
2890
0xA0,0x2B,0x7A,0x81,0x10,0xC2,0xB7,0x98,0x88,0x19,0x2C,0x03,0xB1,0xA4,0xA1,0x0C,
2891
0x3B,0x78,0x88,0x85,0xB1,0xA0,0x1B,0x3A,0x4A,0x08,0x94,0x81,0xF1,0x80,0x00,0x0C,
2892
0x59,0x09,0x18,0x90,0xA6,0x92,0x8C,0x1A,0x79,0x92,0xA8,0x00,0x81,0x2E,0x2A,0x13,
2893
0xA2,0xB0,0xA5,0x88,0x88,0x89,0x11,0x19,0xA0,0xF3,0x82,0xB0,0x83,0x5F,0x2A,0x01,
2894
0xA1,0x94,0xB0,0x09,0x78,0x98,0xA3,0xA6,0xA0,0x91,0x80,0x93,0x98,0xC1,0x12,0x18,
2895
0xC9,0x17,0xA0,0xA0,0x1A,0x21,0x80,0x99,0xD4,0x30,0x9D,0x00,0x10,0x2F,0x08,0x1C,
2896
0x21,0x08,0xB4,0xC3,0x2B,0xA9,0x52,0xD2,0xA3,0xD1,0x09,0x10,0x8B,0x24,0x92,0xD1,
2897
0x80,0x19,0xA0,0x2C,0x12,0x49,0xAA,0xB6,0x95,0xB8,0x08,0x3A,0x2B,0x01,0xF3,0xB3,
2898
0x0B,0x09,0x79,0x18,0xA2,0xA4,0xA0,0x18,0x0C,0x20,0x08,0xA9,0x16,0x0C,0x00,0x1B,
2899
0x08,0x2B,0x7B,0x01,0x01,0xB9,0x59,0x19,0x8B,0x45,0xA8,0x80,0x0C,0x1A,0x41,0x1E,
2900
0x00,0x28,0xA8,0x5A,0x00,0xC1,0x49,0x99,0x21,0x1D,0x08,0x85,0x99,0x95,0x89,0x90,
2901
0x11,0x90,0xD1,0x28,0xB2,0xA7,0x99,0x81,0x02,0xAC,0x13,0x81,0xB2,0xA6,0xA9,0x28,
2902
0x1C,0xB1,0x33,0xD1,0xC1,0x58,0xA8,0x14,0xB0,0xB7,0x91,0xA0,0x82,0x89,0xC2,0x28,
2903
0xA1,0xB2,0x49,0xD2,0x94,0xC8,0x12,0x80,0x99,0x85,0x08,0xD3,0x09,0xA2,0xB3,0x1E,
2904
0x08,0x21,0xB9,0x23,0xB4,0xAB,0x41,0xAC,0x87,0x09,0xA2,0xC5,0x0B,0x2A,0x5A,0x91,
2905
0x20,0x9A,0x89,0x78,0x9B,0x31,0x89,0x80,0x29,0x0A,0xB7,0x3C,0x98,0x48,0x1D,0x00,
2906
0x01,0xB0,0x20,0x2F,0x29,0x4A,0x89,0x94,0x1C,0x88,0x28,0x2B,0x10,0x88,0x9A,0x71,
2907
0x9A,0x08,0x4A,0x2F,0x18,0x2B,0x18,0x02,0xA8,0x4B,0x7A,0x99,0x48,0x80,0xA8,0x20,
2908
0x1D,0x40,0xA8,0x10,0x08,0xA8,0xC5,0x88,0xC2,0x18,0x88,0x2A,0x12,0xF3,0x82,0xD8,
2909
0x20,0x0A,0x09,0xA6,0x98,0x04,0xB9,0x11,0x18,0xC3,0xE1,0x29,0xA1,0x11,0xC1,0x03,
2910
0xE2,0x9A,0x33,0xA9,0xB5,0x98,0x92,0xA1,0x02,0xF8,0x21,0xA8,0x10,0x02,0xC1,0xB7,
2911
0x1B,0x90,0x5B,0x3C,0x83,0x93,0xE0,0x19,0x1A,0x11,0x11,0xF1,0x92,0x89,0x19,0x2C,
2912
0x2C,0x41,0x99,0x92,0x90,0x3F,0x18,0x4B,0x00,0x08,0xD2,0x01,0xB2,0xAA,0x78,0x09,
2913
0x01,0x91,0xA2,0x98,0x2F,0x3A,0x2C,0x01,0x00,0x93,0xE0,0x28,0x2C,0x2B,0x01,0x12,
2914
0xE1,0x80,0xB3,0x3D,0x3A,0x0A,0x50,0x98,0xC2,0xA0,0x11,0xAA,0x30,0x87,0x90,0xC2,
2915
0x29,0x88,0x38,0xC8,0xB5,0x90,0xBA,0x70,0x1A,0x02,0x94,0xD0,0x80,0x1A,0x82,0xA6,
2916
0xB0,0x91,0x18,0xB3,0x00,0x13,0xF1,0xA2,0xC1,0x82,0xB0,0x00,0x15,0x0B,0xD3,0x02,
2917
0xA8,0x91,0x2B,0x1F,0x49,0x88,0xA6,0x80,0x88,0x08,0x1B,0xA5,0x80,0xB9,0x06,0x0B,
2918
0x90,0x21,0x9D,0x48,0x18,0xA0,0x15,0xC9,0x82,0x2B,0x1A,0x42,0x9A,0xC4,0x39,0xBC,
2919
0x69,0x00,0xA0,0x29,0x8C,0x39,0x59,0x08,0x09,0x49,0xA9,0x6B,0x81,0x00,0x98,0xB0,
2920
0x68,0x3D,0x81,0x88,0x18,0x19,0x1D,0x12,0x80,0xB2,0x3A,0x3F,0x85,0x92,0xD0,0x00,
2921
0x0A,0x19,0x12,0xF1,0x02,0x9B,0x19,0x40,0xB9,0x11,0x02,0xF2,0x1A,0x08,0x94,0x0A,
2922
0xC2,0x83,0x0B,0xB4,0xA4,0xC0,0x32,0xD8,0x86,0x98,0x90,0x95,0x89,0xA3,0x83,0xC2,
2923
0x92,0xE1,0x92,0x82,0xD9,0x03,0x08,0xA9,0x85,0x92,0xA2,0x80,0xE0,0x30,0x8B,0xB3,
2924
0x87,0x89,0x90,0x83,0xA0,0x08,0x92,0x93,0x3E,0xAB,0x43,0x89,0xE3,0x80,0x83,0x2F,
2925
0x00,0xA3,0x80,0xC9,0x22,0x3F,0x08,0x81,0x0B,0x33,0x9A,0xA3,0x7B,0x0C,0x29,0x4A,
2926
0x1B,0x21,0xAA,0x70,0x1B,0x0D,0x48,0x1A,0x81,0x88,0xB1,0x39,0x3F,0x08,0x58,0xA0,
2927
0x81,0x1A,0x1A,0x2B,0x6D,0x11,0x0A,0x91,0x01,0x1A,0x98,0x5A,0x0C,0x03,0xB1,0x84,
2928
0xA3,0xAD,0x58,0x2A,0xA1,0x84,0xB1,0xA0,0x5C,0x2B,0x13,0xA8,0x95,0x83,0xE8,0x10,
2929
0x81,0xB0,0x00,0xC2,0x96,0xA0,0x91,0x00,0x2C,0x90,0x30,0xF2,0x80,0xA8,0x39,0x21,
2930
0xC1,0x03,0xAC,0x39,0x7C,0x29,0x91,0x1A,0x00,0x19,0x2C,0x3A,0x93,0xB0,0x29,0x8F,
2931
0x28,0x02,0x93,0xF3,0xA9,0x01,0x03,0xE0,0x08,0x09,0x1D,0x58,0xA1,0x83,0xA9,0x6B,
2932
0x2A,0x3C,0x21,0x89,0xC2,0x2C,0x4B,0x8A,0x50,0x81,0x98,0xA8,0x32,0x0C,0x8E,0x24,
2933
0x0B,0x1A,0x81,0x92,0xA1,0x4F,0x18,0x3A,0x0A,0xB4,0x18,0x2E,0x39,0x82,0x19,0xD3,
2934
0xD0,0x28,0x1B,0x11,0x98,0x07,0xAA,0x28,0x00,0x88,0xB4,0x89,0x1B,0x1F,0x22,0x00,
2935
0xB3,0xC9,0x33,0xAB,0x2B,0xB5,0x48,0x98,0x98,0xA7,0x10,0xD2,0xC1,0x23,0xCA,0x93,
2936
0xC6,0x80,0xA1,0x88,0x02,0x89,0xE2,0x09,0x38,0xBA,0x40,0x89,0x21,0xD8,0x49,0x10,
2937
0x8D,0x02,0x90,0xC3,0x9A,0x24,0x89,0x08,0x84,0xA5,0x9C,0x10,0x11,0x9C,0x88,0x30,
2938
0x3C,0xA1,0x94,0x58,0x8C,0x0B,0x69,0x29,0x9A,0x81,0x12,0x2B,0x8B,0x79,0x94,0xB0,
2939
0xC1,0x84,0xC2,0x99,0x25,0x99,0x11,0xA2,0x93,0xE4,0x99,0x80,0x0A,0x00,0x10,0xB7,
2940
0xB0,0x31,0xBA,0x3C,0x21,0xB3,0xF1,0x18,0xA0,0x2A,0x20,0xA3,0x06,0xE8,0x28,0xA1,
2941
0xB4,0x08,0x0B,0x11,0x4B,0xB7,0x90,0xA5,0x98,0x3D,0x19,0x02,0xA1,0xC4,0xB2,0x19,
2942
0x28,0xC0,0xA5,0x92,0xB1,0xA3,0x0A,0x0A,0x08,0x2B,0x70,0xC4,0xB3,0x00,0xBC,0x4B,
2943
0x39,0x12,0xE3,0xA0,0x00,0x3F,0x18,0x29,0x94,0xD1,0x19,0x09,0x00,0xA1,0x83,0x99,
2944
0x9B,0x35,0x80,0xC4,0xB1,0x6A,0x1A,0x1C,0x29,0x38,0x0E,0x19,0x5A,0x1A,0x82,0x8A,
2945
0x59,0x2A,0x2E,0x20,0x88,0xA8,0x3A,0x38,0x3D,0x00,0xB3,0x29,0xAD,0x49,0x10,0x0C,
2946
0x01,0x01,0xA3,0x8F,0x85,0x09,0x1B,0x88,0x10,0xA3,0xD2,0x90,0x3C,0x5C,0x39,0x03,
2947
0xD1,0xA0,0x00,0x2A,0x0B,0x04,0xA7,0x90,0xA0,0x11,0x90,0x99,0x83,0xB4,0xB1,0xF1,
2948
0x84,0x88,0x90,0x18,0x18,0xD3,0xD2,0xB3,0xA0,0x1A,0x21,0xA7,0xB2,0xB3,0x92,0x9A,
2949
0x22,0xB9,0x28,0x38,0xBD,0x87,0x2A,0xB1,0x13,0x0D,0x0A,0x38,0xC9,0x24,0xC0,0x19,
2950
0x23,0x0F,0x01,0x88,0xC0,0x2A,0x82,0x18,0x28,0xF0,0x18,0x2A,0x29,0x4B,0x35,0xB8,
2951
0xA3,0x9D,0x18,0x1B,0x40,0x00,0x9A,0x5C,0x3A,0x09,0x2F,0x38,0x8A,0x3B,0x3B,0x11,
2952
0x5C,0x19,0x2B,0x4A,0x08,0x0A,0x3D,0x20,0x4F,0x3A,0x19,0x2A,0x18,0x4D,0x1B,0x3A,
2953
0x11,0x0D,0x3A,0x3C,0x4B,0x93,0x81,0xAA,0x6B,0x4A,0x18,0x00,0xC3,0xC3,0x9A,0x59,
2954
0x2A,0x1B,0xA7,0xA1,0x81,0x88,0x88,0x58,0xB2,0xB1,0x2B,0x83,0xD4,0x81,0x08,0x0F,
2955
0x00,0x20,0xC2,0xE2,0x80,0x08,0x1C,0x29,0x04,0xB1,0xA2,0x01,0x1C,0x91,0x00,0x0C,
2956
0x49,0xB0,0x43,0xF2,0x99,0x39,0x3F,0x00,0x81,0x94,0xC1,0x09,0x1A,0x69,0x90,0x80,
2957
0x94,0xAA,0x20,0x2A,0x91,0xB1,0x39,0x7A,0x38,0xD1,0x10,0x8A,0x8C,0x5A,0x01,0xB5,
2958
0x98,0x80,0x2A,0x0B,0x32,0x92,0xF1,0x81,0x9A,0x23,0x8A,0xA3,0xB7,0x09,0x03,0x08,
2959
0xD0,0x94,0x9A,0x09,0x01,0x93,0xB7,0xC2,0x8C,0x3A,0x83,0x99,0x05,0xA0,0x0B,0x29,
2960
0x93,0xE5,0x80,0x89,0x38,0x90,0x8A,0xD7,0xA1,0x19,0x1B,0x48,0x98,0x92,0xC3,0xA1,
2961
0x09,0x3F,0x02,0x0C,0x22,0xC3,0xB2,0xA1,0x01,0x9F,0x4A,0x01,0xA3,0xD3,0xB0,0x28,
2962
0x3F,0x29,0x20,0xA2,0xC2,0xB1,0x08,0x5A,0x98,0x13,0xD2,0xC1,0x01,0xB2,0x80,0x3D,
2963
0x03,0xC1,0x89,0x96,0x90,0x90,0x3A,0x1A,0x9A,0x32,0xB6,0xA2,0x8E,0x4A,0x28,0x8A,
2964
0x84,0xA2,0x8A,0x2D,0x49,0x09,0x88,0x18,0x30,0x9D,0x2C,0x23,0xB1,0x0C,0x92,0x2D,
2965
0x39,0x82,0xC4,0x2E,0x10,0x1A,0x10,0xB9,0x48,0x19,0x39,0xBA,0x34,0xDA,0x2D,0x48,
2966
0x1A,0xA6,0x98,0x83,0x9A,0x1D,0x38,0x04,0xD0,0x18,0x90,0x2C,0x11,0x93,0xD3,0x9A,
2967
0x11,0x08,0x82,0xF1,0x01,0xA0,0x2A,0x93,0xD3,0xB4,0xB8,0x82,0x2F,0x11,0xA3,0xB3,
2968
0xA8,0x3B,0x09,0x23,0x96,0xC8,0x3B,0x3F,0x93,0x82,0xA1,0x90,0x3F,0x28,0x81,0xD1,
2969
0x93,0x08,0x2D,0x18,0x91,0xB3,0xB5,0x98,0x2A,0x2B,0x84,0xB1,0x5B,0x8A,0x31,0x18,
2970
0x80,0x8B,0x7E,0x39,0x2B,0x02,0xC1,0x8B,0x6C,0x49,0x09,0x10,0xA1,0x08,0x01,0x0C,
2971
0x20,0xA1,0x09,0x4F,0x18,0x00,0x01,0xA0,0x5C,0x1B,0x5B,0x10,0x92,0x90,0x2B,0x5A,
2972
0x3D,0x18,0x91,0x19,0x98,0x2D,0x39,0x89,0x2D,0x3A,0x48,0x2C,0x11,0xB5,0x9A,0x19,
2973
0x5B,0x28,0x90,0x95,0x98,0x89,0x2B,0x40,0x08,0x90,0xF3,0x0A,0x08,0xA6,0x80,0x91,
2974
0xB2,0xA0,0x02,0xF2,0xA1,0xB7,0x89,0x81,0x82,0x91,0xB1,0x21,0xAB,0x32,0xE9,0x04,
2975
0xA2,0x8D,0x12,0x91,0xA3,0xA3,0xD2,0x8B,0x39,0xD1,0x84,0xE2,0x90,0x00,0x2B,0x29,
2976
0xA3,0xD4,0xA1,0x91,0x1D,0x5A,0x08,0x19,0x11,0x99,0x08,0x18,0x49,0x0F,0x18,0x10,
2977
0x82,0xF1,0x00,0x89,0x2F,0x3A,0x01,0xB3,0xC2,0x81,0x3F,0x29,0x08,0x10,0xA1,0xA1,
2978
0x3B,0x5D,0x19,0x28,0x0B,0x38,0x82,0x91,0x19,0xBD,0x3B,0x7A,0x80,0x12,0xB3,0xE0,
2979
0x0B,0x6A,0x01,0x88,0xA4,0x08,0x0B,0x08,0x59,0x80,0x80,0x1D,0x49,0x89,0x00,0x84,
2980
0x99,0x1A,0x2B,0x32,0xE3,0xB4,0xA9,0x3A,0x99,0x31,0xE3,0xAA,0x58,0x3B,0x88,0x95,
2981
0xC0,0x18,0x4A,0x09,0x30,0xF2,0xA3,0x1C,0x1B,0x49,0x00,0xD3,0xB2,0xA0,0x18,0x11,
2982
0x92,0xD3,0xB2,0x91,0x80,0xE7,0xA1,0x91,0x98,0x19,0x22,0xC2,0xD2,0x18,0x8D,0x3B,
2983
0x10,0xA5,0x91,0x98,0x02,0x3E,0x80,0x01,0x90,0xAA,0x13,0xF1,0x02,0xD1,0x08,0x19,
2984
0x49,0xB4,0x91,0xB4,0x99,0x2A,0x0C,0x32,0xC0,0x05,0x88,0x0B,0x80,0x2C,0x81,0x10,
2985
0x0B,0x51,0xA9,0x19,0x05,0xBF,0x28,0x20,0xE1,0x90,0x80,0x28,0x19,0x08,0x26,0xB1,
2986
0xA1,0x18,0x88,0x2A,0xF0,0x12,0x8A,0xB3,0x14,0x1B,0xD4,0xD8,0x10,0x08,0x8A,0x17,
2987
0xA0,0x98,0x2B,0x3A,0x29,0x48,0xA4,0x99,0x0E,0x4A,0x12,0x8B,0x31,0x8B,0x4E,0x1A,
2988
0x11,0xB5,0x89,0x91,0x29,0x89,0xC2,0x97,0x90,0x0A,0x19,0x11,0x91,0xC1,0xD5,0x08,
2989
0x89,0x20,0x91,0xB1,0x1A,0x2D,0x18,0x29,0xD2,0x3B,0x3E,0x3A,0x2A,0x90,0x82,0x1C,
2990
0x49,0x3B,0x93,0xB6,0xC8,0x4C,0x02,0x91,0x93,0xF2,0x88,0x2D,0x28,0x81,0x82,0xC1,
2991
0x89,0x2D,0x6B,0x19,0x82,0x80,0x18,0x8B,0x39,0x39,0xC8,0x3A,0x6A,0x0A,0x22,0xD2,
2992
0x09,0x2C,0x1A,0x68,0x92,0xE2,0x89,0x2A,0x2A,0x30,0xC2,0xA3,0xB4,0x1D,0x2A,0x09,
2993
0x93,0x18,0xF2,0x89,0x28,0xB3,0x01,0x8F,0x18,0x11,0xA1,0x93,0x90,0xD1,0x7A,0x20,
2994
0xC3,0xA2,0xA8,0x88,0x1D,0x28,0xA5,0xA2,0xA2,0x0B,0x29,0x2B,0x87,0xC1,0x80,0x0A,
2995
0x19,0x01,0x12,0xF1,0x10,0x80,0x0A,0x18,0x08,0x2F,0x4A,0x02,0x89,0x1B,0x29,0x5D,
2996
0x4C,0x08,0x82,0xA1,0x0A,0x3A,0x4B,0x29,0xC6,0xC3,0x09,0x09,0x88,0x39,0x98,0x82,
2997
0xA5,0x1A,0x30,0x11,0xBD,0x3F,0x12,0x8B,0x28,0xC3,0x88,0x3F,0x2B,0x3B,0x48,0xA1,
2998
0x80,0x8A,0x4D,0x39,0x01,0x93,0xA2,0xF1,0x19,0x19,0x0A,0x02,0xB2,0x8B,0x24,0xD2,
2999
0x4B,0x12,0xC8,0x2E,0x10,0xB5,0x89,0x01,0x09,0x1C,0x2A,0x03,0xD4,0x91,0x98,0x99,
3000
0x11,0x2B,0xE4,0x00,0x00,0x01,0xE0,0xA5,0x89,0x99,0x31,0x18,0xD0,0xB7,0x98,0x18,
3001
0x0A,0x10,0x94,0xC2,0x90,0x18,0x00,0x99,0x87,0xA0,0x90,0x2A,0x3C,0x02,0xB8,0xC1,
3002
0x79,0x1A,0x20,0x08,0xA1,0xD2,0x1C,0x29,0x03,0xD1,0x29,0x99,0x2C,0x50,0xB3,0xD1,
3003
0x08,0x09,0x3C,0x10,0x04,0xB2,0x0D,0x2B,0x59,0x80,0x90,0x01,0x0F,0x3A,0x18,0x01,
3004
0xA2,0x9B,0x5B,0x3D,0x81,0x03,0xD2,0x98,0x59,0x90,0x81,0x92,0xB4,0x8B,0x1B,0x40,
3005
0xB2,0xB5,0x08,0x4B,0x01,0x09,0xD1,0x91,0x8B,0x7A,0x10,0xB3,0xC3,0x99,0x49,0x1A,
3006
0x29,0xB5,0xA2,0xAB,0x40,0x81,0x19,0xB7,0xB0,0x20,0x2B,0xD4,0x88,0xA1,0x91,0x3C,
3007
0x82,0x37,0xD3,0xB1,0x8A,0x1B,0x30,0xB3,0xF4,0xA1,0x91,0x09,0x10,0x03,0xD0,0x83,
3008
0xA9,0x8F,0x10,0x01,0x90,0x18,0x80,0x20,0x2B,0xF1,0x28,0x99,0x2A,0x41,0xF0,0x12,
3009
0xAA,0x83,0x82,0xD1,0xC1,0x08,0x89,0x59,0x09,0x83,0x87,0xB0,0x2A,0x4D,0x18,0x09,
3010
0x19,0xB3,0x4B,0x3F,0x39,0x19,0x09,0x01,0x89,0x03,0x1F,0x00,0x1A,0x0B,0x10,0x68,
3011
0xA0,0x18,0x8C,0x6A,0x09,0x08,0x97,0xA1,0x81,0x1B,0x2B,0x4C,0x03,0xB4,0xA8,0x92,
3012
0x4B,0x3C,0xA1,0x81,0x95,0xA8,0x81,0x12,0xBB,0x92,0x45,0xB9,0x93,0xF4,0x88,0x0A,
3013
0x2D,0x28,0x00,0xA3,0xA3,0x8A,0x3F,0x48,0xB1,0x92,0xB4,0xA8,0x30,0x80,0xD3,0x80,
3014
0xD1,0x19,0x3B,0xC4,0x81,0xC1,0x29,0x0D,0x20,0x13,0xC8,0xB4,0x4C,0x09,0x00,0x82,
3015
0xC2,0x3B,0x0D,0x30,0x0B,0x12,0xF0,0x1B,0x20,0x0A,0xA6,0x80,0x0A,0x4A,0x4A,0x80,
3016
0x94,0xB1,0x2E,0x3B,0x1A,0x10,0x93,0x10,0x4C,0x3D,0x08,0x82,0xC9,0x19,0x6A,0x2B,
3017
0x38,0xD1,0x08,0x19,0x2A,0x5A,0x82,0xB1,0x8D,0x29,0x78,0x09,0x82,0x0A,0x2C,0x1B,
3018
0x19,0x41,0xB8,0x8C,0x79,0x2B,0x11,0x88,0x82,0x91,0xDC,0x28,0x11,0xB0,0x11,0x18,
3019
0xC9,0x62,0xA1,0x91,0x98,0x3B,0x3A,0xB0,0xF4,0x01,0xC0,0x29,0x39,0xF8,0x95,0x91,
3020
0x88,0x88,0x91,0x03,0xA1,0xE2,0x18,0x82,0xD1,0xA2,0xD1,0x80,0x19,0x20,0x83,0xB1,
3021
0xE3,0x80,0x91,0x4D,0x1A,0x03,0xB2,0x09,0x18,0xD1,0x19,0x09,0x92,0xA6,0xA0,0xB6,
3022
0xB2,0x8B,0x38,0x10,0x42,0xD3,0xD0,0xA8,0x20,0x2C,0x10,0x01,0xB1,0xB4,0xAB,0x5B,
3023
0x79,0x80,0x10,0x1A,0xA8,0x3D,0x18,0x20,0xB3,0x8F,0x18,0x01,0x00,0x09,0xF3,0x89,
3024
0x69,0x88,0x81,0x91,0x08,0xE1,0x1A,0x08,0x11,0x81,0x1E,0x29,0xA0,0x01,0x00,0x90,
3025
0x3E,0x7B,0x18,0x82,0xC3,0xA1,0x2A,0x2C,0x5B,0x81,0xA5,0x90,0x81,0x00,0x0B,0x1A,
3026
0x1C,0x2C,0x32,0xC0,0xF3,0x80,0x2D,0x2A,0x10,0x02,0xE4,0xC1,0x89,0x4A,0x09,0x01,
3027
0x03,0xD2,0x98,0x2A,0x39,0x8A,0x89,0x26,0xB1,0xB2,0x12,0xC0,0x0A,0x5A,0x18,0x98,
3028
0xF3,0x92,0x99,0x99,0x79,0x01,0xB5,0xA1,0x80,0x80,0x90,0x83,0xA0,0xE2,0x81,0x29,
3029
0x93,0x8A,0x0A,0x6A,0x1F,0x18,0x02,0xC8,0x01,0x19,0x3B,0x4A,0x98,0x17,0xA8,0x0D,
3030
0x38,0xA1,0x91,0x10,0xA2,0x2B,0x4C,0xA6,0x81,0xBA,0x21,0x4C,0x80,0x21,0xD1,0x92,
3031
0x2C,0x08,0x30,0x9F,0x93,0x2A,0x89,0x03,0x8B,0x87,0x0A,0x0D,0x12,0x98,0xA4,0x93,
3032
0xBB,0x59,0x18,0xA1,0x32,0xE9,0x84,0x08,0x8A,0x02,0xA1,0x91,0x4B,0xB4,0x20,0x88,
3033
0xF0,0x3A,0x1A,0x88,0x87,0xB1,0x92,0x0A,0x08,0x6B,0x83,0xC3,0x91,0xC0,0x2B,0x79,
3034
0x08,0x8A,0x84,0xA0,0x89,0x40,0x1B,0xA1,0x39,0x98,0x17,0xC2,0xA2,0x12,0xCD,0x20,
3035
0x89,0x92,0x25,0xB0,0x2D,0x3A,0x8B,0x58,0x2A,0xA0,0x4C,0x08,0x30,0xAE,0x82,0x59,
3036
0x89,0x1A,0x10,0xC2,0x18,0x2C,0x40,0x1E,0x01,0xA3,0x8A,0x81,0x2C,0x29,0x29,0xA9,
3037
0x13,0x51,0xAD,0x12,0x89,0x8F,0x18,0x2C,0x39,0x00,0xC1,0x10,0x3C,0x2A,0x41,0xC8,
3038
0xA2,0x91,0x0A,0x6C,0x10,0x12,0x88,0xE8,0x30,0x91,0x81,0xD8,0x01,0x1B,0x0D,0x07,
3039
0x00,0xA8,0x92,0x0A,0x28,0xD2,0xC3,0x02,0xAA,0x94,0x81,0xB4,0xB3,0x1A,0x0B,0x13,
3040
0xF9,0x16,0xA1,0x8A,0x59,0x19,0x02,0xC1,0x91,0x8B,0x3D,0x18,0x3B,0xA4,0x94,0x80,
3041
0x99,0x88,0x1C,0x79,0x0A,0x02,0x03,0xF8,0x90,0x39,0x5B,0x19,0x02,0xC3,0x90,0xBB,
3042
0x58,0x6A,0x09,0x02,0x89,0x91,0x88,0x1A,0x69,0x8A,0x19,0x15,0xA0,0xA2,0x00,0x9A,
3043
0x6B,0x49,0x88,0xA3,0x92,0xBB,0x6B,0x3D,0x38,0x01,0x98,0x91,0x3F,0x09,0x18,0x20,
3044
0x90,0x80,0xAC,0x70,0x91,0x9B,0x51,0x09,0x88,0x99,0x14,0x8B,0x98,0x83,0x79,0xA0,
3045
0x99,0x13,0x01,0x19,0xE0,0x83,0x0B,0xB0,0x0C,0x31,0x95,0xB5,0xC2,0x8A,0x39,0x20,
3046
0x80,0x39,0xF3,0xB1,0x10,0x88,0x5E,0x18,0x94,0xA1,0x88,0xA1,0x98,0x15,0xAA,0x39,
3047
0xD4,0x84,0xC0,0xA2,0xA2,0x0C,0x81,0x86,0xB5,0xA1,0xB1,0x14,0x1B,0xB1,0x02,0x92,
3048
0xC3,0xE0,0x88,0x11,0xAA,0x69,0x18,0x81,0xA3,0xB0,0x01,0xBF,0x2A,0x31,0x93,0xF1,
3049
0x00,0x89,0x18,0x19,0x11,0xD3,0xE0,0x10,0x18,0xB1,0x18,0x24,0x9A,0x2B,0xA4,0xC0,
3050
0xB0,0x31,0x6C,0x19,0xB4,0x12,0xA8,0xEA,0x58,0x10,0x8B,0x93,0x82,0x88,0x9A,0x41,
3051
0x10,0xC3,0xEA,0x41,0xA9,0x9C,0x34,0xA1,0x2A,0x79,0xA2,0x01,0xA8,0xB3,0x28,0xCC,
3052
0x41,0x9A,0xB3,0x4B,0xB3,0x27,0x8B,0x83,0x2B,0x2F,0x08,0x28,0xB2,0x80,0x2C,0x30,
3053
0x5E,0x09,0x12,0x9B,0x09,0x22,0x5B,0x19,0x8A,0x11,0x59,0x99,0xA4,0x32,0xCD,0x18,
3054
0x08,0x10,0x85,0xB3,0xB4,0x1E,0x88,0x28,0x8A,0x11,0x09,0xC0,0x79,0x80,0x91,0x3B,
3055
0x80,0x10,0x0F,0x01,0x80,0x91,0x19,0x3D,0x92,0x28,0xA8,0x37,0x9A,0x0A,0x3A,0x8A,
3056
0x45,0xA9,0xA4,0x00,0xAA,0x09,0x3D,0x59,0x20,0xE1,0x08,0x98,0x90,0x59,0x10,0x09,
3057
0xA3,0xC3,0x93,0x99,0x2B,0x69,0x11,0xD1,0xB1,0xA4,0x91,0x3C,0x89,0x83,0xF0,0x10,
3058
0x91,0xA1,0x89,0x59,0x05,0x99,0x93,0x94,0xC8,0x08,0x0A,0x09,0x17,0xB1,0x83,0xC1,
3059
0x91,0x40,0xA2,0xC2,0x98,0xC3,0xBA,0x28,0x23,0x0F,0x80,0x50,0xB8,0x19,0x10,0x96,
3060
0x98,0x8C,0x05,0x98,0x19,0x29,0x2B,0x3B,0x0A,0xE2,0x01,0x0F,0x3C,0x38,0x08,0x09,
3061
0x81,0x4A,0x6C,0x08,0x00,0x88,0x98,0x38,0x2C,0x5A,0x1B,0x20,0x1A,0x39,0xB0,0x09,
3062
0xCB,0x5B,0x49,0x09,0x71,0x00,0xC1,0x0E,0x08,0x38,0x0C,0x02,0x10,0x0E,0x10,0x8A,
3063
0x48,0x19,0x90,0x92,0x0D,0xA3,0x98,0x3B,0x79,0x19,0x01,0x10,0xE1,0x80,0x19,0x2B,
3064
0x10,0xF2,0x02,0xAB,0x84,0x9A,0x29,0xB4,0x80,0x92,0x03,0x88,0x95,0xD0,0x03,0x90,
3065
0xA0,0xC7,0xA1,0xB0,0xA2,0x02,0x18,0xB5,0xD4,0x01,0xC0,0x08,0xA2,0x93,0xA8,0xA0,
3066
0xC3,0x20,0xF3,0x90,0x00,0xD5,0x08,0x89,0xA5,0x80,0xA0,0x81,0x82,0xC2,0x09,0xD1,
3067
0x13,0xCB,0x03,0x84,0x91,0xE1,0x1B,0x12,0x08,0xAB,0x87,0x18,0xAB,0x58,0x89,0x28,
3068
0x81,0xC9,0x33,0xA9,0x80,0x2E,0x20,0x83,0xB9,0x20,0x3B,0x9E,0x7A,0x08,0x81,0x18,
3069
0x0B,0x88,0x79,0x80,0x8B,0x00,0x12,0x0E,0x89,0x51,0x1B,0x81,0xA0,0x3A,0x01,0xAF,
3070
0x11,0x28,0xBA,0x35,0x98,0x88,0x52,0xC0,0x83,0x2F,0xA9,0x11,0x0A,0x19,0x25,0xD0,
3071
0x30,0x9C,0x08,0x21,0x98,0x81,0x2A,0xF3,0x2A,0x80,0xB6,0x2B,0x08,0x93,0xE9,0x02,
3072
0x81,0x8C,0x21,0x00,0xA6,0xA9,0x94,0x01,0x8F,0x80,0x94,0x98,0x93,0xB4,0x00,0x08,
3073
0xC0,0x14,0x98,0xB3,0xB4,0xC1,0x09,0x18,0xA7,0x00,0xA3,0xC8,0x0A,0x3C,0x19,0x96,
3074
0x83,0xC1,0x99,0x19,0x4A,0x85,0x80,0xC1,0x91,0x99,0x90,0x2A,0x17,0x95,0x99,0x88,
3075
0x12,0xAE,0x39,0x08,0x92,0x84,0xB0,0xA8,0x79,0x09,0x19,0x01,0xB2,0xA3,0x8F,0x28,
3076
0x2B,0xA2,0x40,0x82,0xA0,0x4C,0xA9,0x39,0x8D,0x81,0x70,0x88,0xA0,0x1A,0x49,0x2D,
3077
0x1A,0x26,0xA8,0x98,0x08,0x29,0x0B,0x12,0x96,0xB1,0xB2,0x3A,0x13,0x9B,0x60,0xA0,
3078
0x88,0xB2,0x34,0xEA,0x1A,0x2A,0x79,0x98,0x10,0x04,0x8C,0x1C,0x81,0x04,0x8C,0x83,
3079
0x19,0x2F,0x81,0x93,0x98,0x10,0x08,0x30,0x2A,0xFA,0x05,0x08,0x2A,0x89,0x91,0xA3,
3080
0xFA,0x11,0x11,0x00,0x8C,0x04,0x8A,0x2A,0xB5,0x10,0xA9,0xC2,0x3D,0x1B,0x32,0x04,
3081
0x0A,0x1A,0x09,0x40,0x1F,0x92,0x1D,0x2A,0x91,0x10,0x30,0x2F,0x0B,0x68,0x99,0xA2,
3082
0x92,0x88,0x78,0xA9,0x20,0x28,0xE2,0x92,0x1A,0x99,0x4B,0x19,0x22,0xA1,0xE2,0x21,
3083
0x2F,0x98,0x29,0x18,0x91,0x08,0xB0,0x79,0x1A,0x82,0x3B,0xB1,0xA7,0x8A,0xB3,0x98,
3084
0x5B,0x23,0xCA,0x42,0x83,0xF0,0x90,0x18,0x98,0x08,0xB4,0x20,0xA3,0xC0,0x43,0xD8,
3085
0x80,0x81,0xA3,0x99,0xD9,0xA7,0x19,0x90,0x10,0x05,0xB1,0x8B,0x02,0xA4,0xBD,0x23,
3086
0x93,0x8A,0x99,0x4B,0x03,0xC1,0xF8,0x38,0x09,0x2B,0x14,0xD0,0x03,0x8A,0x2A,0x39,
3087
0xB9,0x97,0x90,0xAA,0x50,0x01,0x99,0x51,0xD1,0x09,0x1A,0xB5,0x00,0x8B,0x93,0x08,
3088
0x98,0x11,0xF9,0x85,0x2B,0x08,0x96,0x89,0x90,0x2A,0x12,0x4A,0xD8,0x85,0x2B,0x0E,
3089
0x10,0x00,0x01,0xB1,0x9B,0x69,0x1A,0x90,0x40,0xB8,0x01,0x08,0x0A,0x2C,0x09,0x14,
3090
0x4B,0xE2,0x82,0x88,0xB1,0x78,0x0A,0x01,0xC2,0x93,0x19,0xCE,0x20,0x3C,0x82,0xB4,
3091
0x1B,0x20,0x8C,0x3B,0x29,0xAB,0x86,0x23,0xD8,0x81,0x9A,0x5A,0x49,0xB0,0x16,0xA0,
3092
0xB0,0x28,0x1B,0x13,0x93,0xE4,0xA2,0xA9,0x08,0x5A,0xB3,0x12,0xC1,0xE1,0x10,0x88,
3093
0x01,0x0C,0x92,0x08,0x89,0xB7,0x88,0x81,0x10,0x9A,0x17,0xA0,0xB0,0x13,0x99,0xE0,
3094
0x39,0x31,0xD2,0xB2,0x80,0x0B,0x2D,0x49,0x80,0x01,0xB0,0x06,0x09,0x0C,0x3A,0x69,
3095
0xA0,0x08,0xB2,0xA1,0x69,0x2B,0x5A,0x81,0x92,0xBA,0x21,0xB1,0x7D,0x10,0x80,0x08,
3096
0x88,0x82,0x32,0x0D,0xB0,0x1A,0x1C,0x21,0x94,0xA9,0x58,0xB9,0x5A,0x4A,0xA0,0x13,
3097
0xA9,0x80,0x7C,0x00,0x20,0x8A,0x04,0x0C,0x00,0x82,0x2A,0xB2,0xAC,0x4B,0x69,0xA0,
3098
0xA6,0x81,0x9B,0x19,0x38,0x8B,0x17,0xB2,0x81,0x2A,0xBB,0x94,0x29,0xA2,0x15,0xBA,
3099
0x97,0xA3,0xB9,0x79,0x01,0xB2,0x02,0xF1,0x90,0x0A,0x29,0x11,0x88,0xE5,0xA0,0x81,
3100
0x19,0x91,0x90,0x28,0xB3,0x14,0xD0,0xB5,0x91,0x9A,0x29,0x0B,0x07,0xA2,0xB3,0x01,
3101
0x9D,0x28,0x41,0xD0,0x91,0x90,0x82,0x1A,0xA8,0x44,0x9A,0xA9,0x21,0xE3,0xA9,0x4B,
3102
0x19,0x78,0x89,0x83,0xA3,0xB9,0x5A,0x3D,0x80,0x82,0xA2,0xA0,0x6C,0x10,0x20,0x8B,
3103
0x93,0x8B,0x0E,0x33,0xA9,0xB1,0x68,0x8A,0x31,0xAC,0x94,0xB4,0x8B,0x32,0x0B,0xB4,
3104
0x81,0x91,0x1D,0x33,0xD9,0x31,0xE1,0x8B,0x3B,0x30,0x12,0x49,0xD2,0x8E,0x29,0x18,
3105
0x8A,0x92,0x02,0xAA,0x59,0x1C,0x32,0x88,0x01,0x23,0xFB,0x83,0x29,0xDA,0x59,0x01,
3106
0x81,0x92,0xE1,0x18,0x8A,0x1D,0x30,0x93,0xF1,0x00,0x01,0x0B,0x39,0x92,0x89,0xA0,
3107
0x11,0x5B,0xE0,0x82,0x09,0x13,0xAA,0xB4,0x16,0xD8,0x91,0x2A,0x29,0x84,0x1B,0xC5,
3108
0x98,0x98,0x31,0x98,0x99,0x17,0xA9,0x20,0x92,0xC3,0x18,0x9D,0x20,0x3D,0x89,0x94,
3109
0xA2,0x1C,0x5C,0x29,0x39,0xA0,0xB3,0x00,0x0C,0x4C,0x48,0x92,0x0A,0x91,0x85,0x9A,
3110
0x01,0x82,0x1F,0x10,0x99,0x15,0xC1,0xA0,0x39,0x1A,0x1D,0x85,0xB4,0x90,0x1A,0x2A,
3111
0x4B,0x01,0xB2,0x93,0xBE,0x12,0x83,0xC9,0x18,0x09,0x20,0x78,0xF1,0x08,0x19,0x88,
3112
0x3A,0x83,0xB3,0xA9,0x93,0x7A,0x0A,0x96,0x98,0x00,0xA8,0x3A,0x30,0x92,0xF2,0x9B,
3113
0x3D,0x38,0x92,0x92,0xC3,0xB8,0x6B,0x29,0x01,0x01,0xB2,0x2F,0x09,0x19,0x18,0x01,
3114
0x3B,0x7B,0x10,0xA1,0x90,0x39,0x0F,0x38,0x0A,0xB5,0xA4,0x89,0x8B,0x6A,0x2B,0x12,
3115
0xC8,0x90,0x40,0x2A,0x9E,0x22,0x88,0x18,0x09,0x3A,0xC3,0xE8,0x09,0x59,0x08,0x12,
3116
0x94,0xD0,0x1A,0x2C,0x38,0x00,0xA1,0x83,0xE8,0x08,0x3A,0x08,0x10,0x9E,0x83,0x1D,
3117
0x92,0x19,0x2C,0x39,0x3B,0x59,0x04,0xE1,0x80,0x08,0x8D,0x21,0x81,0xB2,0xB2,0x02,
3118
0x99,0x91,0xA4,0xD6,0x98,0x99,0x03,0x80,0x98,0xA7,0x91,0x09,0xA1,0xB2,0xB3,0xE1,
3119
0x12,0x92,0xB1,0x81,0x06,0x99,0x0A,0x23,0xC4,0xB1,0xF2,0x89,0x19,0x3A,0x94,0x82,
3120
0xE0,0x89,0x38,0x0B,0xA4,0xA5,0x80,0x80,0x8C,0x34,0xB9,0xA9,0x23,0x13,0xB9,0xC1,
3121
0xC7,0x1B,0x89,0x10,0x20,0x11,0xE3,0xA8,0x4B,0x0B,0x40,0x91,0x90,0x1B,0x5F,0x2A,
3122
0x18,0x82,0x91,0x0B,0x4A,0x28,0xCA,0x40,0x80,0x5B,0x2C,0x13,0xB0,0x8A,0xA9,0x5A,
3123
0x58,0x89,0x82,0x88,0x2E,0x3B,0x31,0xA1,0x9B,0x01,0x7A,0x2C,0x01,0x91,0x93,0x3F,
3124
0x88,0x39,0x10,0xF1,0x91,0x8B,0x48,0x0A,0x12,0xE3,0xA8,0x18,0x28,0x92,0x97,0x98,
3125
0x99,0x19,0xA1,0x11,0xB6,0x88,0x3B,0x10,0xD3,0xC3,0xA1,0x2A,0x8A,0x49,0x04,0xF1,
3126
0x91,0x02,0x8A,0x89,0x04,0xF1,0x98,0x80,0x18,0x12,0xE3,0x81,0x98,0x80,0x01,0xB3,
3127
0xF2,0x99,0x12,0x2A,0xB5,0xB3,0x92,0xAA,0x19,0x50,0xB2,0xC3,0x92,0xD0,0x2B,0x68,
3128
0x93,0x99,0xC0,0x2C,0x3E,0x80,0x20,0x08,0x93,0x0D,0x2A,0x31,0x8D,0x02,0x2B,0x91,
3129
0x08,0x0A,0x03,0x2C,0x3C,0x52,0xB9,0xA0,0x12,0xBF,0x3A,0x29,0x01,0x88,0xC0,0x6A,
3130
0x3C,0x0A,0x49,0x18,0x0B,0x39,0x2B,0x69,0x0A,0x84,0x2A,0x2A,0x1C,0x2A,0xC3,0x8C,
3131
0x19,0x50,0x09,0x91,0xA7,0x8D,0x18,0x1A,0x28,0x00,0xA0,0x94,0x10,0x1F,0x20,0x90,
3132
0x8A,0x12,0xD0,0x1A,0x5A,0x81,0x04,0xBC,0x23,0x10,0xE0,0x90,0x90,0x18,0x1A,0xA6,
3133
0x12,0xB1,0xD0,0x4A,0x08,0x82,0x92,0xB6,0x9A,0x0A,0x12,0x88,0xC3,0xC5,0x8A,0x89,
3134
0x20,0xB5,0x93,0x0B,0x18,0x00,0x09,0xF2,0x88,0x2A,0x4A,0x08,0x05,0xB2,0xA9,0x3B,
3135
0x5D,0x28,0xA4,0xB1,0x00,0x19,0x19,0x7A,0xA3,0xB3,0x0A,0x90,0xA1,0xC4,0x80,0xBA,
3136
0x50,0x13,0xC1,0xC2,0x9A,0x2A,0x7B,0x28,0x84,0xC1,0x09,0x3B,0x4E,0x20,0x91,0xA1,
3137
0x18,0xAB,0x79,0x10,0xB4,0x08,0x9A,0x11,0x2B,0xF0,0x93,0xAA,0x01,0x6A,0x01,0x93,
3138
0x80,0xB8,0x2A,0x5B,0x10,0x80,0x89,0x4A,0x5B,0x92,0x15,0xB2,0xA0,0x2F,0x19,0x93,
3139
0xB8,0x95,0x80,0x1C,0x21,0xA9,0x02,0x0B,0xA0,0x5A,0x18,0x98,0x39,0x1B,0x68,0x00,
3140
0x91,0x91,0x9C,0x39,0x3E,0x18,0x84,0xB3,0x9B,0x7A,0x08,0x18,0x0A,0xB5,0x91,0x0B,
3141
0x28,0x39,0x19,0x90,0x0A,0x50,0xAC,0x11,0x01,0xAB,0x88,0x52,0x1B,0x83,0xC4,0xA2,
3142
0x9A,0xAB,0x03,0x90,0x19,0x93,0x81,0x08,0x92,0x9A,0x68,0x98,0x19,0x39,0xC1,0x92,
3143
0x8A,0x38,0x4E,0x02,0xB1,0x90,0xC3,0x18,0x2B,0x04,0xC3,0xD2,0x91,0x90,0x81,0x89,
3144
0x13,0xF1,0x88,0x93,0xA2,0x00,0x91,0xC0,0x5B,0x21,0x99,0x93,0x06,0x9A,0x1B,0x48,
3145
0x99,0xB7,0x90,0x89,0x18,0x1B,0x11,0xA4,0xB2,0x81,0x9A,0x08,0x97,0x98,0x91,0x10,
3146
0xB8,0x06,0xA2,0xA0,0x29,0x2B,0x21,0xC2,0xD1,0x10,0x1A,0x4A,0x29,0xF1,0x98,0x29,
3147
0x1B,0x31,0x10,0xA0,0xA1,0x1D,0x5A,0x29,0xB2,0x82,0xA8,0x0F,0x28,0x21,0x09,0x91,
3148
0x82,0x4D,0x10,0xA3,0xB0,0x89,0x4C,0x39,0xA0,0xA4,0xA1,0x89,0x1E,0x28,0x29,0xA3,
3149
0xC3,0x2D,0x19,0x01,0x49,0x01,0x9B,0x0C,0x21,0xC2,0xA2,0x93,0x7C,0x2A,0x10,0x90,
3150
 
3151
/* Source: 08HH.ROM */
3152
/* Length: 384 / 0x00000180 */
3153
 
3154
0x75,0xF2,0xAB,0x7D,0x7E,0x5C,0x3B,0x4B,0x3C,0x4D,0x4A,0x02,0xB3,0xC5,0xE7,0xE3,
3155
0x92,0xB3,0xC4,0xB3,0xC3,0x8A,0x3B,0x5D,0x5C,0x3A,0x84,0xC2,0x91,0xA4,0xE7,0xF7,
3156
0xF7,0xF4,0xA1,0x1B,0x49,0xA5,0xB1,0x1E,0x7F,0x5A,0x00,0x89,0x39,0xB7,0xA8,0x3D,
3157
0x4A,0x84,0xE7,0xF7,0xE2,0x2D,0x4C,0x3A,0x4E,0x7D,0x04,0xB0,0x2D,0x4B,0x10,0x80,
3158
0xA3,0x99,0x10,0x0E,0x59,0x93,0xC4,0xB1,0x81,0xC4,0xA2,0xB2,0x88,0x08,0x3F,0x3B,
3159
0x28,0xA6,0xC3,0xA2,0xA2,0xC5,0xC1,0x3F,0x7E,0x39,0x81,0x93,0xC2,0xA3,0xE5,0xD2,
3160
0x80,0x93,0xB8,0x6D,0x49,0x82,0xD4,0xA1,0x90,0x01,0xA0,0x09,0x04,0xE3,0xB2,0x91,
3161
0xB7,0xB3,0xA8,0x2A,0x03,0xF3,0xA1,0x92,0xC5,0xC3,0xB2,0x0B,0x30,0xB3,0x8E,0x6D,
3162
0x4A,0x01,0xB4,0xB4,0xC4,0xC3,0x99,0x3B,0x12,0xE3,0xA1,0x88,0x82,0xB4,0x9A,0x5C,
3163
0x3A,0x18,0x93,0xC3,0xB3,0xB4,0xA8,0x19,0x04,0xF3,0xA8,0x3B,0x10,0xA2,0x88,0xA5,
3164
0xB2,0x0B,0x6D,0x4B,0x10,0x91,0x89,0x3C,0x18,0x18,0xA6,0xC4,0xC3,0x98,0x19,0x2B,
3165
0x20,0x91,0xA0,0x4E,0x28,0x93,0xB3,0xC2,0x92,0xA9,0x5A,0x96,0xC4,0xC2,0x09,0x01,
3166
0xC4,0xA1,0x92,0xC4,0xA1,0x89,0x10,0xA3,0xA1,0x90,0x1C,0x5A,0x01,0xC5,0xA1,0x92,
3167
0xD4,0xB3,0xC4,0xC4,0xC3,0xA1,0x88,0x1A,0x28,0x89,0x3C,0x3A,0x3D,0x29,0x00,0x93,
3168
0xB0,0x3D,0x28,0x80,0x91,0x82,0xE3,0x99,0x2A,0x11,0xD6,0xC3,0x99,0x29,0x82,0xC4,
3169
0xC3,0xA1,0x0A,0x3B,0x3D,0x3A,0x02,0xC3,0xA2,0x99,0x3B,0x2C,0x7C,0x28,0x81,0xA3,
3170
0xB2,0xA3,0xB1,0x08,0x1A,0x3C,0x18,0x2E,0x4C,0x39,0xA5,0xB3,0xB4,0xC2,0x88,0x08,
3171
0x19,0x0A,0x49,0xB7,0xB3,0xA2,0xA1,0x92,0xA1,0x93,0xB1,0x0C,0x7D,0x39,0x93,0xB3,
3172
0xB1,0x1A,0x19,0x5D,0x28,0xA6,0xC4,0xB2,0x90,0x09,0x2A,0x18,0x1B,0x5B,0x28,0x88,
3173
0x2C,0x29,0x82,0xA0,0x18,0x91,0x2D,0x29,0x2B,0x5C,0x4C,0x3B,0x4C,0x28,0x80,0x92,
3174
0x90,0x09,0x2B,0x28,0x1D,0x6B,0x11,0xC5,0xB2,0x0B,0x39,0x09,0x4D,0x28,0x88,0x00,
3175
0x1B,0x28,0x94,0xE3,0xA0,0x1A,0x28,0xB5,0xB4,0xB3,0xB2,0x93,0xE2,0x91,0x92,0xD4,
3176
0xA0,0x1B,0x4A,0x01,0xA1,0x88,0x2D,0x5C,0x3B,0x28,0x08,0x93,0xD4,0xB2,0x91,0xB4,
3177
0xA0,0x3E,0x3B,0x4B,0x3B,0x29,0x08,0x93,0x9B,0x7B,0x3A,0x19,0x00,0x80,0x80,0xA0,
3178
 
3179
/* Source: 10TOM.ROM */
3180
/* Length: 640 / 0x00000280 */
3181
 
3182
0x77,0x27,0x87,0x01,0x2D,0x4F,0xC3,0xC1,0x92,0x91,0x89,0x59,0x83,0x1A,0x32,0xC2,
3183
0x95,0xB1,0x81,0x88,0x81,0x4A,0x3D,0x11,0x9E,0x0B,0x88,0x0C,0x18,0x3B,0x11,0x11,
3184
0x91,0x00,0xA0,0xE2,0x0A,0x48,0x13,0x24,0x81,0x48,0x1B,0x39,0x1C,0x83,0x84,0xA1,
3185
0xD1,0x8E,0x8A,0x0B,0xC0,0x98,0x92,0xB8,0x39,0x90,0x10,0x92,0xF0,0xB5,0x88,0x32,
3186
0x49,0x51,0x21,0x03,0x82,0x10,0x8A,0x7A,0x09,0x00,0xA2,0xCA,0x1B,0xCC,0x1C,0xB9,
3187
0x8E,0x89,0x89,0xA1,0x89,0x92,0x29,0x11,0x60,0x40,0x14,0x22,0x32,0x78,0x40,0x01,
3188
0x02,0x90,0x81,0xAB,0x0B,0x00,0xAF,0x99,0xCC,0xAB,0xDA,0xA9,0x99,0x1B,0x30,0x14,
3189
0x92,0x22,0x19,0x68,0x32,0x14,0x26,0x13,0x23,0x23,0x20,0x12,0x9A,0xA8,0xB9,0xFA,
3190
0xAA,0xCA,0xCC,0x0C,0xA8,0xAE,0x88,0xB9,0x88,0xA0,0x02,0x21,0x50,0x43,0x03,0x81,
3191
0x2A,0x11,0x34,0x63,0x24,0x33,0x22,0x38,0x8B,0xEA,0xAE,0x99,0xA0,0x90,0x82,0x00,
3192
0x89,0xBF,0x8A,0xE8,0xA9,0x90,0x01,0x12,0x13,0x12,0x08,0xA9,0xAA,0xC9,0x22,0x63,
3193
0x63,0x12,0x44,0x00,0x10,0x88,0x9C,0x98,0xA1,0x85,0x03,0x32,0x36,0x80,0x89,0xDB,
3194
0xDB,0xBB,0xB9,0xBA,0x01,0x81,0x28,0x19,0xCB,0xFA,0xBC,0x09,0x13,0x37,0x34,0x34,
3195
0x23,0x31,0x20,0x10,0x00,0x00,0x28,0x38,0x10,0x88,0xEC,0x8D,0xCB,0xBC,0xCC,0xBB,
3196
0xBB,0xC9,0x99,0x00,0x00,0x33,0x11,0x22,0x81,0x07,0x41,0x54,0x34,0x34,0x22,0x31,
3197
0x00,0x88,0x9A,0x9B,0x98,0xAB,0x8E,0x9B,0xBD,0x9C,0xBC,0xBB,0xDA,0xAA,0xA9,0x99,
3198
0x18,0x38,0x60,0x20,0x31,0x13,0x13,0x51,0x14,0x31,0x53,0x33,0x35,0x22,0x01,0x8A,
3199
0x9C,0xA9,0xCA,0xC9,0xA8,0x00,0x10,0x81,0x9C,0x9E,0xAB,0xCC,0xAB,0xBA,0x98,0x30,
3200
0x52,0x03,0x81,0x08,0x9C,0xAC,0xAC,0x18,0x11,0x03,0x51,0x61,0x41,0x31,0x31,0x02,
3201
0x01,0x20,0x24,0x43,0x44,0x40,0x30,0x10,0xBC,0xBE,0xCB,0xDB,0xAB,0xBA,0x99,0x98,
3202
0x99,0xAA,0xBD,0xAA,0xC8,0x90,0x11,0x53,0x37,0x23,0x43,0x34,0x33,0x33,0x33,0x11,
3203
0x28,0x00,0x19,0xA9,0x9A,0xCB,0xCE,0xBB,0xEB,0xBC,0xBB,0xCA,0xBA,0xA8,0x88,0x11,
3204
0x12,0x21,0x20,0x22,0x26,0x26,0x23,0x23,0x43,0x24,0x22,0x32,0x20,0x31,0x81,0x9A,
3205
0xBC,0xBC,0xCB,0xBD,0x9A,0xA9,0x90,0x98,0xBA,0xCC,0xCB,0xBC,0x8B,0x88,0x22,0x35,
3206
0x23,0x12,0x99,0x8B,0xAA,0xAA,0x89,0x82,0x93,0x31,0x42,0x23,0x23,0x21,0x32,0x11,
3207
0x20,0x13,0x13,0x24,0x24,0x24,0x22,0x11,0x8A,0x9E,0xAC,0xAC,0xAA,0xBA,0xAA,0xAB,
3208
0xBD,0xBC,0xCB,0xCB,0xA9,0xA8,0x91,0x12,0x44,0x43,0x44,0x34,0x34,0x42,0x33,0x42,
3209
0x21,0x11,0x11,0x88,0x80,0xAA,0x0B,0xAC,0xCB,0xEC,0xAC,0xBA,0xCA,0xAB,0x9A,0x99,
3210
0x80,0x91,0x09,0x08,0x10,0x22,0x44,0x43,0x44,0x33,0x43,0x22,0x13,0x21,0x22,0x20,
3211
0x09,0x88,0xB9,0xC8,0xBB,0xAB,0xAB,0xA9,0xA9,0x9B,0x9B,0x99,0x90,0x90,0x00,0x81,
3212
0x00,0x08,0x09,0x8A,0x9A,0xAA,0xA9,0xA9,0x99,0x90,0x80,0x01,0x80,0x00,0x09,0x31,
3213
0x32,0x44,0x33,0x43,0x34,0x33,0x24,0x22,0x23,0x12,0x10,0x09,0x9B,0xAB,0xCA,0xCC,
3214
0xBB,0xCB,0xDA,0xCA,0xAB,0xCA,0xAB,0xA9,0xA8,0x92,0x12,0x43,0x53,0x35,0x23,0x33,
3215
0x43,0x43,0x52,0x22,0x22,0x21,0x01,0x09,0x89,0xA9,0xBB,0xBD,0xBC,0xCB,0xDA,0xAB,
3216
0xAB,0xAB,0xAA,0xA9,0x99,0xA8,0x09,0x01,0x11,0x34,0x25,0x23,0x33,0x51,0x22,0x31,
3217
0x12,0x20,0x21,0x12,0x10,0x80,0x99,0x9A,0x99,0x99,0x88,0x08,0x00,0x88,0xA9,0x99,
3218
0x99,0x80,0x80,0x10,0x01,0x00,0x9A,0xAA,0xBB,0xBA,0xBA,0xA9,0x99,0x99,0x89,0x99,
3219
0x99,0x00,0x01,0x33,0x35,0x24,0x23,0x34,0x23,0x33,0x34,0x33,0x43,0x32,0x21,0x88,
3220
0xAB,0xBD,0xBB,0xDB,0xAB,0xBA,0xBB,0xDA,0xBB,0xCB,0xBB,0xBC,0xA8,0x90,0x01,0x12,
3221
0x23,0x43,0x53,0x34,0x34,0x39,0x80,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
3222
 
3223
/* Source: 20RIM.ROM */
3224
/* Length: 128 / 0x00000080 */
3225
 
3226
0x0F,0xFF,0x73,0x8E,0x71,0xCD,0x00,0x49,0x10,0x90,0x21,0x49,0xA0,0xDB,0x02,0x3A,
3227
0xE3,0x0A,0x50,0x98,0xC0,0x59,0xA2,0x99,0x09,0x22,0xA2,0x80,0x10,0xA8,0x5B,0xD2,
3228
0x88,0x21,0x09,0x96,0xA8,0x10,0x0A,0xE0,0x08,0x48,0x19,0xAB,0x52,0xA8,0x92,0x0C,
3229
0x03,0x19,0xE2,0x0A,0x12,0xC2,0x81,0x1E,0x01,0xD0,0x48,0x88,0x98,0x01,0x49,0x91,
3230
0xAA,0x2C,0x25,0x89,0x88,0xB5,0x81,0xA2,0x9A,0x12,0x9E,0x38,0x3B,0x81,0x9B,0x59,
3231
0x01,0x93,0xCA,0x4A,0x21,0xA0,0x3D,0x0A,0x39,0x3D,0x12,0xA8,0x3F,0x18,0x01,0x92,
3232
0x1C,0x00,0xB2,0x48,0xB9,0x94,0xA3,0x19,0x4F,0x19,0xB2,0x32,0x90,0xBA,0x01,0xE6,
3233
0x91,0x80,0xC1,0xA4,0x2A,0x08,0xA1,0xB1,0x25,0xD2,0x88,0x99,0x21,0x80,0x88,0x80,
3234
};
3235
 
3236
 
3237
 
3238
/* flag enable control 0x110 */
3239
INLINE void YM2608IRQFlagWrite(FM_OPN *OPN, YM2608 *F2608, int v)
3240
{
3241
        if( v & 0x80 )
3242
        {   /* Reset IRQ flag */
3243
                FM_STATUS_RESET(&OPN->ST, 0xf7); /* don't touch BUFRDY flag otherwise we'd have to call ymdeltat module to set the flag back */
3244
        }
3245
        else
3246
        {   /* Set status flag mask */
3247
                F2608->flagmask = (~(v&0x1f));
3248
                FM_IRQMASK_SET(&OPN->ST, (F2608->irqmask & F2608->flagmask) );
3249
        }
3250
}
3251
 
3252
/* compatible mode & IRQ enable control 0x29 */
3253
INLINE void YM2608IRQMaskWrite(FM_OPN *OPN, YM2608 *F2608, int v)
3254
{
3255
        /* SCH,xx,xxx,EN_ZERO,EN_BRDY,EN_EOS,EN_TB,EN_TA */
3256
 
3257
        /* extend 3ch. enable/disable */
3258
        if(v&0x80)
3259
                OPN->type |= TYPE_6CH;  /* OPNA mode - 6 FM channels */
3260
        else
3261
                OPN->type &= ~TYPE_6CH; /* OPN mode - 3 FM channels */
3262
 
3263
        /* IRQ MASK store and set */
3264
        F2608->irqmask = v&0x1f;
3265
        FM_IRQMASK_SET(&OPN->ST, (F2608->irqmask & F2608->flagmask) );
3266
}
3267
 
3268
/* Generate samples for one of the YM2608s */
3269
void ym2608_update_one(void *chip, FMSAMPLE **buffer, int length)
3270
{
3271
        YM2608 *F2608 = (YM2608 *)chip;
3272
        FM_OPN *OPN   = &F2608->OPN;
3273
        YM_DELTAT *DELTAT = &F2608->deltaT;
3274
        int i,j;
3275
        FMSAMPLE  *bufL,*bufR;
3276
        FM_CH   *cch[6];
3277
        INT32 *out_fm = OPN->out_fm;
3278
 
3279
        /* set bufer */
3280
        bufL = buffer[0];
3281
        bufR = buffer[1];
3282
 
3283
        cch[0]   = &F2608->CH[0];
3284
        cch[1]   = &F2608->CH[1];
3285
        cch[2]   = &F2608->CH[2];
3286
        cch[3]   = &F2608->CH[3];
3287
        cch[4]   = &F2608->CH[4];
3288
        cch[5]   = &F2608->CH[5];
3289
 
3290
        /* refresh PG and EG */
3291
        refresh_fc_eg_chan( OPN, cch[0] );
3292
        refresh_fc_eg_chan( OPN, cch[1] );
3293
        if( (OPN->ST.mode & 0xc0) )
3294
        {
3295
                /* 3SLOT MODE */
3296
                if( cch[2]->SLOT[SLOT1].Incr==-1)
3297
                {
3298
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT1] , OPN->SL3.fc[1] , OPN->SL3.kcode[1] );
3299
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT2] , OPN->SL3.fc[2] , OPN->SL3.kcode[2] );
3300
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT3] , OPN->SL3.fc[0] , OPN->SL3.kcode[0] );
3301
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT4] , cch[2]->fc , cch[2]->kcode );
3302
                }
3303
        }
3304
        else
3305
                refresh_fc_eg_chan( OPN, cch[2] );
3306
        refresh_fc_eg_chan( OPN, cch[3] );
3307
        refresh_fc_eg_chan( OPN, cch[4] );
3308
        refresh_fc_eg_chan( OPN, cch[5] );
3309
 
3310
 
3311
        /* buffering */
3312
        for(i=0; i < length ; i++)
3313
        {
3314
 
3315
                advance_lfo(OPN);
3316
 
3317
                /* clear output acc. */
3318
                OPN->out_adpcm[OUTD_LEFT] = OPN->out_adpcm[OUTD_RIGHT] = OPN->out_adpcm[OUTD_CENTER] = 0;
3319
                OPN->out_delta[OUTD_LEFT] = OPN->out_delta[OUTD_RIGHT] = OPN->out_delta[OUTD_CENTER] = 0;
3320
                /* clear outputs */
3321
                out_fm[0] = 0;
3322
                out_fm[1] = 0;
3323
                out_fm[2] = 0;
3324
                out_fm[3] = 0;
3325
                out_fm[4] = 0;
3326
                out_fm[5] = 0;
3327
 
3328
                /* calculate FM */
3329
                chan_calc(OPN, cch[0], 0 );
3330
                chan_calc(OPN, cch[1], 1 );
3331
                chan_calc(OPN, cch[2], 2 );
3332
                chan_calc(OPN, cch[3], 3 );
3333
                chan_calc(OPN, cch[4], 4 );
3334
                chan_calc(OPN, cch[5], 5 );
3335
 
3336
                /* deltaT ADPCM */
3337
                if( DELTAT->portstate&0x80 )
3338
                        YM_DELTAT_ADPCM_CALC(DELTAT);
3339
 
3340
                /* ADPCMA */
3341
                for( j = 0; j < 6; j++ )
3342
                {
3343
                        if( F2608->adpcm[j].flag )
3344
                                ADPCMA_calc_chan( F2608, &F2608->adpcm[j]);
3345
                }
3346
 
3347
                /* advance envelope generator */
3348
                OPN->eg_timer += OPN->eg_timer_add;
3349
                while (OPN->eg_timer >= OPN->eg_timer_overflow)
3350
                {
3351
                        OPN->eg_timer -= OPN->eg_timer_overflow;
3352
                        OPN->eg_cnt++;
3353
 
3354
                        advance_eg_channel(OPN, &cch[0]->SLOT[SLOT1]);
3355
                        advance_eg_channel(OPN, &cch[1]->SLOT[SLOT1]);
3356
                        advance_eg_channel(OPN, &cch[2]->SLOT[SLOT1]);
3357
                        advance_eg_channel(OPN, &cch[3]->SLOT[SLOT1]);
3358
                        advance_eg_channel(OPN, &cch[4]->SLOT[SLOT1]);
3359
                        advance_eg_channel(OPN, &cch[5]->SLOT[SLOT1]);
3360
                }
3361
 
3362
                /* buffering */
3363
                {
3364
                        int lt,rt;
3365
 
3366
                        lt =  OPN->out_adpcm[OUTD_LEFT]  + OPN->out_adpcm[OUTD_CENTER];
3367
                        rt =  OPN->out_adpcm[OUTD_RIGHT] + OPN->out_adpcm[OUTD_CENTER];
3368
                        lt += (OPN->out_delta[OUTD_LEFT]  + OPN->out_delta[OUTD_CENTER])>>9;
3369
                        rt += (OPN->out_delta[OUTD_RIGHT] + OPN->out_delta[OUTD_CENTER])>>9;
3370
                        lt += ((out_fm[0]>>1) & OPN->pan[0]);   /* shift right verified on real YM2608 */
3371
                        rt += ((out_fm[0]>>1) & OPN->pan[1]);
3372
                        lt += ((out_fm[1]>>1) & OPN->pan[2]);
3373
                        rt += ((out_fm[1]>>1) & OPN->pan[3]);
3374
                        lt += ((out_fm[2]>>1) & OPN->pan[4]);
3375
                        rt += ((out_fm[2]>>1) & OPN->pan[5]);
3376
                        lt += ((out_fm[3]>>1) & OPN->pan[6]);
3377
                        rt += ((out_fm[3]>>1) & OPN->pan[7]);
3378
                        lt += ((out_fm[4]>>1) & OPN->pan[8]);
3379
                        rt += ((out_fm[4]>>1) & OPN->pan[9]);
3380
                        lt += ((out_fm[5]>>1) & OPN->pan[10]);
3381
                        rt += ((out_fm[5]>>1) & OPN->pan[11]);
3382
 
3383
                        lt >>= FINAL_SH;
3384
                        rt >>= FINAL_SH;
3385
 
3386
                        Limit( lt, MAXOUT, MINOUT );
3387
                        Limit( rt, MAXOUT, MINOUT );
3388
                        /* buffering */
3389
                        bufL[i] = lt;
3390
                        bufR[i] = rt;
3391
 
3392
                        #ifdef SAVE_SAMPLE
3393
                                SAVE_ALL_CHANNELS
3394
                        #endif
3395
 
3396
                }
3397
 
3398
                /* timer A control */
3399
                INTERNAL_TIMER_A( &OPN->ST , cch[2] )
3400
        }
3401
        INTERNAL_TIMER_B(&OPN->ST,length)
3402
 
3403
 
3404
        /* check IRQ for DELTA-T EOS */
3405
        FM_STATUS_SET(&OPN->ST, 0);
3406
 
3407
}
3408
#ifdef __SAVE_H__
3409
void ym2608_postload(void *chip)
3410
{
3411
        if (chip)
3412
        {
3413
                YM2608 *F2608 = (YM2608 *)chip;
3414
                int r;
3415
 
3416
                /* prescaler */
3417
                OPNPrescaler_w(&F2608->OPN,1,2);
3418
                F2608->deltaT.freqbase = F2608->OPN.ST.freqbase;
3419
                /* IRQ mask / mode */
3420
                YM2608IRQMaskWrite(&F2608->OPN, F2608, F2608->REGS[0x29]);
3421
                /* SSG registers */
3422
                for(r=0;r<16;r++)
3423
                {
3424
                        (*F2608->OPN.ST.SSG->write)(F2608->OPN.ST.param,0,r);
3425
                        (*F2608->OPN.ST.SSG->write)(F2608->OPN.ST.param,1,F2608->REGS[r]);
3426
                }
3427
 
3428
                /* OPN registers */
3429
                /* DT / MULTI , TL , KS / AR , AMON / DR , SR , SL / RR , SSG-EG */
3430
                for(r=0x30;r<0x9e;r++)
3431
                        if((r&3) != 3)
3432
                        {
3433
                                OPNWriteReg(&F2608->OPN,r,F2608->REGS[r]);
3434
                                OPNWriteReg(&F2608->OPN,r|0x100,F2608->REGS[r|0x100]);
3435
                        }
3436
                /* FB / CONNECT , L / R / AMS / PMS */
3437
                for(r=0xb0;r<0xb6;r++)
3438
                        if((r&3) != 3)
3439
                        {
3440
                                OPNWriteReg(&F2608->OPN,r,F2608->REGS[r]);
3441
                                OPNWriteReg(&F2608->OPN,r|0x100,F2608->REGS[r|0x100]);
3442
                        }
3443
                /* FM channels */
3444
                /*FM_channel_postload(F2608->CH,6);*/
3445
                /* rhythm(ADPCMA) */
3446
                FM_ADPCMAWrite(F2608,1,F2608->REGS[0x111]);
3447
                for( r=0x08 ; r<0x0c ; r++)
3448
                        FM_ADPCMAWrite(F2608,r,F2608->REGS[r+0x110]);
3449
                /* Delta-T ADPCM unit */
3450
                YM_DELTAT_postload(&F2608->deltaT , &F2608->REGS[0x100] );
3451
        }
3452
}
3453
 
3454
static void YM2608_save_state(YM2608 *F2608, device_t *device)
3455
{
3456
        device->save_item(NAME(F2608->REGS));
3457
        FMsave_state_st(device,&F2608->OPN.ST);
3458
        FMsave_state_channel(device,F2608->CH,6);
3459
        /* 3slots */
3460
        device->save_item(NAME(F2608->OPN.SL3.fc));
3461
        device->save_item(NAME(F2608->OPN.SL3.fn_h));
3462
        device->save_item(NAME(F2608->OPN.SL3.kcode));
3463
        /* address register1 */
3464
        device->save_item(NAME(F2608->addr_A1));
3465
        /* rhythm(ADPCMA) */
3466
        FMsave_state_adpcma(device,F2608->adpcm);
3467
        /* Delta-T ADPCM unit */
3468
        YM_DELTAT_savestate(device,&F2608->deltaT);
3469
}
3470
#endif /* _STATE_H */
3471
 
3472
static void YM2608_deltat_status_set(void *chip, UINT8 changebits)
3473
{
3474
        YM2608 *F2608 = (YM2608 *)chip;
3475
        FM_STATUS_SET(&(F2608->OPN.ST), changebits);
3476
}
3477
static void YM2608_deltat_status_reset(void *chip, UINT8 changebits)
3478
{
3479
        YM2608 *F2608 = (YM2608 *)chip;
3480
        FM_STATUS_RESET(&(F2608->OPN.ST), changebits);
3481
}
3482
/* YM2608(OPNA) */
3483
void * ym2608_init(void *param, device_t *device, int clock, int rate,
3484
                                void *pcmrom,int pcmsize,
3485
                                FM_TIMERHANDLER timer_handler,FM_IRQHANDLER IRQHandler, const ssg_callbacks *ssg)
3486
{
3487
        YM2608 *F2608;
3488
 
3489
        /* allocate extend state space */
3490
        F2608 = auto_alloc_clear(device->machine(), YM2608);
3491
        /* allocate total level table (128kb space) */
3492
        if( !init_tables() )
3493
        {
3494
                auto_free( device->machine(), F2608 );
3495
                return NULL;
3496
        }
3497
 
3498
        F2608->OPN.ST.param = param;
3499
        F2608->OPN.type = TYPE_YM2608;
3500
        F2608->OPN.P_CH = F2608->CH;
3501
        F2608->OPN.ST.device = device;
3502
        F2608->OPN.ST.clock = clock;
3503
        F2608->OPN.ST.rate = rate;
3504
 
3505
        /* External handlers */
3506
        F2608->OPN.ST.timer_handler = timer_handler;
3507
        F2608->OPN.ST.IRQ_Handler   = IRQHandler;
3508
        F2608->OPN.ST.SSG           = ssg;
3509
 
3510
        /* DELTA-T */
3511
        F2608->deltaT.memory = (UINT8 *)pcmrom;
3512
        F2608->deltaT.memory_size = pcmsize;
3513
 
3514
        /*F2608->deltaT.write_time = 20.0 / clock;*/    /* a single byte write takes 20 cycles of main clock */
3515
        /*F2608->deltaT.read_time  = 18.0 / clock;*/    /* a single byte read takes 18 cycles of main clock */
3516
 
3517
        F2608->deltaT.status_set_handler = YM2608_deltat_status_set;
3518
        F2608->deltaT.status_reset_handler = YM2608_deltat_status_reset;
3519
        F2608->deltaT.status_change_which_chip = F2608;
3520
        F2608->deltaT.status_change_EOS_bit = 0x04; /* status flag: set bit2 on End Of Sample */
3521
        F2608->deltaT.status_change_BRDY_bit = 0x08;    /* status flag: set bit3 on BRDY */
3522
        F2608->deltaT.status_change_ZERO_bit = 0x10;    /* status flag: set bit4 if silence continues for more than 290 miliseconds while recording the ADPCM */
3523
 
3524
        /* ADPCM Rhythm */
3525
        F2608->pcmbuf   = YM2608_ADPCM_ROM;
3526
        F2608->pcm_size = 0x2000;
3527
 
3528
        Init_ADPCMATable();
3529
 
3530
#ifdef __SAVE_H__
3531
        YM2608_save_state(F2608, device);
3532
#endif
3533
        return F2608;
3534
}
3535
 
3536
/* shut down emulator */
3537
void ym2608_shutdown(void *chip)
3538
{
3539
        YM2608 *F2608 = (YM2608 *)chip;
3540
 
3541
        FMCloseTable();
3542
        auto_free(F2608->OPN.ST.device->machine(), F2608);
3543
}
3544
 
3545
/* reset one of chips */
3546
void ym2608_reset_chip(void *chip)
3547
{
3548
        int i;
3549
        YM2608 *F2608 = (YM2608 *)chip;
3550
        FM_OPN *OPN   = &F2608->OPN;
3551
        YM_DELTAT *DELTAT = &F2608->deltaT;
3552
 
3553
        /* Reset Prescaler */
3554
        OPNPrescaler_w(OPN , 0 , 2);
3555
        F2608->deltaT.freqbase = OPN->ST.freqbase;
3556
        /* reset SSG section */
3557
        (*OPN->ST.SSG->reset)(OPN->ST.param);
3558
 
3559
        /* status clear */
3560
        FM_BUSY_CLEAR(&OPN->ST);
3561
 
3562
        /* register 0x29 - default value after reset is:
3563
            enable only 3 FM channels and enable all the status flags */
3564
        YM2608IRQMaskWrite(OPN, F2608, 0x1f );  /* default value for D4-D0 is 1 */
3565
 
3566
        /* register 0x10, A1=1 - default value is 1 for D4, D3, D2, 0 for the rest */
3567
        YM2608IRQFlagWrite(OPN, F2608, 0x1c );  /* default: enable timer A and B, disable EOS, BRDY and ZERO */
3568
 
3569
        OPNWriteMode(OPN,0x27,0x30);    /* mode 0 , timer reset */
3570
 
3571
        OPN->eg_timer = 0;
3572
        OPN->eg_cnt   = 0;
3573
 
3574
        FM_STATUS_RESET(&OPN->ST, 0xff);
3575
 
3576
        reset_channels( &OPN->ST , F2608->CH , 6 );
3577
        /* reset OPerator paramater */
3578
        for(i = 0xb6 ; i >= 0xb4 ; i-- )
3579
        {
3580
                OPNWriteReg(OPN,i      ,0xc0);
3581
                OPNWriteReg(OPN,i|0x100,0xc0);
3582
        }
3583
        for(i = 0xb2 ; i >= 0x30 ; i-- )
3584
        {
3585
                OPNWriteReg(OPN,i      ,0);
3586
                OPNWriteReg(OPN,i|0x100,0);
3587
        }
3588
        for(i = 0x26 ; i >= 0x20 ; i-- ) OPNWriteReg(OPN,i,0);
3589
 
3590
        /* ADPCM - percussion sounds */
3591
        for( i = 0; i < 6; i++ )
3592
        {
3593
                if (i<=3)   /* channels 0,1,2,3 */
3594
                        F2608->adpcm[i].step      = (UINT32)((float)(1<<ADPCM_SHIFT)*((float)F2608->OPN.ST.freqbase)/3.0);
3595
                else        /* channels 4 and 5 work with slower clock */
3596
                        F2608->adpcm[i].step      = (UINT32)((float)(1<<ADPCM_SHIFT)*((float)F2608->OPN.ST.freqbase)/6.0);
3597
 
3598
                F2608->adpcm[i].start     = YM2608_ADPCM_ROM_addr[i*2];
3599
                F2608->adpcm[i].end       = YM2608_ADPCM_ROM_addr[i*2+1];
3600
 
3601
                F2608->adpcm[i].now_addr  = 0;
3602
                F2608->adpcm[i].now_step  = 0;
3603
                /* F2608->adpcm[i].delta     = 21866; */
3604
                F2608->adpcm[i].vol_mul   = 0;
3605
                F2608->adpcm[i].pan       = &OPN->out_adpcm[OUTD_CENTER]; /* default center */
3606
                F2608->adpcm[i].flagMask  = 0;
3607
                F2608->adpcm[i].flag      = 0;
3608
                F2608->adpcm[i].adpcm_acc = 0;
3609
                F2608->adpcm[i].adpcm_step= 0;
3610
                F2608->adpcm[i].adpcm_out = 0;
3611
        }
3612
        F2608->adpcmTL = 0x3f;
3613
 
3614
        F2608->adpcm_arrivedEndAddress = 0; /* not used */
3615
 
3616
        /* DELTA-T unit */
3617
        DELTAT->freqbase = OPN->ST.freqbase;
3618
        DELTAT->output_pointer = OPN->out_delta;
3619
        DELTAT->portshift = 5;      /* always 5bits shift */ /* ASG */
3620
        DELTAT->output_range = 1<<23;
3621
        YM_DELTAT_ADPCM_Reset(DELTAT,OUTD_CENTER,YM_DELTAT_EMULATION_MODE_NORMAL);
3622
}
3623
 
3624
/* YM2608 write */
3625
/* n = number  */
3626
/* a = address */
3627
/* v = value   */
3628
int ym2608_write(void *chip, int a,UINT8 v)
3629
{
3630
        YM2608 *F2608 = (YM2608 *)chip;
3631
        FM_OPN *OPN   = &F2608->OPN;
3632
        int addr;
3633
 
3634
        v &= 0xff;  /*adjust to 8 bit bus */
3635
 
3636
 
3637
        switch(a&3)
3638
        {
3639
        case 0: /* address port 0 */
3640
                OPN->ST.address = v;
3641
                F2608->addr_A1 = 0;
3642
 
3643
                /* Write register to SSG emulator */
3644
                if( v < 16 ) (*OPN->ST.SSG->write)(OPN->ST.param,0,v);
3645
                /* prescaler selecter : 2d,2e,2f  */
3646
                if( v >= 0x2d && v <= 0x2f )
3647
                {
3648
                        OPNPrescaler_w(OPN , v , 2);
3649
                        F2608->deltaT.freqbase = OPN->ST.freqbase;
3650
                }
3651
                break;
3652
 
3653
        case 1: /* data port 0    */
3654
                if (F2608->addr_A1 != 0)
3655
                        break;  /* verified on real YM2608 */
3656
 
3657
                addr = OPN->ST.address;
3658
                F2608->REGS[addr] = v;
3659
                switch(addr & 0xf0)
3660
                {
3661
                case 0x00:  /* SSG section */
3662
                        /* Write data to SSG emulator */
3663
                        (*OPN->ST.SSG->write)(OPN->ST.param,a,v);
3664
                        break;
3665
                case 0x10:  /* 0x10-0x1f : Rhythm section */
3666
                        ym2608_update_req(OPN->ST.param);
3667
                        FM_ADPCMAWrite(F2608,addr-0x10,v);
3668
                        break;
3669
                case 0x20:  /* Mode Register */
3670
                        switch(addr)
3671
                        {
3672
                        case 0x29:  /* SCH,xx,xxx,EN_ZERO,EN_BRDY,EN_EOS,EN_TB,EN_TA */
3673
                                YM2608IRQMaskWrite(OPN, F2608, v);
3674
                                break;
3675
                        default:
3676
                                ym2608_update_req(OPN->ST.param);
3677
                                OPNWriteMode(OPN,addr,v);
3678
                        }
3679
                        break;
3680
                default:    /* OPN section */
3681
                        ym2608_update_req(OPN->ST.param);
3682
                        OPNWriteReg(OPN,addr,v);
3683
                }
3684
                break;
3685
 
3686
        case 2: /* address port 1 */
3687
                OPN->ST.address = v;
3688
                F2608->addr_A1 = 1;
3689
                break;
3690
 
3691
        case 3: /* data port 1    */
3692
                if (F2608->addr_A1 != 1)
3693
                        break;  /* verified on real YM2608 */
3694
 
3695
                addr = OPN->ST.address;
3696
                F2608->REGS[addr | 0x100] = v;
3697
                ym2608_update_req(OPN->ST.param);
3698
                switch( addr & 0xf0 )
3699
                {
3700
                case 0x00:  /* DELTAT PORT */
3701
                        switch( addr )
3702
                        {
3703
                        case 0x0e:  /* DAC data */
3704
                                logerror("YM2608: write to DAC data (unimplemented) value=%02x\n",v);
3705
                                break;
3706
                        default:
3707
                                /* 0x00-0x0d */
3708
                                YM_DELTAT_ADPCM_Write(&F2608->deltaT,addr,v);
3709
                        }
3710
                        break;
3711
                case 0x10:  /* IRQ Flag control */
3712
                        if( addr == 0x10 )
3713
                        {
3714
                                YM2608IRQFlagWrite(OPN, F2608, v);
3715
                        }
3716
                        break;
3717
                default:
3718
                        OPNWriteReg(OPN,addr | 0x100,v);
3719
                }
3720
        }
3721
        return OPN->ST.irq;
3722
}
3723
 
3724
UINT8 ym2608_read(void *chip,int a)
3725
{
3726
        YM2608 *F2608 = (YM2608 *)chip;
3727
        int addr = F2608->OPN.ST.address;
3728
        UINT8 ret = 0;
3729
 
3730
        switch( a&3 )
3731
        {
3732
        case 0: /* status 0 : YM2203 compatible */
3733
                /* BUSY:x:x:x:x:x:FLAGB:FLAGA */
3734
                ret = FM_STATUS_FLAG(&F2608->OPN.ST) & 0x83;
3735
                break;
3736
 
3737
        case 1: /* status 0, ID  */
3738
                if( addr < 16 ) ret = (*F2608->OPN.ST.SSG->read)(F2608->OPN.ST.param);
3739
                else if(addr == 0xff) ret = 0x01; /* ID code */
3740
                break;
3741
 
3742
        case 2: /* status 1 : status 0 + ADPCM status */
3743
                /* BUSY : x : PCMBUSY : ZERO : BRDY : EOS : FLAGB : FLAGA */
3744
                ret = (FM_STATUS_FLAG(&F2608->OPN.ST) & (F2608->flagmask|0x80)) | ((F2608->deltaT.PCM_BSY & 1)<<5) ;
3745
                break;
3746
 
3747
        case 3:
3748
                if(addr == 0x08)
3749
                {
3750
                        ret = YM_DELTAT_ADPCM_Read(&F2608->deltaT);
3751
                }
3752
                else
3753
                {
3754
                        if(addr == 0x0f)
3755
                        {
3756
                                logerror("YM2608 A/D convertion is accessed but not implemented !\n");
3757
                                ret = 0x80; /* 2's complement PCM data - result from A/D convertion */
3758
                        }
3759
                }
3760
                break;
3761
        }
3762
        return ret;
3763
}
3764
 
3765
int ym2608_timer_over(void *chip,int c)
3766
{
3767
        YM2608 *F2608 = (YM2608 *)chip;
3768
 
3769
        switch(c)
3770
        {
3771
#if 0
3772
        case 2:
3773
                {   /* BUFRDY flag */
3774
                        YM_DELTAT_BRDY_callback( &F2608->deltaT );
3775
                }
3776
                break;
3777
#endif
3778
        case 1:
3779
                {   /* Timer B */
3780
                        TimerBOver( &(F2608->OPN.ST) );
3781
                }
3782
                break;
3783
        case 0:
3784
                {   /* Timer A */
3785
                        ym2608_update_req(F2608->OPN.ST.param);
3786
                        /* timer update */
3787
                        TimerAOver( &(F2608->OPN.ST) );
3788
                        /* CSM mode key,TL controll */
3789
                        if( F2608->OPN.ST.mode & 0x80 )
3790
                        {   /* CSM mode total level latch and auto key on */
3791
                                CSMKeyControll( F2608->OPN.type, &(F2608->CH[2]) );
3792
                        }
3793
                }
3794
                break;
3795
        default:
3796
                break;
3797
        }
3798
 
3799
        return F2608->OPN.ST.irq;
3800
}
3801
 
3802
#endif /* BUILD_YM2608 */
3803
 
3804
 
3805
 
3806
#if (BUILD_YM2610||BUILD_YM2610B)
3807
/* YM2610(OPNB) */
3808
 
3809
/* Generate samples for one of the YM2610s */
3810
void ym2610_update_one(void *chip, FMSAMPLE **buffer, int length)
3811
{
3812
        YM2610 *F2610 = (YM2610 *)chip;
3813
        FM_OPN *OPN   = &F2610->OPN;
3814
        YM_DELTAT *DELTAT = &F2610->deltaT;
3815
        int i,j;
3816
        FMSAMPLE  *bufL,*bufR;
3817
        FM_CH   *cch[4];
3818
        INT32 *out_fm = OPN->out_fm;
3819
 
3820
        /* buffer setup */
3821
        bufL = buffer[0];
3822
        bufR = buffer[1];
3823
 
3824
        cch[0] = &F2610->CH[1];
3825
        cch[1] = &F2610->CH[2];
3826
        cch[2] = &F2610->CH[4];
3827
        cch[3] = &F2610->CH[5];
3828
 
3829
#ifdef YM2610B_WARNING
3830
#define FM_KEY_IS(SLOT) ((SLOT)->key)
3831
#define FM_MSG_YM2610B "YM2610-%p.CH%d is playing,Check whether the type of the chip is YM2610B\n"
3832
        /* Check YM2610B warning message */
3833
        if( FM_KEY_IS(&F2610->CH[0].SLOT[3]) )
3834
                LOG(LOG_WAR,(FM_MSG_YM2610B,F2610->OPN.ST.param,0));
3835
        if( FM_KEY_IS(&F2610->CH[3].SLOT[3]) )
3836
                LOG(LOG_WAR,(FM_MSG_YM2610B,F2610->OPN.ST.param,3));
3837
#endif
3838
 
3839
        /* refresh PG and EG */
3840
        refresh_fc_eg_chan( OPN, cch[0] );
3841
        if( (OPN->ST.mode & 0xc0) )
3842
        {
3843
                /* 3SLOT MODE */
3844
                if( cch[1]->SLOT[SLOT1].Incr==-1)
3845
                {
3846
                        refresh_fc_eg_slot(OPN, &cch[1]->SLOT[SLOT1] , OPN->SL3.fc[1] , OPN->SL3.kcode[1] );
3847
                        refresh_fc_eg_slot(OPN, &cch[1]->SLOT[SLOT2] , OPN->SL3.fc[2] , OPN->SL3.kcode[2] );
3848
                        refresh_fc_eg_slot(OPN, &cch[1]->SLOT[SLOT3] , OPN->SL3.fc[0] , OPN->SL3.kcode[0] );
3849
                        refresh_fc_eg_slot(OPN, &cch[1]->SLOT[SLOT4] , cch[1]->fc , cch[1]->kcode );
3850
                }
3851
        }
3852
        else
3853
                refresh_fc_eg_chan( OPN, cch[1] );
3854
        refresh_fc_eg_chan( OPN, cch[2] );
3855
        refresh_fc_eg_chan( OPN, cch[3] );
3856
 
3857
        /* buffering */
3858
        for(i=0; i < length ; i++)
3859
        {
3860
 
3861
                advance_lfo(OPN);
3862
 
3863
                /* clear output acc. */
3864
                OPN->out_adpcm[OUTD_LEFT] = OPN->out_adpcm[OUTD_RIGHT] = OPN->out_adpcm[OUTD_CENTER] = 0;
3865
                OPN->out_delta[OUTD_LEFT] = OPN->out_delta[OUTD_RIGHT] = OPN->out_delta[OUTD_CENTER] = 0;
3866
                /* clear outputs */
3867
                out_fm[1] = 0;
3868
                out_fm[2] = 0;
3869
                out_fm[4] = 0;
3870
                out_fm[5] = 0;
3871
 
3872
                /* advance envelope generator */
3873
                OPN->eg_timer += OPN->eg_timer_add;
3874
                while (OPN->eg_timer >= OPN->eg_timer_overflow)
3875
                {
3876
                        OPN->eg_timer -= OPN->eg_timer_overflow;
3877
                        OPN->eg_cnt++;
3878
 
3879
                        advance_eg_channel(OPN, &cch[0]->SLOT[SLOT1]);
3880
                        advance_eg_channel(OPN, &cch[1]->SLOT[SLOT1]);
3881
                        advance_eg_channel(OPN, &cch[2]->SLOT[SLOT1]);
3882
                        advance_eg_channel(OPN, &cch[3]->SLOT[SLOT1]);
3883
                }
3884
 
3885
                /* calculate FM */
3886
                chan_calc(OPN, cch[0], 1 ); /*remapped to 1*/
3887
                chan_calc(OPN, cch[1], 2 ); /*remapped to 2*/
3888
                chan_calc(OPN, cch[2], 4 ); /*remapped to 4*/
3889
                chan_calc(OPN, cch[3], 5 ); /*remapped to 5*/
3890
 
3891
                /* deltaT ADPCM */
3892
                if( DELTAT->portstate&0x80 )
3893
                        YM_DELTAT_ADPCM_CALC(DELTAT);
3894
 
3895
                /* ADPCMA */
3896
                for( j = 0; j < 6; j++ )
3897
                {
3898
                        if( F2610->adpcm[j].flag )
3899
                                ADPCMA_calc_chan( F2610, &F2610->adpcm[j]);
3900
                }
3901
 
3902
                /* buffering */
3903
                {
3904
                        int lt,rt;
3905
 
3906
                        lt =  OPN->out_adpcm[OUTD_LEFT]  + OPN->out_adpcm[OUTD_CENTER];
3907
                        rt =  OPN->out_adpcm[OUTD_RIGHT] + OPN->out_adpcm[OUTD_CENTER];
3908
                        lt += (OPN->out_delta[OUTD_LEFT]  + OPN->out_delta[OUTD_CENTER])>>9;
3909
                        rt += (OPN->out_delta[OUTD_RIGHT] + OPN->out_delta[OUTD_CENTER])>>9;
3910
 
3911
 
3912
                        lt += ((out_fm[1]>>1) & OPN->pan[2]);   /* the shift right was verified on real chip */
3913
                        rt += ((out_fm[1]>>1) & OPN->pan[3]);
3914
                        lt += ((out_fm[2]>>1) & OPN->pan[4]);
3915
                        rt += ((out_fm[2]>>1) & OPN->pan[5]);
3916
 
3917
                        lt += ((out_fm[4]>>1) & OPN->pan[8]);
3918
                        rt += ((out_fm[4]>>1) & OPN->pan[9]);
3919
                        lt += ((out_fm[5]>>1) & OPN->pan[10]);
3920
                        rt += ((out_fm[5]>>1) & OPN->pan[11]);
3921
 
3922
 
3923
                        lt >>= FINAL_SH;
3924
                        rt >>= FINAL_SH;
3925
 
3926
                        Limit( lt, MAXOUT, MINOUT );
3927
                        Limit( rt, MAXOUT, MINOUT );
3928
 
3929
                        #ifdef SAVE_SAMPLE
3930
                                SAVE_ALL_CHANNELS
3931
                        #endif
3932
 
3933
                        /* buffering */
3934
                        bufL[i] = lt;
3935
                        bufR[i] = rt;
3936
                }
3937
 
3938
                /* timer A control */
3939
                INTERNAL_TIMER_A( &OPN->ST , cch[1] )
3940
        }
3941
        INTERNAL_TIMER_B(&OPN->ST,length)
3942
 
3943
}
3944
 
3945
#if BUILD_YM2610B
3946
/* Generate samples for one of the YM2610Bs */
3947
void ym2610b_update_one(void *chip, FMSAMPLE **buffer, int length)
3948
{
3949
        YM2610 *F2610 = (YM2610 *)chip;
3950
        FM_OPN *OPN   = &F2610->OPN;
3951
        YM_DELTAT *DELTAT = &F2610->deltaT;
3952
        int i,j;
3953
        FMSAMPLE  *bufL,*bufR;
3954
        FM_CH   *cch[6];
3955
        INT32 *out_fm = OPN->out_fm;
3956
 
3957
        /* buffer setup */
3958
        bufL = buffer[0];
3959
        bufR = buffer[1];
3960
 
3961
        cch[0] = &F2610->CH[0];
3962
        cch[1] = &F2610->CH[1];
3963
        cch[2] = &F2610->CH[2];
3964
        cch[3] = &F2610->CH[3];
3965
        cch[4] = &F2610->CH[4];
3966
        cch[5] = &F2610->CH[5];
3967
 
3968
        /* refresh PG and EG */
3969
        refresh_fc_eg_chan( OPN, cch[0] );
3970
        refresh_fc_eg_chan( OPN, cch[1] );
3971
        if( (OPN->ST.mode & 0xc0) )
3972
        {
3973
                /* 3SLOT MODE */
3974
                if( cch[2]->SLOT[SLOT1].Incr==-1)
3975
                {
3976
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT1] , OPN->SL3.fc[1] , OPN->SL3.kcode[1] );
3977
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT2] , OPN->SL3.fc[2] , OPN->SL3.kcode[2] );
3978
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT3] , OPN->SL3.fc[0] , OPN->SL3.kcode[0] );
3979
                        refresh_fc_eg_slot(OPN, &cch[2]->SLOT[SLOT4] , cch[2]->fc , cch[2]->kcode );
3980
                }
3981
        }
3982
        else
3983
                refresh_fc_eg_chan( OPN, cch[2] );
3984
        refresh_fc_eg_chan( OPN, cch[3] );
3985
        refresh_fc_eg_chan( OPN, cch[4] );
3986
        refresh_fc_eg_chan( OPN, cch[5] );
3987
 
3988
        /* buffering */
3989
        for(i=0; i < length ; i++)
3990
        {
3991
 
3992
                advance_lfo(OPN);
3993
 
3994
                /* clear output acc. */
3995
                OPN->out_adpcm[OUTD_LEFT] = OPN->out_adpcm[OUTD_RIGHT] = OPN->out_adpcm[OUTD_CENTER] = 0;
3996
                OPN->out_delta[OUTD_LEFT] = OPN->out_delta[OUTD_RIGHT] = OPN->out_delta[OUTD_CENTER] = 0;
3997
                /* clear outputs */
3998
                out_fm[0] = 0;
3999
                out_fm[1] = 0;
4000
                out_fm[2] = 0;
4001
                out_fm[3] = 0;
4002
                out_fm[4] = 0;
4003
                out_fm[5] = 0;
4004
 
4005
                /* advance envelope generator */
4006
                OPN->eg_timer += OPN->eg_timer_add;
4007
                while (OPN->eg_timer >= OPN->eg_timer_overflow)
4008
                {
4009
                        OPN->eg_timer -= OPN->eg_timer_overflow;
4010
                        OPN->eg_cnt++;
4011
 
4012
                        advance_eg_channel(OPN, &cch[0]->SLOT[SLOT1]);
4013
                        advance_eg_channel(OPN, &cch[1]->SLOT[SLOT1]);
4014
                        advance_eg_channel(OPN, &cch[2]->SLOT[SLOT1]);
4015
                        advance_eg_channel(OPN, &cch[3]->SLOT[SLOT1]);
4016
                        advance_eg_channel(OPN, &cch[4]->SLOT[SLOT1]);
4017
                        advance_eg_channel(OPN, &cch[5]->SLOT[SLOT1]);
4018
                }
4019
 
4020
                /* calculate FM */
4021
                chan_calc(OPN, cch[0], 0 );
4022
                chan_calc(OPN, cch[1], 1 );
4023
                chan_calc(OPN, cch[2], 2 );
4024
                chan_calc(OPN, cch[3], 3 );
4025
                chan_calc(OPN, cch[4], 4 );
4026
                chan_calc(OPN, cch[5], 5 );
4027
 
4028
                /* deltaT ADPCM */
4029
                if( DELTAT->portstate&0x80 )
4030
                        YM_DELTAT_ADPCM_CALC(DELTAT);
4031
 
4032
                /* ADPCMA */
4033
                for( j = 0; j < 6; j++ )
4034
                {
4035
                        if( F2610->adpcm[j].flag )
4036
                                ADPCMA_calc_chan( F2610, &F2610->adpcm[j]);
4037
                }
4038
 
4039
                /* buffering */
4040
                {
4041
                        int lt,rt;
4042
 
4043
                        lt =  OPN->out_adpcm[OUTD_LEFT]  + OPN->out_adpcm[OUTD_CENTER];
4044
                        rt =  OPN->out_adpcm[OUTD_RIGHT] + OPN->out_adpcm[OUTD_CENTER];
4045
                        lt += (OPN->out_delta[OUTD_LEFT]  + OPN->out_delta[OUTD_CENTER])>>9;
4046
                        rt += (OPN->out_delta[OUTD_RIGHT] + OPN->out_delta[OUTD_CENTER])>>9;
4047
 
4048
                        lt += ((out_fm[0]>>1) & OPN->pan[0]);   /* the shift right is verified on YM2610 */
4049
                        rt += ((out_fm[0]>>1) & OPN->pan[1]);
4050
                        lt += ((out_fm[1]>>1) & OPN->pan[2]);
4051
                        rt += ((out_fm[1]>>1) & OPN->pan[3]);
4052
                        lt += ((out_fm[2]>>1) & OPN->pan[4]);
4053
                        rt += ((out_fm[2]>>1) & OPN->pan[5]);
4054
                        lt += ((out_fm[3]>>1) & OPN->pan[6]);
4055
                        rt += ((out_fm[3]>>1) & OPN->pan[7]);
4056
                        lt += ((out_fm[4]>>1) & OPN->pan[8]);
4057
                        rt += ((out_fm[4]>>1) & OPN->pan[9]);
4058
                        lt += ((out_fm[5]>>1) & OPN->pan[10]);
4059
                        rt += ((out_fm[5]>>1) & OPN->pan[11]);
4060
 
4061
 
4062
                        lt >>= FINAL_SH;
4063
                        rt >>= FINAL_SH;
4064
 
4065
                        Limit( lt, MAXOUT, MINOUT );
4066
                        Limit( rt, MAXOUT, MINOUT );
4067
 
4068
                        #ifdef SAVE_SAMPLE
4069
                                SAVE_ALL_CHANNELS
4070
                        #endif
4071
 
4072
                        /* buffering */
4073
                        bufL[i] = lt;
4074
                        bufR[i] = rt;
4075
                }
4076
 
4077
                /* timer A control */
4078
                INTERNAL_TIMER_A( &OPN->ST , cch[2] )
4079
        }
4080
        INTERNAL_TIMER_B(&OPN->ST,length)
4081
 
4082
}
4083
#endif /* BUILD_YM2610B */
4084
 
4085
 
4086
#ifdef __SAVE_H__
4087
void ym2610_postload(void *chip)
4088
{
4089
        if (chip)
4090
        {
4091
                YM2610 *F2610 = (YM2610 *)chip;
4092
                int r;
4093
 
4094
                /* SSG registers */
4095
                for(r=0;r<16;r++)
4096
                {
4097
                        (*F2610->OPN.ST.SSG->write)(F2610->OPN.ST.param,0,r);
4098
                        (*F2610->OPN.ST.SSG->write)(F2610->OPN.ST.param,1,F2610->REGS[r]);
4099
                }
4100
 
4101
                /* OPN registers */
4102
                /* DT / MULTI , TL , KS / AR , AMON / DR , SR , SL / RR , SSG-EG */
4103
                for(r=0x30;r<0x9e;r++)
4104
                        if((r&3) != 3)
4105
                        {
4106
                                OPNWriteReg(&F2610->OPN,r,F2610->REGS[r]);
4107
                                OPNWriteReg(&F2610->OPN,r|0x100,F2610->REGS[r|0x100]);
4108
                        }
4109
                /* FB / CONNECT , L / R / AMS / PMS */
4110
                for(r=0xb0;r<0xb6;r++)
4111
                        if((r&3) != 3)
4112
                        {
4113
                                OPNWriteReg(&F2610->OPN,r,F2610->REGS[r]);
4114
                                OPNWriteReg(&F2610->OPN,r|0x100,F2610->REGS[r|0x100]);
4115
                        }
4116
                /* FM channels */
4117
                /*FM_channel_postload(F2610->CH,6);*/
4118
 
4119
                /* rhythm(ADPCMA) */
4120
                FM_ADPCMAWrite(F2610,1,F2610->REGS[0x101]);
4121
                for( r=0 ; r<6 ; r++)
4122
                {
4123
                        FM_ADPCMAWrite(F2610,r+0x08,F2610->REGS[r+0x108]);
4124
                        FM_ADPCMAWrite(F2610,r+0x10,F2610->REGS[r+0x110]);
4125
                        FM_ADPCMAWrite(F2610,r+0x18,F2610->REGS[r+0x118]);
4126
                        FM_ADPCMAWrite(F2610,r+0x20,F2610->REGS[r+0x120]);
4127
                        FM_ADPCMAWrite(F2610,r+0x28,F2610->REGS[r+0x128]);
4128
                }
4129
                /* Delta-T ADPCM unit */
4130
                YM_DELTAT_postload(&F2610->deltaT , &F2610->REGS[0x010] );
4131
        }
4132
}
4133
 
4134
static void YM2610_save_state(YM2610 *F2610, device_t *device)
4135
{
4136
        device->save_item(NAME(F2610->REGS));
4137
        FMsave_state_st(device,&F2610->OPN.ST);
4138
        FMsave_state_channel(device,F2610->CH,6);
4139
        /* 3slots */
4140
        device->save_item(NAME(F2610->OPN.SL3.fc));
4141
        device->save_item(NAME(F2610->OPN.SL3.fn_h));
4142
        device->save_item(NAME(F2610->OPN.SL3.kcode));
4143
        /* address register1 */
4144
        device->save_item(NAME(F2610->addr_A1));
4145
 
4146
        device->save_item(NAME(F2610->adpcm_arrivedEndAddress));
4147
        /* rhythm(ADPCMA) */
4148
        FMsave_state_adpcma(device,F2610->adpcm);
4149
        /* Delta-T ADPCM unit */
4150
        YM_DELTAT_savestate(device,&F2610->deltaT);
4151
}
4152
#endif /* _STATE_H */
4153
 
4154
static void YM2610_deltat_status_set(void *chip, UINT8 changebits)
4155
{
4156
        YM2610 *F2610 = (YM2610 *)chip;
4157
        F2610->adpcm_arrivedEndAddress |= changebits;
4158
}
4159
static void YM2610_deltat_status_reset(void *chip, UINT8 changebits)
4160
{
4161
        YM2610 *F2610 = (YM2610 *)chip;
4162
        F2610->adpcm_arrivedEndAddress &= (~changebits);
4163
}
4164
 
4165
void *ym2610_init(void *param, device_t *device, int clock, int rate,
4166
                                void *pcmroma,int pcmsizea,void *pcmromb,int pcmsizeb,
4167
                                FM_TIMERHANDLER timer_handler,FM_IRQHANDLER IRQHandler, const ssg_callbacks *ssg)
4168
 
4169
{
4170
        YM2610 *F2610;
4171
 
4172
        /* allocate extend state space */
4173
        F2610 = auto_alloc_clear(device->machine(), YM2610);
4174
        /* allocate total level table (128kb space) */
4175
        if( !init_tables() )
4176
        {
4177
                auto_free( device->machine(), F2610 );
4178
                return NULL;
4179
        }
4180
 
4181
        /* FM */
4182
        F2610->OPN.ST.param = param;
4183
        F2610->OPN.type = TYPE_YM2610;
4184
        F2610->OPN.P_CH = F2610->CH;
4185
        F2610->OPN.ST.device = device;
4186
        F2610->OPN.ST.clock = clock;
4187
        F2610->OPN.ST.rate = rate;
4188
        /* Extend handler */
4189
        F2610->OPN.ST.timer_handler = timer_handler;
4190
        F2610->OPN.ST.IRQ_Handler   = IRQHandler;
4191
        F2610->OPN.ST.SSG           = ssg;
4192
        /* ADPCM */
4193
        F2610->pcmbuf   = (const UINT8 *)pcmroma;
4194
        F2610->pcm_size = pcmsizea;
4195
        /* DELTA-T */
4196
        F2610->deltaT.memory = (UINT8 *)pcmromb;
4197
        F2610->deltaT.memory_size = pcmsizeb;
4198
 
4199
        F2610->deltaT.status_set_handler = YM2610_deltat_status_set;
4200
        F2610->deltaT.status_reset_handler = YM2610_deltat_status_reset;
4201
        F2610->deltaT.status_change_which_chip = F2610;
4202
        F2610->deltaT.status_change_EOS_bit = 0x80; /* status flag: set bit7 on End Of Sample */
4203
 
4204
        Init_ADPCMATable();
4205
#ifdef __SAVE_H__
4206
        YM2610_save_state(F2610, device);
4207
#endif
4208
        return F2610;
4209
}
4210
 
4211
/* shut down emulator */
4212
void ym2610_shutdown(void *chip)
4213
{
4214
        YM2610 *F2610 = (YM2610 *)chip;
4215
 
4216
        FMCloseTable();
4217
        auto_free(F2610->OPN.ST.device->machine(), F2610);
4218
}
4219
 
4220
/* reset one of chip */
4221
void ym2610_reset_chip(void *chip)
4222
{
4223
        int i;
4224
        YM2610 *F2610 = (YM2610 *)chip;
4225
        FM_OPN *OPN   = &F2610->OPN;
4226
        YM_DELTAT *DELTAT = &F2610->deltaT;
4227
 
4228
        astring name;
4229
        device_t* dev = F2610->OPN.ST.device;
4230
 
4231
        /* setup PCM buffers again */
4232
        name.printf("%s",dev->tag());
4233
        F2610->pcmbuf   = (const UINT8 *)dev->machine().root_device().memregion(name)->base();
4234
        F2610->pcm_size = dev->machine().root_device().memregion(name)->bytes();
4235
        name.printf("%s.deltat",dev->tag());
4236
        F2610->deltaT.memory = (UINT8 *)dev->machine().root_device().memregion(name)->base();
4237
        if(F2610->deltaT.memory == NULL)
4238
        {
4239
                F2610->deltaT.memory = (UINT8*)F2610->pcmbuf;
4240
                F2610->deltaT.memory_size = F2610->pcm_size;
4241
        }
4242
        else
4243
                F2610->deltaT.memory_size = dev->machine().root_device().memregion(name)->bytes();
4244
 
4245
        /* Reset Prescaler */
4246
        OPNSetPres( OPN, 6*24, 6*24, 4*2); /* OPN 1/6 , SSG 1/4 */
4247
        /* reset SSG section */
4248
        (*OPN->ST.SSG->reset)(OPN->ST.param);
4249
        /* status clear */
4250
        FM_IRQMASK_SET(&OPN->ST,0x03);
4251
        FM_BUSY_CLEAR(&OPN->ST);
4252
        OPNWriteMode(OPN,0x27,0x30); /* mode 0 , timer reset */
4253
 
4254
        OPN->eg_timer = 0;
4255
        OPN->eg_cnt   = 0;
4256
 
4257
        FM_STATUS_RESET(&OPN->ST, 0xff);
4258
 
4259
        reset_channels( &OPN->ST , F2610->CH , 6 );
4260
        /* reset OPerator paramater */
4261
        for(i = 0xb6 ; i >= 0xb4 ; i-- )
4262
        {
4263
                OPNWriteReg(OPN,i      ,0xc0);
4264
                OPNWriteReg(OPN,i|0x100,0xc0);
4265
        }
4266
        for(i = 0xb2 ; i >= 0x30 ; i-- )
4267
        {
4268
                OPNWriteReg(OPN,i      ,0);
4269
                OPNWriteReg(OPN,i|0x100,0);
4270
        }
4271
        for(i = 0x26 ; i >= 0x20 ; i-- ) OPNWriteReg(OPN,i,0);
4272
        /**** ADPCM work initial ****/
4273
        for( i = 0; i < 6 ; i++ )
4274
        {
4275
                F2610->adpcm[i].step      = (UINT32)((float)(1<<ADPCM_SHIFT)*((float)F2610->OPN.ST.freqbase)/3.0);
4276
                F2610->adpcm[i].now_addr  = 0;
4277
                F2610->adpcm[i].now_step  = 0;
4278
                F2610->adpcm[i].start     = 0;
4279
                F2610->adpcm[i].end       = 0;
4280
                /* F2610->adpcm[i].delta     = 21866; */
4281
                F2610->adpcm[i].vol_mul   = 0;
4282
                F2610->adpcm[i].pan       = &OPN->out_adpcm[OUTD_CENTER]; /* default center */
4283
                F2610->adpcm[i].flagMask  = 1<<i;
4284
                F2610->adpcm[i].flag      = 0;
4285
                F2610->adpcm[i].adpcm_acc = 0;
4286
                F2610->adpcm[i].adpcm_step= 0;
4287
                F2610->adpcm[i].adpcm_out = 0;
4288
        }
4289
        F2610->adpcmTL = 0x3f;
4290
 
4291
        F2610->adpcm_arrivedEndAddress = 0;
4292
 
4293
        /* DELTA-T unit */
4294
        DELTAT->freqbase = OPN->ST.freqbase;
4295
        DELTAT->output_pointer = OPN->out_delta;
4296
        DELTAT->portshift = 8;      /* allways 8bits shift */
4297
        DELTAT->output_range = 1<<23;
4298
        YM_DELTAT_ADPCM_Reset(DELTAT,OUTD_CENTER,YM_DELTAT_EMULATION_MODE_YM2610);
4299
}
4300
 
4301
/* YM2610 write */
4302
/* n = number  */
4303
/* a = address */
4304
/* v = value   */
4305
int ym2610_write(void *chip, int a, UINT8 v)
4306
{
4307
        YM2610 *F2610 = (YM2610 *)chip;
4308
        FM_OPN *OPN   = &F2610->OPN;
4309
        int addr;
4310
        int ch;
4311
 
4312
        v &= 0xff;  /* adjust to 8 bit bus */
4313
 
4314
        switch( a&3 )
4315
        {
4316
        case 0: /* address port 0 */
4317
                OPN->ST.address = v;
4318
                F2610->addr_A1 = 0;
4319
 
4320
                /* Write register to SSG emulator */
4321
                if( v < 16 ) (*OPN->ST.SSG->write)(OPN->ST.param,0,v);
4322
                break;
4323
 
4324
        case 1: /* data port 0    */
4325
                if (F2610->addr_A1 != 0)
4326
                        break;  /* verified on real YM2608 */
4327
 
4328
                addr = OPN->ST.address;
4329
                F2610->REGS[addr] = v;
4330
                switch(addr & 0xf0)
4331
                {
4332
                case 0x00:  /* SSG section */
4333
                        /* Write data to SSG emulator */
4334
                        (*OPN->ST.SSG->write)(OPN->ST.param,a,v);
4335
                        break;
4336
                case 0x10: /* DeltaT ADPCM */
4337
                        ym2610_update_req(OPN->ST.param);
4338
 
4339
                        switch(addr)
4340
                        {
4341
                        case 0x10:  /* control 1 */
4342
                        case 0x11:  /* control 2 */
4343
                        case 0x12:  /* start address L */
4344
                        case 0x13:  /* start address H */
4345
                        case 0x14:  /* stop address L */
4346
                        case 0x15:  /* stop address H */
4347
 
4348
                        case 0x19:  /* delta-n L */
4349
                        case 0x1a:  /* delta-n H */
4350
                        case 0x1b:  /* volume */
4351
                                {
4352
                                        YM_DELTAT_ADPCM_Write(&F2610->deltaT,addr-0x10,v);
4353
                                }
4354
                                break;
4355
 
4356
                        case 0x1c: /*  FLAG CONTROL : Extend Status Clear/Mask */
4357
                                {
4358
                                        UINT8 statusmask = ~v;
4359
                                        /* set arrived flag mask */
4360
                                        for(ch=0;ch<6;ch++)
4361
                                                F2610->adpcm[ch].flagMask = statusmask&(1<<ch);
4362
 
4363
                                        F2610->deltaT.status_change_EOS_bit = statusmask & 0x80;    /* status flag: set bit7 on End Of Sample */
4364
 
4365
                                        /* clear arrived flag */
4366
                                        F2610->adpcm_arrivedEndAddress &= statusmask;
4367
                                }
4368
                                break;
4369
 
4370
                        default:
4371
                                logerror("YM2610: write to unknown deltat register %02x val=%02x\n",addr,v);
4372
                                break;
4373
                        }
4374
 
4375
                        break;
4376
                case 0x20:  /* Mode Register */
4377
                        ym2610_update_req(OPN->ST.param);
4378
                        OPNWriteMode(OPN,addr,v);
4379
                        break;
4380
                default:    /* OPN section */
4381
                        ym2610_update_req(OPN->ST.param);
4382
                        /* write register */
4383
                        OPNWriteReg(OPN,addr,v);
4384
                }
4385
                break;
4386
 
4387
        case 2: /* address port 1 */
4388
                OPN->ST.address = v;
4389
                F2610->addr_A1 = 1;
4390
                break;
4391
 
4392
        case 3: /* data port 1    */
4393
                if (F2610->addr_A1 != 1)
4394
                        break;  /* verified on real YM2608 */
4395
 
4396
                ym2610_update_req(OPN->ST.param);
4397
                addr = OPN->ST.address;
4398
                F2610->REGS[addr | 0x100] = v;
4399
                if( addr < 0x30 )
4400
                        /* 100-12f : ADPCM A section */
4401
                        FM_ADPCMAWrite(F2610,addr,v);
4402
                else
4403
                        OPNWriteReg(OPN,addr | 0x100,v);
4404
        }
4405
        return OPN->ST.irq;
4406
}
4407
 
4408
UINT8 ym2610_read(void *chip,int a)
4409
{
4410
        YM2610 *F2610 = (YM2610 *)chip;
4411
        int addr = F2610->OPN.ST.address;
4412
        UINT8 ret = 0;
4413
 
4414
        switch( a&3)
4415
        {
4416
        case 0: /* status 0 : YM2203 compatible */
4417
                ret = FM_STATUS_FLAG(&F2610->OPN.ST) & 0x83;
4418
                break;
4419
        case 1: /* data 0 */
4420
                if( addr < 16 ) ret = (*F2610->OPN.ST.SSG->read)(F2610->OPN.ST.param);
4421
                if( addr == 0xff ) ret = 0x01;
4422
                break;
4423
        case 2: /* status 1 : ADPCM status */
4424
                /* ADPCM STATUS (arrived End Address) */
4425
                /* B,--,A5,A4,A3,A2,A1,A0 */
4426
                /* B     = ADPCM-B(DELTA-T) arrived end address */
4427
                /* A0-A5 = ADPCM-A          arrived end address */
4428
                ret = F2610->adpcm_arrivedEndAddress;
4429
                break;
4430
        case 3:
4431
                ret = 0;
4432
                break;
4433
        }
4434
        return ret;
4435
}
4436
 
4437
int ym2610_timer_over(void *chip,int c)
4438
{
4439
        YM2610 *F2610 = (YM2610 *)chip;
4440
 
4441
        if( c )
4442
        {   /* Timer B */
4443
                TimerBOver( &(F2610->OPN.ST) );
4444
        }
4445
        else
4446
        {   /* Timer A */
4447
                ym2610_update_req(F2610->OPN.ST.param);
4448
                /* timer update */
4449
                TimerAOver( &(F2610->OPN.ST) );
4450
                /* CSM mode key,TL controll */
4451
                if( F2610->OPN.ST.mode & 0x80 )
4452
                {   /* CSM mode total level latch and auto key on */
4453
                        CSMKeyControll( F2610->OPN.type, &(F2610->CH[2]) );
4454
                }
4455
        }
4456
        return F2610->OPN.ST.irq;
4457
}
4458
 
4459
#endif /* (BUILD_YM2610||BUILD_YM2610B) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.