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