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  static const string text("ROM image of a cartridge");
51  return text;
52 }
53 
54 std::string_view MSXRomCLI::fileTypeCategoryName() const
55 {
56  return "rom";
57 }
58 
59 void MSXRomCLI::parse(const string& arg, const string& slotname,
60  span<string>& cmdLine)
61 {
62  // parse extra options -ips and -romtype
63  std::vector<TclObject> options;
64  while (true) {
65  string option = peekArgument(cmdLine);
66  if (option == one_of("-ips", "-romtype")) {
67  options.emplace_back(option);
68  cmdLine = cmdLine.subspan(1);
69  options.emplace_back(getArgument(option, cmdLine));
70  } else {
71  break;
72  }
73  }
74  MSXMotherBoard* motherboard = cmdLineParser.getMotherBoard();
75  assert(motherboard);
76  motherboard->insertExtension("ROM",
77  HardwareConfig::createRomConfig(*motherboard, arg, slotname, options));
78 }
79 
80 void MSXRomCLI::IpsOption::parseOption(const string& /*option*/,
81  span<string>& /*cmdLine*/)
82 {
83  throw FatalError(
84  "-ips options should immediately follow a ROM or disk image.");
85 }
86 
87 std::string_view MSXRomCLI::IpsOption::optionHelp() const
88 {
89  return "Apply the given IPS patch to the ROM or disk image specified "
90  "in the preceding option";
91 }
92 
93 void MSXRomCLI::RomTypeOption::parseOption(const string& /*option*/,
94  span<string>& /*cmdLine*/)
95 {
96  throw FatalError("-romtype options should immediately follow a ROM.");
97 }
98 
99 std::string_view MSXRomCLI::RomTypeOption::optionHelp() const
100 {
101  return "Specify the rom type for the ROM image specified in the "
102  "preceding option";
103 }
104 
105 } // namespace openmsx
one_of.hh
HardwareConfig.hh
MSXRomCLI.hh
openmsx::CommandLineParser::registerOption
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
Definition: CommandLineParser.cc:84
openmsx::CommandLineParser::getMotherBoard
MSXMotherBoard * getMotherBoard() const
Definition: CommandLineParser.cc:296
openmsx::MSXRomCLI::fileTypeHelp
std::string_view fileTypeHelp() const override
Definition: MSXRomCLI.cc:48
CommandLineParser.hh
openmsx::CLIOption::peekArgument
std::string peekArgument(const span< std::string > &cmdLine) const
Definition: CLIOption.cc:21
MSXException.hh
openmsx::MSXRomCLI::optionHelp
std::string_view optionHelp() const override
Definition: MSXRomCLI.cc:38
span::subspan
constexpr subspan_return_t< Offset, Count > subspan() const
Definition: span.hh:266
span
Definition: span.hh:126
openmsx::MSXRomCLI::parseOption
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: MSXRomCLI.cc:26
one_of
Definition: one_of.hh:7
openmsx::HardwareConfig::createRomConfig
static std::unique_ptr< HardwareConfig > createRomConfig(MSXMotherBoard &motherBoard, std::string romfile, std::string slotname, span< const TclObject > options)
Definition: HardwareConfig.cc:50
openmsx::MSXRomCLI::parseFileType
void parseFileType(const std::string &arg, span< std::string > &cmdLine) override
Definition: MSXRomCLI.cc:43
openmsx::CommandLineParser
Definition: CommandLineParser.hh:35
openmsx::MSXRomCLI::fileTypeCategoryName
std::string_view fileTypeCategoryName() const override
Definition: MSXRomCLI.cc:54
openmsx::CommandLineParser::registerFileType
void registerFileType(std::initializer_list< std::string_view > extensions, CLIFileType &cliFileType)
Definition: CommandLineParser.cc:90
openmsx::CLIOption::getArgument
std::string getArgument(const std::string &option, span< std::string > &cmdLine) const
Definition: CLIOption.cc:11
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
MSXMotherBoard.hh
openmsx::MSXRomCLI::MSXRomCLI
MSXRomCLI(CommandLineParser &cmdLineParser)
Definition: MSXRomCLI.cc:13