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