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