59using std::make_unique;
61using std::string_view;
74 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
84 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
95 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
105 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
106 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
115 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
116 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
126 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
127 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
136 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
137 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
147 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
148 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
158 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
159 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
169 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
170 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
179 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
180 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
189 void execute(std::span<const TclObject> tokens,
191 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
194 const string configName;
201 void execute(std::span<const TclObject> tokens,
203 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
205 const uint64_t reference;
212 void execute(std::span<const TclObject> tokens,
214 [[nodiscard]] std::string
help(std::span<const TclObject> tokens)
const override;
224 shortcuts = make_unique<Shortcuts>();
225 rtScheduler = make_unique<RTScheduler>();
226 eventDistributor = make_unique<EventDistributor>(*
this);
227 globalCliComm = make_unique<GlobalCliComm>();
228 globalCommandController = make_unique<GlobalCommandController>(
229 *eventDistributor, *globalCliComm, *
this);
230 globalSettings = make_unique<GlobalSettings>(
231 *globalCommandController);
232 inputEventGenerator = make_unique<InputEventGenerator>(
233 *globalCommandController, *eventDistributor, *globalSettings);
234 symbolManager = make_unique<SymbolManager>(
235 *globalCommandController);
236 imGuiManager = make_unique<ImGuiManager>(*
this);
237 diskFactory = make_unique<DiskFactory>(*
this);
238 diskManipulator = make_unique<DiskManipulator>(
239 *globalCommandController, *
this);
240 virtualDrive = make_unique<DiskChanger>(
241 *
this,
"virtual_drive");
242 filePool = make_unique<FilePool>(*globalCommandController, *
this);
243 userSettings = make_unique<UserSettings>(
244 *globalCommandController);
245 afterCommand = make_unique<AfterCommand>(
246 *
this, *eventDistributor, *globalCommandController);
247 exitCommand = make_unique<ExitCommand>(
248 *globalCommandController, *eventDistributor);
249 messageCommand = make_unique<MessageCommand>(
250 *globalCommandController);
251 machineCommand = make_unique<MachineCommand>(
252 *globalCommandController, *
this);
253 testMachineCommand = make_unique<TestMachineCommand>(
254 *globalCommandController, *
this);
255 createMachineCommand = make_unique<CreateMachineCommand>(
256 *globalCommandController, *
this);
257 deleteMachineCommand = make_unique<DeleteMachineCommand>(
258 *globalCommandController, *
this);
259 listMachinesCommand = make_unique<ListMachinesCommand>(
260 *globalCommandController, *
this);
261 activateMachineCommand = make_unique<ActivateMachineCommand>(
262 *globalCommandController, *
this);
263 storeMachineCommand = make_unique<StoreMachineCommand>(
264 *globalCommandController, *
this);
265 restoreMachineCommand = make_unique<RestoreMachineCommand>(
266 *globalCommandController, *
this);
267 getClipboardCommand = make_unique<GetClipboardCommand>(
268 *globalCommandController, *
this);
269 setClipboardCommand = make_unique<SetClipboardCommand>(
270 *globalCommandController, *
this);
271 aviRecordCommand = make_unique<AviRecorder>(*
this);
272 extensionInfo = make_unique<ConfigInfo>(
274 machineInfo = make_unique<ConfigInfo>(
276 realTimeInfo = make_unique<RealTimeInfo>(
278 softwareInfoTopic = make_unique<SoftwareInfoTopic>(
280 tclCallbackMessages = make_unique<TclCallbackMessages>(
281 *globalCliComm, *globalCommandController);
283 createMachineSetting();
297 deleteBoard(activeBoard);
310 mixer = make_unique<Mixer>(*
this, *globalCommandController);
317 if (!softwareDatabase) {
318 softwareDatabase = make_unique<RomDatabase>(*globalCliComm);
320 return *softwareDatabase;
325 return *globalCliComm;
335 return *globalCommandController;
340 return globalCommandController->getOpenMSXInfoCommand();
345 return globalCommandController->getHotKey();
350 vector<string> result;
352 auto fileAction = [&](
const std::string& , std::string_view name) {
353 if (name.ends_with(
".xml")) {
354 name.remove_suffix(4);
355 result.emplace_back(name);
358 auto dirAction = [&](std::string& path, std::string_view name) {
359 auto size = path.size();
360 path +=
"/hardwareconfig.xml";
362 result.emplace_back(name);
381 if (
const auto* keyb = board->getKeyboard()) {
382 return keyb->getMsxChar2Unicode();
389 return defaultMsxChars;
393void Reactor::createMachineSetting()
397 machines.reserve(names.size() + 1);
401 machines.emplace_back(
"C-BIOS_MSX2+", 0);
403 machineSetting = make_unique<EnumSetting<int>>(
404 *globalCommandController,
"default_machine",
405 "default machine (takes effect next time openMSX is started)",
406 0, std::move(machines));
412 return activeBoard.get();
417 return activeBoard ? activeBoard->getMachineID() : string_view{};
423 it != boards.end()) {
431 return std::make_shared<MSXMotherBoard>(*
this);
439 boards.push_back(newBoard);
443 [](
auto& b) {
return b.get(); });
446 if (*it == activeBoard) {
447 switchBoard(newBoard);
457 display = make_unique<Display>(*
this);
461 display->createVideoSystem();
472 newBoard->loadMachine(machine);
473 boards.push_back(newBoard);
475 auto oldBoard = activeBoard;
476 switchBoard(newBoard);
477 deleteBoard(oldBoard);
480void Reactor::switchBoard(Board newBoard)
483 assert(!newBoard ||
contains(boards, newBoard));
484 assert(!activeBoard ||
contains(boards, activeBoard));
486 activeBoard->activate(
false);
492 std::scoped_lock lock(mbMutex);
493 activeBoard = newBoard;
495 eventDistributor->distributeEvent(MachineLoadedEvent());
498 activeBoard->activate(
true);
502void Reactor::deleteBoard(Board board)
512 if (board == activeBoard) {
514 switchBoard(
nullptr);
526 activeBoard->exitCPULoopSync();
529 std::scoped_lock lock(mbMutex);
531 activeBoard->exitCPULoopAsync();
538 auto& commandController = *globalCommandController;
542 commandController.source(
559 commandController.executeCommand(cmd);
561 throw FatalError(
"Couldn't execute command: ", cmd,
562 '\n', e.getMessage());
574 tclCallbackMessages->redoPostponedCallbacks();
586 activeBoard->powerUp();
593 eventDistributor->deliverEvents();
594 bool blocked = (blockedCounter > 0) || !activeBoard;
598 auto copy = activeBoard;
599 blocked = !copy->execute();
608 eventDistributor->sleep(20 * 1000);
613void Reactor::unpause()
641 assert(blockedCounter >= 0);
649 const auto& pauseSetting = getGlobalSettings().getPauseSetting();
650 if (&
setting == &pauseSetting) {
651 if (pauseSetting.getBoolean()) {
660bool Reactor::signalEvent(
const Event& event)
663 [&](
const QuitEvent& ) {
667 [&](
const WindowEvent&
e) {
670 if (
e.isMainWindow()) {
680 if (
e.getSdlWindowEvent().type == SDL_WINDOWEVENT_FOCUS_GAINED) {
682 }
else if (
e.getSdlWindowEvent().type == SDL_WINDOWEVENT_FOCUS_LOST) {
688 [](
const EventBase ) {
700 :
Command(commandController_,
"exit")
701 , distributor(distributor_)
708 switch (tokens.size()) {
721 return "Use this command to stop the emulator.\n"
722 "Optionally you can pass an exit-code.\n";
730 :
Command(commandController_,
"machine")
738 switch (tokens.size()) {
757 return "Switch to a different MSX machine.";
770 :
Command(commandController_,
"test_machine")
783 result = e.getMessage();
789 return "Test the configuration for the given machine. "
790 "Returns an error message explaining why the configuration is "
791 "invalid or an empty string in case of success.";
804 :
Command(commandController_,
"create_machine")
813 result = newBoard->getMachineID();
814 reactor.boards.push_back(std::move(newBoard));
819 return "Creates a new (empty) MSX machine. Returns the ID for the new "
821 "Use 'load_machine' to actually load a machine configuration "
822 "into this new machine.\n"
823 "The main reason create_machine and load_machine are two "
824 "separate commands is that sometimes you already want to know "
825 "the ID of the machine before load_machine starts emitting "
826 "events for this machine.";
834 :
Command(commandController_,
"delete_machine")
843 reactor.deleteBoard(reactor.
getMachine(tokens[1].getString()));
848 return "Deletes the given MSX machine.";
861 :
Command(commandController_,
"list_machines")
874 return "Returns a list of all machine IDs.";
882 :
Command(commandController_,
"activate_machine")
891 switch (tokens.size()) {
895 reactor.switchBoard(reactor.
getMachine(tokens[1].getString()));
903 return "Make another machine the active msx machine.\n"
904 "Or when invoked without arguments, query the ID of the "
905 "active msx machine.";
918 :
Command(commandController_,
"store_machine")
926 const auto& machineID = tokens[1].getString();
927 const auto& filename = tokens[2].getString();
929 const auto& board = *reactor.
getMachine(machineID);
940 "store_machine machineID <filename> Save state of machine \"machineID\" to indicated file\n"
942 "This is a low-level command, the 'savestate' script is easier to use.";
955 :
Command(commandController_,
"restore_machine")
981 newBoard->getStateChangeDistributor().stopReplay(newBoard->getCurrentTime());
983 result = newBoard->getMachineID();
984 reactor.boards.push_back(std::move(newBoard));
989 return "restore_machine Load state from last saved state in default directory\n"
990 "restore_machine <filename> Load state from indicated file\n"
992 "This is a low-level command, the 'loadstate' script is easier to use.";
1005 :
Command(commandController_,
"get_clipboard_text")
1020 return "Returns the (text) content of the clipboard as a string.";
1028 :
Command(commandController_,
"set_clipboard_text")
1041 return "Send the given string to the clipboard.";
1048 const string& configName_)
1049 :
InfoTopic(openMSXInfoCommand, configName_)
1050 , configName(configName_)
1057 switch (tokens.size()) {
1064 std::array<char, 8192> allocBuffer;
1065 XMLDocument doc{allocBuffer.data(),
sizeof(allocBuffer)};
1067 doc, configName, tokens[2].getString());
1068 if (
const auto* info = doc.getRoot()->findChild(
"info")) {
1069 for (
const auto& c : info->getChildren()) {
1075 "Couldn't get config info: ", e.getMessage());
1086 return strCat(
"Shows a list of available ", configName,
", "
1087 "or get meta information about the selected item.\n");
1099 :
InfoTopic(openMSXInfoCommand,
"realtime")
1100 , reference(Timer::getTime())
1108 result = narrow_cast<double>(delta) * (1.0 / 1000000.0);
1113 return "Returns the time in seconds since openMSX was started.";
1120 :
InfoTopic(openMSXInfoCommand,
"software")
1126 std::span<const TclObject> tokens,
TclObject& result)
const
1128 if (tokens.size() != 3) {
1132 Sha1Sum sha1sum(tokens[2].getString());
1134 const RomInfo* romInfo = romDatabase.fetchRomInfo(sha1sum);
1138 "Software with sha1sum ", sha1sum.
toString(),
" not found");
1141 const char* bufStart = romDatabase.getBufferStart();
1143 "year", romInfo->
getYear(bufStart),
1155 return "Returns information about the software "
1156 "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
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 command.
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.
std::span< const std::string > getPaths() const
std::string resolve(std::string_view filename) const
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)
GlobalCliComm & getGlobalCliComm()
Board createEmptyMotherBoard()
Interpreter & getInterpreter()
const HotKey & getHotKey() const
void replaceBoard(MSXMotherBoard &oldBoard, Board newBoard)
std::string_view getMachineID() const
const MsxChar2Unicode & getMsxChar2Unicode() const
static std::vector< std::string > getHwConfigs(std::string_view type)
void runStartupScripts(const CommandLineParser &parser)
RomDatabase & getSoftwareDatabase()
Board getMachine(std::string_view machineID) const
auto getMachineIDs() const
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
static zstring_view romTypeToName(RomType type)
std::string_view getCompany(const char *buf) const
std::string_view getRemark(const char *buf) const
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)
string expandTilde(string path)
Expand the '~' character to the users home directory.
bool isRegularFile(const Stat &st)
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()
const FileContext & userFileContext()
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
const FileContext & preferSystemFileContext()
bool foreach_file_and_directory(std::string path, FileAction fileAction, DirAction dirAction)
auto unique(ForwardRange &&range)
auto find(InputRange &&range, const T &value)
constexpr void sort(RandomAccessRange &&range)
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.
constexpr auto end(const zstring_view &x)