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  [[nodiscard]] 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 initState();
77 
81  void initNoise();
82 
83  [[nodiscard]] word peekRegister(unsigned reg, EmuTime::param time) const;
84  void writeRegister(unsigned reg, word value, EmuTime::param time);
85  template<bool NOISE> void synthesizeChannel(
86  float*& buffer, unsigned num, unsigned generator);
87 
88 private:
89  NoiseShifter noiseShifter;
90 
94  word regs[8];
95 
98  byte registerLatch;
99 
104  word counters[4];
105 
108  byte outputs[4];
109 
110  struct Debuggable final : SimpleDebuggable {
111  Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
112  [[nodiscard]] byte read(unsigned address, EmuTime::param time) override;
113  void write(unsigned address, byte value, EmuTime::param time) override;
114  } debuggable;
115 };
116 
117 } // namespace openmsx
118 
119 #endif
This class implements the Texas Instruments SN76489 sound chip.
Definition: SN76489.hh:25
void generateChannels(float **buffers, unsigned num) override
Abstract method to generate the actual sound data.
Definition: SN76489.cc:286
void serialize(Archive &ar, unsigned version)
Definition: SN76489.cc:308
void reset(EmuTime::param time)
Definition: SN76489.cc:140
void write(byte value, EmuTime::param time)
Definition: SN76489.cc:146
SN76489(const DeviceConfig &config)
Definition: SN76489.cc:91
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
void advance(octet_iterator &it, distance_type n, octet_iterator end)