openMSX
SaveStateCLI.cc
Go to the documentation of this file.
1 #include "SaveStateCLI.hh"
2 #include "CommandLineParser.hh"
4 #include "MSXException.hh"
5 #include "TclObject.hh"
6 
7 using std::deque;
8 using std::string;
9 
10 namespace openmsx {
11 
13  : parser(parser_)
14 {
15  parser.registerOption("-savestate", *this);
16  parser.registerFileClass("openMSX savestate", *this);
17 }
18 
19 void SaveStateCLI::parseOption(const string& option, deque<string>& cmdLine)
20 {
21  parseFileType(getArgument(option, cmdLine), cmdLine);
22 }
23 
25 {
26  return "Load savestate and start emulation from there";
27 }
28 
29 void SaveStateCLI::parseFileType(const string& filename,
30  deque<string>& /*cmdLine*/)
31 {
32  // TODO: this is basically a C++ version of a part of savestate.tcl.
33  // Can that be improved?
35  TclObject command(controller.getInterpreter());
36  command.addListElement("restore_machine");
37  command.addListElement(filename);
38  string newId = command.executeCommand();
39  command = TclObject(controller.getInterpreter());
40  command.addListElement("machine");
41  string currentId = command.executeCommand();
42  if (currentId != "") {
43  command = TclObject(controller.getInterpreter());
44  command.addListElement("delete_machine");
45  command.addListElement(currentId);
46  command.executeCommand();
47  }
48  command = TclObject(controller.getInterpreter());
49  command.addListElement("activate_machine");
50  command.addListElement(newId);
51  command.executeCommand();
52 }
53 
55 {
56  return "openMSX savestate";
57 }
58 
59 } // namespace openmsx