openMSX
YMF278.cc
Go to the documentation of this file.
1 // Based on ymf278b.c written by R. Belmont and O. Galibert
2 
3 // Improved by Valley Bell, 2018
4 // Thanks to niekniek and l_oliveira for providing recordings from OPL4 hardware.
5 // Thanks to superctr and wouterv for discussing changes.
6 //
7 // Improvements:
8 // - added TL interpolation, recordings show that internal TL levels are 0x00..0xff
9 // - fixed ADSR speeds, attack rate 15 is now instant
10 // - correct clamping of intermediate Rate Correction values
11 // - emulation of "loop glitch" (going out-of-bounds by playing a sample faster than it the loop is long)
12 // - made calculation of sample position cleaner and closer to how the HW works
13 // - increased output resolution from TL (0.375dB) to envelope (0.09375dB)
14 // - fixed volume table -6dB steps are done using bit shifts, steps in between are multiplicators
15 // - made octave -8 freeze the sample
16 // - verified that TL and envelope levels are applied separately, both go silent at -60dB
17 // - implemented pseudo-reverb and damping according to manual
18 // - made pseudo-reverb ignore Rate Correction (real hardware ignores it)
19 // - reimplemented LFO, speed exactly matches the formulas that were probably used when creating the manual
20 // - fixed LFO (tremolo) amplitude modulation
21 // - made LFO vibrato and tremolo accurate to hardware
22 //
23 // Known issues:
24 // - Octave -8 was only tested with fnum 0. Other fnum values might behave differently.
25 
26 // This class doesn't model a full YMF278b chip. Instead it only models the
27 // wave part. The FM part in modeled in YMF262 (it's almost 100% compatible,
28 // the small differences are handled in YMF262). The status register and
29 // interaction with the FM registers (e.g. the NEW2 bit) is currently handled
30 // in the MSXMoonSound class.
31 
32 #include "YMF278.hh"
33 #include "DeviceConfig.hh"
34 #include "MSXMotherBoard.hh"
35 #include "MSXException.hh"
36 #include "Math.hh"
37 #include "likely.hh"
38 #include "outer.hh"
39 #include "ranges.hh"
40 #include "serialize.hh"
41 
42 namespace openmsx {
43 
44 // envelope output entries
45 // fixed to match recordings from actual OPL4 -Valley Bell
46 constexpr int MAX_ATT_INDEX = 0x280; // makes attack phase right and also goes well with "envelope stops at -60dB"
47 constexpr int MIN_ATT_INDEX = 0;
48 constexpr int TL_SHIFT = 2; // envelope values are 4x as fine as TL levels
49 
50 constexpr unsigned LFO_SHIFT = 18; // LFO period of up to 0x40000 sample
51 constexpr unsigned LFO_PERIOD = 1 << LFO_SHIFT;
52 
53 // Envelope Generator phases
54 constexpr int EG_ATT = 4;
55 constexpr int EG_DEC = 3;
56 constexpr int EG_SUS = 2;
57 constexpr int EG_REL = 1;
58 constexpr int EG_OFF = 0;
59 // these 2 are only used in old savestates (and are converted to EG_REL on load)
60 constexpr int EG_REV = 5; // pseudo reverb
61 constexpr int EG_DMP = 6; // damp
62 
63 // Pan values, units are -3dB, i.e. 8.
64 constexpr uint8_t pan_left[16] = {
65  0, 8, 16, 24, 32, 40, 48, 255, 255, 0, 0, 0, 0, 0, 0, 0
66 };
67 constexpr uint8_t pan_right[16] = {
68  0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 48, 40, 32, 24, 16, 8
69 };
70 
71 // decay level table (3dB per step)
72 // 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)
73 static constexpr int16_t SC(int dB) { return int16_t(dB / 3 * 0x20); }
74 constexpr int16_t dl_tab[16] = {
75  SC( 0), SC( 3), SC( 6), SC( 9), SC(12), SC(15), SC(18), SC(21),
76  SC(24), SC(27), SC(30), SC(33), SC(36), SC(39), SC(42), SC(93)
77 };
78 
79 constexpr byte RATE_STEPS = 8;
80 constexpr byte eg_inc[15 * RATE_STEPS] = {
81 //cycle:0 1 2 3 4 5 6 7
82  0, 1, 0, 1, 0, 1, 0, 1, // 0 rates 00..12 0 (increment by 0 or 1)
83  0, 1, 0, 1, 1, 1, 0, 1, // 1 rates 00..12 1
84  0, 1, 1, 1, 0, 1, 1, 1, // 2 rates 00..12 2
85  0, 1, 1, 1, 1, 1, 1, 1, // 3 rates 00..12 3
86 
87  1, 1, 1, 1, 1, 1, 1, 1, // 4 rate 13 0 (increment by 1)
88  1, 1, 1, 2, 1, 1, 1, 2, // 5 rate 13 1
89  1, 2, 1, 2, 1, 2, 1, 2, // 6 rate 13 2
90  1, 2, 2, 2, 1, 2, 2, 2, // 7 rate 13 3
91 
92  2, 2, 2, 2, 2, 2, 2, 2, // 8 rate 14 0 (increment by 2)
93  2, 2, 2, 4, 2, 2, 2, 4, // 9 rate 14 1
94  2, 4, 2, 4, 2, 4, 2, 4, // 10 rate 14 2
95  2, 4, 4, 4, 2, 4, 4, 4, // 11 rate 14 3
96 
97  4, 4, 4, 4, 4, 4, 4, 4, // 12 rates 15 0, 15 1, 15 2, 15 3 for decay
98  8, 8, 8, 8, 8, 8, 8, 8, // 13 rates 15 0, 15 1, 15 2, 15 3 for attack (zero time)
99  0, 0, 0, 0, 0, 0, 0, 0, // 14 infinity rates for attack and decay(s)
100 };
101 
102 static constexpr byte O(int a) { return a * RATE_STEPS; }
103 constexpr byte eg_rate_select[64] = {
104  O(14),O(14),O(14),O(14), // inf rate
105  O( 0),O( 1),O( 2),O( 3),
106  O( 0),O( 1),O( 2),O( 3),
107  O( 0),O( 1),O( 2),O( 3),
108  O( 0),O( 1),O( 2),O( 3),
109  O( 0),O( 1),O( 2),O( 3),
110  O( 0),O( 1),O( 2),O( 3),
111  O( 0),O( 1),O( 2),O( 3),
112  O( 0),O( 1),O( 2),O( 3),
113  O( 0),O( 1),O( 2),O( 3),
114  O( 0),O( 1),O( 2),O( 3),
115  O( 0),O( 1),O( 2),O( 3),
116  O( 0),O( 1),O( 2),O( 3),
117  O( 4),O( 5),O( 6),O( 7),
118  O( 8),O( 9),O(10),O(11),
119  O(12),O(12),O(12),O(12),
120 };
121 
122 // rate 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
123 // shift 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0
124 // mask 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 0, 0, 0
125 constexpr byte eg_rate_shift[64] = {
126  12, 12, 12, 12,
127  11, 11, 11, 11,
128  10, 10, 10, 10,
129  9, 9, 9, 9,
130  8, 8, 8, 8,
131  7, 7, 7, 7,
132  6, 6, 6, 6,
133  5, 5, 5, 5,
134  4, 4, 4, 4,
135  3, 3, 3, 3,
136  2, 2, 2, 2,
137  1, 1, 1, 1,
138  0, 0, 0, 0,
139  0, 0, 0, 0,
140  0, 0, 0, 0,
141  0, 0, 0, 0,
142 };
143 
144 
145 // number of steps the LFO counter advances per sample
146 // LFO frequency (Hz) -> LFO counter steps per sample
147 static constexpr int L(double a) { return int((LFO_PERIOD * a) / 44100.0 + 0.5); }
148 constexpr int lfo_period[8] = {
149  L(0.168), // step: 1, period: 262144 samples
150  L(2.019), // step: 12, period: 21845 samples
151  L(3.196), // step: 19, period: 13797 samples
152  L(4.206), // step: 25, period: 10486 samples
153  L(5.215), // step: 31, period: 8456 samples
154  L(5.888), // step: 35, period: 7490 samples
155  L(6.224), // step: 37, period: 7085 samples
156  L(7.066), // step: 42, period: 6242 samples
157 };
158 
159 
160 // formula used by Yamaha docs:
161 // vib_depth_cents(x) = (log2(0x400 + x) - 10) * 1200
162 constexpr int16_t vib_depth[8] = {
163  0, // 0.000 cents
164  2, // 3.378 cents
165  3, // 5.065 cents
166  4, // 6.750 cents
167  6, // 10.114 cents
168  12, // 20.170 cents
169  24, // 40.106 cents
170  48, // 79.307 cents
171 };
172 
173 
174 // formula used by Yamaha docs:
175 // am_depth_db(x) = (x-1) / 0x40 * 6.0
176 // They use (x-1), because the depth is multiplied with the AM counter, which has a range of 0..0x7F.
177 // Thus the maximum attenuation with x=0x80 is (0x7F * 0x80) >> 7 = 0x7F.
178 // reversed formula:
179 // am_depth(dB) = round(dB / 6.0 * 0x40) + 1
180 constexpr uint8_t am_depth[8] = {
181  0x00, // 0.000 dB
182  0x14, // 1.781 dB
183  0x20, // 2.906 dB
184  0x28, // 3.656 dB
185  0x30, // 4.406 dB
186  0x40, // 5.906 dB
187  0x50, // 7.406 dB
188  0x80, // 11.910 dB
189 };
190 
191 
192 YMF278::Slot::Slot()
193 {
194  reset();
195 }
196 
197 // Sign extend a 4-bit value to int (32-bit)
198 // require: x in range [0..15]
199 static int sign_extend_4(int x)
200 {
201  return (x ^ 8) - 8;
202 }
203 
204 // Params: oct in [-8 .. +7]
205 // fn in [ 0 .. 1023]
206 // We want to interpret oct as a signed 4-bit number and calculate
207 // ((fn | 1024) + vib) << (5 + sign_extend_4(oct))
208 // Though in this formula the shift can go over a negative distance (in that
209 // case we should shift in the other direction).
210 static unsigned calcStep(int8_t oct, uint16_t fn, int16_t vib = 0)
211 {
212  if (oct == -8) return 0;
213  unsigned t = (fn + 1024 + vib) << (8 + oct); // use '+' iso '|' (generates slightly better code)
214  return t >> 3; // was shifted 3 positions too far
215 }
216 
217 void YMF278::Slot::reset()
218 {
219  wave = FN = OCT = TLdest = TL = pan = vib = AM = 0;
220  DL = AR = D1R = D2R = RC = RR = 0;
221  PRVB = keyon = DAMP = false;
222  stepptr = 0;
223  step = calcStep(OCT, FN);
224  bits = startaddr = loopaddr = endaddr = 0;
225  env_vol = MAX_ATT_INDEX;
226 
227  lfo_active = false;
228  lfo_cnt = 0;
229  lfo = 0;
230 
231  state = EG_OFF;
232 
233  // not strictly needed, but avoid UMR on savestate
234  pos = sample1 = sample2 = 0;
235 }
236 
237 int YMF278::Slot::compute_rate(int val) const
238 {
239  if (val == 0) {
240  return 0;
241  } else if (val == 15) {
242  return 63;
243  }
244  int res = val * 4;
245  if (RC != 15) {
246  // clamping verified with HW tests -Valley Bell
247  res += 2 * Math::clip<0, 15>(OCT + RC);
248  res += (FN & 0x200) ? 1 : 0;
249  }
250  return Math::clip<0, 63>(res);
251 }
252 
253 int YMF278::Slot::compute_decay_rate(int val) const
254 {
255  if (DAMP) {
256  // damping
257  // The manual lists these values for time and attenuation: (44100 samples/second)
258  // -12dB at 5.8ms, sample 256
259  // -48dB at 8.0ms, sample 352
260  // -72dB at 9.4ms, sample 416
261  // -96dB at 10.9ms, sample 480
262  // This results in these durations and rate values for the respective phases:
263  // 0dB .. -12dB: 256 samples (5.80ms) -> 128 samples per -6dB = rate 48
264  // -12dB .. -48dB: 96 samples (2.18ms) -> 16 samples per -6dB = rate 63
265  // -48dB .. -72dB: 64 samples (1.45ms) -> 16 samples per -6dB = rate 63
266  // -72dB .. -96dB: 64 samples (1.45ms) -> 16 samples per -6dB = rate 63
267  // Damping was verified to ignore rate correction.
268  if (env_vol < dl_tab[4]) {
269  return 48; // 0dB .. -12dB
270  } else {
271  return 63; // -12dB .. -96dB
272  }
273  }
274  if (PRVB) {
275  // pseudo reverb
276  // activated when reaching -18dB, overrides D1R/D2R/RR with reverb rate 5
277  //
278  // The manual is actually a bit unclear and just says "RATE=5",
279  // referring to the D1R/D2R/RR register value. However, later
280  // pages use "RATE" to refer to the "internal" rate, which is
281  // (register * 4) + rate correction. HW recordings prove that
282  // Rate Correction is ignored, so pseudo reverb just sets the
283  // "internal" rate to a value of 4*5 = 20.
284  if (env_vol >= dl_tab[6]) {
285  return 20;
286  }
287  }
288  return compute_rate(val);
289 }
290 
291 int16_t YMF278::Slot::compute_vib() const
292 {
293  // verified via hardware recording:
294  // With LFO speed 0 (period 262144 samples), each vibrato step takes
295  // 4096 samples.
296  // -> 64 steps total
297  // Also, with vibrato depth 7 (80 cents) and an F-Num of 0x400, the
298  // final F-Nums are: 0x400 .. 0x43C, 0x43C .. 0x400, 0x400 .. 0x3C4,
299  // 0x3C4 .. 0x400
300  int16_t lfo_fm = lfo_cnt / (LFO_PERIOD / 0x40);
301  // results in +0x00..+0x0F, +0x0F..+0x00, -0x00..-0x0F, -0x0F..-0x00
302  if (lfo_fm & 0x10) lfo_fm ^= 0x1F;
303  if (lfo_fm & 0x20) lfo_fm = -(lfo_fm & 0x0F);
304 
305  return (lfo_fm * vib_depth[vib]) / 12;
306 }
307 
308 uint16_t YMF278::Slot::compute_am() const
309 {
310  // verified via hardware recording:
311  // With LFO speed 0 (period 262144 samples), each tremolo step takes
312  // 1024 samples.
313  // -> 256 steps total
314  uint16_t lfo_am = lfo_cnt / (LFO_PERIOD / 0x100);
315  // results in 0x00..0x7F, 0x7F..0x00
316  if (lfo_am >= 0x80) lfo_am ^= 0xFF;
317 
318  return (lfo_am * am_depth[AM]) >> 7;
319 }
320 
321 
322 void YMF278::advance()
323 {
324  eg_cnt++;
325 
326  // modulo counters for volume interpolation
327  int tl_int_cnt = eg_cnt % 9; // 0 .. 8
328  int tl_int_step = (eg_cnt / 9) % 3; // 0 .. 2
329 
330  for (auto& op : slots) {
331  // volume interpolation
332  if (tl_int_cnt == 0) {
333  if (tl_int_step == 0) {
334  // decrease volume by one step every 27 samples
335  if (op.TL < op.TLdest) ++op.TL;
336  } else {
337  // increase volume by one step every 13.5 samples
338  if (op.TL > op.TLdest) --op.TL;
339  }
340  }
341 
342  if (op.lfo_active) {
343  op.lfo_cnt = (op.lfo_cnt + lfo_period[op.lfo]) & (LFO_PERIOD - 1);
344  }
345 
346  // Envelope Generator
347  switch (op.state) {
348  case EG_ATT: { // attack phase
349  uint8_t rate = op.compute_rate(op.AR);
350  // Verified by HW recording (and matches Nemesis' tests of the YM2612):
351  // AR = 0xF during KeyOn results in instant switch to EG_DEC. (see keyOnHelper)
352  // Setting AR = 0xF while the attack phase is in progress freezes the envelope.
353  if (rate >= 63) {
354  break;
355  }
356  uint8_t shift = eg_rate_shift[rate];
357  if (!(eg_cnt & ((1 << shift) - 1))) {
358  uint8_t select = eg_rate_select[rate];
359  // >>4 makes the attack phase's shape match the actual chip -Valley Bell
360  op.env_vol += (~op.env_vol * eg_inc[select + ((eg_cnt >> shift) & 7)]) >> 4;
361  if (op.env_vol <= MIN_ATT_INDEX) {
362  op.env_vol = MIN_ATT_INDEX;
363  // TODO does the real HW skip EG_DEC completely,
364  // or is it active for 1 sample?
365  op.state = op.DL ? EG_DEC : EG_SUS;
366  }
367  }
368  break;
369  }
370  case EG_DEC: { // decay phase
371  uint8_t rate = op.compute_decay_rate(op.D1R);
372  uint8_t shift = eg_rate_shift[rate];
373  if (!(eg_cnt & ((1 << shift) - 1))) {
374  uint8_t select = eg_rate_select[rate];
375  op.env_vol += eg_inc[select + ((eg_cnt >> shift) & 7)];
376  if (op.env_vol >= op.DL) {
377  op.state = (op.env_vol < MAX_ATT_INDEX) ? EG_SUS : EG_OFF;
378  }
379  }
380  break;
381  }
382  case EG_SUS: { // sustain phase
383  uint8_t rate = op.compute_decay_rate(op.D2R);
384  uint8_t shift = eg_rate_shift[rate];
385  if (!(eg_cnt & ((1 << shift) - 1))) {
386  uint8_t select = eg_rate_select[rate];
387  op.env_vol += eg_inc[select + ((eg_cnt >> shift) & 7)];
388  if (op.env_vol >= MAX_ATT_INDEX) {
389  op.env_vol = MAX_ATT_INDEX;
390  op.state = EG_OFF;
391  }
392  }
393  break;
394  }
395  case EG_REL: { // release phase
396  uint8_t rate = op.compute_decay_rate(op.RR);
397  uint8_t shift = eg_rate_shift[rate];
398  if (!(eg_cnt & ((1 << shift) - 1))) {
399  uint8_t select = eg_rate_select[rate];
400  op.env_vol += eg_inc[select + ((eg_cnt >> shift) & 7)];
401  if (op.env_vol >= MAX_ATT_INDEX) {
402  op.env_vol = MAX_ATT_INDEX;
403  op.state = EG_OFF;
404  }
405  }
406  break;
407  }
408  case EG_OFF:
409  // nothing
410  break;
411 
412  default:
413  UNREACHABLE;
414  }
415  }
416 }
417 
418 int16_t YMF278::getSample(Slot& op)
419 {
420  // TODO How does this behave when R#2 bit 0 = 1?
421  // As-if read returns 0xff? (Like for CPU memory reads.) Or is
422  // sound generation blocked at some higher level?
423  int16_t sample;
424  switch (op.bits) {
425  case 0: {
426  // 8 bit
427  sample = readMem(op.startaddr + op.pos) << 8;
428  break;
429  }
430  case 1: {
431  // 12 bit
432  unsigned addr = op.startaddr + ((op.pos / 2) * 3);
433  if (op.pos & 1) {
434  sample = (readMem(addr + 2) << 8) |
435  ((readMem(addr + 1) << 4) & 0xF0);
436  } else {
437  sample = (readMem(addr + 0) << 8) |
438  (readMem(addr + 1) & 0xF0);
439  }
440  break;
441  }
442  case 2: {
443  // 16 bit
444  unsigned addr = op.startaddr + (op.pos * 2);
445  sample = (readMem(addr + 0) << 8) |
446  (readMem(addr + 1));
447  break;
448  }
449  default:
450  // TODO unspecified
451  sample = 0;
452  }
453  return sample;
454 }
455 
456 bool YMF278::anyActive()
457 {
458  return ranges::any_of(slots, [](auto& op) { return op.state != EG_OFF; });
459 }
460 
461 // In: 'envVol', 0=max volume, others -> -3/32 = -0.09375 dB/step
462 // Out: 'x' attenuated by the corresponding factor.
463 // Note: microbenchmarks have shown that re-doing this calculation is about the
464 // same speed as using a 4kB lookup table.
465 static int vol_factor(int x, unsigned envVol)
466 {
467  if (envVol >= MAX_ATT_INDEX) return 0; // hardware clips to silence below -60dB
468  int vol_mul = 0x80 - (envVol & 0x3F); // 0x40 values per 6dB
469  int vol_shift = 7 + (envVol >> 6);
470  return (x * ((0x8000 * vol_mul) >> vol_shift)) >> 15;
471 }
472 
473 void YMF278::setMixLevel(uint8_t x, EmuTime::param time)
474 {
475  static constexpr float level[8] = {
476  (1.00f / 1), // 0dB
477  (0.75f / 1), // -3dB (approx)
478  (1.00f / 2), // -6dB
479  (0.75f / 2), // -9dB (approx)
480  (1.00f / 4), // -12dB
481  (0.75f / 4), // -15dB (approx)
482  (1.00f / 8), // -18dB
483  (0.00f ), // -inf dB
484  };
485  setSoftwareVolume(level[x & 7], level[(x >> 3) & 7], time);
486 }
487 
488 void YMF278::generateChannels(float** bufs, unsigned num)
489 {
490  if (!anyActive()) {
491  // TODO update internal state, even if muted
492  // TODO also mute individual channels
493  for (int i = 0; i < 24; ++i) {
494  bufs[i] = nullptr;
495  }
496  return;
497  }
498 
499  for (unsigned j = 0; j < num; ++j) {
500  for (int i = 0; i < 24; ++i) {
501  auto& sl = slots[i];
502  if (sl.state == EG_OFF) {
503  //bufs[i][2 * j + 0] += 0;
504  //bufs[i][2 * j + 1] += 0;
505  continue;
506  }
507 
508  int16_t sample = (sl.sample1 * (0x10000 - sl.stepptr) +
509  sl.sample2 * sl.stepptr) >> 16;
510  // TL levels are 00..FF internally (TL register value 7F is mapped to TL level FF)
511  // Envelope levels have 4x the resolution (000..3FF)
512  // Volume levels are approximate logarithmic. -6dB result in half volume. Steps in between use linear interpolation.
513  // A volume of -60dB or lower results in silence. (value 0x280..0x3FF).
514  // Recordings from actual hardware indicate that TL level and envelope level are applied separarely.
515  // Each of them is clipped to silence below -60dB, but TL+envelope might result in a lower volume. -Valley Bell
516  uint16_t envVol = std::min(sl.env_vol + ((sl.lfo_active && sl.AM) ? sl.compute_am() : 0),
517  MAX_ATT_INDEX);
518  int smplOut = vol_factor(vol_factor(sample, envVol), sl.TL << TL_SHIFT);
519 
520  // Panning is also done separately. (low-volume TL + low-volume panning goes below -60dB)
521  // I'll be taking wild guess and assume that -3dB is approximated with 75%. (same as with TL and envelope levels)
522  // The same applies to the PCM mix level.
523  int32_t volLeft = pan_left [sl.pan]; // note: register 0xF9 is handled externally
524  int32_t volRight = pan_right[sl.pan];
525  // 0 -> 0x20, 8 -> 0x18, 16 -> 0x10, 24 -> 0x0C, etc. (not using vol_factor here saves array boundary checks)
526  volLeft = (0x20 - (volLeft & 0x0f)) >> (volLeft >> 4);
527  volRight = (0x20 - (volRight & 0x0f)) >> (volRight >> 4);
528 
529  bufs[i][2 * j + 0] += (smplOut * volLeft ) >> 5;
530  bufs[i][2 * j + 1] += (smplOut * volRight) >> 5;
531 
532  unsigned step = (sl.lfo_active && sl.vib)
533  ? calcStep(sl.OCT, sl.FN, sl.compute_vib())
534  : sl.step;
535  sl.stepptr += step;
536 
537  // If there is a 4-sample loop and you advance 12 samples per step,
538  // it may exceed the end offset.
539  // This is abused by the "Lizard Star" song to generate noise at 0:52. -Valley Bell
540  if (sl.stepptr >= 0x10000) {
541  sl.sample1 = sl.sample2;
542  sl.sample2 = getSample(sl);
543  sl.pos += (sl.stepptr >> 16);
544  sl.stepptr &= 0xffff;
545  if ((uint32_t(sl.pos) + sl.endaddr) >= 0x10000) { // check position >= (negated) end address
546  sl.pos += sl.endaddr + sl.loopaddr; // This is how the actual chip does it.
547  }
548  }
549  }
550  advance();
551  }
552 }
553 
554 void YMF278::keyOnHelper(YMF278::Slot& slot)
555 {
556  // Unlike FM, the envelope level is reset. (And it makes sense, because you restart the sample.)
557  slot.env_vol = MAX_ATT_INDEX;
558  if (slot.compute_rate(slot.AR) < 63) {
559  slot.state = EG_ATT;
560  } else {
561  // Nuke.YKT verified that the FM part does it exactly this way,
562  // and the OPL4 manual says it's instant as well.
563  slot.env_vol = MIN_ATT_INDEX;
564  // see comment in 'case EG_ATT' in YMF278::advance()
565  slot.state = slot.DL ? EG_DEC : EG_SUS;
566  }
567  slot.stepptr = 0;
568  slot.pos = 0;
569  slot.sample1 = getSample(slot);
570  slot.pos = 1;
571  slot.sample2 = getSample(slot);
572 }
573 
574 void YMF278::writeReg(byte reg, byte data, EmuTime::param time)
575 {
576  updateStream(time); // TODO optimize only for regs that directly influence sound
577  writeRegDirect(reg, data, time);
578 }
579 
580 void YMF278::writeRegDirect(byte reg, byte data, EmuTime::param time)
581 {
582  // Handle slot registers specifically
583  if (reg >= 0x08 && reg <= 0xF7) {
584  int snum = (reg - 8) % 24;
585  auto& slot = slots[snum];
586  switch ((reg - 8) / 24) {
587  case 0: {
588  slot.wave = (slot.wave & 0x100) | data;
589  int wavetblhdr = (regs[2] >> 2) & 0x7;
590  int base = (slot.wave < 384 || !wavetblhdr) ?
591  (slot.wave * 12) :
592  (wavetblhdr * 0x80000 + ((slot.wave - 384) * 12));
593  byte buf[12];
594  for (int i = 0; i < 12; ++i) {
595  // TODO What if R#2 bit 0 = 1?
596  // See also getSample()
597  buf[i] = readMem(base + i);
598  }
599  slot.bits = (buf[0] & 0xC0) >> 6;
600  slot.startaddr = buf[2] | (buf[1] << 8) | ((buf[0] & 0x3F) << 16);
601  slot.loopaddr = buf[4] | (buf[3] << 8);
602  slot.endaddr = buf[6] | (buf[5] << 8);
603  for (int i = 7; i < 12; ++i) {
604  // Verified on real YMF278:
605  // After tone loading, if you read these
606  // registers, their value actually has changed.
607  writeRegDirect(8 + snum + (i - 2) * 24, buf[i], time);
608  }
609  if (slot.keyon) {
610  keyOnHelper(slot);
611  }
612  break;
613  }
614  case 1: {
615  slot.wave = (slot.wave & 0xFF) | ((data & 0x1) << 8);
616  slot.FN = (slot.FN & 0x380) | (data >> 1);
617  slot.step = calcStep(slot.OCT, slot.FN);
618  break;
619  }
620  case 2: {
621  slot.FN = (slot.FN & 0x07F) | ((data & 0x07) << 7);
622  slot.PRVB = (data & 0x08) != 0;
623  slot.OCT = sign_extend_4((data & 0xF0) >> 4);
624  slot.step = calcStep(slot.OCT, slot.FN);
625  break;
626  }
627  case 3: {
628  uint8_t t = data >> 1;
629  slot.TLdest = (t != 0x7f) ? t : 0xff; // verified on HW via volume interpolation
630  if (data & 1) {
631  // directly change volume
632  slot.TL = slot.TLdest;
633  } else {
634  // interpolate volume
635  }
636  break;
637  }
638  case 4:
639  if (data & 0x10) {
640  // output to DO1 pin:
641  // this pin is not used in moonsound
642  // we emulate this by muting the sound
643  slot.pan = 8; // both left/right -inf dB
644  } else {
645  slot.pan = data & 0x0F;
646  }
647 
648  if (data & 0x20) {
649  // LFO reset
650  slot.lfo_active = false;
651  slot.lfo_cnt = 0;
652  } else {
653  // LFO activate
654  slot.lfo_active = true;
655  }
656 
657  slot.DAMP = (data & 0x40) != 0;
658 
659  if (data & 0x80) {
660  if (!slot.keyon) {
661  slot.keyon = true;
662  keyOnHelper(slot);
663  }
664  } else {
665  if (slot.keyon) {
666  slot.keyon = false;
667  slot.state = EG_REL;
668  }
669  }
670  break;
671  case 5:
672  slot.lfo = (data >> 3) & 0x7;
673  slot.vib = data & 0x7;
674  break;
675  case 6:
676  slot.AR = data >> 4;
677  slot.D1R = data & 0xF;
678  break;
679  case 7:
680  slot.DL = dl_tab[data >> 4];
681  slot.D2R = data & 0xF;
682  break;
683  case 8:
684  slot.RC = data >> 4;
685  slot.RR = data & 0xF;
686  break;
687  case 9:
688  slot.AM = data & 0x7;
689  break;
690  }
691  } else {
692  // All non-slot registers
693  switch (reg) {
694  case 0x00: // TEST
695  case 0x01:
696  break;
697 
698  case 0x02:
699  // wave-table-header / memory-type / memory-access-mode
700  // Simply store in regs[2]
701  break;
702 
703  case 0x03:
704  // Verified on real YMF278:
705  // * Don't update the 'memadr' variable on writes to
706  // reg 3 and 4. Only store the value in the 'regs'
707  // array for later use.
708  // * The upper 2 bits are not used to address the
709  // external memories (so from a HW pov they don't
710  // matter). But if you read back this register, the
711  // upper 2 bits always read as '0' (even if you wrote
712  // '1'). So we mask the bits here already.
713  data &= 0x3F;
714  break;
715 
716  case 0x04:
717  // See reg 3.
718  break;
719 
720  case 0x05:
721  // Verified on real YMF278: (see above)
722  // Only writes to reg 5 change the (full) 'memadr'.
723  memadr = (regs[3] << 16) | (regs[4] << 8) | data;
724  break;
725 
726  case 0x06: // memory data
727  if (regs[2] & 1) {
728  writeMem(memadr, data);
729  ++memadr; // no need to mask (again) here
730  } else {
731  // Verified on real YMF278:
732  // - writes are ignored
733  // - memadr is NOT increased
734  }
735  break;
736 
737  case 0xf8: // These are implemented in MSXMoonSound.cc
738  case 0xf9:
739  break;
740  }
741  }
742 
743  regs[reg] = data;
744 }
745 
747 {
748  // no need to call updateStream(time)
749  byte result = peekReg(reg);
750  if (reg == 6) {
751  // Memory Data Register
752  if (regs[2] & 1) {
753  // Verified on real YMF278:
754  // memadr is only increased when 'regs[2] & 1'
755  ++memadr; // no need to mask (again) here
756  }
757  }
758  return result;
759 }
760 
762 {
763  byte result;
764  switch (reg) {
765  case 2: // 3 upper bits are device ID
766  result = (regs[2] & 0x1F) | 0x20;
767  break;
768 
769  case 6: // Memory Data Register
770  if (regs[2] & 1) {
771  result = readMem(memadr);
772  } else {
773  // Verified on real YMF278
774  result = 0xff;
775  }
776  break;
777 
778  default:
779  result = regs[reg];
780  break;
781  }
782  return result;
783 }
784 
785 constexpr unsigned INPUT_RATE = 44100;
786 
787 YMF278::YMF278(const std::string& name_, int ramSize_,
788  const DeviceConfig& config)
789  : ResampledSoundDevice(config.getMotherBoard(), name_, "MoonSound wave-part",
790  24, INPUT_RATE, true)
791  , motherBoard(config.getMotherBoard())
792  , debugRegisters(motherBoard, getName())
793  , debugMemory (motherBoard, getName())
794  , rom(getName() + " ROM", "rom", config)
795  , ram(config, getName() + " RAM", "YMF278 sample RAM",
796  ramSize_ * 1024) // size in kB
797 {
798  if (rom.getSize() != 0x200000) { // 2MB
799  throw MSXException(
800  "Wrong ROM for MoonSound (YMF278). The ROM (usually "
801  "called yrw801.rom) should have a size of exactly 2MB.");
802  }
803  if ((ramSize_ != 0) && // - -
804  (ramSize_ != 128) && // 128kB -
805  (ramSize_ != 256) && // 128kB 128kB
806  (ramSize_ != 512) && // 512kB -
807  (ramSize_ != 640) && // 512kB 128kB
808  (ramSize_ != 1024) && // 512kB 512kB
809  (ramSize_ != 2048)) { // 512kB 512kB 512kB 512kB
810  throw MSXException(
811  "Wrong sampleram size for MoonSound (YMF278). "
812  "Got ", ramSize_, ", but must be one of "
813  "0, 128, 256, 512, 640, 1024 or 2048.");
814  }
815 
816  memadr = 0; // avoid UMR
817 
818  registerSound(config);
819  reset(motherBoard.getCurrentTime()); // must come after registerSound() because of call to setSoftwareVolume() via setMixLevel()
820 }
821 
823 {
824  unregisterSound();
825 }
826 
828 {
829  ram.clear(0);
830 }
831 
832 void YMF278::reset(EmuTime::param time)
833 {
834  updateStream(time);
835 
836  eg_cnt = 0;
837 
838  for (auto& op : slots) {
839  op.reset();
840  }
841  regs[2] = 0; // avoid UMR
842  for (int i = 0xf7; i >= 0; --i) { // reverse order to avoid UMR
843  writeRegDirect(i, 0, time);
844  }
845  memadr = 0;
846  setMixLevel(0, time);
847 }
848 
849 // This routine translates an address from the (upper) MoonSound address space
850 // to an address inside the (linearized) SRAM address space.
851 //
852 // The following info is based on measurements on a real MoonSound (v2.0)
853 // PCB. This PCB can have several possible SRAM configurations:
854 // 128kB:
855 // 1 SRAM chip of 128kB, chip enable (/CE) of this SRAM chip is connected to
856 // the 1Y0 output of a 74LS139 (2-to-4 decoder). The enable input of the
857 // 74LS139 is connected to YMF278 pin /MCS6 and the 74LS139 1B:1A inputs are
858 // connected to YMF278 pins MA18:MA17. So the SRAM is selected when /MC6 is
859 // active and MA18:MA17 == 0:0.
860 // 256kB:
861 // 2 SRAM chips of 128kB. First one connected as above. Second one has /CE
862 // connected to 74LS139 pin 1Y1. So SRAM2 is selected when /MSC6 is active
863 // and MA18:MA17 == 0:1.
864 // 512kB:
865 // 1 SRAM chip of 512kB, /CE connected to /MCS6
866 // 640kB:
867 // 1 SRAM chip of 512kB, /CE connected to /MCS6
868 // 1 SRAM chip of 128kB, /CE connected to /MCS7.
869 // (This means SRAM2 is potentially mirrored over a 512kB region)
870 // 1024kB:
871 // 1 SRAM chip of 512kB, /CE connected to /MCS6
872 // 1 SRAM chip of 512kB, /CE connected to /MCS7
873 // 2048kB:
874 // 1 SRAM chip of 512kB, /CE connected to /MCS6
875 // 1 SRAM chip of 512kB, /CE connected to /MCS7
876 // 1 SRAM chip of 512kB, /CE connected to /MCS8
877 // 1 SRAM chip of 512kB, /CE connected to /MCS9
878 // This configuration is not so easy to create on the v2.0 PCB. So it's
879 // very rare.
880 //
881 // So the /MCS6 and /MCS7 (and /MCS8 and /MCS9 in case of 2048kB) signals are
882 // used to select the different SRAM chips. The meaning of these signals
883 // depends on the 'memory access mode'. This mode can be changed at run-time
884 // via bit 1 in register 2. The following table indicates for which regions
885 // these signals are active (normally MoonSound should be used with mode=0):
886 // mode=0 mode=1
887 // /MCS6 0x200000-0x27FFFF 0x380000-0x39FFFF
888 // /MCS7 0x280000-0x2FFFFF 0x3A0000-0x3BFFFF
889 // /MCS8 0x300000-0x37FFFF 0x3C0000-0x3DFFFF
890 // /MCS9 0x380000-0x3FFFFF 0x3E0000-0x3FFFFF
891 //
892 // (For completeness) MoonSound also has 2MB ROM (YRW801), /CE of this ROM is
893 // connected to YMF278 /MCS0. In both mode=0 and mode=1 this signal is active
894 // for the region 0x000000-0x1FFFFF. (But this routine does not handle ROM).
895 unsigned YMF278::getRamAddress(unsigned addr) const
896 {
897  addr -= 0x200000; // RAM starts at 0x200000
898  if (unlikely(regs[2] & 2)) {
899  // Normally MoonSound is used in 'memory access mode = 0'. But
900  // in the rare case that mode=1 we adjust the address.
901  if ((0x180000 <= addr) && (addr <= 0x1FFFFF)) {
902  addr -= 0x180000;
903  switch (addr & 0x060000) {
904  case 0x000000: // [0x380000-0x39FFFF]
905  // 1st 128kB of SRAM1
906  break;
907  case 0x020000: // [0x3A0000-0x3BFFFF]
908  if (ram.getSize() == 256 * 1024) {
909  // 2nd 128kB SRAM chip
910  } else {
911  // 2nd block of 128kB in SRAM2
912  // In case of 512+128, we use mirroring
913  addr += 0x080000;
914  }
915  break;
916  case 0x040000: // [0x3C0000-0x3DFFFF]
917  // 3rd 128kB block in SRAM3
918  addr += 0x100000;
919  break;
920  case 0x060000: // [0x3EFFFF-0x3FFFFF]
921  // 4th 128kB block in SRAM4
922  addr += 0x180000;
923  break;
924  }
925  } else {
926  addr = unsigned(-1); // unmapped
927  }
928  }
929  if (ram.getSize() == 640 * 1024) {
930  // Verified on real MoonSound cartridge (v2.0): In case of
931  // 640kB (1x512kB + 1x128kB), the 128kB SRAM chip is 4 times
932  // visible. None of the other SRAM configurations show similar
933  // mirroring (because the others are powers of two).
934  if (addr > 0x080000) {
935  addr &= ~0x060000;
936  }
937  }
938  return addr;
939 }
940 
941 byte YMF278::readMem(unsigned address) const
942 {
943  // Verified on real YMF278: address space wraps at 4MB.
944  address &= 0x3FFFFF;
945  if (address < 0x200000) {
946  // ROM connected to /MCS0
947  return rom[address];
948  } else {
949  unsigned ramAddr = getRamAddress(address);
950  if (ramAddr < ram.getSize()) {
951  return ram[ramAddr];
952  } else {
953  // unmapped region
954  return 255; // TODO check
955  }
956  }
957 }
958 
959 void YMF278::writeMem(unsigned address, byte value)
960 {
961  address &= 0x3FFFFF;
962  if (address < 0x200000) {
963  // can't write to ROM
964  } else {
965  unsigned ramAddr = getRamAddress(address);
966  if (ramAddr < ram.getSize()) {
967  ram.write(ramAddr, value);
968  } else {
969  // can't write to unmapped memory
970  }
971  }
972 }
973 
974 // version 1: initial version, some variables were saved as char
975 // version 2: serialization framework was fixed to save/load chars as numbers
976 // but for backwards compatibility we still load old savestates as
977 // characters
978 // version 3: 'step' is no longer stored (it is recalculated)
979 // version 4:
980 // - removed members: 'lfo', 'LD', 'active'
981 // - new members 'TLdest', 'keyon', 'DAMP' restored from registers instead of serialized
982 // - store 'OCT' sign-extended
983 // - store 'endaddr' as 2s complement
984 // - removed EG_DMP and EG_REV enum values from 'state'
985 // version 5:
986 // - re-added 'lfo' member. This is not stored in the savestate, instead it's
987 // restored from register values in YMF278::serialize()
988 // - removed members 'lfo_step' and ' 'lfo_max'
989 // - 'lfo_cnt' has changed meaning (but we don't try to translate old to new meaning)
990 template<typename Archive>
991 void YMF278::Slot::serialize(Archive& ar, unsigned version)
992 {
993  // TODO restore more state from registers
994  ar.serialize("startaddr", startaddr,
995  "loopaddr", loopaddr,
996  "stepptr", stepptr,
997  "pos", pos,
998  "sample1", sample1,
999  "sample2", sample2,
1000  "env_vol", env_vol,
1001  "lfo_cnt", lfo_cnt,
1002  "DL", DL,
1003  "wave", wave,
1004  "FN", FN);
1005  if (ar.versionAtLeast(version, 4)) {
1006  ar.serialize("endaddr", endaddr,
1007  "OCT", OCT);
1008  } else {
1009  unsigned e = 0; ar.serialize("endaddr", e); endaddr = (e ^ 0xffff) + 1;
1010 
1011  char O = 0;
1012  if (ar.versionAtLeast(version, 2)) {
1013  ar.serialize("OCT", O);
1014  } else {
1015  ar.serializeChar("OCT", O);
1016  }
1017  OCT = sign_extend_4(O);
1018  }
1019 
1020  if (ar.versionAtLeast(version, 2)) {
1021  ar.serialize("PRVB", PRVB,
1022  "TL", TL,
1023  "pan", pan,
1024  "vib", vib,
1025  "AM", AM,
1026  "AR", AR,
1027  "D1R", D1R,
1028  "D2R", D2R,
1029  "RC", RC,
1030  "RR", RR);
1031  } else {
1032  // for backwards compatibility with old savestates
1033  char PRVB_ = 0; ar.serializeChar("PRVB", PRVB_); PRVB = PRVB_;
1034  char TL_ = 0; ar.serializeChar("TL", TL_ ); TL = TL_;
1035  char pan_ = 0; ar.serializeChar("pan", pan_); pan = pan_;
1036  char vib_ = 0; ar.serializeChar("vib", vib_); vib = vib_;
1037  char AM_ = 0; ar.serializeChar("AM", AM_ ); AM = AM_;
1038  char AR_ = 0; ar.serializeChar("AR", AR_ ); AR = AR_;
1039  char D1R_ = 0; ar.serializeChar("D1R", D1R_); D1R = D1R_;
1040  char D2R_ = 0; ar.serializeChar("D2R", D2R_); D2R = D2R_;
1041  char RC_ = 0; ar.serializeChar("RC", RC_ ); RC = RC_;
1042  char RR_ = 0; ar.serializeChar("RR", RR_ ); RR = RR_;
1043  }
1044  ar.serialize("bits", bits,
1045  "lfo_active", lfo_active);
1046 
1047  ar.serialize("state", state);
1048  if (ar.versionBelow(version, 4)) {
1049  assert(ar.isLoader());
1050  if ((state == EG_REV) || (state == EG_DMP)) {
1051  state = EG_REL;
1052  }
1053  }
1054 
1055  // Recalculate redundant state
1056  if (ar.isLoader()) {
1057  step = calcStep(OCT, FN);
1058  }
1059 
1060  // This old comment is NOT completely true:
1061  // Older version also had "env_vol_step" and "env_vol_lim" but those
1062  // members were nowhere used, so removed those in the current
1063  // version (it's ok to remove members from the savestate without
1064  // updating the version number).
1065  // When you remove member variables without increasing the version
1066  // number, new openMSX executables can still read old savestates. And
1067  // if you try to load a new savestate in an old openMSX version you do
1068  // get a (cryptic) error message. But if the version number is
1069  // increased the error message is much clearer.
1070 }
1071 
1072 // version 1: initial version
1073 // version 2: loadTime and busyTime moved to MSXMoonSound class
1074 // version 3: memadr cannot be restored from register values
1075 // version 4: implement ram via Ram class
1076 template<typename Archive>
1077 void YMF278::serialize(Archive& ar, unsigned version)
1078 {
1079  ar.serialize("slots", slots,
1080  "eg_cnt", eg_cnt);
1081  if (ar.versionAtLeast(version, 4)) {
1082  ar.serialize("ram", ram);
1083  } else {
1084  ar.serialize_blob("ram", ram.getWriteBackdoor(), ram.getSize());
1085  }
1086  ar.serialize_blob("registers", regs, sizeof(regs));
1087  if (ar.versionAtLeast(version, 3)) { // must come after 'regs'
1088  ar.serialize("memadr", memadr);
1089  } else {
1090  assert(ar.isLoader());
1091  // Old formats didn't store 'memadr' so we also can't magically
1092  // restore the correct value. The best we can do is restore the
1093  // last set address.
1094  regs[3] &= 0x3F; // mask upper two bits
1095  memadr = (regs[3] << 16) | (regs[4] << 8) | regs[5];
1096  }
1097 
1098  // TODO restore more state from registers
1099  if (ar.isLoader()) {
1100  for (int i = 0; i < 24; ++i) {
1101  Slot& sl = slots[i];
1102 
1103  auto t = regs[0x50 + i] >> 1;
1104  sl.TLdest = (t != 0x7f) ? t : 0xff;
1105 
1106  sl.keyon = (regs[0x68 + i] & 0x80) != 0;
1107  sl.DAMP = (regs[0x68 + i] & 0x40) != 0;
1108  sl.lfo = (regs[0x80 + i] >> 3) & 7;
1109  }
1110  }
1111 }
1113 
1114 
1115 // class DebugRegisters
1116 
1117 YMF278::DebugRegisters::DebugRegisters(MSXMotherBoard& motherBoard_,
1118  const std::string& name_)
1119  : SimpleDebuggable(motherBoard_, name_ + " regs",
1120  "OPL4 registers", 0x100)
1121 {
1122 }
1123 
1124 byte YMF278::DebugRegisters::read(unsigned address)
1125 {
1126  auto& ymf278 = OUTER(YMF278, debugRegisters);
1127  return ymf278.peekReg(address);
1128 }
1129 
1130 void YMF278::DebugRegisters::write(unsigned address, byte value, EmuTime::param time)
1131 {
1132  auto& ymf278 = OUTER(YMF278, debugRegisters);
1133  ymf278.writeReg(address, value, time);
1134 }
1135 
1136 
1137 // class DebugMemory
1138 
1139 YMF278::DebugMemory::DebugMemory(MSXMotherBoard& motherBoard_,
1140  const std::string& name_)
1141  : SimpleDebuggable(motherBoard_, name_ + " mem",
1142  "OPL4 memory (includes both ROM and RAM)", 0x400000) // 4MB
1143 {
1144 }
1145 
1146 byte YMF278::DebugMemory::read(unsigned address)
1147 {
1148  auto& ymf278 = OUTER(YMF278, debugMemory);
1149  return ymf278.readMem(address);
1150 }
1151 
1152 void YMF278::DebugMemory::write(unsigned address, byte value)
1153 {
1154  auto& ymf278 = OUTER(YMF278, debugMemory);
1155  ymf278.writeMem(address, value);
1156 }
1157 
1158 } // namespace openmsx
void clearRam()
Definition: YMF278.cc:827
constexpr unsigned LFO_SHIFT
Definition: YMF278.cc:50
void setSoftwareVolume(float volume, EmuTime::param time)
Change the &#39;software volume&#39; of this sound device.
Definition: SoundDevice.cc:141
constexpr int TL_SHIFT
Definition: YMF278.cc:48
byte readReg(byte reg)
Definition: YMF278.cc:746
#define unlikely(x)
Definition: likely.hh:15
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:269
const std::string & getName() const
Get the unique name that identifies this sound device.
Definition: SoundDevice.hh:24
constexpr unsigned RATE_STEPS
Definition: YM2151.cc:59
constexpr uint8_t am_depth[8]
Definition: YMF278.cc:180
byte * getWriteBackdoor()
Definition: TrackedRam.hh:52
void clear(byte c=0xff)
Definition: TrackedRam.hh:43
constexpr byte eg_inc[19 *RATE_STEPS]
Definition: YM2151.cc:60
void unregisterSound()
Unregisters this sound device with the Mixer.
Definition: SoundDevice.cc:131
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
constexpr uint8_t pan_right[16]
Definition: YMF278.cc:67
void writeReg(byte reg, byte data, EmuTime::param time)
Definition: YMF278.cc:574
unsigned getSize() const
Definition: TrackedRam.hh:20
void writeMem(unsigned address, byte value)
Definition: YMF278.cc:959
constexpr auto step
Definition: eeprom.cc:9
void updateStream(EmuTime::param time)
Definition: SoundDevice.cc:136
constexpr int MIN_ATT_INDEX
Definition: YM2151.cc:29
void serialize(Archive &ar, unsigned version)
Definition: YMF278.cc:1077
void setMixLevel(uint8_t x, EmuTime::param time)
Definition: YMF278.cc:473
byte readMem(unsigned address) const
Definition: YMF278.cc:941
constexpr int MAX_ATT_INDEX
Definition: YM2151.cc:28
constexpr unsigned EG_OFF
Definition: YM2151.cc:35
constexpr int lfo_period[8]
Definition: YMF278.cc:148
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
constexpr unsigned EG_ATT
Definition: YM2151.cc:31
bool any_of(InputRange &&range, UnaryPredicate pred)
Definition: ranges.hh:125
constexpr SlTable sl
constexpr int16_t vib_depth[8]
Definition: YMF278.cc:162
unsigned getSize() const
Definition: Rom.hh:32
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
constexpr unsigned EG_SUS
Definition: YM2151.cc:33
constexpr byte eg_rate_select[32+64+32]
Definition: YM2151.cc:92
constexpr unsigned EG_DEC
Definition: YM2151.cc:32
constexpr int16_t dl_tab[16]
Definition: YMF278.cc:74
YMF278(const std::string &name, int ramSize, const DeviceConfig &config)
Definition: YMF278.cc:787
constexpr auto INPUT_RATE
Definition: SCC.cc:113
constexpr unsigned LFO_PERIOD
Definition: YMF278.cc:51
constexpr int EG_REV
Definition: YMF278.cc:60
EmuTime::param getCurrentTime()
Convenience method: This is the same as getScheduler().getCurrentTime().
constexpr byte eg_rate_shift[32+64+32]
Definition: YM2151.cc:136
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:1377
constexpr uint8_t pan_left[16]
Definition: YMF278.cc:64
#define OUTER(type, member)
Definition: outer.hh:38
constexpr unsigned EG_REL
Definition: YM2151.cc:34
constexpr int EG_DMP
Definition: YMF278.cc:61
TclObject t
byte peekReg(byte reg) const
Definition: YMF278.cc:761
void serialize(Archive &ar, T &t, unsigned version)
void reset(EmuTime::param time)
Definition: YMF278.cc:832
void write(unsigned addr, byte value)
Definition: TrackedRam.hh:38
void registerSound(const DeviceConfig &config)
Registers this sound device with the Mixer.
Definition: SoundDevice.cc:90
#define UNREACHABLE
Definition: unreachable.hh:38