ScummVM API documentation
fmopl.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AUDIO_FMOPL_H
23 #define AUDIO_FMOPL_H
24 
25 #include "audio/chip.h"
26 
27 namespace Audio {
28 class SoundHandle;
29 }
30 
31 namespace Common {
32 class String;
33 }
34 
35 namespace OPL {
36 
37 class OPL;
38 
47 class Config {
48 public:
49  enum OplFlags {
50  kFlagOpl2 = (1 << 0),
51  kFlagDualOpl2 = (1 << 1),
52  kFlagOpl3 = (1 << 2)
53  };
54 
58  enum OplType {
59  kOpl2,
60  kDualOpl2,
61  kOpl3
62  };
63 
64  typedef int8 DriverId;
66  const char *name;
67  const char *description;
68 
69  DriverId id; // A unique ID for each driver
70  uint32 flags; // Capabilities of this driver
71  };
72 
77  static const EmulatorDescription *getAvailable() { return _drivers; }
78 
82  static DriverId parse(const Common::String &name);
83 
88  static const EmulatorDescription *findDriver(DriverId id);
89 
96  static DriverId detect(OplType type);
97 
101  static OPL *create(DriverId driver, OplType type);
102 
107  static OPL *create(OplType type = kOpl2);
108 
109 private:
110  static const EmulatorDescription _drivers[];
111 };
112 
116 class OPL : virtual public Audio::Chip {
117 private:
118  static bool _hasInstance;
119 public:
120  OPL();
121  virtual ~OPL() { _hasInstance = false; }
122 
128  virtual bool init() = 0;
129 
133  virtual void reset() = 0;
134 
141  virtual void write(int a, int v) = 0;
142 
152  virtual void writeReg(int r, int v) = 0;
153 
154  using Audio::Chip::start;
155  void start(TimerCallback *callback) { start(callback, kDefaultCallbackFrequency); }
156 
157  enum {
161  kDefaultCallbackFrequency = 250
162  };
163 
164 protected:
171  void initDualOpl2OnOpl3(Config::OplType oplType);
172 
185  bool emulateDualOpl2OnOpl3(int r, int v, Config::OplType oplType);
186 
187  bool _rhythmMode;
188  int _connectionFeedbackValues[3];
189 };
190 
195 class NullOPL final : public ::OPL::OPL, public Audio::RealChip {
196 public:
197  bool init() override { return true; }
198  void reset() override {}
199  void write(int a, int v) override {}
200  void writeReg(int r, int v) override {}
201 };
202 
204 } // End of namespace OPL
205 
206 #endif
Definition: str.h:59
void reset() override
Definition: fmopl.h:198
void writeReg(int r, int v) override
Definition: fmopl.h:200
void start(TimerCallback *callback, int timerFrequency)
static const EmulatorDescription * getAvailable()
Definition: fmopl.h:77
Definition: fmopl.h:47
bool init() override
Definition: fmopl.h:197
Definition: chip.h:33
OplType
Definition: fmopl.h:58
Definition: algorithm.h:29
Definition: fmopl.h:35
Definition: fmopl.h:195
Definition: chip.h:81
Definition: fmopl.h:65
void write(int a, int v) override
Definition: fmopl.h:199
Definition: system.h:38
Definition: fmopl.h:116