openMSX
Y8950Adpcm.hh
Go to the documentation of this file.
1 #ifndef Y8950ADPCM_HH
2 #define Y8950ADPCM_HH
3 
4 #include "TrackedRam.hh"
5 #include "Schedulable.hh"
6 #include "Clock.hh"
7 #include "serialize_meta.hh"
8 #include "openmsx.hh"
9 
10 namespace openmsx {
11 
12 class DeviceConfig;
13 class Y8950;
14 
15 class Y8950Adpcm final : public Schedulable
16 {
17 public:
18  Y8950Adpcm(Y8950& y8950, const DeviceConfig& config,
19  const std::string& name, unsigned sampleRam);
20 
21  void clearRam();
22  void reset(EmuTime::param time);
23  [[nodiscard]] bool isMuted() const;
24  void writeReg(byte rg, byte data, EmuTime::param time);
25  [[nodiscard]] byte readReg(byte rg, EmuTime::param time);
26  [[nodiscard]] byte peekReg(byte rg, EmuTime::param time) const;
27  [[nodiscard]] int calcSample();
28  void sync(EmuTime::param time);
29  void resetStatus();
30 
31  template<typename Archive>
32  void serialize(Archive& ar, unsigned version);
33 
34 private:
35  // This data is updated while playing
36  struct PlayData {
37  unsigned memPtr;
38  unsigned nowStep;
39  int out;
40  int output;
41  int diff;
42  int nextLeveling;
43  int sampleStep;
44  byte adpcm_data;
45  };
46 
47  // Schedulable
48  void executeUntil(EmuTime::param time) override;
49 
50  void schedule();
51  void restart(PlayData& pd);
52 
53  [[nodiscard]] bool isPlaying() const;
54  void writeData(byte data);
55  [[nodiscard]] byte peekReg(byte rg) const;
56  [[nodiscard]] byte readData();
57  [[nodiscard]] byte peekData() const;
58  void writeMemory(unsigned memPntr, byte value);
59  [[nodiscard]] byte readMemory(unsigned memPntr) const;
60  [[nodiscard]] int calcSample(bool doEmu);
61 
62 private:
63  Y8950& y8950;
64  TrackedRam ram;
65 
66  // copy/pasted from Y8950.hh
67  static constexpr int CLOCK_FREQ = 3579545;
68  static constexpr int CLOCK_FREQ_DIV = 72;
70 
71  PlayData emu; // used for emulator behaviour (read back of sample data)
72  PlayData aud; // used by audio generation thread
73 
74  unsigned startAddr;
75  unsigned stopAddr;
76  unsigned addrMask;
77  int volume;
78  int volumeWStep;
79  int readDelay;
80  int delta;
81  byte reg7;
82  byte reg15;
83  bool romBank;
84 };
86 
87 } // namespace openmsx
88 
89 #endif
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
void sync(EmuTime::param time)
Definition: Y8950Adpcm.cc:106
byte readReg(byte rg, EmuTime::param time)
Definition: Y8950Adpcm.cc:301
bool isMuted() const
Definition: Y8950Adpcm.cc:89
byte peekReg(byte rg, EmuTime::param time) const
Definition: Y8950Adpcm.cc:310
Y8950Adpcm(Y8950 &y8950, const DeviceConfig &config, const std::string &name, unsigned sampleRam)
Definition: Y8950Adpcm.cc:47
void writeReg(byte rg, byte data, EmuTime::param time)
Definition: Y8950Adpcm.cc:151
void serialize(Archive &ar, unsigned version)
Definition: Y8950Adpcm.cc:517
void reset(EmuTime::param time)
Definition: Y8950Adpcm.cc:63
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)