openMSX
SN76489.hh
Go to the documentation of this file.
1#ifndef SN76489_HH
2#define SN76489_HH
3
5#include "SimpleDebuggable.hh"
6#include <array>
7
8namespace openmsx {
9
25class SN76489 final : public ResampledSoundDevice
26{
27public:
28 SN76489(const DeviceConfig& config);
29 ~SN76489();
30
31 // ResampledSoundDevice
32 void generateChannels(std::span<float*> buffers, unsigned num) override;
33
34 void reset(EmuTime::param time);
35 void write(byte value, EmuTime::param time);
36
37 template<typename Archive>
38 void serialize(Archive& ar, unsigned version);
39
40private:
41 class NoiseShifter {
42 public:
46 inline void initState(unsigned pattern, unsigned period);
47
50 [[nodiscard]] inline unsigned getOutput() const;
51
54 inline void advance();
55
59 inline void queueAdvance(unsigned steps);
60
63 void catchUp();
64
65 template<typename Archive>
66 void serialize(Archive& ar, unsigned version);
67
68 private:
69 unsigned pattern;
70 unsigned period;
71 unsigned random;
72 unsigned stepsBehind;
73 };
74
77 void initState();
78
82 void initNoise();
83
84 [[nodiscard]] word peekRegister(unsigned reg, EmuTime::param time) const;
85 void writeRegister(unsigned reg, word value, EmuTime::param time);
86 template<bool NOISE> void synthesizeChannel(
87 float*& buffer, unsigned num, unsigned generator);
88
89private:
90 NoiseShifter noiseShifter;
91
95 std::array<word, 8> regs;
96
99 byte registerLatch;
100
105 std::array<word, 4> counters;
106
109 std::array<byte, 4> outputs;
110
111 struct Debuggable final : SimpleDebuggable {
112 Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
113 [[nodiscard]] byte read(unsigned address, EmuTime::param time) override;
114 void write(unsigned address, byte value, EmuTime::param time) override;
115 } debuggable;
116};
117
118} // namespace openmsx
119
120#endif
This class implements the Texas Instruments SN76489 sound chip.
Definition SN76489.hh:26
void serialize(Archive &ar, unsigned version)
Definition SN76489.cc:309
void reset(EmuTime::param time)
Definition SN76489.cc:141
void write(byte value, EmuTime::param time)
Definition SN76489.cc:147
void generateChannels(std::span< float * > buffers, unsigned num) override
Abstract method to generate the actual sound data.
Definition SN76489.cc:287
This file implemented 3 utility functions:
Definition Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
void serialize(Archive &ar, T &t, unsigned version)