| e8555c89 Andy McCall |
1 |
#ifndef SN76489_HH |
| 2 |
#define SN76489_HH |
| 3 |
|
| 4 |
#include "ResampledSoundDevice.hh" |
| 5 |
#include "SimpleDebuggable.hh" |
| 6 |
|
| 7 |
#include <array> |
| 8 |
|
| 9 |
namespace openmsx { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
class SN76489 final : public ResampledSoundDevice |
| 27 |
{ |
| 28 |
public: |
| 29 |
explicit SN76489(const DeviceConfig& config); |
| 30 |
~SN76489(); |
| 31 |
|
| 32 |
|
| 33 |
void generateChannels(std::span<float*> buffers, unsigned num) override; |
| 34 |
|
| 35 |
void reset(EmuTime time); |
| 36 |
void write(uint8_t value, EmuTime time); |
| 37 |
|
| 38 |
template<typename Archive> |
| 39 |
void serialize(Archive& ar, unsigned version); |
| 40 |
|
| 41 |
private: |
| 42 |
class NoiseShifter { |
| 43 |
public: |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
void initState(unsigned pattern, unsigned period); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
[[nodiscard]] unsigned getOutput() const; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
void advance(); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
void queueAdvance(unsigned steps); |
| 61 |
|
| 62 |
|
| 63 |
|
| 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 |
|
| 76 |
|
| 77 |
|
| 78 |
void initState(); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
void initNoise(); |
| 84 |
|
| 85 |
[[nodiscard]] uint16_t peekRegister(unsigned reg, EmuTime time) const; |
| 86 |
void writeRegister(unsigned reg, uint16_t value, EmuTime time); |
| 87 |
template<bool NOISE> void synthesizeChannel( |
| 88 |
float*& buffer, unsigned num, unsigned generator); |
| 89 |
|
| 90 |
private: |
| 91 |
NoiseShifter noiseShifter; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
std::array<uint16_t, 8> regs; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
uint8_t registerLatch; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
std::array<uint16_t, 4> counters; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
std::array<uint8_t, 4> outputs; |
| 111 |
|
| 112 |
struct Debuggable final : SimpleDebuggable { |
| 113 |
Debuggable(MSXMotherBoard& motherBoard, const std::string& name); |
| 114 |
[[nodiscard]] uint8_t read(unsigned address, EmuTime time) override; |
| 115 |
void write(unsigned address, uint8_t value, EmuTime time) override; |
| 116 |
} debuggable; |
| 117 |
}; |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
#endif |