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