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#include <array>
8
9namespace openmsx {
10
26class SN76489 final : public ResampledSoundDevice
27{
28public:
29 explicit SN76489(const DeviceConfig& config);
30 ~SN76489();
31
32 // ResampledSoundDevice
33 void generateChannels(std::span<float*> buffers, unsigned num) override;
34
35 void reset(EmuTime::param time);
36 void write(byte value, EmuTime::param time);
37
38 template<typename Archive>
39 void serialize(Archive& ar, unsigned version);
40
41private:
42 class NoiseShifter {
43 public:
47 void initState(unsigned pattern, unsigned period);
48
51 [[nodiscard]] unsigned getOutput() const;
52
55 void advance();
56
60 void queueAdvance(unsigned steps);
61
64 void catchUp();
65
66 template<typename Archive>
67 void serialize(Archive& ar, unsigned version);
68
69 private:
70 unsigned pattern;
71 unsigned period;
72 unsigned random;
73 unsigned stepsBehind;
74 };
75
78 void initState();
79
83 void initNoise();
84
85 [[nodiscard]] word peekRegister(unsigned reg, EmuTime::param time) const;
86 void writeRegister(unsigned reg, word value, EmuTime::param time);
87 template<bool NOISE> void synthesizeChannel(
88 float*& buffer, unsigned num, unsigned generator);
89
90private:
91 NoiseShifter noiseShifter;
92
96 std::array<word, 8> regs;
97
100 byte registerLatch;
101
106 std::array<word, 4> counters;
107
110 std::array<byte, 4> outputs;
111
112 struct Debuggable final : SimpleDebuggable {
113 Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
114 [[nodiscard]] byte read(unsigned address, EmuTime::param time) override;
115 void write(unsigned address, byte value, EmuTime::param time) override;
116 } debuggable;
117};
118
119} // namespace openmsx
120
121#endif
This class implements the Texas Instruments SN76489 sound chip.
Definition SN76489.hh:27
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:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
void serialize(Archive &ar, T &t, unsigned version)