openMSX
MSXRomCLI.cc
Go to the documentation of this file.
1#include "MSXRomCLI.hh"
3#include "HardwareConfig.hh"
4#include "MSXMotherBoard.hh"
5#include "MSXException.hh"
6#include "one_of.hh"
7#include <cassert>
8
9using std::string;
10
11namespace 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
26void MSXRomCLI::parseOption(const string& option, std::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
38std::string_view MSXRomCLI::optionHelp() const
39{
40 return "Insert the ROM file (cartridge) specified in argument";
41}
42
43void MSXRomCLI::parseFileType(const string& arg, std::span<string>& cmdLine)
44{
45 parse(arg, "any", cmdLine);
46}
47
48std::string_view MSXRomCLI::fileTypeHelp() const
49{
50 return "ROM image of a cartridge";
51}
52
53std::string_view MSXRomCLI::fileTypeCategoryName() const
54{
55 return "rom";
56}
57
58void MSXRomCLI::parse(const string& arg, const string& slotName,
59 std::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
79void MSXRomCLI::IpsOption::parseOption(const string& /*option*/,
80 std::span<string>& /*cmdLine*/)
81{
82 throw FatalError(
83 "-ips options should immediately follow a ROM or disk image.");
84}
85
86std::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
92void MSXRomCLI::RomTypeOption::parseOption(const string& /*option*/,
93 std::span<string>& /*cmdLine*/)
94{
95 throw FatalError("-romtype options should immediately follow a ROM.");
96}
97
98std::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 getArgument(const std::string &option, std::span< std::string > &cmdLine)
Definition: CLIOption.cc:9
static std::string peekArgument(const std::span< std::string > &cmdLine)
Definition: CLIOption.cc:19
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_view romFile, std::string_view slotName, std::span< const TclObject > options)
void parseFileType(const std::string &arg, std::span< std::string > &cmdLine) override
Definition: MSXRomCLI.cc:43
std::string_view fileTypeCategoryName() const override
Definition: MSXRomCLI.cc:53
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
void parseOption(const std::string &option, std::span< std::string > &cmdLine) override
Definition: MSXRomCLI.cc:26
This file implemented 3 utility functions:
Definition: Autofire.cc:9