| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#ifndef YM2151_HH |
| 35 |
#define YM2151_HH |
| 36 |
|
| 37 |
#include "EmuTimer.hh" |
| 38 |
#include "ResampledSoundDevice.hh" |
| 39 |
|
| 40 |
#include "EmuTime.hh" |
| 41 |
#include "IRQHelper.hh" |
| 42 |
|
| 43 |
#include <array> |
| 44 |
#include <cstdint> |
| 45 |
#include <memory> |
| 46 |
#include <string> |
| 47 |
|
| 48 |
namespace openmsx { |
| 49 |
|
| 50 |
class DeviceConfig; |
| 51 |
|
| 52 |
class YM2151 final : public ResampledSoundDevice, private EmuTimerCallback |
| 53 |
{ |
| 54 |
public: |
| 55 |
enum class Variant : char { |
| 56 |
YM2151, |
| 57 |
YM2164, |
| 58 |
}; |
| 59 |
|
| 60 |
YM2151(const std::string& name, static_string_view desc, |
| 61 |
const DeviceConfig& config, EmuTime time, Variant variant); |
| 62 |
~YM2151(); |
| 63 |
|
| 64 |
void reset(EmuTime time); |
| 65 |
void writeReg(uint8_t r, uint8_t v, EmuTime time); |
| 66 |
[[nodiscard]] uint8_t readStatus() const; |
| 67 |
|
| 68 |
template<typename Archive> |
| 69 |
void serialize(Archive& ar, unsigned version); |
| 70 |
|
| 71 |
private: |
| 72 |
|
| 73 |
struct YM2151Operator { |
| 74 |
template<typename Archive> |
| 75 |
void serialize(Archive& ar, unsigned version); |
| 76 |
|
| 77 |
int* connect; |
| 78 |
int* mem_connect; |
| 79 |
|
| 80 |
unsigned phase; |
| 81 |
unsigned freq; |
| 82 |
int dt1; |
| 83 |
unsigned mul; |
| 84 |
unsigned dt1_i; |
| 85 |
unsigned dt2; |
| 86 |
|
| 87 |
int mem_value; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
unsigned fb_shift; |
| 92 |
int fb_out_curr; |
| 93 |
int fb_out_prev; |
| 94 |
unsigned kc; |
| 95 |
unsigned kc_i; |
| 96 |
int8_t pms; |
| 97 |
unsigned ams; |
| 98 |
|
| 99 |
unsigned AMmask; |
| 100 |
unsigned state; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
unsigned tl; |
| 106 |
int volume; |
| 107 |
unsigned d1l; |
| 108 |
|
| 109 |
unsigned key; |
| 110 |
|
| 111 |
unsigned ks; |
| 112 |
unsigned ar; |
| 113 |
unsigned d1r; |
| 114 |
unsigned d2r; |
| 115 |
unsigned rr; |
| 116 |
|
| 117 |
uint8_t eg_sh_ar; |
| 118 |
uint8_t eg_sel_ar; |
| 119 |
uint8_t eg_sh_d1r; |
| 120 |
uint8_t eg_sel_d1r; |
| 121 |
|
| 122 |
uint8_t eg_sh_d2r; |
| 123 |
uint8_t eg_sel_d2r; |
| 124 |
uint8_t eg_sh_rr; |
| 125 |
uint8_t eg_sel_rr; |
| 126 |
}; |
| 127 |
|
| 128 |
void setConnect(std::span<YM2151Operator, 4> o, int cha, int v); |
| 129 |
|
| 130 |
|
| 131 |
void generateChannels(std::span<float*> bufs, unsigned num) override; |
| 132 |
|
| 133 |
void callback(uint8_t flag) override; |
| 134 |
void setStatus(uint8_t flags); |
| 135 |
void resetStatus(uint8_t flags); |
| 136 |
|
| 137 |
|
| 138 |
void envelopeKONKOFF(std::span<YM2151Operator, 4> op, int v) const; |
| 139 |
static void refreshEG(std::span<YM2151Operator, 4> op); |
| 140 |
[[nodiscard]] int opCalc(const YM2151Operator& op, unsigned env, int pm) const; |
| 141 |
[[nodiscard]] int opCalc1(const YM2151Operator& op, unsigned env, int pm) const; |
| 142 |
[[nodiscard]] inline unsigned volumeCalc(const YM2151Operator& op, unsigned AM) const; |
| 143 |
inline void keyOn(YM2151Operator& op, unsigned keySet) const; |
| 144 |
inline void keyOff(YM2151Operator& op, unsigned keyClear) const; |
| 145 |
|
| 146 |
|
| 147 |
void chanCalc(unsigned chan); |
| 148 |
void chan7Calc(); |
| 149 |
|
| 150 |
void advanceEG(); |
| 151 |
void advance(); |
| 152 |
|
| 153 |
[[nodiscard]] bool checkMuteHelper(); |
| 154 |
|
| 155 |
IRQHelper irq; |
| 156 |
|
| 157 |
|
| 158 |
const std::unique_ptr<EmuTimer> timer1; |
| 159 |
const std::unique_ptr<EmuTimer> timer2; |
| 160 |
|
| 161 |
std::array<YM2151Operator, 32> oper; |
| 162 |
|
| 163 |
std::array<unsigned, 16> pan; |
| 164 |
|
| 165 |
unsigned eg_cnt; |
| 166 |
unsigned eg_timer; |
| 167 |
|
| 168 |
unsigned lfo_phase; |
| 169 |
unsigned lfo_timer; |
| 170 |
unsigned lfo_overflow; |
| 171 |
|
| 172 |
unsigned lfo_counter; |
| 173 |
unsigned lfo_counter_add; |
| 174 |
unsigned lfa; |
| 175 |
int lfp; |
| 176 |
|
| 177 |
unsigned noise; |
| 178 |
|
| 179 |
unsigned noise_rng; |
| 180 |
int noise_p; |
| 181 |
int noise_f; |
| 182 |
|
| 183 |
unsigned csm_req; |
| 184 |
|
| 185 |
unsigned irq_enable; |
| 186 |
|
| 187 |
|
| 188 |
uint8_t status; |
| 189 |
|
| 190 |
std::array<int, 8> chanOut; |
| 191 |
int m2, c1, c2; |
| 192 |
int mem; |
| 193 |
|
| 194 |
uint16_t timer_A_val{0}; |
| 195 |
|
| 196 |
uint8_t lfo_wsel; |
| 197 |
|
| 198 |
uint8_t amd; |
| 199 |
int8_t pmd; |
| 200 |
|
| 201 |
uint8_t test; |
| 202 |
uint8_t ct; |
| 203 |
|
| 204 |
std::array<uint8_t, 256> regs = {}; |
| 205 |
const Variant variant; |
| 206 |
}; |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
#endif |