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