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