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