openMSX
DeviceFactory.cc
Go to the documentation of this file.
1 #include "DeviceFactory.hh"
2 #include "XMLElement.hh"
3 #include "DeviceConfig.hh"
4 #include "MSXRam.hh"
5 #include "MSXPPI.hh"
6 #include "VDP.hh"
7 #include "MSXE6Timer.hh"
8 #include "MSXFacMidiInterface.hh"
10 #include "MSXTurboRPause.hh"
11 #include "MSXTurboRPCM.hh"
12 #include "MSXS1985.hh"
13 #include "MSXS1990.hh"
14 #include "MSXPSG.hh"
15 #include "MSXMusic.hh"
16 #include "MSXFmPac.hh"
17 #include "MSXAudio.hh"
18 #include "MSXMoonSound.hh"
19 #include "MSXOPL3Cartridge.hh"
20 #include "MSXYamahaSFG.hh"
21 #include "MC6850.hh"
22 #include "MSXKanji.hh"
23 #include "MSXBunsetsu.hh"
24 #include "MSXMemoryMapper.hh"
25 #include "PanasonicRam.hh"
26 #include "MSXRTC.hh"
27 #include "PasswordCart.hh"
28 #include "RomFactory.hh"
29 #include "MSXPrinterPort.hh"
30 #include "MSXSCCPlusCart.hh"
31 #include "PhilipsFDC.hh"
32 #include "MicrosolFDC.hh"
33 #include "AVTFDC.hh"
34 #include "NationalFDC.hh"
35 #include "VictorFDC.hh"
36 #include "SanyoFDC.hh"
37 #include "TurboRFDC.hh"
38 #include "SunriseIDE.hh"
39 #include "BeerIDE.hh"
40 #include "GoudaSCSI.hh"
41 #include "MegaSCSI.hh"
42 #include "ESE_RAM.hh"
43 #include "ESE_SCC.hh"
44 #include "MSXMatsushita.hh"
46 #include "MSXCielTurbo.hh"
47 #include "MSXKanji12.hh"
48 #include "MSXMidi.hh"
49 #include "MSXRS232.hh"
50 #include "MSXMegaRam.hh"
51 #include "MSXPac.hh"
52 #include "MSXHBI55.hh"
53 #include "DebugDevice.hh"
54 #include "V9990.hh"
55 #include "Video9000.hh"
56 #include "ADVram.hh"
57 #include "NowindInterface.hh"
58 #include "MSXMirrorDevice.hh"
59 #include "DummyDevice.hh"
60 #include "MSXDeviceSwitch.hh"
61 #include "MSXMapperIO.hh"
62 #include "VDPIODelay.hh"
63 #include "CliComm.hh"
64 #include "MSXException.hh"
65 #include "memory.hh"
66 #include "components.hh"
67 #include "SensorKid.hh"
68 
69 #if COMPONENT_LASERDISC
70 #include "PioneerLDControl.hh"
71 #endif
72 
73 using std::unique_ptr;
74 
75 namespace openmsx {
76 
77 static unique_ptr<MSXDevice> createWD2793BasedFDC(const DeviceConfig& conf)
78 {
79  const XMLElement* styleEl = conf.findChild("connectionstyle");
80  std::string type;
81  if (!styleEl) {
82  conf.getCliComm().printWarning(
83  "WD2793 as FDC type without a connectionstyle is "
84  "deprecated, please update your config file to use "
85  "WD2793 with connectionstyle Philips!");
86  type = "Philips";
87  } else {
88  type = styleEl->getData();
89  }
90  if ((type == "Philips") || (type == "Sony")) {
91  return make_unique<PhilipsFDC>(conf);
92  } else if (type == "Microsol") {
93  return make_unique<MicrosolFDC>(conf);
94  } else if (type == "AVT") {
95  return make_unique<AVTFDC>(conf);
96  } else if (type == "National") {
97  return make_unique<NationalFDC>(conf);
98  } else if (type == "Sanyo") {
99  return make_unique<SanyoFDC>(conf);
100  } else if (type == "Victor") {
101  return make_unique<VictorFDC>(conf);
102  }
103  throw MSXException("Unknown WD2793 FDC connection style " + type);
104 }
105 
106 unique_ptr<MSXDevice> DeviceFactory::create(const DeviceConfig& conf)
107 {
108  unique_ptr<MSXDevice> result;
109  const std::string& type = conf.getXML()->getName();
110  if (type == "PPI") {
111  result = make_unique<MSXPPI>(conf);
112  } else if (type == "RAM") {
113  result = make_unique<MSXRam>(conf);
114  } else if (type == "VDP") {
115  result = make_unique<VDP>(conf);
116  } else if (type == "E6Timer") {
117  result = make_unique<MSXE6Timer>(conf);
118  } else if (type == "ResetStatusRegister" || type == "F4Device") {
119  result = make_unique<MSXResetStatusRegister>(conf);
120  } else if (type == "TurboRPause") {
121  result = make_unique<MSXTurboRPause>(conf);
122  } else if (type == "TurboRPCM") {
123  result = make_unique<MSXTurboRPCM>(conf);
124  } else if (type == "S1985") {
125  result = make_unique<MSXS1985>(conf);
126  } else if (type == "S1990") {
127  result = make_unique<MSXS1990>(conf);
128  } else if (type == "PSG") {
129  result = make_unique<MSXPSG>(conf);
130  } else if (type == "MSX-MUSIC") {
131  result = make_unique<MSXMusic>(conf);
132  } else if (type == "MSX-MUSIC-WX") {
133  result = make_unique<MSXMusicWX>(conf);
134  } else if (type == "FMPAC") {
135  result = make_unique<MSXFmPac>(conf);
136  } else if (type == "MSX-AUDIO") {
137  result = make_unique<MSXAudio>(conf);
138  } else if (type == "MusicModuleMIDI") {
139  result = make_unique<MC6850>(conf);
140  } else if (type == "FACMIDIInterface") {
141  result = make_unique<MSXFacMidiInterface>(conf);
142  } else if (type == "YamahaSFG") {
143  result = make_unique<MSXYamahaSFG>(conf);
144  } else if (type == "MoonSound") {
145  result = make_unique<MSXMoonSound>(conf);
146  } else if (type == "OPL3Cartridge") {
147  result = make_unique<MSXOPL3Cartridge>(conf);
148  } else if (type == "Kanji") {
149  result = make_unique<MSXKanji>(conf);
150  } else if (type == "Bunsetsu") {
151  result = make_unique<MSXBunsetsu>(conf);
152  } else if (type == "MemoryMapper") {
153  result = make_unique<MSXMemoryMapper>(conf);
154  } else if (type == "PanasonicRAM") {
155  result = make_unique<PanasonicRam>(conf);
156  } else if (type == "RTC") {
157  result = make_unique<MSXRTC>(conf);
158  } else if (type == "PasswordCart") {
159  result = make_unique<PasswordCart>(conf);
160  } else if (type == "ROM") {
161  result = RomFactory::create(conf);
162  } else if (type == "PrinterPort") {
163  result = make_unique<MSXPrinterPort>(conf);
164  } else if (type == "SCCplus") { // Note: it's actually called SCC-I
165  result = make_unique<MSXSCCPlusCart>(conf);
166  } else if ((type == "WD2793") || (type == "WD1770")) {
167  result = createWD2793BasedFDC(conf);
168  } else if (type == "Microsol") {
169  conf.getCliComm().printWarning(
170  "Microsol as FDC type is deprecated, please update "
171  "your config file to use WD2793 with connectionstyle "
172  "Microsol!");
173  result = make_unique<MicrosolFDC>(conf);
174  } else if (type == "MB8877A") {
175  conf.getCliComm().printWarning(
176  "MB8877A as FDC type is deprecated, please update your "
177  "config file to use WD2793 with connectionstyle National!");
178  result = make_unique<NationalFDC>(conf);
179  } else if (type == "TC8566AF") {
180  result = make_unique<TurboRFDC>(conf);
181  } else if (type == "BeerIDE") {
182  result = make_unique<BeerIDE>(conf);
183  } else if (type == "SunriseIDE") {
184  result = make_unique<SunriseIDE>(conf);
185  } else if (type == "GoudaSCSI") {
186  result = make_unique<GoudaSCSI>(conf);
187  } else if (type == "MegaSCSI") {
188  result = make_unique<MegaSCSI>(conf);
189  } else if (type == "ESERAM") {
190  result = make_unique<ESE_RAM>(conf);
191  } else if (type == "WaveSCSI") {
192  result = make_unique<ESE_SCC>(conf, true);
193  } else if (type == "ESESCC") {
194  result = make_unique<ESE_SCC>(conf, false);
195  } else if (type == "Matsushita") {
196  result = make_unique<MSXMatsushita>(conf);
197  } else if (type == "VictorHC9xSystemControl") {
198  result = make_unique<MSXVictorHC9xSystemControl>(conf);
199  } else if (type == "CielTurbo") {
200  result = make_unique<MSXCielTurbo>(conf);
201  } else if (type == "Kanji12") {
202  result = make_unique<MSXKanji12>(conf);
203  } else if (type == "MSX-MIDI") {
204  result = make_unique<MSXMidi>(conf);
205  } else if (type == "MSX-RS232") {
206  result = make_unique<MSXRS232>(conf);
207  } else if (type == "MegaRam") {
208  result = make_unique<MSXMegaRam>(conf);
209  } else if (type == "PAC") {
210  result = make_unique<MSXPac>(conf);
211  } else if (type == "HBI55") {
212  result = make_unique<MSXHBI55>(conf);
213  } else if (type == "DebugDevice") {
214  result = make_unique<DebugDevice>(conf);
215  } else if (type == "V9990") {
216  result = make_unique<V9990>(conf);
217  } else if (type == "Video9000") {
218  result = make_unique<Video9000>(conf);
219  } else if (type == "ADVram") {
220  result = make_unique<ADVram>(conf);
221  } else if (type == "PioneerLDControl") {
222 #if COMPONENT_LASERDISC
223  result = make_unique<PioneerLDControl>(conf);
224 #else
225  throw MSXException("Laserdisc component not compiled in");
226 #endif
227  } else if (type == "Nowind") {
228  result = make_unique<NowindInterface>(conf);
229  } else if (type == "Mirror") {
230  result = make_unique<MSXMirrorDevice>(conf);
231  } else if (type == "SensorKid") {
232  result = make_unique<SensorKid>(conf);
233  } else {
234  throw MSXException("Unknown device \"" + type +
235  "\" specified in configuration");
236  }
237  if (result) result->init();
238  return result;
239 }
240 
241 static XMLElement createConfig(string_ref name, string_ref id)
242 {
243  XMLElement config(name);
244  config.addAttribute("id", id);
245  return config;
246 }
247 
248 unique_ptr<DummyDevice> DeviceFactory::createDummyDevice(
249  const HardwareConfig& hwConf)
250 {
251  static XMLElement xml(createConfig("Dummy", ""));
252  return make_unique<DummyDevice>(DeviceConfig(hwConf, xml));
253 }
254 
255 unique_ptr<MSXDeviceSwitch> DeviceFactory::createDeviceSwitch(
256  const HardwareConfig& hwConf)
257 {
258  static XMLElement xml(createConfig("DeviceSwitch", "DeviceSwitch"));
259  return make_unique<MSXDeviceSwitch>(DeviceConfig(hwConf, xml));
260 }
261 
262 unique_ptr<MSXMapperIO> DeviceFactory::createMapperIO(
263  const HardwareConfig& hwConf)
264 {
265  static XMLElement xml(createConfig("MapperIO", "MapperIO"));
266  return make_unique<MSXMapperIO>(DeviceConfig(hwConf, xml));
267 }
268 
269 unique_ptr<VDPIODelay> DeviceFactory::createVDPIODelay(
270  const HardwareConfig& hwConf, MSXCPUInterface& cpuInterface)
271 {
272  static XMLElement xml(createConfig("VDPIODelay", "VDPIODelay"));
273  return make_unique<VDPIODelay>(DeviceConfig(hwConf, xml), cpuInterface);
274 }
275 
276 } // namespace openmsx
void printWarning(string_ref message)
Definition: CliComm.cc:28
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
static std::unique_ptr< DummyDevice > createDummyDevice(const HardwareConfig &hcConf)
static std::unique_ptr< MSXDevice > create(const DeviceConfig &conf)
const std::string & getName() const
Definition: XMLElement.hh:30
static std::unique_ptr< VDPIODelay > createVDPIODelay(const HardwareConfig &hcConf, MSXCPUInterface &cpuInterface)
static std::unique_ptr< MSXDeviceSwitch > createDeviceSwitch(const HardwareConfig &hcConf)
const XMLElement * getXML() const
Definition: DeviceConfig.hh:54
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
unique_ptr< MSXDevice > create(const DeviceConfig &config)
Definition: RomFactory.cc:156
static std::unique_ptr< MSXMapperIO > createMapperIO(const HardwareConfig &hcConf)