-
Notifications
You must be signed in to change notification settings - Fork 3
/
playcfg.cpp
754 lines (679 loc) · 24.1 KB
/
playcfg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
#include <string.h>
#include <vector>
#include <string>
#ifdef _MSC_VER
#define stricmp _stricmp
#define strnicmp _strnicmp
#else
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif
#include <stdtype.h>
#include <player/playerbase.hpp>
#include <player/vgmplayer.hpp>
#include <player/playera.hpp>
extern "C"
{
#include <emu/SoundDevs.h>
// libvgm-emu headers for configuration
#include <emu/EmuCores.h>
#include <emu/EmuStructs.h> // for DEVRI_SRMODE_* constants
#include <emu/cores/2612intf.h>
#include <emu/cores/ayintf.h>
#include <emu/cores/gb.h>
#include <emu/cores/nesintf.h>
#include <emu/cores/okim6258.h>
#include <emu/cores/scsp.h>
#include <emu/cores/c352.h>
#include "ini_func.h"
}
#include "playcfg.hpp"
struct ChipCfgSectDef
{
UINT8 chipType;
const char* entryName;
};
//#define BIT_MASK(startBit, bitCnt) (((1 << bitCnt) - 1) << startBit)
static inline UINT32 MulDivRoundU32(UINT32 val, UINT32 mul, UINT32 div);
static inline UINT32 Str2FCC(const std::string& fcc);
static inline std::string FCC2Str(UINT32 fcc);
static UINT32 ReadIniDef_Integer(const char* section, const char* key, UINT32 default);
static INT16 ReadIniDef_SIntSht(const char* section, const char* key, INT16 default);
static UINT8 ReadIniDef_IntByte(const char* section, const char* key, UINT8 default);
static bool ReadIniDef_Boolean(const char* section, const char* key, bool default);
static float ReadIniDef_Float(const char* section, const char* key, float default);
UINT32 EmuTypeNum2CoreFCC(UINT8 chipType, UINT8 emuType, bool* isSubType);
void LoadConfiguration(PluginConfig& pCfg, const char* iniFileName);
static void LoadCfg_General(GeneralOptions& opts);
static void LoadCfg_ChipSection(ChipOptions& opts, const char* chipName);
void SaveConfiguration(const PluginConfig& pCfg, const char* iniFileName);
static void SaveCfg_General(const GeneralOptions& opts);
static void SaveCfg_ChipSection(const ChipOptions& opts, const char* chipName);
void ApplyCfg_General(PlayerA& player, const GeneralOptions& opts);
void ApplyCfg_Chip(PlayerA& player, const GeneralOptions& gOpts, const ChipOptions& cOpts);
// We use a hardcoded list of sound chips here, to ensure that renaming a sound chip in libvgm
// does not discard the previous configuration.
static const ChipCfgSectDef CFG_CHIP_LIST[] =
{
{ DEVID_SN76496, "SN76496"},
{ DEVID_YM2413, "YM2413"},
{ DEVID_YM2612, "YM2612"},
{ DEVID_YM2151, "YM2151"},
{ DEVID_SEGAPCM, "SegaPCM"},
{ DEVID_RF5C68, "RF5C68"},
{ DEVID_YM2203, "YM2203"},
{ DEVID_YM2608, "YM2608"},
{ DEVID_YM2610, "YM2610"},
{ DEVID_YM3812, "YM3812"},
{ DEVID_YM3526, "YM3526"},
{ DEVID_Y8950, "Y8950"},
{ DEVID_YMF262, "YMF262"},
{ DEVID_YMF278B, "YMF278B"},
{ DEVID_YMF271, "YMF271"},
{ DEVID_YMZ280B, "YMZ280B"},
{ DEVID_32X_PWM, "PWM"},
{ DEVID_AY8910 , "AY8910"},
{ DEVID_GB_DMG, "GameBoy"},
{ DEVID_NES_APU, "NES APU"},
{ DEVID_YMW258, "YMW258"},
{ DEVID_uPD7759, "uPD7759"},
{ DEVID_OKIM6258, "OKIM6258"},
{ DEVID_OKIM6295, "OKIM6295"},
{ DEVID_K051649, "K051649"},
{ DEVID_K054539, "K054539"},
{ DEVID_C6280, "HuC6280"},
{ DEVID_C140, "C140"},
{ DEVID_C219, "C219"},
{ DEVID_K053260, "K053260"},
{ DEVID_POKEY, "Pokey"},
{ DEVID_QSOUND, "QSound"},
{ DEVID_SCSP, "SCSP"},
{ DEVID_WSWAN, "WSwan"},
{ DEVID_VBOY_VSU, "VSU"},
{ DEVID_SAA1099, "SAA1099"},
{ DEVID_ES5503, "ES5503"},
{ DEVID_ES5506, "ES5506"},
{ DEVID_X1_010, "X1-010"},
{ DEVID_C352, "C352"},
{ DEVID_GA20, "GA20"},
{ DEVID_MIKEY, "Mikey"},
};
static const size_t CFG_CHIP_COUNT = sizeof(CFG_CHIP_LIST) / sizeof(CFG_CHIP_LIST[0]);
static inline UINT32 MulDivRoundU32(UINT32 val, UINT32 mul, UINT32 div)
{
return (UINT32)(((UINT64)val * mul + (div / 2)) / div);
}
static inline UINT32 Str2FCC(const std::string& fcc)
{
UINT8 buf[4];
strncpy((char*)buf, fcc.c_str(), 4);
return (buf[0] << 24) | (buf[1] << 16) |
(buf[2] << 8) | (buf[3] << 0);
}
static inline std::string FCC2Str(UINT32 fcc)
{
std::string result(4, '\0');
result[0] = (char)((fcc >> 24) & 0xFF);
result[1] = (char)((fcc >> 16) & 0xFF);
result[2] = (char)((fcc >> 8) & 0xFF);
result[3] = (char)((fcc >> 0) & 0xFF);
return result;
}
static UINT32 ReadIniDef_Integer(const char* section, const char* key, UINT32 default)
{
ReadIni_Integer(section, key, &default);
return default;
}
static INT16 ReadIniDef_SIntSht(const char* section, const char* key, INT16 default)
{
ReadIni_SIntSht(section, key, &default);
return default;
}
static UINT8 ReadIniDef_IntByte(const char* section, const char* key, UINT8 default)
{
ReadIni_IntByte(section, key, &default);
return default;
}
static bool ReadIniDef_Boolean(const char* section, const char* key, bool default)
{
ReadIni_Boolean(section, key, &default);
return default;
}
static float ReadIniDef_Float(const char* section, const char* key, float default)
{
ReadIni_Float(section, key, &default);
return default;
}
UINT32 EmuTypeNum2CoreFCC(UINT8 chipType, UINT8 emuType, bool* isSubType)
{
if (isSubType != NULL)
*isSubType = false;
switch(chipType)
{
case DEVID_SN76496:
if (emuType == 0)
return FCC_MAME;
else if (emuType == 1)
return FCC_MAXM;
break;
case DEVID_YM2413:
if (emuType == 0)
return FCC_EMU_;
else if (emuType == 1)
return FCC_MAME;
else if (emuType == 2)
return FCC_NUKE;
break;
case DEVID_YM2612:
if (emuType == 0)
return FCC_GPGX;
else if (emuType == 1)
return FCC_NUKE;
else if (emuType == 2)
return FCC_GENS;
break;
case DEVID_YM2151:
if (emuType == 0)
return FCC_MAME;
else if (emuType == 1)
return FCC_NUKE;
break;
case DEVID_YM2203:
case DEVID_YM2608:
case DEVID_YM2610:
if (isSubType != NULL)
*isSubType = true;
if (emuType == 0)
return FCC_EMU_;
else if (emuType == 1)
return FCC_MAME;
break;
case DEVID_YM3812:
if (emuType == 0)
return FCC_ADLE;
else if (emuType == 1)
return FCC_MAME;
else if (emuType == 2)
return FCC_NUKE;
break;
case DEVID_YMF262:
if (emuType == 0)
return FCC_ADLE;
else if (emuType == 1)
return FCC_MAME;
else if (emuType == 2)
return FCC_NUKE;
break;
case DEVID_AY8910:
if (emuType == 0)
return FCC_EMU_;
else if (emuType == 1)
return FCC_MAME;
break;
case DEVID_NES_APU:
if (emuType == 0)
return FCC_NSFP;
else if (emuType == 1)
return FCC_MAME;
break;
case DEVID_C6280:
if (emuType == 0)
return FCC_OOTK;
else if (emuType == 1)
return FCC_MAME;
break;
case DEVID_QSOUND:
if (emuType == 0)
return FCC_CTR_;
else if (emuType == 1)
return FCC_MAME;
break;
case DEVID_SAA1099:
if (emuType == 0)
return FCC_VBEL;
else if (emuType == 1)
return FCC_MAME;
break;
} // end switch(chipType) for emuCore
return 0x00;
}
void LoadConfiguration(PluginConfig& pCfg, const char* iniFileName)
{
size_t curChp;
size_t curCI; // chip instance
Ini_SetFilePath(iniFileName);
LoadCfg_General(pCfg.genOpts);
pCfg.chipOpts.resize(CFG_CHIP_COUNT);
for (curChp = 0; curChp < CFG_CHIP_COUNT; curChp ++)
{
const ChipCfgSectDef& cfgChip = CFG_CHIP_LIST[curChp];
for (curCI = 0; curCI < 2; curCI ++)
{
ChipOptions& opts = pCfg.chipOpts[curChp][curCI];
opts.chipType = cfgChip.chipType;
opts.chipInstance = (UINT8)curCI;
LoadCfg_ChipSection(opts, cfgChip.entryName);
}
}
return;
}
static void LoadCfg_General(GeneralOptions& opts)
{
char tempStr[0x80];
opts.immediateUpdate = ReadIniDef_Boolean("General", "ImmdtUpdate", false);
opts.noInfoCache = ReadIniDef_Boolean("General", "NoInfoCache", false);
opts.fileTypes.vgm = ReadIniDef_Boolean("General", "FormatEnable_VGM", true);
opts.fileTypes.s98 = ReadIniDef_Boolean("General", "FormatEnable_S98", false);
opts.fileTypes.dro = ReadIniDef_Boolean("General", "FormatEnable_DRO", false);
opts.fileTypes.gym = ReadIniDef_Boolean("General", "FormatEnable_GYM", false);
opts.smplRate = ReadIniDef_Integer("Playback", "SampleRate", 44100);
opts.smplBits = ReadIniDef_Integer("Playback", "SampleBits", 16);
opts.fadeTime = ReadIniDef_Integer("Playback", "FadeTime", 5000);
opts.pauseTime_jingle = ReadIniDef_Integer("Playback", "PauseNoLoop", 1000);
opts.pauseTime_loop = ReadIniDef_Integer("Playback", "PauseLoop", 0);
opts.hardStopOld = ReadIniDef_IntByte("Playback", "HardStopOld", 0);
opts.volume = ReadIniDef_Float ("Playback", "Volume", 1.0);
opts.pbSpeed = ReadIniDef_Float ("Playback", "PlaybackSpeed", 1.0);
opts.maxLoops = ReadIniDef_Integer("Playback", "MaxLoops", 2);
opts.pbRate = ReadIniDef_Integer("Playback", "PlaybackRate", 0);
opts.resmplMode = ReadIniDef_IntByte("Playback", "ResamplMode", 0);
opts.chipSmplMode = ReadIniDef_IntByte("Playback", "ChipSmplMode", 0);
opts.chipSmplRate = ReadIniDef_Integer("Playback", "ChipSmplRate", 0);
opts.pseudoSurround = ReadIniDef_Boolean("Playback", "SurroundSnd", false);
strcpy(tempStr, "%t (%g) - %a");
ReadIni_String ("Tags", "TitleFormat", tempStr, 0x80); opts.titleFormat = tempStr;
opts.preferJapTag = ReadIniDef_Boolean("Tags", "UseJapTags", false);
opts.appendFM2413 = ReadIniDef_Boolean("Tags", "AppendFM2413", false);
opts.showDevCore = ReadIniDef_Boolean("Tags", "ShowChipCore", false);
opts.trimWhitespace = ReadIniDef_Boolean("Tags", "TrimWhitespc", true);
opts.stdSeparators = ReadIniDef_Boolean("Tags", "SeparatorStd", true);
opts.fidTagFallback = ReadIniDef_Boolean("Tags", "TagFallback", false);
opts.mediaLibFileType = ReadIniDef_Integer("Tags", "MLFileType", 0);
opts.resetMuting = ReadIniDef_Boolean("Muting", "Reset", true);
return;
}
static void LoadCfg_ChipSection(ChipOptions& opts, const char* chipName)
{
const UINT8 chipType = opts.chipType;
char tempStr[0x80];
// parse muting options
memset(&opts.muteMask[0], 0x00, sizeof(opts.muteMask));
memset(&opts.panMask[0][0], 0x00, sizeof(opts.panMask));
sprintf(tempStr, "%s #%u", chipName, opts.chipInstance);
opts.muteMask[0] = ReadIniDef_Integer("Muting", tempStr, 0);
sprintf(tempStr, "%s #%u_%u", chipName, opts.chipInstance, 2);
opts.muteMask[1] = ReadIniDef_Integer("Muting", tempStr, 0);
#if 0
{
UINT32 ayMute;
sprintf(tempStr, "%s #%u_%u", chipName, opts.chipInstance, 3);
ayMute = ReadIniDef_Integer("Muting", tempStr, 0);
if (chipType == DEVID_YM2203 || chipType == DEVID_YM2608 || chipType == DEVID_YM2610)
{
opts.muteMask[0] |= (opts.muteMask[1] << 6); // move ADPCM mute mask into primary array
opts.muteMask[1] = ayMute;
}
}
#endif
{
// TODO: don't hardcode this
opts.chnCnt[0] = 0;
opts.chnCnt[1] = 0;
if (chipType == DEVID_SN76496)
opts.chnCnt[0] = 4;
else if (chipType == DEVID_YM2413)
opts.chnCnt[0] = 9 + 5;
else if (chipType == DEVID_AY8910)
opts.chnCnt[0] = 3;
else if (chipType == DEVID_YM2203 || chipType == DEVID_YM2608 || chipType == DEVID_YM2610)
opts.chnCnt[1] = 3;
for (UINT8 subChip = 0; subChip < 2; subChip++)
{
int digits = (opts.chnCnt[subChip] < 10) ? 1 : 2;
for (UINT8 curChn = 0; curChn < opts.chnCnt[subChip]; curChn ++)
{
if (subChip == 0)
sprintf(tempStr, "%s #%u %0*u", chipName, opts.chipInstance, digits, curChn);
else
sprintf(tempStr, "%s/%u #%u %0*u", chipName, subChip, opts.chipInstance, digits, curChn);
opts.panMask[subChip][curChn] = ReadIniDef_SIntSht("Panning", tempStr, 0);
}
}
}
sprintf(tempStr, "%s #%u All", chipName, opts.chipInstance);
bool chipMute = ReadIniDef_Boolean("Muting", tempStr, false);
opts.chipDisable = chipMute ? 0xFF : 0x00;
{
UINT8 emuType = ReadIniDef_IntByte("EmuCore", chipName, /*0xFF*/0);
opts.emuType = emuType;
if (emuType != 0xFF)
{
// select emuCore based on number
bool subType;
UINT32 coreFCC = EmuTypeNum2CoreFCC(opts.chipType, emuType, &subType);
if (subType)
opts.emuCoreSub = coreFCC;
else
opts.emuCore = coreFCC;
}
}
{
std::string coreStr;
tempStr[0] = '\0';
ReadIni_String ("EmuCore", chipName, tempStr, 0x10); coreStr = tempStr;
// ignore empty strings - and the ones with only 1 character (old-style number)
if (coreStr.size() > 1)
opts.emuCore = Str2FCC(coreStr);
tempStr[0] = '\0';
ReadIni_String ("EmuCoreSub", chipName, tempStr, 0x10); coreStr = tempStr;
if (! coreStr.empty())
opts.emuCoreSub = Str2FCC(coreStr);
}
// chip-specific options
switch(chipType)
{
case DEVID_YM2612:
sprintf(tempStr, "%s PseudoStereo", chipName);
opts.addOpts = ReadIniDef_Integer("ChipOpts", tempStr, 0) ? OPT_YM2612_PSEUDO_STEREO : 0x00;
sprintf(tempStr, "%s Gens DACHighpass", chipName);
opts.addOpts |= ReadIniDef_Integer("ChipOpts", tempStr, 0) ? OPT_YM2612_DAC_HIGHPASS : 0x00;
sprintf(tempStr, "%s Gens SSG-EG", chipName);
opts.addOpts |= ReadIniDef_Integer("ChipOpts", tempStr, 0) ? OPT_YM2612_SSGEG : 0x00;
sprintf(tempStr, "%s NukedType", chipName);
opts.addOpts |= (ReadIniDef_Integer("ChipOpts", tempStr, 0) & 0x03) << 4;
break;
case DEVID_YM2203:
case DEVID_YM2608:
case DEVID_YM2610:
//sprintf(tempStr, "%s Disable AY", chipName);
//opts.chipDisable |= ReadIniDef_Integer("ChipOpts", tempStr, 0) ? 0x02 : 0x00;
break;
case DEVID_YMF278B:
//sprintf(tempStr, "%s Disable FM", chipName);
//opts.chipDisable |= ReadIniDef_Integer("ChipOpts", tempStr, 0) ? 0x02 : 0x00;
break;
case DEVID_AY8910:
sprintf(tempStr, "%s PCM3chDetect", chipName);
opts.addOpts = ReadIniDef_Integer("ChipOpts", tempStr, 1) ? OPT_AY8910_PCM3CH_DETECT : 0x00;
break;
case DEVID_GB_DMG:
sprintf(tempStr, "%s BoostWaveChn", chipName);
opts.addOpts = ReadIniDef_Integer("ChipOpts", tempStr, 1) ? OPT_GB_DMG_BOOST_WAVECH : 0x00;
sprintf(tempStr, "%s NoWaveCorrupt", chipName);
opts.addOpts = ReadIniDef_Integer("ChipOpts", tempStr, 1) ? OPT_GB_DMG_NO_WAVE_CORRUPT : 0x00;
break;
case DEVID_NES_APU:
sprintf(tempStr, "%s Shared Opts", chipName);
opts.addOpts = (ReadIniDef_Integer("ChipOpts", tempStr, 0x03) & 0x03) << 0;
sprintf(tempStr, "%s APU Opts", chipName);
opts.addOpts |= (ReadIniDef_Integer("ChipOpts", tempStr, 0x01) & 0x01) << 2;
sprintf(tempStr, "%s DMC Opts", chipName);
opts.addOpts |= (ReadIniDef_Integer("ChipOpts", tempStr, 0x3B) & 0x3F) << 4;
sprintf(tempStr, "%s FDS Opts", chipName);
opts.addOpts |= (ReadIniDef_Integer("ChipOpts", tempStr, 0x00) & 0x03) << 10;
break;
case DEVID_OKIM6258:
sprintf(tempStr, "%s Internal 10bit", chipName);
opts.addOpts = ReadIniDef_Integer("ChipOpts", tempStr, 0) ? OPT_OKIM6258_FORCE_12BIT : 0x00;
break;
case DEVID_SCSP:
sprintf(tempStr, "%s Bypass DSP", chipName);
opts.addOpts = ReadIniDef_Integer("ChipOpts", tempStr, 1) ? OPT_SCSP_BYPASS_DSP : 0x00;
break;
case DEVID_C352:
sprintf(tempStr, "%s Disable Rear", chipName);
opts.addOpts = ReadIniDef_Integer("ChipOpts", tempStr, 0) ? OPT_C352_MUTE_REAR : 0x00;
break;
} // end switch(chipType) for chip-specific options
return;
}
void SaveConfiguration(const PluginConfig& pCfg, const char* iniFileName)
{
size_t curChp;
size_t curCI; // chip instance
Ini_SetFilePath(iniFileName);
SaveCfg_General(pCfg.genOpts);
for (curChp = 0; curChp < pCfg.chipOpts.size(); curChp ++)
{
const ChipCfgSectDef& cfgChip = CFG_CHIP_LIST[curChp];
for (curCI = 0; curCI < 2; curCI ++)
{
const ChipOptions& opts = pCfg.chipOpts[curChp][curCI];
if (opts.chipType == 0xFF)
continue;
SaveCfg_ChipSection(opts, cfgChip.entryName);
}
}
return;
}
static void SaveCfg_General(const GeneralOptions& opts)
{
WriteIni_Boolean("General", "ImmdtUpdate", opts.immediateUpdate);
WriteIni_Boolean("General", "NoInfoCache", opts.noInfoCache);
WriteIni_Boolean("General", "FormatEnable_VGM", opts.fileTypes.vgm);
WriteIni_Boolean("General", "FormatEnable_S98", opts.fileTypes.s98);
WriteIni_Boolean("General", "FormatEnable_DRO", opts.fileTypes.dro);
WriteIni_Boolean("General", "FormatEnable_GYM", opts.fileTypes.gym);
WriteIni_Integer("Playback", "SampleRate", opts.smplRate);
WriteIni_Integer("Playback", "SampleBits", opts.smplBits);
WriteIni_Integer("Playback", "FadeTime", opts.fadeTime);
WriteIni_Integer("Playback", "PauseNoLoop", opts.pauseTime_jingle);
WriteIni_Integer("Playback", "PauseLoop", opts.pauseTime_loop);
WriteIni_Integer("Playback", "HardStopOld", opts.hardStopOld);
WriteIni_Float ("Playback", "Volume", (float)opts.volume);
WriteIni_Float ("Playback", "PlaybackSpeed", (float)opts.pbSpeed);
WriteIni_Integer("Playback", "MaxLoops", opts.maxLoops);
WriteIni_Integer("Playback", "PlaybackRate", opts.pbRate);
WriteIni_Integer("Playback", "ResamplMode", opts.resmplMode);
WriteIni_Integer("Playback", "ChipSmplMode", opts.chipSmplMode);
WriteIni_Integer("Playback", "ChipSmplRate", opts.chipSmplRate);
WriteIni_Boolean("Playback", "SurroundSnd", opts.pseudoSurround);
WriteIni_String ("Tags", "TitleFormat", opts.titleFormat.c_str());
WriteIni_Boolean("Tags", "UseJapTags", opts.preferJapTag);
WriteIni_Boolean("Tags", "AppendFM2413", opts.appendFM2413);
WriteIni_Boolean("Tags", "ShowChipCore", opts.showDevCore);
WriteIni_Boolean("Tags", "TrimWhitespc", opts.trimWhitespace);
WriteIni_Boolean("Tags", "SeparatorStd", opts.stdSeparators);
WriteIni_Boolean("Tags", "TagFallback", opts.fidTagFallback);
WriteIni_XInteger("Tags", "MLFileType", opts.mediaLibFileType);
WriteIni_Boolean("Muting", "Reset", opts.resetMuting);
return;
}
static void SaveCfg_ChipSection(const ChipOptions& opts, const char* chipName)
{
const UINT8 chipType = opts.chipType;
char tempStr[0x80];
WriteIni_Integer("EmuCore", chipName, opts.emuType);
//WriteIni_String ("EmuCore", chipName, FCC2Str(opts.emuCore).c_str());
//WriteIni_String ("EmuCoreSub", chipName, FCC2Str(opts.emuCoreSub).c_str());
sprintf(tempStr, "%s #%u All", chipName, opts.chipInstance);
WriteIni_Boolean("Muting", tempStr, !!opts.chipDisable);
sprintf(tempStr, "%s #%u", chipName, opts.chipInstance);
WriteIni_XInteger("Muting", tempStr, opts.muteMask[0]);
if (chipType == DEVID_YM2203 || chipType == DEVID_YM2608 || chipType == DEVID_YM2610 ||
chipType == DEVID_YMF278B)
{
sprintf(tempStr, "%s #%u_%u", chipName, opts.chipInstance, 2);
WriteIni_XInteger("Muting", tempStr, opts.muteMask[1]);
}
{
for (UINT8 subChip = 0; subChip < 2; subChip++)
{
int digits = (opts.chnCnt[subChip] < 10) ? 1 : 2;
for (UINT8 curChn = 0; curChn < opts.chnCnt[subChip]; curChn ++)
{
if (subChip == 0)
sprintf(tempStr, "%s #%u %0*u", chipName, opts.chipInstance, digits, curChn);
else
sprintf(tempStr, "%s/%u #%u %0*u", chipName, subChip, opts.chipInstance, digits, curChn);
WriteIni_SInteger("Panning", tempStr, opts.panMask[subChip][curChn]);
}
}
}
if (opts.chipInstance > 0)
return; // the remaining options are global
// chip-specific options
switch(chipType)
{
case DEVID_YM2612:
sprintf(tempStr, "%s PseudoStereo", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_YM2612_PSEUDO_STEREO));
sprintf(tempStr, "%s Gens DACHighpass", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_YM2612_DAC_HIGHPASS));
sprintf(tempStr, "%s Gens SSG-EG", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_YM2612_SSGEG));
sprintf(tempStr, "%s NukedType", chipName);
WriteIni_XInteger("ChipOpts", tempStr, (opts.addOpts >> 4) & 0x03);
break;
case DEVID_YM2203:
case DEVID_YM2608:
case DEVID_YM2610:
//sprintf(tempStr, "%s Disable AY", chipName);
//WriteIni_XInteger("ChipOpts", tempStr, !!(opts.chipDisable & 0x02));
break;
case DEVID_YMF278B:
//sprintf(tempStr, "%s Disable FM", chipName);
//WriteIni_XInteger("ChipOpts", tempStr, !!(opts.chipDisable & 0x02));
break;
case DEVID_AY8910:
sprintf(tempStr, "%s PCM3chDetect", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_AY8910_PCM3CH_DETECT));
break;
case DEVID_GB_DMG:
sprintf(tempStr, "%s BoostWaveChn", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_GB_DMG_BOOST_WAVECH));
sprintf(tempStr, "%s NoWaveCorrupt", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_GB_DMG_NO_WAVE_CORRUPT));
break;
case DEVID_NES_APU:
sprintf(tempStr, "%s Shared Opts", chipName);
WriteIni_XInteger("ChipOpts", tempStr, (opts.addOpts >> 0) & 0x03);
sprintf(tempStr, "%s APU Opts", chipName);
WriteIni_XInteger("ChipOpts", tempStr, (opts.addOpts >> 2) & 0x01);
sprintf(tempStr, "%s DMC Opts", chipName);
WriteIni_XInteger("ChipOpts", tempStr, (opts.addOpts >> 4) & 0x3F);
sprintf(tempStr, "%s FDS Opts", chipName);
WriteIni_XInteger("ChipOpts", tempStr, (opts.addOpts >> 10) & 0x03);
break;
case DEVID_OKIM6258:
sprintf(tempStr, "%s Internal 10bit", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_OKIM6258_FORCE_12BIT));
break;
case DEVID_SCSP:
sprintf(tempStr, "%s Bypass DSP", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_SCSP_BYPASS_DSP));
break;
case DEVID_C352:
sprintf(tempStr, "%s Disable Rear", chipName);
WriteIni_XInteger("ChipOpts", tempStr, !!(opts.addOpts & OPT_C352_MUTE_REAR));
break;
} // end switch(chipType) for chip-specific options
return;
}
void ApplyCfg_General(PlayerA& player, const GeneralOptions& opts, bool noLiveOpts)
{
const std::vector<PlayerBase*>& plrs = player.GetRegisteredPlayers();
size_t curPlr;
UINT8 retVal;
PlayerA::Config pwCfg;
pwCfg = player.GetConfiguration();
pwCfg.chnInvert = opts.pseudoSurround ? 0x02 : 0x00;
pwCfg.loopCount = opts.maxLoops;
if (! noLiveOpts)
{
player.SetSampleRate(opts.smplRate);
pwCfg.masterVol = (INT32)(0x10000 * opts.volume + 0.5);
pwCfg.fadeSmpls = MulDivRoundU32(opts.fadeTime, opts.smplRate, 1000);
pwCfg.endSilenceSmpls = MulDivRoundU32(opts.pauseTime_jingle, opts.smplRate, 1000);
pwCfg.pbSpeed = opts.pbSpeed;
}
player.SetConfiguration(pwCfg);
for (curPlr = 0; curPlr < plrs.size(); curPlr ++)
{
PlayerBase* pBase = plrs[curPlr];
switch(pBase->GetPlayerType())
{
case FCC_VGM:
{
VGMPlayer* vgmplay = dynamic_cast<VGMPlayer*>(pBase);
VGM_PLAY_OPTIONS vpOpts;
retVal = vgmplay->GetPlayerOptions(vpOpts);
if (retVal)
break;
vpOpts.playbackHz = opts.pbRate;
vpOpts.hardStopOld = opts.hardStopOld;
vgmplay->SetPlayerOptions(vpOpts);
}
break;
}
}
return;
}
static UINT8 ConvertChipSmplModeOption(UINT8 devID, UINT8 option)
{
switch(option)
{
case 0x00: // native
return DEVRI_SRMODE_NATIVE;
case 0x01: // highest sampling rate (native/custom)
return DEVRI_SRMODE_HIGHEST;
case 0x02: // custom sample rate
return DEVRI_SRMODE_CUSTOM;
case 0x03: // native for FM, highest for others
{
bool isFM = false;
isFM = (devID == DEVID_YM3526 || devID == DEVID_Y8950 || devID == DEVID_YM3812 ||
devID == DEVID_YM2413 || devID == DEVID_YMF262 || devID == DEVID_YM2151 ||
devID == DEVID_YM2203 || devID == DEVID_YM2608 || devID == DEVID_YM2610 || devID == DEVID_YM2612);
return isFM ? DEVRI_SRMODE_NATIVE : DEVRI_SRMODE_HIGHEST;
}
default:
return 0x00;
}
}
void ApplyCfg_Chip(PlayerA& player, const GeneralOptions& gOpts, const ChipOptions& cOpts)
{
const std::vector<PlayerBase*>& plrs = player.GetRegisteredPlayers();
size_t curPlr;
UINT8 retVal;
UINT32 devID;
if (cOpts.chipInstance != 0xFF)
devID = PLR_DEV_ID(cOpts.chipType, cOpts.chipInstance);
else
devID = PLR_DEV_ID(cOpts.chipType, 0x00);
for (curPlr = 0; curPlr < plrs.size(); curPlr ++)
{
PlayerBase* pBase = plrs[curPlr];
PLR_DEV_OPTS devOpts;
UINT8 curInst;
UINT8 curChn;
retVal = pBase->GetDeviceOptions(devID, devOpts);
if (retVal)
continue; // this player doesn't support this chip
devOpts.emuCore[0] = cOpts.emuCore;
devOpts.emuCore[1] = cOpts.emuCoreSub;
devOpts.srMode = ConvertChipSmplModeOption(cOpts.chipType, gOpts.chipSmplMode);
devOpts.resmplMode = gOpts.resmplMode;
devOpts.smplRate = gOpts.chipSmplRate;
devOpts.coreOpts = cOpts.addOpts;
devOpts.muteOpts.disable = cOpts.chipDisable;
for (curInst = 0; curInst < 2; curInst ++)
{
devOpts.muteOpts.chnMute[curInst] = cOpts.muteMask[curInst];
for (curChn = 0; curChn < 32; curChn ++)
devOpts.panOpts.chnPan[curInst][curChn] = cOpts.panMask[curInst][curChn];
}
//printf("Player %s: Setting chip options for chip 0x%02X, instance 0x%02X\n",
// pBase->GetPlayerName(), cOpts.chipType, cOpts.chipInstance);
if (cOpts.chipInstance != 0xFF)
{
pBase->SetDeviceOptions(devID, devOpts);
}
else
{
for (curInst = 0; curInst < 2; curInst ++)
pBase->SetDeviceOptions(PLR_DEV_ID(cOpts.chipType, curInst), devOpts);
}
}
return;
}