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