openMSX
SaveStateCLI.cc
Go to the documentation of this file.
1 #include "SaveStateCLI.hh"
2 #include "CommandLineParser.hh"
3 #include "TclObject.hh"
4 
5 using std::string;
6 
7 namespace openmsx {
8 
10  : parser(parser_)
11 {
12  parser.registerOption("-savestate", *this);
13  parser.registerFileType({"oms"}, *this);
14 }
15 
16 void SaveStateCLI::parseOption(const string& option, span<string>& cmdLine)
17 {
18  parseFileType(getArgument(option, cmdLine), cmdLine);
19 }
20 
21 std::string_view SaveStateCLI::optionHelp() const
22 {
23  return "Load savestate and start emulation from there";
24 }
25 
27  span<string>& /*cmdLine*/)
28 {
29  // TODO: this is basically a C++ version of a part of savestate.tcl.
30  // Can that be improved?
31  auto& interp = parser.getInterpreter();
32 
33  TclObject command1 = makeTclList("restore_machine", filename);
34  auto newId = command1.executeCommand(interp);
35 
36  TclObject command2 = makeTclList("machine");
37  auto currentId = command2.executeCommand(interp);
38 
39  if (!currentId.empty()) {
40  TclObject command3 = makeTclList("delete_machine", currentId);
41  command3.executeCommand(interp);
42  }
43 
44  TclObject command4 = makeTclList("activate_machine", newId);
45  command4.executeCommand(interp);
46 }
47 
48 std::string_view SaveStateCLI::fileTypeHelp() const
49 {
50  return "openMSX savestate";
51 }
52 
53 std::string_view SaveStateCLI::fileTypeCategoryName() const
54 {
55  return "savestate";
56 }
57 
58 } // namespace openmsx
openmsx::SaveStateCLI::parseOption
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: SaveStateCLI.cc:16
openmsx::CommandLineParser::registerOption
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
Definition: CommandLineParser.cc:84
TclObject.hh
openmsx::CommandLineParser::getInterpreter
Interpreter & getInterpreter() const
Definition: CommandLineParser.cc:306
CommandLineParser.hh
SaveStateCLI.hh
span
Definition: span.hh:34
openmsx::SaveStateCLI::SaveStateCLI
SaveStateCLI(CommandLineParser &parser)
Definition: SaveStateCLI.cc:9
openmsx::SaveStateCLI::fileTypeHelp
std::string_view fileTypeHelp() const override
Definition: SaveStateCLI.cc:48
openmsx::SaveStateCLI::optionHelp
std::string_view optionHelp() const override
Definition: SaveStateCLI.cc:21
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::SaveStateCLI::parseFileType
void parseFileType(const std::string &filename, span< std::string > &cmdLine) override
Definition: SaveStateCLI.cc:26
openmsx::TclObject::executeCommand
TclObject executeCommand(Interpreter &interp, bool compile=false)
Interpret this TclObject as a command and execute it.
Definition: TclObject.cc:172
openmsx::CommandLineParser
Definition: CommandLineParser.hh:34
openmsx::SaveStateCLI::fileTypeCategoryName
std::string_view fileTypeCategoryName() const override
Definition: SaveStateCLI.cc:53
openmsx::makeTclList
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:280
openmsx::TclObject
Definition: TclObject.hh:21
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
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5