openMSX
MSXRomCLI.cc
Go to the documentation of this file.
1 #include "MSXRomCLI.hh"
2 #include "CommandLineParser.hh"
3 #include "HardwareConfig.hh"
4 #include "MSXMotherBoard.hh"
5 #include "MSXException.hh"
6 #include "one_of.hh"
7 #include <cassert>
8 
9 using std::string;
10 
11 namespace openmsx {
12 
14  : cmdLineParser(cmdLineParser_)
15 {
16  cmdLineParser.registerOption("-ips", ipsOption);
17  cmdLineParser.registerOption("-romtype", romTypeOption);
18  cmdLineParser.registerOption("-cart", *this);
19  cmdLineParser.registerOption("-carta", *this);
20  cmdLineParser.registerOption("-cartb", *this);
21  cmdLineParser.registerOption("-cartc", *this);
22  cmdLineParser.registerOption("-cartd", *this);
23  cmdLineParser.registerFileType({"ri", "rom", "mx1", "mx2"}, *this);
24 }
25 
26 void MSXRomCLI::parseOption(const string& option, span<string>& cmdLine)
27 {
28  string arg = getArgument(option, cmdLine);
29  string slotname;
30  if (option.size() == 6) {
31  slotname = option[5];
32  } else {
33  slotname = "any";
34  }
35  parse(arg, slotname, cmdLine);
36 }
37 
38 std::string_view MSXRomCLI::optionHelp() const
39 {
40  return "Insert the ROM file (cartridge) specified in argument";
41 }
42 
43 void MSXRomCLI::parseFileType(const string& arg, span<string>& cmdLine)
44 {
45  parse(arg, "any", cmdLine);
46 }
47 
48 std::string_view MSXRomCLI::fileTypeHelp() const
49 {
50  return "ROM image of a cartridge";
51 }
52 
53 std::string_view MSXRomCLI::fileTypeCategoryName() const
54 {
55  return "rom";
56 }
57 
58 void MSXRomCLI::parse(const string& arg, const string& slotname,
59  span<string>& cmdLine)
60 {
61  // parse extra options -ips and -romtype
62  std::vector<TclObject> options;
63  while (true) {
64  string option = peekArgument(cmdLine);
65  if (option == one_of("-ips", "-romtype")) {
66  options.emplace_back(option);
67  cmdLine = cmdLine.subspan(1);
68  options.emplace_back(getArgument(option, cmdLine));
69  } else {
70  break;
71  }
72  }
73  MSXMotherBoard* motherboard = cmdLineParser.getMotherBoard();
74  assert(motherboard);
75  motherboard->insertExtension("ROM",
76  HardwareConfig::createRomConfig(*motherboard, arg, slotname, options));
77 }
78 
79 void MSXRomCLI::IpsOption::parseOption(const string& /*option*/,
80  span<string>& /*cmdLine*/)
81 {
82  throw FatalError(
83  "-ips options should immediately follow a ROM or disk image.");
84 }
85 
86 std::string_view MSXRomCLI::IpsOption::optionHelp() const
87 {
88  return "Apply the given IPS patch to the ROM or disk image specified "
89  "in the preceding option";
90 }
91 
92 void MSXRomCLI::RomTypeOption::parseOption(const string& /*option*/,
93  span<string>& /*cmdLine*/)
94 {
95  throw FatalError("-romtype options should immediately follow a ROM.");
96 }
97 
98 std::string_view MSXRomCLI::RomTypeOption::optionHelp() const
99 {
100  return "Specify the rom type for the ROM image specified in the "
101  "preceding option";
102 }
103 
104 } // namespace openmsx
Definition: one_of.hh:7
static std::string peekArgument(const span< std::string > &cmdLine)
Definition: CLIOption.cc:19
static std::string getArgument(const std::string &option, span< std::string > &cmdLine)
Definition: CLIOption.cc:9
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
void registerFileType(std::initializer_list< std::string_view > extensions, CLIFileType &cliFileType)
MSXMotherBoard * getMotherBoard() const
static std::unique_ptr< HardwareConfig > createRomConfig(MSXMotherBoard &motherBoard, std::string romfile, std::string slotname, span< const TclObject > options)
void parseFileType(const std::string &arg, span< std::string > &cmdLine) override
Definition: MSXRomCLI.cc:43
std::string_view fileTypeCategoryName() const override
Definition: MSXRomCLI.cc:53
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: MSXRomCLI.cc:26
std::string_view fileTypeHelp() const override
Definition: MSXRomCLI.cc:48
std::string_view optionHelp() const override
Definition: MSXRomCLI.cc:38
MSXRomCLI(CommandLineParser &cmdLineParser)
Definition: MSXRomCLI.cc:13
Definition: span.hh:126
constexpr subspan_return_t< Offset, Count > subspan() const
Definition: span.hh:266
This file implemented 3 utility functions:
Definition: Autofire.cc:9