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