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