openMSX
YM2413.cc
Go to the documentation of this file.
1 #include "YM2413.hh"
2 #include "YM2413Okazaki.hh"
3 #include "YM2413Burczynski.hh"
4 #include "SimpleDebuggable.hh"
5 #include "DeviceConfig.hh"
6 #include "serialize.hh"
7 #include "memory.hh"
8 
9 namespace openmsx {
10 
11 // YM2413Debuggable
12 
14 {
15 public:
16  YM2413Debuggable(MSXMotherBoard& motherBoard, YM2413& ym2413);
17  virtual byte read(unsigned address);
18  virtual void write(unsigned address, byte value, EmuTime::param time);
19 private:
20  YM2413& ym2413;
21 };
22 
23 
25  MSXMotherBoard& motherBoard, YM2413& ym2413_)
26  : SimpleDebuggable(motherBoard, ym2413_.getName() + " regs",
27  "MSX-MUSIC", 0x40)
28  , ym2413(ym2413_)
29 {
30 }
31 
32 byte YM2413Debuggable::read(unsigned address)
33 {
34  return ym2413.core->peekReg(address);
35 }
36 
37 void YM2413Debuggable::write(unsigned address, byte value, EmuTime::param time)
38 {
39  ym2413.writeReg(address, value, time);
40 }
41 
42 
43 // YM2413
44 
45 static std::unique_ptr<YM2413Core> createCore(const DeviceConfig& config)
46 {
47  if (config.getChildDataAsBool("alternative", false)) {
48  return make_unique<YM2413Burczynski::YM2413>();
49  } else {
50  return make_unique<YM2413Okazaki::YM2413>();
51  }
52 }
53 
54 YM2413::YM2413(const std::string& name, const DeviceConfig& config)
55  : ResampledSoundDevice(config.getMotherBoard(), name, "MSX-MUSIC", 9 + 5)
56  , core(createCore(config))
57  , debuggable(make_unique<YM2413Debuggable>(
58  config.getMotherBoard(), *this))
59 {
60  double input = YM2413Core::CLOCK_FREQ / 72.0;
61  setInputRate(int(input + 0.5));
62 
63  registerSound(config);
64 }
65 
67 {
69 }
70 
72 {
73  updateStream(time);
74  core->reset();
75 }
76 
77 void YM2413::writeReg(byte reg, byte value, EmuTime::param time)
78 {
79  updateStream(time);
80  core->writeReg(reg, value);
81 }
82 
83 void YM2413::generateChannels(int** bufs, unsigned num)
84 {
85  core->generateChannels(bufs, num);
86 }
87 
88 int YM2413::getAmplificationFactor() const
89 {
90  return core->getAmplificationFactor();
91 }
92 
93 
94 template<typename Archive>
95 void YM2413::serialize(Archive& ar, unsigned /*version*/)
96 {
97  ar.serializePolymorphic("ym2413", *core);
98 }
100 
101 } // namespace openmsx