openMSX
SN76489.hh
Go to the documentation of this file.
1 #ifndef SN76489_HH
2 #define SN76489_HH
3 
5 #include "SimpleDebuggable.hh"
6 
7 namespace openmsx {
8 
24 class SN76489 final : public ResampledSoundDevice
25 {
26 public:
27  SN76489(const DeviceConfig& config);
28  ~SN76489();
29 
30  // ResampledSoundDevice
31  void generateChannels(float** buffers, unsigned num) override;
32 
33  void reset(EmuTime::param time);
34  void write(byte value, EmuTime::param time);
35 
36  template<typename Archive>
37  void serialize(Archive& ar, unsigned version);
38 
39 private:
40  class NoiseShifter {
41  public:
45  inline void initState(unsigned pattern, unsigned period);
46 
49  inline unsigned getOutput() const;
50 
53  inline void advance();
54 
58  inline void queueAdvance(unsigned steps);
59 
62  void catchUp();
63 
64  template<typename Archive>
65  void serialize(Archive& ar, unsigned version);
66 
67  private:
68  unsigned pattern;
69  unsigned period;
70  unsigned random;
71  unsigned stepsBehind;
72  };
73 
76  void initVolumeTable(int volume);
77 
80  void initState();
81 
85  void initNoise();
86 
87  word peekRegister(unsigned reg, EmuTime::param time) const;
88  void writeRegister(unsigned reg, word value, EmuTime::param time);
89  template <bool NOISE> void synthesizeChannel(
90  float*& buffer, unsigned num, unsigned generator);
91 
92  unsigned volTable[16];
93 
94  NoiseShifter noiseShifter;
95 
99  word regs[8];
100 
103  byte registerLatch;
104 
109  word counters[4];
110 
113  byte outputs[4];
114 
115  struct Debuggable final : SimpleDebuggable {
116  Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
117  byte read(unsigned address, EmuTime::param time) override;
118  void write(unsigned address, byte value, EmuTime::param time) override;
119  } debuggable;
120 };
121 
122 } // namespace openmsx
123 
124 #endif
openmsx::ResampledSoundDevice
Definition: ResampledSoundDevice.hh:16
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
openmsx::SimpleDebuggable
Definition: SimpleDebuggable.hh:11
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:59
SimpleDebuggable.hh
openmsx::SN76489::serialize
void serialize(Archive &ar, unsigned version)
Definition: SN76489.cc:303
openmsx::SN76489::SN76489
SN76489(const DeviceConfig &config)
Definition: SN76489.cc:74
openmsx::SN76489
This class implements the Texas Instruments SN76489 sound chip.
Definition: SN76489.hh:24
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::SN76489::generateChannels
void generateChannels(float **buffers, unsigned num) override
Abstract method to generate the actual sound data.
Definition: SN76489.cc:281
openmsx::SN76489::~SN76489
~SN76489()
Definition: SN76489.cc:84
utf8::advance
void advance(octet_iterator &it, distance_type n, octet_iterator end)
Definition: utf8_checked.hh:186
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::SN76489::write
void write(byte value, EmuTime::param time)
Definition: SN76489.cc:141
openmsx::SN76489::reset
void reset(EmuTime::param time)
Definition: SN76489.cc:135
ResampledSoundDevice.hh