openMSX
YMF278.hh
Go to the documentation of this file.
1#ifndef YMF278_HH
2#define YMF278_HH
3
5#include "SimpleDebuggable.hh"
6#include "Rom.hh"
7#include "TrackedRam.hh"
8#include "EmuTime.hh"
9#include "openmsx.hh"
10#include "serialize_meta.hh"
11#include <string>
12
13namespace openmsx {
14
15class DeviceConfig;
16
17class YMF278 final : public ResampledSoundDevice
18{
19public:
20 YMF278(const std::string& name, int ramSize,
21 const DeviceConfig& config);
22 ~YMF278();
23 void clearRam();
24 void reset(EmuTime::param time);
25 void writeReg(byte reg, byte data, EmuTime::param time);
26 [[nodiscard]] byte readReg(byte reg);
27 [[nodiscard]] byte peekReg(byte reg) const;
28
29 [[nodiscard]] byte readMem(unsigned address) const;
30 void writeMem(unsigned address, byte value);
31
32 void setMixLevel(uint8_t x, EmuTime::param time);
33
34 template<typename Archive>
35 void serialize(Archive& ar, unsigned version);
36
37private:
38 class Slot {
39 public:
40 Slot();
41 void reset();
42 [[nodiscard]] int compute_rate(int val) const;
43 [[nodiscard]] int compute_decay_rate(int val) const;
44 [[nodiscard]] unsigned decay_rate(int num, int sample_rate);
45 void envelope_next(int sample_rate);
46 [[nodiscard]] int16_t compute_vib() const;
47 [[nodiscard]] uint16_t compute_am() const;
48
49 template<typename Archive>
50 void serialize(Archive& ar, unsigned version);
51
52 uint32_t startaddr;
53 uint16_t loopaddr;
54 uint16_t endaddr; // Note: stored in 2s complement (0x0000 = 0, 0x0001 = -65536, 0xffff = -1)
55 uint32_t step; // fixed-point frequency step
56 // invariant: step == calcStep(OCT, FN)
57 uint32_t stepptr; // fixed-point pointer into the sample
58 uint16_t pos;
59
60 int16_t env_vol;
61
62 uint32_t lfo_cnt;
63
64 int16_t DL;
65 uint16_t wave; // wavetable number
66 uint16_t FN; // f-number TODO store 'FN | 1024'?
67 int8_t OCT; // octave [-8..+7]
68 bool PRVB; // pseudo-reverb
69 uint8_t TLdest; // destination total level
70 uint8_t TL; // total level (goes towards TLdest)
71 uint8_t pan; // panpot 0..15
72 bool keyon; // slot keyed on
73 bool DAMP;
74 uint8_t lfo; // LFO speed 0..7
75 uint8_t vib; // vibrato 0..7
76 uint8_t AM; // AM level 0..7
77 uint8_t AR; // 0..15
78 uint8_t D1R; // 0..15
79 uint8_t D2R; // 0..15
80 uint8_t RC; // rate correction 0..15
81 uint8_t RR; // 0..15
82
83 uint8_t bits; // width of the samples
84
85 uint8_t state; // envelope generator state
86 bool lfo_active;
87 };
88
89 // SoundDevice
90 void generateChannels(float** bufs, unsigned num) override;
91
92 void writeRegDirect(byte reg, byte data, EmuTime::param time);
93 [[nodiscard]] unsigned getRamAddress(unsigned addr) const;
94 [[nodiscard]] int16_t getSample(Slot& slot, uint16_t pos) const;
95 [[nodiscard]] static uint16_t nextPos(Slot& slot, uint16_t pos, uint16_t increment);
96 void advance();
97 [[nodiscard]] bool anyActive();
98 void keyOnHelper(Slot& slot);
99
100 MSXMotherBoard& motherBoard;
101
102 struct DebugRegisters final : SimpleDebuggable {
103 DebugRegisters(MSXMotherBoard& motherBoard, const std::string& name);
104 [[nodiscard]] byte read(unsigned address) override;
105 void write(unsigned address, byte value, EmuTime::param time) override;
106 } debugRegisters;
107
108 struct DebugMemory final : SimpleDebuggable {
109 DebugMemory(MSXMotherBoard& motherBoard, const std::string& name);
110 [[nodiscard]] byte read(unsigned address) override;
111 void write(unsigned address, byte value) override;
112 } debugMemory;
113
114 Slot slots[24];
115
117 unsigned eg_cnt;
118
119 int memAdr;
120
121 Rom rom;
122 TrackedRam ram;
123
124 byte regs[256];
125};
126SERIALIZE_CLASS_VERSION(YMF278::Slot, 6);
128
129} // namespace openmsx
130
131#endif
byte readMem(unsigned address) const
Definition: YMF278.cc:935
void writeReg(byte reg, byte data, EmuTime::param time)
Definition: YMF278.cc:569
void setMixLevel(uint8_t x, EmuTime::param time)
Definition: YMF278.cc:481
YMF278(const std::string &name, int ramSize, const DeviceConfig &config)
Definition: YMF278.cc:780
void writeMem(unsigned address, byte value)
Definition: YMF278.cc:953
void reset(EmuTime::param time)
Definition: YMF278.cc:826
byte readReg(byte reg)
Definition: YMF278.cc:744
void clearRam()
Definition: YMF278.cc:821
byte peekReg(byte reg) const
Definition: YMF278.cc:759
void serialize(Archive &ar, unsigned version)
Definition: YMF278.cc:1071
constexpr auto step
Definition: eeprom.cc:9
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:127