OXYGENHUB
◆ main openmsx / src / sound / Y8950Adpcm.hh
2.0 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef Y8950ADPCM_HH
2
#define Y8950ADPCM_HH
3
4
#include "Clock.hh"
5
#include "Schedulable.hh"
6
#include "TrackedRam.hh"
7
#include "serialize_meta.hh"
8
9
#include <cstdint>
10
11
namespace openmsx {
12
13
class DeviceConfig;
14
class Y8950;
15
16
class Y8950Adpcm final : public Schedulable
17
{
18
public:
19
	Y8950Adpcm(Y8950& y8950, const DeviceConfig& config,
20
	           const std::string& name, unsigned sampleRam);
21
22
	void clearRam();
23
	void reset(EmuTime time);
24
	[[nodiscard]] bool isMuted() const;
25
	void writeReg(uint8_t rg, uint8_t data, EmuTime time);
26
	[[nodiscard]] uint8_t readReg(uint8_t rg, EmuTime time);
27
	[[nodiscard]] uint8_t peekReg(uint8_t rg, EmuTime time) const;
28
	[[nodiscard]] int calcSample();
29
	void sync(EmuTime time);
30
	void resetStatus();
31
32
	template<typename Archive>
33
	void serialize(Archive& ar, unsigned version);
34
35
private:
36
	// This data is updated while playing
37
	struct PlayData {
38
		unsigned memPtr;
39
		unsigned nowStep;
40
		int out;
41
		int output;
42
		int diff;
43
		int nextLeveling;
44
		int sampleStep;
45
		uint8_t adpcm_data;
46
	};
47
48
	// Schedulable
49
	void executeUntil(EmuTime time) override;
50
51
	void schedule();
52
	void restart(PlayData& pd) const;
53
54
	[[nodiscard]] bool isPlaying() const;
55
	void writeData(uint8_t data);
56
	[[nodiscard]] uint8_t peekReg(uint8_t rg) const;
57
	[[nodiscard]] uint8_t readData();
58
	[[nodiscard]] uint8_t peekData() const;
59
	void writeMemory(unsigned memPtr, uint8_t value);
60
	[[nodiscard]] uint8_t readMemory(unsigned memPtr) const;
61
	[[nodiscard]] int calcSample(bool doEmu);
62
63
private:
64
	Y8950& y8950;
65
	TrackedRam ram;
66
67
	// copy/pasted from Y8950.hh
68
	static constexpr int CLOCK_FREQ     = 3579545;
69
	static constexpr int CLOCK_FREQ_DIV = 72;
70
	Clock<CLOCK_FREQ, CLOCK_FREQ_DIV> clock;
71
72
	PlayData emu; // used for emulator behaviour (read back of sample data)
73
	PlayData aud; // used by audio generation thread
74
75
	unsigned startAddr;
76
	unsigned stopAddr;
77
	unsigned addrMask;
78
	int volume = 0;
79
	int volumeWStep;
80
	int readDelay;
81
	int delta;
82
	uint8_t reg7;
83
	uint8_t reg15;
84
	bool romBank;
85
};
86
SERIALIZE_CLASS_VERSION(Y8950Adpcm, 2);
87
88
} // namespace openmsx
89
90
#endif