52using std::make_unique;
54using std::string_view;
67 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
77 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
88 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
99 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
108 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
109 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
119 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
120 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
129 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
130 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
140 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
141 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
151 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
152 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
162 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
163 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
172 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
173 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
182 void execute(std::span<const TclObject> tokens,
184 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
187 const string configName;
194 void execute(std::span<const TclObject> tokens,
196 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
198 const uint64_t reference;
205 void execute(std::span<const TclObject> tokens,
207 [[nodiscard]] std::string
help(std::span<const TclObject> tokens)
const override;
217 rtScheduler = make_unique<RTScheduler>();
218 eventDistributor = make_unique<EventDistributor>(*
this);
219 globalCliComm = make_unique<GlobalCliComm>();
220 globalCommandController = make_unique<GlobalCommandController>(
221 *eventDistributor, *globalCliComm, *
this);
222 globalSettings = make_unique<GlobalSettings>(
223 *globalCommandController);
224 inputEventGenerator = make_unique<InputEventGenerator>(
225 *globalCommandController, *eventDistributor, *globalSettings);
226 diskFactory = make_unique<DiskFactory>(
228 diskManipulator = make_unique<DiskManipulator>(
229 *globalCommandController, *
this);
230 virtualDrive = make_unique<DiskChanger>(
231 *
this,
"virtual_drive");
232 filePool = make_unique<FilePool>(*globalCommandController, *
this);
233 userSettings = make_unique<UserSettings>(
234 *globalCommandController);
235 afterCommand = make_unique<AfterCommand>(
236 *
this, *eventDistributor, *globalCommandController);
237 exitCommand = make_unique<ExitCommand>(
238 *globalCommandController, *eventDistributor);
239 messageCommand = make_unique<MessageCommand>(
240 *globalCommandController);
241 machineCommand = make_unique<MachineCommand>(
242 *globalCommandController, *
this);
243 testMachineCommand = make_unique<TestMachineCommand>(
244 *globalCommandController, *
this);
245 createMachineCommand = make_unique<CreateMachineCommand>(
246 *globalCommandController, *
this);
247 deleteMachineCommand = make_unique<DeleteMachineCommand>(
248 *globalCommandController, *
this);
249 listMachinesCommand = make_unique<ListMachinesCommand>(
250 *globalCommandController, *
this);
251 activateMachineCommand = make_unique<ActivateMachineCommand>(
252 *globalCommandController, *
this);
253 storeMachineCommand = make_unique<StoreMachineCommand>(
254 *globalCommandController, *
this);
255 restoreMachineCommand = make_unique<RestoreMachineCommand>(
256 *globalCommandController, *
this);
257 getClipboardCommand = make_unique<GetClipboardCommand>(
258 *globalCommandController, *
this);
259 setClipboardCommand = make_unique<SetClipboardCommand>(
260 *globalCommandController, *
this);
261 aviRecordCommand = make_unique<AviRecorder>(*
this);
262 extensionInfo = make_unique<ConfigInfo>(
264 machineInfo = make_unique<ConfigInfo>(
266 realTimeInfo = make_unique<RealTimeInfo>(
268 softwareInfoTopic = make_unique<SoftwareInfoTopic>(
270 tclCallbackMessages = make_unique<TclCallbackMessages>(
271 *globalCliComm, *globalCommandController);
273 createMachineSetting();
287 deleteBoard(activeBoard);
300 mixer = make_unique<Mixer>(*
this, *globalCommandController);
307 if (!softwareDatabase) {
308 softwareDatabase = make_unique<RomDatabase>(*globalCliComm);
310 return *softwareDatabase;
315 return *globalCliComm;
325 return *globalCommandController;
330 return globalCommandController->getOpenMSXInfoCommand();
335 vector<string> result;
337 auto fileAction = [&](
const std::string& , std::string_view name) {
338 if (name.ends_with(
".xml")) {
339 name.remove_suffix(4);
340 result.emplace_back(name);
343 auto dirAction = [&](std::string& path, std::string_view name) {
344 auto size = path.size();
345 path +=
"/hardwareconfig.xml";
347 result.emplace_back(name);
359void Reactor::createMachineSetting()
363 machines.reserve(names.size() + 1);
367 machines.emplace_back(
"C-BIOS_MSX2+", 0);
369 machineSetting = make_unique<EnumSetting<int>>(
370 *globalCommandController,
"default_machine",
371 "default machine (takes effect next time openMSX is started)",
372 0, std::move(machines));
378 return activeBoard.get();
383 return activeBoard ? activeBoard->getMachineID() : string_view{};
389 it != boards.end()) {
392 throw CommandException(
"No machine with ID: ", machineID);
397 return std::make_shared<MSXMotherBoard>(*
this);
405 boards.push_back(newBoard);
409 [](
auto& b) {
return b.get(); });
412 if (*it == activeBoard) {
413 switchBoard(newBoard);
423 display = make_unique<Display>(*
this);
427 display->createVideoSystem();
438 newBoard->loadMachine(machine);
439 boards.push_back(newBoard);
441 auto oldBoard = activeBoard;
442 switchBoard(newBoard);
443 deleteBoard(oldBoard);
446void Reactor::switchBoard(Board newBoard)
449 assert(!newBoard ||
contains(boards, newBoard));
450 assert(!activeBoard ||
contains(boards, activeBoard));
452 activeBoard->activate(
false);
458 std::lock_guard<std::mutex> lock(mbMutex);
459 activeBoard = newBoard;
461 eventDistributor->distributeEvent(
462 Event::create<MachineLoadedEvent>());
465 activeBoard->activate(
true);
469void Reactor::deleteBoard(Board board)
479 if (board == activeBoard) {
481 switchBoard(
nullptr);
493 activeBoard->exitCPULoopSync();
496 std::lock_guard<std::mutex> lock(mbMutex);
498 activeBoard->exitCPULoopAsync();
505 auto& commandController = *globalCommandController;
509 commandController.source(
526 commandController.executeCommand(cmd);
528 throw FatalError(
"Couldn't execute command: ", cmd,
529 '\n',
e.getMessage());
541 tclCallbackMessages->redoPostponedCallbacks();
552 activeBoard->powerUp();
556 while (doOneIteration()) {
561bool Reactor::doOneIteration()
563 eventDistributor->deliverEvents();
564 bool blocked = (blockedCounter > 0) || !activeBoard;
568 auto copy = activeBoard;
569 blocked = !
copy->execute();
578 eventDistributor->sleep(20 * 1000);
583void Reactor::unpause()
611 assert(blockedCounter >= 0);
619 auto& pauseSetting = getGlobalSettings().getPauseSetting();
620 if (&
setting == &pauseSetting) {
621 if (pauseSetting.getBoolean()) {
630int Reactor::signalEvent(
const Event& event)
633 [&](
const QuitEvent& ) {
637 [&](
const FocusEvent&
e) {
656 [](
const EventBase ) {
668 :
Command(commandController_,
"exit")
669 , distributor(distributor_)
676 switch (tokens.size()) {
689 return "Use this command to stop the emulator.\n"
690 "Optionally you can pass an exit-code.\n";
698 :
Command(commandController_,
"machine")
706 switch (tokens.size()) {
725 return "Switch to a different MSX machine.";
738 :
Command(commandController_,
"test_machine")
751 result =
e.getMessage();
757 return "Test the configuration for the given machine. "
758 "Returns an error message explaining why the configuration is "
759 "invalid or an empty string in case of success.";
772 :
Command(commandController_,
"create_machine")
781 result = newBoard->getMachineID();
782 reactor.boards.push_back(std::move(newBoard));
787 return "Creates a new (empty) MSX machine. Returns the ID for the new "
789 "Use 'load_machine' to actually load a machine configuration "
790 "into this new machine.\n"
791 "The main reason create_machine and load_machine are two "
792 "separate commands is that sometimes you already want to know "
793 "the ID of the machine before load_machine starts emitting "
794 "events for this machine.";
802 :
Command(commandController_,
"delete_machine")
811 reactor.deleteBoard(reactor.getMachine(tokens[1].getString()));
816 return "Deletes the given MSX machine.";
829 :
Command(commandController_,
"list_machines")
842 return "Returns a list of all machine IDs.";
850 :
Command(commandController_,
"activate_machine")
859 switch (tokens.size()) {
863 reactor.switchBoard(reactor.getMachine(tokens[1].getString()));
871 return "Make another machine the active msx machine.\n"
872 "Or when invoked without arguments, query the ID of the "
873 "active msx machine.";
886 :
Command(commandController_,
"store_machine")
895 string_view machineID;
896 switch (tokens.size()) {
902 machineID = tokens[1].getString();
906 machineID = tokens[1].getString();
907 filename = tokens[2].getString();
911 auto& board = *reactor.getMachine(machineID);
922 "store_machine Save state of current machine to file \"openmsxNNNN.xml.gz\"\n"
923 "store_machine machineID Save state of machine \"machineID\" to file \"openmsxNNNN.xml.gz\"\n"
924 "store_machine machineID <filename> Save state of machine \"machineID\" to indicated file\n"
926 "This is a low-level command, the 'savestate' script is easier to use.";
939 :
Command(commandController_,
"restore_machine")
951 switch (tokens.size()) {
959 time_t modTime = st.st_mtime;
960 if (modTime > lastTime) {
965 if (filename.empty()) {
989 newBoard->getStateChangeDistributor().stopReplay(newBoard->getCurrentTime());
991 result = newBoard->getMachineID();
992 reactor.boards.push_back(std::move(newBoard));
997 return "restore_machine Load state from last saved state in default directory\n"
998 "restore_machine <filename> Load state from indicated file\n"
1000 "This is a low-level command, the 'loadstate' script is easier to use.";
1014 :
Command(commandController_,
"get_clipboard_text")
1029 return "Returns the (text) content of the clipboard as a string.";
1037 :
Command(commandController_,
"set_clipboard_text")
1050 return "Send the given string to the clipboard.";
1057 const string& configName_)
1058 :
InfoTopic(openMSXInfoCommand, configName_)
1059 , configName(configName_)
1066 switch (tokens.size()) {
1073 std::array<char, 8192> allocBuffer;
1074 XMLDocument doc{allocBuffer.data(),
sizeof(allocBuffer)};
1076 doc, configName, tokens[2].getString());
1077 if (
const auto* info = doc.getRoot()->findChild(
"info")) {
1078 for (
const auto& c : info->getChildren()) {
1084 "Couldn't get config info: ",
e.getMessage());
1095 return strCat(
"Shows a list of available ", configName,
", "
1096 "or get meta information about the selected item.\n");
1108 :
InfoTopic(openMSXInfoCommand,
"realtime")
1109 , reference(Timer::getTime())
1117 result = narrow_cast<double>(delta) / 1000000.0;
1122 return "Returns the time in seconds since openMSX was started.";
1129 :
InfoTopic(openMSXInfoCommand,
"software")
1135 std::span<const TclObject> tokens,
TclObject& result)
const
1137 if (tokens.size() != 3) {
1141 Sha1Sum sha1sum(tokens[2].getString());
1143 const RomInfo* romInfo = romDatabase.fetchRomInfo(sha1sum);
1147 "Software with sha1sum ", sha1sum.
toString(),
" not found");
1150 const char* bufStart = romDatabase.getBufferStart();
1152 "year", romInfo->
getYear(bufStart),
1164 return "Returns information about the software "
1165 "given its sha1sum, in a paired list.";
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
ActivateMachineCommand(CommandController &commandController, Reactor &reactor)
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
Interpreter & getInterpreter() const final
const auto & getStartupScripts() const
ParseStatus getParseStatus() const
const auto & getStartupCommands() const
static void completeFileName(std::vector< std::string > &tokens, const FileContext &context, const RANGE &extra)
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
void checkNumArgs(std::span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this topic.
string help(std::span< const TclObject > tokens) const override
Print help for this topic.
ConfigInfo(InfoCommand &openMSXInfoCommand, const string &configName)
void execute(std::span< const TclObject > tokens, TclObject &result) const override
Show info on this topic.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
CreateMachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
DeleteMachineCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
VideoSystem & getVideoSystem()
void distributeEvent(Event &&event)
Schedule the given event for delivery.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
ExitCommand(CommandController &commandController, EventDistributor &distributor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
GetClipboardCommand(CommandController &commandController, Reactor &reactor)
void setAllowExternalCommands()
Interpreter & getInterpreter() override
BooleanSetting & getPauseSetting()
static void loadConfig(XMLDocument &doc, std::string_view type, std::string_view name)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
ListMachinesCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
std::string loadMachine(const std::string &machine)
std::string_view getMachineID() const
MachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void mute()
This methods (un)mute the sound.
Contains the main loop of openMSX.
GlobalSettings & getGlobalSettings()
MSXMotherBoard * getMotherBoard() const
std::shared_ptr< MSXMotherBoard > Board
CommandController & getCommandController()
GlobalCommandController & getGlobalCommandController()
InfoCommand & getOpenMSXInfoCommand()
void switchMachine(const std::string &machine)
void run(CommandLineParser &parser)
Main loop.
GlobalCliComm & getGlobalCliComm()
Board createEmptyMotherBoard()
Interpreter & getInterpreter()
void replaceBoard(MSXMotherBoard &oldBoard, Board newBoard)
std::string_view getMachineID() const
static std::vector< std::string > getHwConfigs(std::string_view type)
RomDatabase & getSoftwareDatabase()
RealTimeInfo(InfoCommand &openMSXInfoCommand)
string help(std::span< const TclObject > tokens) const override
Print help for this topic.
void execute(std::span< const TclObject > tokens, TclObject &result) const override
Show info on this topic.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
RestoreMachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
std::string_view getYear(const char *buf) const
unsigned getGenMSXid() const
std::string_view getTitle(const char *buf) const
std::string_view getCompany(const char *buf) const
std::string_view getRemark(const char *buf) const
static std::string_view romTypeToName(RomType type)
std::string_view getCountry(const char *buf) const
RomType getRomType() const
std::string_view getOrigType(const char *buf) const
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
SetClipboardCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
This class represents the result of a sha1 calculation (a 160-bit value).
std::string toString() const
std::string help(std::span< const TclObject > tokens) const override
Print help for this topic.
void execute(std::span< const TclObject > tokens, TclObject &result) const override
Show info on this topic.
SoftwareInfoTopic(InfoCommand &openMSXInfoCommand, Reactor &reactor)
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
StoreMachineCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void detach(Observer< T > &observer)
void attach(Observer< T > &observer)
void addListElements(ITER first, ITER last)
void addDictKeyValue(const Key &key, const Value &value)
void addDictKeyValues(Args &&... args)
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
TestMachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
virtual void setClipboardText(zstring_view text)=0
virtual std::string getClipboardText()=0
ALWAYS_INLINE void serialize(const char *tag, const T &t, Args &&...args)
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
string expandTilde(string path)
Expand the '~' character to the users home directory.
bool isRegularFile(const Stat &st)
const string & getUserOpenMSXDir()
Get the openMSX dir in the user's home directory.
string getNextNumberedFileName(string_view directory, string_view prefix, string_view extension)
Gets the next numbered file name with the specified prefix in the specified directory,...
string join(string_view part1, string_view part2)
Join two paths.
bool isMainThread()
Returns true when called from the main thread.
uint64_t getTime()
Get current (real) time in us.
This file implemented 3 utility functions:
const FileContext & systemFileContext()
auto visit(Visitor &&visitor, const Event &event)
FileContext userFileContext(string_view savePath)
bool foreach_file(std::string path, FileAction fileAction)
const FileContext & preferSystemFileContext()
bool foreach_file_and_directory(std::string path, FileAction fileAction, DirAction dirAction)
auto unique(ForwardRange &&range)
auto copy(InputRange &&range, OutputIter out)
auto find(InputRange &&range, const T &value)
constexpr void sort(RandomAccessRange &&range)
size_t size(std::string_view utf8)
constexpr auto transform(Range &&range, UnaryOp op)
ITER find_unguarded(ITER first, ITER last, const VAL &val, Proj proj={})
Faster alternative to 'find' when it's guaranteed that the value will be found (if not the behavior i...
void move_pop_back(VECTOR &v, typename VECTOR::iterator it)
Erase the pointed to element from the given vector.
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.
std::string strCat(Ts &&...ts)
constexpr auto end(const zstring_view &x)